@Test public void testLogReportSpan() throws Exception { when(elasticsearchTracingPlugin.isOnlyLogElasticsearchSpanReports()).thenReturn(true); reportSpan(); Mockito.verify(httpClient, times(0)).send(any(), any(), any(), any(), any()); Mockito.verify(spanLogger).info(ArgumentMatchers.startsWith("{\"index\":{\"_index\":\"stagemonitor-spans-")); }
@Test public void should_log_warning_if_toString_is_not_overridden() { Logger log = mock(Logger.class); keys.of(new Object(), log); verifyZeroInteractions(log); // only on non-first runs, to avoid false-positives on singletons keys.of(new Object(), log); verify(log).warn(startsWith("Bad component key")); }
@Test public void shouldHandleBucketNotFoundException() throws BucketNotFoundException { Mockito.when(manager.getRepository(any(), any(), any())) .thenThrow(BucketNotFoundException.class); AsyncEvent event = Mockito.mock(AsyncEvent.class); boolean result = listener.processEvents(Arrays.asList(event)); assertFalse(result); verify(listener, times(1)) .logDebugMessage(startsWith("Bucket not found"), any(BucketNotFoundException.class)); }
@Test public void testLogReportSpan() throws Exception { Mockito.when(elasticsearchTracingPlugin.isOnlyLogElasticsearchSpanReports()).thenReturn(true); final SpanContextInformation spanContext = reportSpanWithCallTree(1000, "Report Me"); final List<MockSpan> sampledSpans = getSampledSpans(); assertThat(sampledSpans).hasSize(1); Mockito.verify(httpClient, Mockito.times(0)).send(any(), any(), any(), any(), any()); Mockito.verify(spanLogger).info(ArgumentMatchers.startsWith("{\"index\":{\"_index\":\"stagemonitor-spans-" + StringUtils.getLogstashStyleDate() + "\",\"_type\":\"spans\"}}\n")); Assert.assertTrue(reporter.isActive(spanContext)); }
@Test public void getAuthenticationWhenUserDetailsServiceAndPasswordManagerThenManagerUsed() throws Exception { UserDetails user = new User("user", "{noop}password", AuthorityUtils.createAuthorityList("ROLE_USER")); this.spring.register(UserDetailsPasswordManagerBeanConfig.class).autowire(); UserDetailsPasswordManagerBeanConfig.Manager manager = this.spring.getContext().getBean(UserDetailsPasswordManagerBeanConfig.Manager.class); AuthenticationManager am = this.spring.getContext().getBean(AuthenticationConfiguration.class).getAuthenticationManager(); when(manager.loadUserByUsername("user")).thenReturn(User.withUserDetails(user).build(), User.withUserDetails(user).build()); when(manager.updatePassword(any(), any())).thenReturn(user); am.authenticate(new UsernamePasswordAuthenticationToken("user", "password")); verify(manager).updatePassword(eq(user), startsWith("{bcrypt}")); }
@Test public void delete() { String sessionId = "testSessionId"; this.repository.deleteById(sessionId); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), eq(sessionId)); }
@Test public void saveNewWithoutTransaction() { this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations); JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); this.repository.save(session); verify(this.jdbcOperations, times(1)).update( startsWith("INSERT INTO SPRING_SESSION"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); verifyZeroInteractions(this.transactionManager); }
@Test public void saveNewWithoutAttributes() { JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("INSERT"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test public void testLogSensitive() throws Exception { class Provider extends ConfigurationOptionProvider { private ConfigurationOption<String> sensitiveOption = ConfigurationOption.stringOption() .key("foo") .sensitive() .buildRequired(); } final ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder() .addOptionProvider(new Provider()) .addConfigSource(new SimpleSource("source").add("foo", "secret")) .build(); configurationLogger.logConfiguration(configurationRegistry); verify(logger).info(startsWith("# stagemonitor configuration")); verify(logger).info(eq("{}: {} (source: {})"), eq("foo"), eq("XXXX"), eq("source")); }
@Test public void saveNewWithSingleAttribute() { JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); session.setAttribute("testName", "testValue"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update( startsWith("INSERT INTO SPRING_SESSION("), isA(PreparedStatementSetter.class)); verify(this.jdbcOperations, times(1)).update( startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test public void cleanupExpiredSessions() { this.repository.cleanUpExpiredSessions(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), anyLong()); }
@Test public void saveUpdatedWithoutTransaction() { this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations); JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession( "primaryKey", new MapSession()); session.setLastAccessedTime(Instant.now()); this.repository.save(session); verify(this.jdbcOperations, times(1)).update(startsWith("UPDATE SPRING_SESSION"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); verifyZeroInteractions(this.transactionManager); }
@Test public void saveUpdatedLastAccessedTime() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setLastAccessedTime(Instant.now()); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update( startsWith("UPDATE SPRING_SESSION SET"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test public void saveUpdatedAddSingleAttribute() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setAttribute("testName", "testValue"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update( startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test public void saveUpdatedAddMultipleAttributes() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setAttribute("testName1", "testValue1"); session.setAttribute("testName2", "testValue2"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).batchUpdate( startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("), isA(BatchPreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test public void saveUpdatedRemoveSingleAttribute() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setAttribute("testName", "testValue"); session.clearChangeFlags(); session.removeAttribute("testName"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update( startsWith("DELETE FROM SPRING_SESSION_ATTRIBUTES WHERE"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test public void saveUpdatedModifySingleAttribute() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setAttribute("testName", "testValue"); session.clearChangeFlags(); session.setAttribute("testName", "testValue"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update( startsWith("UPDATE SPRING_SESSION_ATTRIBUTES SET"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test // gh-1070 public void saveUpdatedAddAndModifyAttribute() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setAttribute("testName", "testValue1"); session.setAttribute("testName", "testValue2"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations).update( startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test // gh-1070 public void saveUpdatedModifyAndRemoveAttribute() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setAttribute("testName", "testValue1"); session.clearChangeFlags(); session.setAttribute("testName", "testValue2"); session.removeAttribute("testName"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations).update( startsWith("DELETE FROM SPRING_SESSION_ATTRIBUTES WHERE"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test // gh-1070 public void saveUpdatedRemoveAndAddAttribute() { JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession()); session.setAttribute("testName", "testValue1"); session.clearChangeFlags(); session.removeAttribute("testName"); session.setAttribute("testName", "testValue2"); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations).update( startsWith("UPDATE SPRING_SESSION_ATTRIBUTES SET"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }