@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 testCancelPopulation() throws FlipFailedKernelException { IndexPopulator indexPopulator1 = createIndexPopulator(); IndexPopulator indexPopulator2 = createIndexPopulator(); addPopulator( indexPopulator1, 1 ); addPopulator( indexPopulator2, 2 ); multipleIndexPopulator.cancel(); verify( indexStoreView, times( 2 ) ).replaceIndexCounts( anyLong(), eq( 0L ), eq( 0L ), eq( 0L ) ); verify( indexPopulator1 ).close( false ); verify( indexPopulator2 ).close( false ); }
@Before public void setUpMocks() throws IOException { when( idGeneratorFactory.open( any( File.class ), eq( idType ), any( LongSupplier.class ), anyLong() ) ) .thenReturn( idGenerator ); when( pageFile.pageSize() ).thenReturn( PAGE_SIZE ); when( pageFile.io( anyLong(), anyInt() ) ).thenReturn( pageCursor ); when( pageCache.map( eq( storeFile ), anyInt() ) ).thenReturn( pageFile ); }
@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 doNotBlockIfPollConditionIsSatisfied() { NetworkClient mockNetworkClient = mock(NetworkClient.class); ConsumerNetworkClient consumerClient = new ConsumerNetworkClient(new LogContext(), mockNetworkClient, metadata, time, 100, 1000, Integer.MAX_VALUE); // expect poll, but with no timeout consumerClient.poll(time.timer(Long.MAX_VALUE), () -> false); verify(mockNetworkClient).poll(eq(0L), anyLong()); }
private void verifyVerifyUniqueness( SchemaIndex index, SchemaDescriptor descriptor, Object... values ) throws IOException, IndexEntryConflictException { @SuppressWarnings( "unchecked" ) ArgumentCaptor<List<Value[]>> captor = ArgumentCaptor.forClass( List.class ); verify( index ).verifyUniqueness( any(), eq( descriptor.getPropertyIds() ), captor.capture() ); assertThat( captor.getValue(), containsInAnyOrder( valueTupleList( values ).toArray() ) ); } }
@Test public void do_not_set_frame_protection_on_integration_resources_with_context() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn("GET"); when(request.getRequestURI()).thenReturn("/sonarqube/integration/vsts/index.html"); when(request.getContextPath()).thenReturn("/sonarqube"); underTest.doFilter(request, response, chain); verify(response, never()).addHeader(eq("X-Frame-Options"), anyString()); verify(response).addHeader("X-XSS-Protection", "1; mode=block"); verify(response).addHeader("X-Content-Type-Options", "nosniff"); }
@Test void shouldCalculateTheDatabaseDirectoryFromConfig() throws IOException, CommandFailed, IncorrectUsage, IncorrectFormat { Path dataDir = testDirectory.directory( "some-other-path" ).toPath(); Path databaseDir = dataDir.resolve( "databases/foo.db" ); Files.createDirectories( databaseDir ); Files.write( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ), singletonList( formatProperty( data_directory, dataDir ) ) ); execute( "foo.db" ); verify( loader ).load( any(), eq( databaseDir ), eq( databaseDir ) ); }
@Test public void should_use_loader() { when(loader.load(eq(globalPropertiesMap), any(Supplier.class), eq(branches), eq(pullRequests))).thenReturn(config); BranchConfiguration result = provider.provide(loader, globalConfiguration, reactor, globalServerSettings, projectServerSettings, branches, pullRequests); assertThat(result).isSameAs(config); }
@Test void shouldDefaultToGraphDb() throws Exception { Path databaseDir = homeDir.resolve( "data/databases/" + GraphDatabaseSettings.DEFAULT_DATABASE_NAME ); Files.createDirectories( databaseDir ); new LoadCommand( homeDir, configDir, loader ).execute( new String[]{"--from=something"} ); verify( loader ).load( any(), eq( databaseDir ), eq( databaseDir ) ); }
@Test public void getSessionSaveWhenCreatedAndStartedThenSavesAndSetsId() { when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.emptyList()); WebSession session = this.sessionManager.getSession(this.exchange).block(); assertSame(this.createSession, session); String sessionId = this.createSession.getId(); when(this.createSession.isStarted()).thenReturn(true); this.exchange.getResponse().setComplete().block(); verify(this.sessionStore).createWebSession(); verify(this.sessionIdResolver).setSessionId(any(), eq(sessionId)); verify(this.createSession).save(); }
@Test public void should_execute() { String comment = "My bulk change comment"; Map<String, Object> properties = newHashMap(); properties.put("comment", comment); DefaultIssue issue = mock(DefaultIssue.class); Action.Context context = mock(Action.Context.class); when(context.issue()).thenReturn(issue); action.execute(properties, context); verify(issueUpdater).addComment(eq(issue), eq(comment), any()); }
@Test void shouldConvertToCanonicalPath() throws Exception { new DumpCommand( homeDir, configDir, dumper ) .execute( new String[]{"--database=" + "foo.db", "--to=foo.dump"} ); verify( dumper ).dump( any( Path.class ), any( Path.class ), eq( Paths.get( new File( "foo.dump" ).getCanonicalPath() ) ), any() ); }
@Test public void shouldRegisterAnInstanceOfEachOfTheRequiredPluginServicesAfterOSGiFrameworkIsInitialized() { spy.start(); verify(bundleContext).registerService(eq(PluginHealthService.class), any(DefaultPluginHealthService.class), isNull(Dictionary.class)); verify(bundleContext).registerService(eq(LoggingService.class), any(DefaultPluginLoggingService.class), isNull(Dictionary.class)); }
@Test void shouldCalculateTheDatabaseDirectoryFromConfig() throws Exception { Path dataDir = testDirectory.directory( "some-other-path" ).toPath(); Path databaseDir = dataDir.resolve( "databases/foo.db" ); putStoreInDirectory( databaseDir ); Files.write( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ), singletonList( formatProperty( data_directory, dataDir ) ) ); execute( "foo.db" ); verify( dumper ).dump( eq( databaseDir ), eq( databaseDir ), any(), any() ); }
@Test public void shouldMakeJobCompletionCall() { when(pluginManager.resolveExtensionVersion(PLUGIN_ID, ELASTIC_AGENT_EXTENSION, SUPPORTED_VERSIONS)).thenReturn("4.0"); final String elasticAgentId = "ea1"; final JobIdentifier jobIdentifier = new JobIdentifier("up42", 2, "Test", "up42_stage", "10", "up42_job"); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(null)); extension.reportJobCompletion(PLUGIN_ID, elasticAgentId, jobIdentifier); verify(pluginManager, times(1)).submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), any(GoPluginApiRequest.class)); }