@Test public void stopTrace_adds_context_after_time_by_default() { tester.setLevel(LoggerLevel.TRACE); addSomeContext(underTest); underTest.start().stopTrace("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.TRACE).get(0)) .startsWith("Rules registered | time=") .endsWith("ms | a_string=bar | an_int=42 | after_start=true"); }
private void verifyDebugLogs(String log, String... otherLogs) { assertThat(logTester.getLogs()).hasSize(1 + otherLogs.length); assertThat(logTester.getLogs(LoggerLevel.DEBUG)) .extracting(LogAndArguments::getFormattedMsg) .containsOnly(Stream.concat(Stream.of(log), Arrays.stream(otherLogs)).toArray(String[]::new)); }
@Test public void return_404_if_resource_not_found_in_installed_plugin() throws Exception { system.pluginStream = null; when(pluginRepository.hasPlugin("myplugin")).thenReturn(true); Response response = call("/static/myplugin/foo.css"); assertThat(response.code()).isEqualTo(404); assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty(); }
@Override protected void after() { LogInterceptors.set(NullInterceptor.NULL_INSTANCE); setLevel(LoggerLevel.INFO); }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); SearchResponse response = es.client().prepareSearch(FakeIndexDefinition.INDEX) .setScroll(TimeValue.timeValueMinutes(1)) .get(); logTester.clear(); es.client().prepareSearchScroll(response.getScrollId()).get(); assertThat(logTester.logs()).hasSize(1); }
@Test public void constructor_writes_info_log_if_workerCount_is_greater_than_1() { int newWorkerCount = randomWorkerCount + 1; ceConfigurationRule.setWorkerCount(newWorkerCount); logTester.clear(); new CeWorkerControllerImpl(ceConfigurationRule); verifyInfoLog(newWorkerCount); }
@Test public void return_404_if_plugin_does_not_exist() throws Exception { system.pluginStream = null; when(pluginRepository.hasPlugin("myplugin")).thenReturn(false); Response response = call("/static/myplugin/foo.css"); assertThat(response.code()).isEqualTo(404); assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty(); }
@Override protected void before() throws Throwable { // this shared instance breaks compatibility with parallel execution of tests LogInterceptors.set(new ListInterceptor()); setLevel(LoggerLevel.INFO); }
@Test public void no_trace_logs() { logTester.setLevel(LoggerLevel.DEBUG); SearchResponse response = es.client().prepareSearch(FakeIndexDefinition.INDEX) .setScroll(TimeValue.timeValueMinutes(1)) .get(); logTester.clear(); es.client().prepareSearchScroll(response.getScrollId()).get(); assertThat(logTester.logs()).isEmpty(); }
@Test public void addToQueue_submits_runnable_to_executorService_which_does_not_fail_if_Runnable_argument_throws_exception() { underTest.addToQueue(() -> { throw new RuntimeException("Faking an exception thrown by Runnable argument"); }); assertThat(logTester.logs()).hasSize(1); assertThat(logTester.logs(LoggerLevel.ERROR)).containsOnly("Asynchronous task failed"); }
@Before public void prepare() { logTester.setLevel(LoggerLevel.INFO); system2 = mock(System2.class); when(system2.properties()).thenReturn(new Properties()); globalServerSettings = mock(GlobalServerSettings.class); hierarchy = mock(InputModuleHierarchy.class); store = mock(InputComponentStore.class); projectServerSettings = mock(ProjectServerSettings.class); publisher = new AnalysisContextReportPublisher(projectServerSettings, analysisMode, pluginRepo, system2, globalServerSettings, hierarchy, store); }
@Test public void load_scm_info_from_cache_when_already_loaded() { addChangesetInReport("john", DATE_1, "rev-1"); ScmInfo scmInfo = underTest.getScmInfo(FILE).get(); assertThat(scmInfo.getAllChangesets()).hasSize(1); assertThat(logTester.logs(TRACE)).hasSize(1); logTester.clear(); underTest.getScmInfo(FILE); assertThat(logTester.logs(TRACE)).isEmpty(); verifyZeroInteractions(dbLoader); verifyZeroInteractions(sourceHashRepository); verifyZeroInteractions(diff); }
private void assertError(String expectedError) throws Exception { assertThat(logTester.logs(LoggerLevel.WARN)).contains(expectedError); verify(response).sendRedirect("/sessions/unauthorized"); assertThat(oAuth2IdentityProvider.isInitCalled()).isFalse(); }
@Test public void login_failure_does_not_interact_with_arguments_if_log_level_is_above_DEBUG() { HttpServletRequest request = mock(HttpServletRequest.class); AuthenticationException exception = mock(AuthenticationException.class); logTester.setLevel(LoggerLevel.INFO); underTest.loginFailure(request, exception); verifyZeroInteractions(request, exception); }
private void assertError(String expectedError) throws Exception { assertThat(logTester.logs(LoggerLevel.WARN)).contains(expectedError); verify(response).sendRedirect("/sessions/unauthorized"); assertThat(oAuth2IdentityProvider.isInitCalled()).isFalse(); }
@Test public void getRootLoggerLevel() { logTester.setLevel(TRACE); assertThat(underTest.getRootLoggerLevel()).isEqualTo(TRACE); }