@Test public void withMissingPropertySource() { thrown.expect(BeanDefinitionStoreException.class); thrown.expectCause(isA(FileNotFoundException.class)); new AnnotationConfigApplicationContext(ConfigWithMissingPropertySource.class); }
@Test public void testIndexTaskTuningConfigTargetPartitionSizeAndNumShards() throws Exception { thrown.expectCause(CoreMatchers.isA(IllegalArgumentException.class)); jsonMapper.readValue( "{\"type\":\"index\", \"targetPartitionSize\":10, \"numShards\":10}", IndexTask.IndexTuningConfig.class ); }
private void expectContainerMissingValueAttribute() { exception.expect(AnnotationConfigurationException.class); exception.expectMessage(startsWith("Invalid declaration of container type")); exception.expectMessage(containsString(ContainerMissingValueAttribute.class.getName())); exception.expectMessage(containsString("for repeatable annotation")); exception.expectMessage(containsString(InvalidRepeatable.class.getName())); exception.expectCause(isA(NoSuchMethodException.class)); }
@Test public void testCheckpointingCustomKvStateJobWithCustomClassLoader() throws IOException, ProgramInvocationException { File checkpointDir = FOLDER.newFolder(); File outputDir = FOLDER.newFolder(); final PackagedProgram program = new PackagedProgram( new File(CHECKPOINTING_CUSTOM_KV_STATE_JAR_PATH), new String[] { checkpointDir.toURI().toString(), outputDir.toURI().toString() }); TestStreamEnvironment.setAsContext( miniClusterResource.getMiniCluster(), parallelism, Collections.singleton(new Path(CHECKPOINTING_CUSTOM_KV_STATE_JAR_PATH)), Collections.<URL>emptyList()); expectedException.expectCause( Matchers.<Throwable>hasProperty("cause", isA(SuccessException.class))); program.invokeInteractiveModeForExecution(); }
@Test public void testMountedComponent() throws Throwable { assertThat( mView, is(componentHost(withLifecycle(isA(Text.class))))); } }
@Test public void testFlowFileDefaultException() { runner.setProperty(DebugFlow.FF_EXCEPTION_ITERATIONS, "1"); runner.assertValid(); runner.enqueue(contents.get(0).getBytes(), attribs.get(0)); exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow")); exception.expectCause(CoreMatchers.isA(RuntimeException.class)); runner.run(2); }
/** * tests a happy-day flow of the <code>/userinfo</code> endpoint */ @Test public void testHappyDay() throws Exception { ResponseEntity<String> user = serverRunning.getForString("/userinfo"); assertEquals(HttpStatus.OK, user.getStatusCode()); String infoResponseString = user.getBody(); assertThat(infoResponseString, hasJsonPath("user_id")); assertThat(infoResponseString, hasJsonPath("sub")); assertThat(infoResponseString, hasJsonPath("email", is(testAccounts.getEmail()))); assertThat(infoResponseString, hasJsonPath("email_verified", isA(Boolean.class))); } }
@Test public void testFlowFileExceptionRollover() { runner.setProperty(DebugFlow.FF_EXCEPTION_ITERATIONS, "2"); runner.assertValid(); for (int n = 0; n < 6; n++) { runner.enqueue(contents.get(n).getBytes(), attribs.get(n)); } exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow")); exception.expectCause(CoreMatchers.isA(RuntimeException.class)); runner.run(8); }
@Test public void test() { AddJobMessage aj1 = factory.obtain(AddJobMessage.class); assertThat(aj1, isA(AddJobMessage.class)); CommandMessage cm1 = factory.obtain(CommandMessage.class); assertThat(cm1, isA(CommandMessage.class)); assertThat(factory.obtain(AddJobMessage.class), not(sameInstance(aj1))); assertThat(factory.obtain(CommandMessage.class), not(sameInstance(cm1))); factory.release(aj1); factory.release(cm1); assertThat(factory.obtain(AddJobMessage.class), sameInstance(aj1)); assertThat(factory.obtain(CommandMessage.class), sameInstance(cm1)); assertThat(factory.obtain(AddJobMessage.class), not(sameInstance(aj1))); assertThat(factory.obtain(CommandMessage.class), not(sameInstance(cm1))); } }
@Test @Title( "Retrieve query metadata" ) @Documented( "By passing in an additional GET parameter when you execute Cypher queries, metadata about the " + "query will be returned, such as how many labels were added or removed by the query." ) @Graph( nodes = {@NODE( name = "I", setNameProperty = true, labels = {@LABEL( "Director" )} )} ) public void testQueryStatistics() throws JsonParseException { // Given String script = createScript( "MATCH (n {name: 'I'}) SET n:Actor REMOVE n:Director RETURN labels(n)" ); // When Map<String,Object> output = jsonToMap( doCypherRestCall( cypherUri() + "?includeStats=true", script, Status.OK ) ); // Then @SuppressWarnings( "unchecked" ) Map<String,Object> stats = (Map<String,Object>) output.get( "stats" ); assertThat( stats, isA( Map.class ) ); assertThat( stats.get( "contains_updates" ), is( true ) ); assertThat( stats.get( "labels_added" ), is( 1 ) ); assertThat( stats.get( "labels_removed" ), is( 1 ) ); assertThat( stats.get( "nodes_created" ), is( 0 ) ); assertThat( stats.get( "nodes_deleted" ), is( 0 ) ); assertThat( stats.get( "properties_set" ), is( 0 ) ); assertThat( stats.get( "relationships_created" ), is( 0 ) ); assertThat( stats.get( "relationship_deleted" ), is( 0 ) ); }
@Test public void testFlowFileNPEException() { runner.setProperty(DebugFlow.FF_EXCEPTION_ITERATIONS, "1"); runner.setProperty(DebugFlow.FF_EXCEPTION_CLASS, "java.lang.NullPointerException"); runner.assertValid(); runner.enqueue(contents.get(0).getBytes(), attribs.get(0)); exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow")); exception.expectCause(CoreMatchers.isA(NullPointerException.class)); runner.run(2); }
@Test public void testFlowFileNonDefaultException() { runner.setProperty(DebugFlow.FF_EXCEPTION_ITERATIONS, "1"); runner.setProperty(DebugFlow.FF_EXCEPTION_CLASS, "java.lang.RuntimeException"); runner.assertValid(); runner.enqueue(contents.get(0).getBytes(), attribs.get(0)); exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow")); exception.expectCause(CoreMatchers.isA(RuntimeException.class)); runner.run(2); }
@Test public void receiveAndConvertFailed() { Message<?> expected = new GenericMessage<>("not a number test"); this.template.setReceiveMessage(expected); this.template.setMessageConverter(new GenericMessageConverter()); thrown.expect(MessageConversionException.class); thrown.expectCause(isA(ConversionFailedException.class)); this.template.receiveAndConvert("somewhere", Integer.class); }
@Test public void testGetParameterizedClassInheritance() throws Exception { // Work before fix... assertThat(ReflectionUtils.getParameterizedClass(Set.class), isA(Object.class)); assertThat(ReflectionUtils.getParameterizedClass(Book.class.getDeclaredField("authorsSet")), is(exactClass(Author.class))); // Works now... assertThat(ReflectionUtils.getParameterizedClass(Book.class.getDeclaredField("authors")), is(exactClass(Author.class))); assertThat(ReflectionUtils.getParameterizedClass(Authors.class), is(exactClass(Author.class))); assertThat(ReflectionUtils.getParameterizedClass(WritingTeam.class), is(is(exactClass(Author.class)))); }
@Test public void testNoFlowFileDefaultException() { runner.setProperty(DebugFlow.NO_FF_EXCEPTION_ITERATIONS, "1"); runner.assertValid(); exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow")); exception.expectCause(CoreMatchers.isA(RuntimeException.class)); runner.run(3); }
@Test public void testNoFlowFileNonDefaultException() { runner.setProperty(DebugFlow.NO_FF_EXCEPTION_ITERATIONS, "1"); runner.setProperty(DebugFlow.NO_FF_EXCEPTION_CLASS, "java.lang.RuntimeException"); runner.assertValid(); exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow")); exception.expectCause(CoreMatchers.isA(RuntimeException.class)); runner.run(3); }
@Test public void testNoFlowFileOtherException() { runner.setProperty(DebugFlow.NO_FF_EXCEPTION_ITERATIONS, "1"); runner.setProperty(DebugFlow.NO_FF_EXCEPTION_CLASS, "java.lang.NullPointerException"); runner.assertValid(); exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow")); exception.expectCause(CoreMatchers.isA(NullPointerException.class)); runner.run(3); }
@Test public void testOverrideLoggerWithCustomOne() throws Exception { // given MorphiaLoggerFactory.reset(); MorphiaLoggerFactory.registerLogger(TestLoggerFactory.class); // when final Logger logger = MorphiaLoggerFactory.get(Object.class); // then assertThat((TestLogger) logger, isA(TestLogger.class)); }
@Test public void shouldReportFailureWhenAllThreadsInThreadPoolAreBusy() throws Throwable { // it's enough to get the bolt state machine into streaming mode to have // the thread sticked to the connection, causing all the available threads // to be busy (logically) connection1 = enterStreaming(); connection2 = enterStreaming(); try { connection3 = connectAndPerformBoltHandshake( newConnection() ); connection3.send( util.chunk( new InitMessage( "TestClient/1.1", emptyMap() ) ) ); assertThat( connection3, util.eventuallyReceives( msgFailure( Status.Request.NoThreadsAvailable, "There are no available threads to serve this request at the moment" ) ) ); userLogProvider.assertContainsMessageContaining( "since there are no available threads to serve it at the moment. You can retry at a later time" ); internalLogProvider.assertAtLeastOnce( AssertableLogProvider .inLog( startsWith( BoltConnection.class.getPackage().getName() ) ) .error( containsString( "since there are no available threads to serve it at the moment. You can retry at a later time" ), isA( RejectedExecutionException.class ) ) ); } finally { exitStreaming( connection1 ); exitStreaming( connection2 ); } }
@Test public void testSimpleInjection() throws Exception { //GIVEN Scope scope = new ScopeImpl(""); Foo foo = new Foo(); //WHEN Toothpick.inject(foo, scope); //THEN assertThat(foo.bar, notNullValue()); assertThat(foo.bar, isA(Bar.class)); }