private ExplicitIndexTransactionStateImpl newExplicitIndexTxState() { indexConfigStore = mock( IndexConfigStore.class ); when( indexConfigStore.get( eq( Node.class ), anyString() ) ).thenReturn( config ); when( indexConfigStore.get( eq( Relationship.class ), anyString() ) ).thenReturn( config ); ExplicitIndexProvider explicitIndexProvider = mock( ExplicitIndexProvider.class ); when( explicitIndexProvider.getProviderByName( anyString() ) ).thenReturn( provider ); return new ExplicitIndexTransactionStateImpl( indexConfigStore, explicitIndexProvider ); } }
@Test public void shouldSwallowAnyExceptionsThrownByTheRequest() throws IOException, ServletException { HttpServletRequest request = mock( HttpServletRequest.class ); when(request.getHeader( anyString() )).thenThrow( new RuntimeException() ); filter.doFilter( request, null, filterChain ); }
private static TransactionStateMachineV1SPI newTransactionStateMachineSPI( KernelTransaction transaction ) throws KernelException { BoltResultHandle resultHandle = newResultHandle(); TransactionStateMachineV1SPI stateMachineSPI = mock( TransactionStateMachineV1SPI.class ); when( stateMachineSPI.beginTransaction( any(), any(), any() ) ).thenReturn( transaction ); when( stateMachineSPI.executeQuery( any(), anyString(), any(), any(), any() ) ).thenReturn( resultHandle ); return stateMachineSPI; }
@Test public void shouldAttachNoRequestHeadersToAccessControlAllowHeadersWhenHeaderIsEmpty() throws Exception { filter.doFilter( emptyRequest, response, chain ); verify( response, never() ).addHeader( eq( ACCESS_CONTROL_ALLOW_HEADERS ), anyString() ); }
@Test public void shouldAttachNoHttpMethodsToAccessControlAllowMethodsWhenHeaderIsEmpty() throws Exception { filter.doFilter( emptyRequest, response, chain ); verify( response, never() ).addHeader( eq( ACCESS_CONTROL_ALLOW_METHODS ), anyString() ); }
private static <T extends PropertyContainer> T mockPropertyContainer( Class<T> type, Properties properties ) { T container = mock( type ); when( container.getProperty( anyString() ) ).thenAnswer( properties ); when( container.getProperty( anyString(), any() ) ).thenAnswer( properties ); when( container.getPropertyKeys() ).thenReturn( properties ); when( container.getAllProperties() ).thenReturn( properties.getProperties() ); return container; } }
@Test public void shouldAttachNoRequestHeadersToAccessControlAllowHeadersWhenHeaderIsNull() throws Exception { HttpServletRequest request = requestMock(); when( request.getHeaders( ACCESS_CONTROL_REQUEST_HEADERS ) ).thenReturn( null ); filter.doFilter( request, response, chain ); verify( response, never() ).addHeader( eq( ACCESS_CONTROL_ALLOW_HEADERS ), anyString() ); }
@Test public void shouldAttachNoHttpMethodsToAccessControlAllowMethodsWhenHeaderIsNull() throws Exception { HttpServletRequest request = requestMock(); when( request.getHeaders( ACCESS_CONTROL_REQUEST_METHOD ) ).thenReturn( null ); filter.doFilter( request, response, chain ); verify( response, never() ).addHeader( eq( ACCESS_CONTROL_ALLOW_METHODS ), anyString() ); }
@Test public void shouldErrorWithNoSuchUser() { tool.execute( homeDir.toPath(), confDir.toPath(), SET_ADMIN, "bob" ); verify( out ).stdErrLine( "command failed: no such user: 'bob'" ); verify( out ).exit( 1 ); verify( out, never() ).stdOutLine( anyString() ); }
@Test public void shouldNotInvokeConsumerWhenEmpty() { DiscoverableURIs empty = new DiscoverableURIs.Builder().build(); empty.forEach( consumer ); verify( consumer, never() ).accept( anyString(), any() ); }
@Test public void shouldLookUpTheIndexByIndexName() throws ProcedureException, IndexNotFoundKernelException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( descriptor.getLabelId() ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( descriptor.getPropertyId() ); when( schemaRead.indexGetForName( "my index" ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( ONLINE ); procedure.awaitIndexByName( "`my index`", TIMEOUT, TIME_UNIT ); verify( schemaRead ).indexGetForName( "my index" ); }
@Test public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws ProcedureException, SchemaRuleNotFoundException { IndexDescriptor index = TestIndexDescriptorFactory.forLabel( 0, 0 ); when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 123 ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( 456 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( index ); procedure.resampleIndex( ":Person(name)" ); verify( schemaRead ).index( 123, 456 ); }
@Test public void shouldLookUpTheCompositeIndexByLabelIdAndPropertyKeyId() throws ProcedureException, SchemaRuleNotFoundException { IndexDescriptor index = TestIndexDescriptorFactory.forLabel( 0, 0, 1 ); when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 123 ); when( tokenRead.propertyKey( "name" ) ).thenReturn( 0 ); when( tokenRead.propertyKey( "lastName" ) ).thenReturn( 1 ); when( schemaRead.index( 123, 0, 1 ) ).thenReturn( index ); procedure.resampleIndex( ":Person(name, lastName)" ); verify( schemaRead ).index( 123, 0, 1 ); }
@Test public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws ProcedureException, IndexNotFoundKernelException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( descriptor.getLabelId() ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( descriptor.getPropertyId() ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( ONLINE ); procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); verify( schemaRead ).index( descriptor.getLabelId(), descriptor.getPropertyId() ); }
@Test public void testNextTupleEmitsAtMostOneTuple() { //The spout should emit at most one message per call to nextTuple //This is necessary for Storm to be able to throttle the spout according to maxSpoutPending KafkaSpout<String, String> spout = SpoutWithMockedConsumerSetupHelper.setupSpout(spoutConfig, conf, contextMock, collectorMock, consumerMock, partition); Map<TopicPartition, List<ConsumerRecord<String, String>>> records = new HashMap<>(); records.put(partition, SpoutWithMockedConsumerSetupHelper.createRecords(partition, 0, 10)); when(consumerMock.poll(anyLong())) .thenReturn(new ConsumerRecords<>(records)); spout.nextTuple(); verify(collectorMock, times(1)).emit(anyString(), anyList(), any(KafkaSpoutMessageId.class)); }
@Test public void mustNotHaveLogsFilesToPruneIfStrategyFindsNoFiles() { when( factory.strategyFromConfigValue( eq( fs ), eq( logFiles ), eq( clock ), anyString() ) ) .thenReturn( x -> LongStream.empty() ); LogPruning pruning = new LogPruningImpl( fs, logFiles, logProvider, factory, clock, config ); assertFalse( pruning.mightHaveLogsToPrune() ); } }
@Test public void shouldReportIndexDoesNotExist() { // given ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); when( indexConfigStore.get( any( Class.class ), anyString() ) ).thenReturn( null ); // when boolean exists = state.checkIndexExistence( IndexEntityType.Relationship, "name", null ); // then assertFalse( exists ); }
@Test public void testFailByNonExistingPopulation() throws FlipFailedKernelException { IndexPopulation nonExistingPopulation = mock( IndexPopulation.class ); IndexPopulator populator = createIndexPopulator(); addPopulator( populator, 1 ); multipleIndexPopulator.fail( nonExistingPopulation, getPopulatorException() ); verify( populator, never() ).markAsFailed( anyString() ); }
@Test public void testFailByPopulation() throws FlipFailedKernelException { IndexPopulator populator1 = createIndexPopulator(); IndexPopulator populator2 = createIndexPopulator(); addPopulator( populator1, 1 ); IndexPopulation population2 = addPopulator( populator2, 2 ); multipleIndexPopulator.fail( population2, getPopulatorException() ); verify( populator1, never() ).markAsFailed( anyString() ); checkPopulatorFailure( populator2 ); }
@Test public void testOnePortAndSearchArchivedIsTrueAndFileOffsetIs1AndByteOffsetIs100() throws IOException { LogviewerLogSearchHandler handler = getStubbedSearchHandler(); handler.deepSearchLogsForTopology("", null, "search", "20", "6700", "1", "100", true, null, null); verify(handler, times(1)).findNMatches(anyList(), anyInt(), anyInt(), anyInt(), anyString()); verify(handler, times(2)).logsForPort(isNull(), any(File.class)); }