@Test public void collections_in_collections_look_alright() { Result result = db.execute( "CREATE (n:TheNode) RETURN [[ [1,2],[3,4] ],[[5,6]]] as x" ); Map<String, Object> next = result.next(); @SuppressWarnings( "unchecked" ) //We know it's a collection. List<List<Object>> x = (List<List<Object>>)next.get( "x" ); Iterable objects = x.get( 0 ); assertThat(objects, isA(Iterable.class)); } }
public void check() { test(); assertThat(e, notNullValue()); assertThat(e, isA(MyException.class)); assertThat(e.getMessage(), nullValue()); } }
@Test public void decodeFromBinaryCannotConvert() throws Exception { setup(NoConvertersConfig.class); Decoder.Binary<MyType> decoder = new MyBinaryDecoder(); assertThat(decoder.willDecode(CONVERTED_BYTES), is(false)); thown.expect(DecodeException.class); thown.expectCause(isA(ConverterNotFoundException.class)); decoder.decode(CONVERTED_BYTES); }
@Test public void decodeFromTextCannotConvert() throws Exception { setup(NoConvertersConfig.class); Decoder.Text<MyType> decoder = new MyTextDecoder(); assertThat(decoder.willDecode(CONVERTED_TEXT), is(false)); thown.expect(DecodeException.class); thown.expectCause(isA(ConverterNotFoundException.class)); decoder.decode(CONVERTED_TEXT); }
@Test public void fromMessageWithFailedConversion() { Message<String> content = MessageBuilder.withPayload("test not a number").build(); thrown.expect(MessageConversionException.class); thrown.expectCause(isA(ConversionException.class)); converter.fromMessage(content, Integer.class); } }
@Test public void encodeToTextCannotConvert() throws Exception { setup(NoConvertersConfig.class); thown.expect(EncodeException.class); thown.expectCause(isA(ConverterNotFoundException.class)); new MyTextEncoder().encode(myType); }
@Test public void encodeToBinaryCannotConvert() throws Exception { setup(NoConvertersConfig.class); thown.expect(EncodeException.class); thown.expectCause(isA(ConverterNotFoundException.class)); new MyBinaryEncoder().encode(myType); }
@Test public void invalidPayloadType() throws JMSException { MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class); Session session = mock(Session.class); this.thrown.expect(ListenerExecutionFailedException.class); this.thrown.expectCause(Matchers.isA(MessageConversionException.class)); this.thrown.expectMessage(getDefaultListenerMethod(Integer.class).toGenericString()); // ref to method listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is not a valid integer }
@Test public void shouldFailECDSA512VerificationWhenProvidedPublicKeyIsNull() throws Exception { exception.expect(SignatureVerificationException.class); exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA512withECDSA"); exception.expectCause(isA(IllegalStateException.class)); exception.expectCause(hasMessage(is("The given Public Key is null."))); ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class); when(provider.getPublicKeyById("my-key-id")).thenReturn(null); String jwt = "eyJhbGciOiJFUzUxMiIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.AGxEwbsYa2bQ7Y7DAcTQnVD8PmLSlhJ20jg2OfdyPnqdXI8SgBaG6lGciq3_pofFhs1HEoFoJ33Jcluha24oMHIvAfwu8qbv_Wq3L2eI9Q0L0p6ul8Pd_BS8adRa2PgLc36xXGcRc7ID5YH-CYaQfsTp5YIaF0Po3h0QyCoQ6ZiYQkqm"; Algorithm algorithm = Algorithm.ECDSA512(provider); algorithm.verify(JWT.decode(jwt)); }
@Test public void emptySendTo() throws JMSException { MessagingMessageListenerAdapter listener = createDefaultInstance(String.class); TextMessage reply = mock(TextMessage.class); Session session = mock(Session.class); given(session.createTextMessage("content")).willReturn(reply); this.thrown.expect(ReplyFailureException.class); this.thrown.expectCause(Matchers.isA(InvalidDestinationException.class)); listener.onMessage(createSimpleJmsTextMessage("content"), session); }
@Test public void invalidMessagePayloadType() throws JMSException { MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class); Session session = mock(Session.class); this.thrown.expect(ListenerExecutionFailedException.class); this.thrown.expectCause(Matchers.isA(MessageConversionException.class)); listener.onMessage(createSimpleJmsTextMessage("test"), session); // Message<String> as Message<Integer> }
@Test public void testCollectionFieldsDefault() throws Exception { TestBean target = new TestBean(); target.setSomeSet(null); target.setSomeList(null); target.setSomeMap(null); WebRequestDataBinder binder = new WebRequestDataBinder(target); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("_someSet", "visible"); request.addParameter("_someList", "visible"); request.addParameter("_someMap", "visible"); binder.bind(new ServletWebRequest(request)); assertThat(target.getSomeSet(), notNullValue()); assertThat(target.getSomeSet(), isA(Set.class)); assertThat(target.getSomeList(), notNullValue()); assertThat(target.getSomeList(), isA(List.class)); assertThat(target.getSomeMap(), notNullValue()); assertThat(target.getSomeMap(), isA(Map.class)); }
@Test public void processNextBatchShouldThrowAssertionErrorIfStatementOpen() throws Exception { BoltConnection connection = newConnection( 1 ); connection.enqueue( Jobs.noop() ); connection.enqueue( Jobs.noop() ); // force to a message waiting loop when( stateMachine.hasOpenStatement() ).thenReturn( true ); connection.processNextBatch(); logProvider.assertExactly( AssertableLogProvider.inLog( DefaultBoltConnection.class.getName() ).error( startsWith( "Unexpected error" ), isA( AssertionError.class ) ) ); }
@Test public void processNextBatchShouldNotThrowAssertionErrorIfStatementOpenButStopping() throws Exception { BoltConnection connection = newConnection( 1 ); connection.enqueue( Jobs.noop() ); connection.enqueue( Jobs.noop() ); // force to a message waiting loop when( stateMachine.hasOpenStatement() ).thenReturn( true ); connection.stop(); connection.processNextBatch(); logProvider.assertNone( AssertableLogProvider.inLog( DefaultBoltConnection.class.getName() ).error( startsWith( "Unexpected error" ), isA( AssertionError.class ) ) ); }
@Test public void shouldNotResolveOptedOutConfigSubtags() throws NoSuchFieldException { PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("cruise", "dev", "ant"); pipelineConfig.setLabelTemplate("2.1-${COUNT}-#{foo}-bar-#{bar}"); pipelineConfig.addParam(param("#{foo}-name", "#{foo}-#{bar}-baz")); new ParamResolver(new ParamSubstitutionHandlerFactory(params(param("foo", "pavan"), param("bar", "jj"))), fieldCache).resolve(pipelineConfig); assertThat(pipelineConfig.getLabelTemplate(), is("2.1-${COUNT}-pavan-bar-jj")); assertThat(pipelineConfig.getParams().get(0), is(param("#{foo}-name", "#{foo}-#{bar}-baz"))); assertThat(pipelineConfig.getClass().getDeclaredField("params").getAnnotation(SkipParameterResolution.class), isA(SkipParameterResolution.class)); }
@Test public void shouldNotResolveOptedOutConfigAttributes() throws NoSuchFieldException { PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("cruise-#{foo}-#{bar}", "dev", "ant"); SvnMaterialConfig svn = (SvnMaterialConfig) pipelineConfig.materialConfigs().get(0); svn.setPassword("#quux-#{foo}-#{bar}"); pipelineConfig.setLabelTemplate("2.1-${COUNT}-#{foo}-bar-#{bar}"); new ParamResolver(new ParamSubstitutionHandlerFactory(params(param("foo", "pavan"), param("bar", "jj"))), fieldCache).resolve(pipelineConfig); assertThat(pipelineConfig.getLabelTemplate(), is("2.1-${COUNT}-pavan-bar-jj")); assertThat(pipelineConfig.name(), is(new CaseInsensitiveString("cruise-#{foo}-#{bar}"))); assertThat(((SvnMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPassword(), is("#quux-#{foo}-#{bar}")); assertThat(pipelineConfig.getClass().getDeclaredField("name").getAnnotation(SkipParameterResolution.class), isA(SkipParameterResolution.class)); }
@Test public void shouldThrowOnECDSA256VerificationWithDERSignature() throws Exception { exception.expect(SignatureVerificationException.class); exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA256withECDSA"); exception.expectCause(isA(SignatureException.class)); exception.expectCause(hasMessage(is("Invalid JOSE signature format."))); String jwt = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.MEYCIQDiJWTf5jS/hFPj/0hpCWn7x1n/h+xPMjKWCs9MMusS9AIhAMcFPJVLe2A9uvb8hl8sRO2IpGoKDRpDmyH14ixNPAHW"; ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC"); Algorithm algorithm = Algorithm.ECDSA256(key); algorithm.verify(JWT.decode(jwt)); }
@Test public void shouldThrowOnECDSA384VerificationWithDERSignature() throws Exception { exception.expect(SignatureVerificationException.class); exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA384withECDSA"); exception.expectCause(isA(SignatureException.class)); exception.expectCause(hasMessage(is("Invalid JOSE signature format."))); String jwt = "eyJhbGciOiJFUzM4NCJ9.eyJpc3MiOiJhdXRoMCJ9.MGUCMQDnRRTlUo10XXB/KRjyNAEqm+4dmh7ohkEmbk2+gHxtH6GdGDq2L4Idua+hG2Ut+ccCMH8CE2v/HCTMuk3pzAtoOtxkB8rXPK2KF6m8LUuEdCqPwF2yxVJn8ZxpzAur+DEv8w=="; ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC"); Algorithm algorithm = Algorithm.ECDSA384(key); algorithm.verify(JWT.decode(jwt)); }
@Test public void shouldFailECDSA256VerificationWhenUsingPrivateKey() throws Exception { exception.expect(SignatureVerificationException.class); exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA256withECDSA"); exception.expectCause(isA(IllegalStateException.class)); exception.expectCause(hasMessage(is("The given Public Key is null."))); String jwt = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.W9qfN1b80B9hnMo49WL8THrOsf1vEjOhapeFemPMGySzxTcgfyudS5esgeBTO908X5SLdAr5jMwPUPBs9b6nNg"; Algorithm algorithm = Algorithm.ECDSA256((ECKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_256, "EC")); algorithm.verify(JWT.decode(jwt)); }
@Test public void shouldDelegateToTheGivenServlet() throws IOException, ServletException { MockServletContext ctx = new MockServletContext(); ctx.addInitParameter(DelegatingListener.DELEGATE_SERVLET, DummyServlet.class.getCanonicalName()); ServletContextEvent evt = new ServletContextEvent(ctx); DelegatingListener listener = new DelegatingListener(); listener.contextInitialized(evt); assertThat((DummyServlet) ctx.getAttribute(DelegatingListener.DELEGATE_SERVLET), isA(DummyServlet.class)); DelegatingServlet servlet = new DelegatingServlet(); servlet.init(new MockServletConfig(ctx)); servlet.service(httpServletRequest, new MockHttpServletResponse()); verify(servletRequestWrapper).setRequestURI("/go/stuff/action"); } }