Here are the examples of the java api @org.springframework.test.context.ContextConfiguration taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
403 Examples
19
Source : ReplacingDefaultDataSourceIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase
@ContextConfiguration
public clreplaced ReplacingDefaultDataSourceIntegrationTest {
@Configuration
static clreplaced Config {
@Bean
@Primary
public DataSource dataSource() {
return mock(DataSource.clreplaced, "mockDataSource");
}
}
@Autowired
private DataSource dataSource;
@Test
public void primaryDataSourceShouldBeReplaced() throws Exception {
replacedertThat(dataSource.unwrap(DataSource.clreplaced)).isExactlyInstanceOf(PGSimpleDataSource.clreplaced);
}
}
19
Source : ZonkyProviderWithConfigurationIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource", provider = ZONKY)
@ContextConfiguration
public clreplaced ZonkyProviderWithConfigurationIntegrationTest {
@Configuration
static clreplaced Config {
@Bean
public Integer randomPort() {
return SocketUtils.findAvailableTcpPort();
}
@Bean
public Consumer<EmbeddedPostgres.Builder> embeddedPostgresCustomizer(Integer randomPort) {
return builder -> builder.setPort(randomPort);
}
}
@Autowired
private Integer randomPort;
@Autowired
private DataSource dataSource;
@Test
public void testDataSource() throws SQLException {
replacedertThat(dataSource.unwrap(PGSimpleDataSource.clreplaced).getPortNumber()).isEqualTo(randomPort);
}
}
19
Source : ZonkyProviderIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource", provider = ZONKY)
@ContextConfiguration
public clreplaced ZonkyProviderIntegrationTest {
@Autowired
private DataSource dataSource;
@Test
public void testDataSource() throws SQLException {
replacedertThat(dataSource.unwrap(PGSimpleDataSource.clreplaced)).isNotNull();
}
}
19
Source : YandexProviderWithConfigurationIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource", provider = YANDEX)
@TestPropertySource(properties = { "zonky.test.database.postgres.yandex-provider.postgres-version=9.6.11-1" })
@ContextConfiguration
public clreplaced YandexProviderWithConfigurationIntegrationTest {
@Autowired
private DataSource dataSource;
@Test
public void testDataSource() throws SQLException {
replacedertThat(dataSource.unwrap(PGSimpleDataSource.clreplaced).getPreplacedword()).isEqualTo("yandex");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String version = jdbcTemplate.queryForObject("show server_version", String.clreplaced);
replacedertThat(version).startsWith("9.6.");
}
}
19
Source : YandexProviderIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource", provider = YANDEX)
@ContextConfiguration
public clreplaced YandexProviderIntegrationTest {
@Autowired
private DataSource dataSource;
@Test
public void testDataSource() throws SQLException {
replacedertThat(dataSource.unwrap(PGSimpleDataSource.clreplaced).getPreplacedword()).isEqualTo("yandex");
}
}
19
Source : DefaultProviderIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource")
@ContextConfiguration
public clreplaced DefaultProviderIntegrationTest {
@Autowired
private DataSource dataSource;
@Test
public void testDataSource() throws SQLException {
replacedertThat(dataSource.unwrap(PGSimpleDataSource.clreplaced)).isNotNull();
}
}
19
Source : MultipleFlywayBeansMethodLevelIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@Category(MultiFlywayIntegrationTests.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource")
@ContextConfiguration
public clreplaced MultipleFlywayBeansMethodLevelIntegrationTest {
@Configuration
static clreplaced Config {
@Primary
@DependsOn("flyway2")
@Bean
public Flyway flyway1(DataSource dataSource) throws Exception {
List<String> locations = ImmutableList.of("db/migration", "db/test_migration/dependent");
return createFlyway(dataSource, "test", locations);
}
@Bean
public Flyway flyway2(DataSource dataSource) throws Exception {
List<String> locations = ImmutableList.of("db/next_migration");
return createFlyway(dataSource, "next", locations);
}
@Bean
public Flyway flyway3(DataSource dataSource) throws Exception {
List<String> locations = ImmutableList.of("db/test_migration/appendable");
return createFlyway(dataSource, "test", locations, false);
}
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
}
@Autowired
private DataSource dataSource;
@Autowired
private JdbcTemplate jdbcTemplate;
@Test
@FlywayTest(flywayName = "flyway1")
@FlywayTest(flywayName = "flyway2", invokeCleanDB = true, invokeMigrateDB = false)
public void databaseShouldBeLoadedByFlyway1() {
replacedertThat(dataSource).isNotNull();
List<Map<String, Object>> persons = jdbcTemplate.queryForList("select * from test.person");
replacedertThat(persons).isNotNull().hreplacedize(2);
replacedertThat(persons).extracting("id", "first_name", "last_name", "full_name").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer", "Dave Syer"), tuple(3L, "Will", "Smith", "Will Smith"));
replacedertThat(jdbcTemplate.queryForObject("select to_regclreplaced('next.person')", String.clreplaced)).isNull();
}
@Test
@FlywayTest(flywayName = "flyway1", invokeCleanDB = true, invokeMigrateDB = false)
@FlywayTest(flywayName = "flyway2")
public void databaseShouldBeLoadedByFlyway2() {
replacedertThat(dataSource).isNotNull();
replacedertThat(jdbcTemplate.queryForObject("select to_regclreplaced('test.person')", String.clreplaced)).isNull();
List<Map<String, Object>> nextPersons = jdbcTemplate.queryForList("select * from next.person");
replacedertThat(nextPersons).isNotNull().hreplacedize(1);
replacedertThat(nextPersons).extracting("id", "first_name", "surname").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer"));
}
@Test
@FlywayTest(flywayName = "flyway1")
@FlywayTest(flywayName = "flyway2")
public void databaseShouldBeOverriddenByFlyway2() {
replacedertThat(dataSource).isNotNull();
List<Map<String, Object>> persons = jdbcTemplate.queryForList("select * from test.person");
replacedertThat(persons).isNotNull().hreplacedize(2);
replacedertThat(persons).extracting("id", "first_name", "last_name", "full_name").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer", "Dave Syer"), tuple(3L, "Will", "Smith", "Will Smith"));
List<Map<String, Object>> nextPersons = jdbcTemplate.queryForList("select * from next.person");
replacedertThat(nextPersons).isNotNull().hreplacedize(1);
replacedertThat(nextPersons).extracting("id", "first_name", "surname").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer"));
}
@Test
@FlywayTest(flywayName = "flyway1")
@FlywayTest(flywayName = "flyway2")
@FlywayTest(flywayName = "flyway3", invokeCleanDB = false)
public void databaseShouldBeLoadedByFlyway1AndAppendedByFlyway3() {
replacedertThat(dataSource).isNotNull();
List<Map<String, Object>> persons = jdbcTemplate.queryForList("select * from test.person");
replacedertThat(persons).isNotNull().hreplacedize(3);
replacedertThat(persons).extracting("id", "first_name", "last_name").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer"), tuple(2L, "Tom", "Hanks"), tuple(3L, "Will", "Smith"));
List<Map<String, Object>> nextPersons = jdbcTemplate.queryForList("select * from next.person");
replacedertThat(nextPersons).isNotNull().hreplacedize(1);
replacedertThat(nextPersons).extracting("id", "first_name", "surname").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer"));
}
}
19
Source : MultipleDataSourcesIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource2")
@ContextConfiguration
public clreplaced MultipleDataSourcesIntegrationTest {
@Configuration
static clreplaced Config {
@Bean
public DataSource dataSource1() {
return mock(DataSource.clreplaced, "mockDataSource1");
}
@Bean
public DataSource dataSource2() {
return mock(DataSource.clreplaced, "mockDataSource2");
}
@Bean
public DataSource dataSource3() {
return mock(DataSource.clreplaced, "mockDataSource3");
}
}
@Autowired
private DataSource dataSource1;
@Autowired
private DataSource dataSource2;
@Autowired
private DataSource dataSource3;
@Test
public void dataSource1ShouldBeMock() {
replacedertThat(dataSource1).is(mockWithName("mockDataSource1"));
}
@Test
public void dataSource2ShouldBePostgresDataSource() {
replacedertThat(dataSource2).isExactlyInstanceOf(BlockingDataSourceWrapper.clreplaced);
}
@Test
public void dataSource3ShouldBeMock() {
replacedertThat(dataSource3).is(mockWithName("mockDataSource3"));
}
}
19
Source : MultipleDatabasesIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@Category(MultiFlywayIntegrationTests.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource1", provider = ZONKY)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource2", provider = DOCKER)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource3", provider = ZONKY)
@ContextConfiguration
public clreplaced MultipleDatabasesIntegrationTest {
private static final String SQL_SELECT_PERSONS = "select * from test.person";
@Configuration
static clreplaced Config {
@Bean(initMethod = "migrate")
public Flyway flyway1(DataSource dataSource1) throws Exception {
return createFlyway(dataSource1, "test");
}
@Bean(initMethod = "migrate")
public Flyway flyway2(DataSource dataSource2) throws Exception {
return createFlyway(dataSource2, "test");
}
@Bean(initMethod = "migrate")
public Flyway flyway3(DataSource dataSource3) throws Exception {
return createFlyway(dataSource3, "test");
}
@Bean
public JdbcTemplate jdbcTemplate1(DataSource dataSource1) {
return new JdbcTemplate(dataSource1);
}
@Bean
public JdbcTemplate jdbcTemplate2(DataSource dataSource2) {
return new JdbcTemplate(dataSource2);
}
@Bean
public JdbcTemplate jdbcTemplate3(DataSource dataSource3) {
return new JdbcTemplate(dataSource3);
}
}
@Autowired
private DataSource dataSource1;
@Autowired
private DataSource dataSource2;
@Autowired
private DataSource dataSource3;
@Autowired
private JdbcTemplate jdbcTemplate1;
@Autowired
private JdbcTemplate jdbcTemplate2;
@Autowired
private JdbcTemplate jdbcTemplate3;
@Test
@FlywayTest(flywayName = "flyway1", locationsForMigrate = "db/test_migration/appendable")
@FlywayTest(flywayName = "flyway2", locationsForMigrate = "db/test_migration/dependent")
@FlywayTest(flywayName = "flyway3", overrideLocations = true, locationsForMigrate = "db/test_migration/separated")
public void loadDefaultMigrations() throws SQLException {
replacedertThat(dataSource1).isNotNull();
replacedertThat(dataSource2).isNotNull();
replacedertThat(dataSource3).isNotNull();
replacedertThat(getPort(dataSource1)).isEqualTo(getPort(dataSource3));
replacedertThat(getPort(dataSource1)).isNotEqualTo(getPort(dataSource2));
replacedertThat(getDatabaseName(dataSource1)).isNotEqualTo(getDatabaseName(dataSource3));
replacedertThat(dataSource1.unwrap(PGSimpleDataSource.clreplaced).getPreplacedword()).isNotEqualTo("docker");
replacedertThat(dataSource2.unwrap(PGSimpleDataSource.clreplaced).getPreplacedword()).isEqualTo("docker");
replacedertThat(dataSource3.unwrap(PGSimpleDataSource.clreplaced).getPreplacedword()).isNotEqualTo("docker");
replacedertThat(jdbcTemplate1.queryForList(SQL_SELECT_PERSONS)).extracting("id", "first_name", "last_name").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer"), tuple(2L, "Tom", "Hanks"));
replacedertThat(jdbcTemplate2.queryForList(SQL_SELECT_PERSONS)).extracting("id", "first_name", "last_name", "full_name").containsExactlyInAnyOrder(tuple(1L, "Dave", "Syer", "Dave Syer"), tuple(3L, "Will", "Smith", "Will Smith"));
List<Map<String, Object>> persons = jdbcTemplate3.queryForList(SQL_SELECT_PERSONS);
replacedertThat(persons).isNotNull().hreplacedize(1);
Map<String, Object> person = persons.get(0);
replacedertThat(person).containsExactly(entry("id", 1L), entry("first_name", "Tom"), entry("last_name", "Hanks"));
}
private static int getPort(DataSource dataSource) throws SQLException {
return dataSource.unwrap(PGSimpleDataSource.clreplaced).getPortNumber();
}
private static String getDatabaseName(DataSource dataSource) throws SQLException {
return dataSource.unwrap(PGSimpleDataSource.clreplaced).getDatabaseName();
}
}
19
Source : ProviderTypePropertyIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource")
@TestPropertySource(properties = "zonky.test.database.provider=docker")
@ContextConfiguration
public clreplaced ProviderTypePropertyIntegrationTest {
@Autowired
private DataSource dataSource;
@Test
public void dockerProviderShouldBeUsed() throws Exception {
replacedertThat(dataSource.unwrap(PGSimpleDataSource.clreplaced).getPreplacedword()).isEqualTo("docker");
}
}
19
Source : ConfigurationPropertiesIntegrationTest.java
with Apache License 2.0
from zonkyio
with Apache License 2.0
from zonkyio
@RunWith(SpringRunner.clreplaced)
@AutoConfigureEmbeddedDatabase(beanName = "dataSource")
@TestPropertySource(properties = { "zonky.test.database.postgres.client.properties.stringtype=unspecified", "zonky.test.database.postgres.initdb.properties.lc-collate=cs_CZ.UTF-8", "zonky.test.database.postgres.server.properties.max_connections=100", "zonky.test.database.postgres.server.properties.shared_buffers=64MB" })
@ContextConfiguration
public clreplaced ConfigurationPropertiesIntegrationTest {
@Autowired
private DataSource dataSource;
@Test
public void testConfigurationProperties() throws Exception {
replacedertThat(dataSource.unwrap(PGSimpleDataSource.clreplaced).getProperty("stringtype")).isEqualTo("unspecified");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String collate = jdbcTemplate.queryForObject("show lc_collate", String.clreplaced);
replacedertThat(collate).isEqualTo("cs_CZ.UTF-8");
String maxConnections = jdbcTemplate.queryForObject("show max_connections", String.clreplaced);
replacedertThat(maxConnections).isEqualTo("100");
String sharedBuffers = jdbcTemplate.queryForObject("show shared_buffers", String.clreplaced);
replacedertThat(sharedBuffers).isEqualTo("64MB");
}
}
19
Source : SpringBootTestContextBootstrapperWithContextConfigurationTests.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
/**
* Tests for {@link SpringBootTestContextBootstrapper} + {@code @ContextConfiguration} (in
* its own package so we can test detection).
*
* @author Phillip Webb
*/
@RunWith(SpringRunner.clreplaced)
@BootstrapWith(SpringBootTestContextBootstrapper.clreplaced)
@ContextConfiguration
public clreplaced SpringBootTestContextBootstrapperWithContextConfigurationTests {
@Autowired
private ApplicationContext context;
@Autowired
private SpringBootTestContextBootstrapperExampleConfig config;
@Test
public void findConfigAutomatically() {
replacedertThat(this.config).isNotNull();
}
@Test
public void contextWasCreatedViaSpringApplication() {
replacedertThat(this.context.getId()).startsWith("application");
}
}
19
Source : MockMvcBuilderMethodChainTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Test for SPR-10277 (multiple method chaining when building MockMvc).
*
* @author Wesley Hall
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@WebAppConfiguration
@ContextConfiguration
public clreplaced MockMvcBuilderMethodChainTests {
@Autowired
private WebApplicationContext wac;
@Test
public void chainMultiple() {
MockMvcBuilders.webAppContextSetup(wac).addFilter(new CharacterEncodingFilter()).defaultRequest(get("/").contextPath("/mywebapp")).build();
}
@Configuration
@EnableWebMvc
static clreplaced WebConfig implements WebMvcConfigurer {
}
}
19
Source : MockMvcReuseTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests that verify that {@link MockMvc} can be reused multiple
* times within the same test method without side effects between independent
* requests.
* <p>See <a href="https://jira.spring.io/browse/SPR-13260" target="_blank">SPR-13260</a>.
*
* @author Sam Brannen
* @author Rob Winch
* @since 4.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@WebAppConfiguration
public clreplaced MockMvcReuseTests {
private static final String HELLO = "hello";
private static final String ENIGMA = "enigma";
private static final String FOO = "foo";
private static final String BAR = "bar";
@Autowired
private WebApplicationContext wac;
private MockMvc mvc;
@Before
public void setUp() {
this.mvc = webAppContextSetup(this.wac).build();
}
@Test
public void sessionAttributesAreClearedBetweenInvocations() throws Exception {
this.mvc.perform(get("/")).andExpect(content().string(HELLO)).andExpect(request().sessionAttribute(FOO, nullValue()));
this.mvc.perform(get("/").sessionAttr(FOO, BAR)).andExpect(content().string(HELLO)).andExpect(request().sessionAttribute(FOO, BAR));
this.mvc.perform(get("/")).andExpect(content().string(HELLO)).andExpect(request().sessionAttribute(FOO, nullValue()));
}
@Test
public void requestParametersAreClearedBetweenInvocations() throws Exception {
this.mvc.perform(get("/")).andExpect(content().string(HELLO));
this.mvc.perform(get("/").param(ENIGMA, "")).andExpect(content().string(ENIGMA));
this.mvc.perform(get("/")).andExpect(content().string(HELLO));
}
@Configuration
@EnableWebMvc
static clreplaced Config {
@Bean
public MyController myController() {
return new MyController();
}
}
@RestController
static clreplaced MyController {
@RequestMapping("/")
public String hello() {
return HELLO;
}
@RequestMapping(path = "/", params = ENIGMA)
public String enigma() {
return ENIGMA;
}
}
}
19
Source : MockMvcConnectionBuilderSupportTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests for {@link MockMvcWebConnectionBuilderSupport}.
*
* @author Rob Winch
* @author Rossen Stoyanchev
* @since 4.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@WebAppConfiguration
@SuppressWarnings("rawtypes")
public clreplaced MockMvcConnectionBuilderSupportTests {
private final WebClient client = mock(WebClient.clreplaced);
private MockMvcWebConnectionBuilderSupport builder;
@Autowired
private WebApplicationContext wac;
@Before
public void setup() {
given(this.client.getWebConnection()).willReturn(mock(WebConnection.clreplaced));
this.builder = new MockMvcWebConnectionBuilderSupport(this.wac) {
};
}
@Test(expected = IllegalArgumentException.clreplaced)
public void constructorMockMvcNull() {
new MockMvcWebConnectionBuilderSupport((MockMvc) null) {
};
}
@Test(expected = IllegalArgumentException.clreplaced)
public void constructorContextNull() {
new MockMvcWebConnectionBuilderSupport((WebApplicationContext) null) {
};
}
@Test
public void context() throws Exception {
WebConnection conn = this.builder.createConnection(this.client);
replacedertMockMvcUsed(conn, "http://localhost/");
replacedertMockMvcNotUsed(conn, "https://example.com/");
}
@Test
public void mockMvc() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
WebConnection conn = new MockMvcWebConnectionBuilderSupport(mockMvc) {
}.createConnection(this.client);
replacedertMockMvcUsed(conn, "http://localhost/");
replacedertMockMvcNotUsed(conn, "https://example.com/");
}
@Test
public void mockMvcExampleDotCom() throws Exception {
WebConnection conn = this.builder.useMockMvcForHosts("example.com").createConnection(this.client);
replacedertMockMvcUsed(conn, "http://localhost/");
replacedertMockMvcUsed(conn, "https://example.com/");
replacedertMockMvcNotUsed(conn, "http://other.com/");
}
@Test
public void mockMvcAlwaysUseMockMvc() throws Exception {
WebConnection conn = this.builder.alwaysUseMockMvc().createConnection(this.client);
replacedertMockMvcUsed(conn, "http://other.com/");
}
@Test
public void defaultContextPathEmpty() throws Exception {
WebConnection conn = this.builder.createConnection(this.client);
replacedertThat(getResponse(conn, "http://localhost/abc").getContentreplacedtring(), equalTo(""));
}
@Test
public void defaultContextPathCustom() throws Exception {
WebConnection conn = this.builder.contextPath("/abc").createConnection(this.client);
replacedertThat(getResponse(conn, "http://localhost/abc/def").getContentreplacedtring(), equalTo("/abc"));
}
private void replacedertMockMvcUsed(WebConnection connection, String url) throws Exception {
replacedertThat(getResponse(connection, url), notNullValue());
}
private void replacedertMockMvcNotUsed(WebConnection connection, String url) throws Exception {
replacedertThat(getResponse(connection, url), nullValue());
}
private WebResponse getResponse(WebConnection connection, String url) throws IOException {
return connection.getResponse(new WebRequest(new URL(url)));
}
@Configuration
@EnableWebMvc
static clreplaced Config {
@RestController
static clreplaced ContextPathController {
@RequestMapping("/def")
public String contextPath(HttpServletRequest request) {
return request.getContextPath();
}
}
}
}
19
Source : WebAppConfigurationBootstrapWithTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* JUnit-based integration tests that verify support for loading a
* {@link WebApplicationContext} with a custom {@link WebTestContextBootstrapper}.
*
* @author Sam Brannen
* @author Phillip Webb
* @since 4.3
*/
@RunWith(SpringRunner.clreplaced)
@ContextConfiguration
@WebAppConfiguration
@BootstrapWith(CustomWebTestContextBootstrapper.clreplaced)
public clreplaced WebAppConfigurationBootstrapWithTests {
@Autowired
WebApplicationContext wac;
@Test
public void webApplicationContextIsLoaded() {
// from: src/test/webapp/resources/Spring.js
Resource resource = wac.getResource("/resources/Spring.js");
replacedertNotNull(resource);
replacedertTrue(resource.exists());
}
@Configuration
static clreplaced Config {
}
/**
* Custom {@link WebTestContextBootstrapper} that requires {@code @WebAppConfiguration}
* but hard codes the resource base path.
*/
static clreplaced CustomWebTestContextBootstrapper extends WebTestContextBootstrapper {
@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
return new WebMergedContextConfiguration(mergedConfig, "src/test/webapp");
}
}
}
19
Source : ServletTestExecutionListenerJUnitIntegrationTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* JUnit-based integration tests for {@link ServletTestExecutionListener}.
*
* @author Sam Brannen
* @since 3.2.9
* @see org.springframework.test.context.testng.web.ServletTestExecutionListenerTestNGIntegrationTests
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@WebAppConfiguration
public clreplaced ServletTestExecutionListenerJUnitIntegrationTests {
@Configuration
static clreplaced Config {
/* no beans required for this test */
}
@Autowired
private MockHttpServletRequest servletRequest;
/**
* Verifies bug fix for <a href="https://jira.spring.io/browse/SPR-11626">SPR-11626</a>.
*
* @see #ensureMocksAreReinjectedBetweenTests_2
*/
@Test
public void ensureMocksAreReinjectedBetweenTests_1() {
replacedertInjectedServletRequestEqualsRequestInRequestContextHolder();
}
/**
* Verifies bug fix for <a href="https://jira.spring.io/browse/SPR-11626">SPR-11626</a>.
*
* @see #ensureMocksAreReinjectedBetweenTests_1
*/
@Test
public void ensureMocksAreReinjectedBetweenTests_2() {
replacedertInjectedServletRequestEqualsRequestInRequestContextHolder();
}
private void replacedertInjectedServletRequestEqualsRequestInRequestContextHolder() {
replacedertEquals("Injected ServletRequest must be stored in the RequestContextHolder", servletRequest, ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
}
19
Source : RequestAndSessionScopedBeansWacTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests that verify support for request and session scoped beans
* in conjunction with the TestContext Framework.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@WebAppConfiguration
public clreplaced RequestAndSessionScopedBeansWacTests {
@Autowired
private WebApplicationContext wac;
@Autowired
private MockHttpServletRequest request;
@Autowired
private MockHttpSession session;
@Test
public void requestScope() throws Exception {
final String beanName = "requestScopedTestBean";
final String contextPath = "/path";
replacedertNull(request.getAttribute(beanName));
request.setContextPath(contextPath);
TestBean testBean = wac.getBean(beanName, TestBean.clreplaced);
replacedertEquals(contextPath, testBean.getName());
replacedertSame(testBean, request.getAttribute(beanName));
replacedertSame(testBean, wac.getBean(beanName, TestBean.clreplaced));
}
@Test
public void sessionScope() throws Exception {
final String beanName = "sessionScopedTestBean";
replacedertNull(session.getAttribute(beanName));
TestBean testBean = wac.getBean(beanName, TestBean.clreplaced);
replacedertSame(testBean, session.getAttribute(beanName));
replacedertSame(testBean, wac.getBean(beanName, TestBean.clreplaced));
}
}
19
Source : BasicXmlWacTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Sam Brannen
* @since 3.2
*/
@ContextConfiguration
public clreplaced BasicXmlWacTests extends AbstractBasicWacTests {
@Test
public void fooBarAutowired() {
replacedertEquals("bar", foo);
}
}
19
Source : BasicGroovyWacTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Sam Brannen
* @since 4.1
* @see BasicXmlWacTests
*/
// Config loaded from BasicGroovyWacTestsContext.groovy
@ContextConfiguration
public clreplaced BasicGroovyWacTests extends AbstractBasicWacTests {
@Test
public void groovyFooAutowired() {
replacedertEquals("Groovy Foo", foo);
}
}
19
Source : BasicAnnotationConfigWacTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Sam Brannen
* @since 3.2
*/
@ContextConfiguration
public clreplaced BasicAnnotationConfigWacTests extends AbstractBasicWacTests {
@Configuration
static clreplaced Config {
@Bean
public String foo() {
return "enigma";
}
@Bean
public ServletContextAwareBean servletContextAwareBean() {
return new ServletContextAwareBean();
}
}
@Autowired
protected ServletContextAwareBean servletContextAwareBean;
@Test
public void fooEnigmaAutowired() {
replacedertEquals("enigma", foo);
}
@Test
public void servletContextAwareBeanProcessed() {
replacedertNotNull(servletContextAwareBean);
replacedertNotNull(servletContextAwareBean.servletContext);
}
}
19
Source : ServletTestExecutionListenerTestNGIntegrationTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* TestNG-based integration tests for {@link ServletTestExecutionListener}.
*
* @author Sam Brannen
* @since 3.2.9
* @see org.springframework.test.context.web.ServletTestExecutionListenerJUnitIntegrationTests
*/
@ContextConfiguration
@WebAppConfiguration
public clreplaced ServletTestExecutionListenerTestNGIntegrationTests extends AbstractTestNGSpringContextTests {
@Configuration
static clreplaced Config {
/* no beans required for this test */
}
@Autowired
private MockHttpServletRequest servletRequest;
/**
* Verifies bug fix for <a href="https://jira.spring.io/browse/SPR-11626">SPR-11626</a>.
*
* @see #ensureMocksAreReinjectedBetweenTests_2
*/
@Test
void ensureMocksAreReinjectedBetweenTests_1() {
replacedertInjectedServletRequestEqualsRequestInRequestContextHolder();
}
/**
* Verifies bug fix for <a href="https://jira.spring.io/browse/SPR-11626">SPR-11626</a>.
*
* @see #ensureMocksAreReinjectedBetweenTests_1
*/
@Test
void ensureMocksAreReinjectedBetweenTests_2() {
replacedertInjectedServletRequestEqualsRequestInRequestContextHolder();
}
private void replacedertInjectedServletRequestEqualsRequestInRequestContextHolder() {
replacedertEquals("Injected ServletRequest must be stored in the RequestContextHolder", servletRequest, ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
}
19
Source : ProgrammaticTxMgmtTestNGTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* This clreplaced is a copy of the JUnit-based {@link ProgrammaticTxMgmtTests} clreplaced
* that has been modified to run with TestNG.
*
* @author Sam Brannen
* @since 4.1
*/
@ContextConfiguration
public clreplaced ProgrammaticTxMgmtTestNGTests extends AbstractTransactionalTestNGSpringContextTests {
private String method;
@Override
public void run(IHookCallBack callBack, ITestResult testResult) {
this.method = testResult.getMethod().getMethodName();
super.run(callBack, testResult);
}
@BeforeTransaction
public void beforeTransaction() {
deleteFromTables("user");
executeSqlScript("clreplacedpath:/org/springframework/test/context/jdbc/data.sql", false);
}
@AfterTransaction
public void afterTransaction() {
switch(method) {
case "commitTxAndStartNewTx":
case "commitTxButDoNotStartNewTx":
{
replacedertUsers("Dogbert");
break;
}
case "rollbackTxAndStartNewTx":
case "rollbackTxButDoNotStartNewTx":
case "startTxWithExistingTransaction":
{
replacedertUsers("Dilbert");
break;
}
case "rollbackTxAndStartNewTxWithDefaultCommitSemantics":
{
replacedertUsers("Dilbert", "Dogbert");
break;
}
default:
{
fail("missing 'after transaction' replacedertion for test method: " + method);
}
}
}
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void isActiveWithNonExistentTransactionContext() {
replacedertFalse(TestTransaction.isActive());
}
@Test(expectedExceptions = IllegalStateException.clreplaced)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void flagForRollbackWithNonExistentTransactionContext() {
TestTransaction.flagForRollback();
}
@Test(expectedExceptions = IllegalStateException.clreplaced)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void flagForCommitWithNonExistentTransactionContext() {
TestTransaction.flagForCommit();
}
@Test(expectedExceptions = IllegalStateException.clreplaced)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void isFlaggedForRollbackWithNonExistentTransactionContext() {
TestTransaction.isFlaggedForRollback();
}
@Test(expectedExceptions = IllegalStateException.clreplaced)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void startTxWithNonExistentTransactionContext() {
TestTransaction.start();
}
@Test(expectedExceptions = IllegalStateException.clreplaced)
public void startTxWithExistingTransaction() {
TestTransaction.start();
}
@Test(expectedExceptions = IllegalStateException.clreplaced)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void endTxWithNonExistentTransactionContext() {
TestTransaction.end();
}
@Test
public void commitTxAndStartNewTx() {
replacedertInTransaction(true);
replacedertTrue(TestTransaction.isActive());
replacedertUsers("Dilbert");
deleteFromTables("user");
replacedertUsers();
// Commit
TestTransaction.flagForCommit();
replacedertFalse(TestTransaction.isFlaggedForRollback());
TestTransaction.end();
replacedertInTransaction(false);
replacedertFalse(TestTransaction.isActive());
replacedertUsers();
executeSqlScript("clreplacedpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
replacedertUsers("Dogbert");
TestTransaction.start();
replacedertInTransaction(true);
replacedertTrue(TestTransaction.isActive());
}
@Test
public void commitTxButDoNotStartNewTx() {
replacedertInTransaction(true);
replacedertTrue(TestTransaction.isActive());
replacedertUsers("Dilbert");
deleteFromTables("user");
replacedertUsers();
// Commit
TestTransaction.flagForCommit();
replacedertFalse(TestTransaction.isFlaggedForRollback());
TestTransaction.end();
replacedertFalse(TestTransaction.isActive());
replacedertInTransaction(false);
replacedertUsers();
executeSqlScript("clreplacedpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
replacedertUsers("Dogbert");
}
@Test
public void rollbackTxAndStartNewTx() {
replacedertInTransaction(true);
replacedertTrue(TestTransaction.isActive());
replacedertUsers("Dilbert");
deleteFromTables("user");
replacedertUsers();
// Rollback (automatically)
replacedertTrue(TestTransaction.isFlaggedForRollback());
TestTransaction.end();
replacedertFalse(TestTransaction.isActive());
replacedertInTransaction(false);
replacedertUsers("Dilbert");
// Start new transaction with default rollback semantics
TestTransaction.start();
replacedertInTransaction(true);
replacedertTrue(TestTransaction.isFlaggedForRollback());
replacedertTrue(TestTransaction.isActive());
executeSqlScript("clreplacedpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
replacedertUsers("Dilbert", "Dogbert");
}
@Test
public void rollbackTxButDoNotStartNewTx() {
replacedertInTransaction(true);
replacedertTrue(TestTransaction.isActive());
replacedertUsers("Dilbert");
deleteFromTables("user");
replacedertUsers();
// Rollback (automatically)
replacedertTrue(TestTransaction.isFlaggedForRollback());
TestTransaction.end();
replacedertFalse(TestTransaction.isActive());
replacedertInTransaction(false);
replacedertUsers("Dilbert");
}
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
replacedertInTransaction(true);
replacedertTrue(TestTransaction.isActive());
replacedertUsers("Dilbert");
deleteFromTables("user");
replacedertUsers();
// Rollback
TestTransaction.flagForRollback();
replacedertTrue(TestTransaction.isFlaggedForRollback());
TestTransaction.end();
replacedertFalse(TestTransaction.isActive());
replacedertInTransaction(false);
replacedertUsers("Dilbert");
// Start new transaction with default commit semantics
TestTransaction.start();
replacedertInTransaction(true);
replacedertFalse(TestTransaction.isFlaggedForRollback());
replacedertTrue(TestTransaction.isActive());
executeSqlScript("clreplacedpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
replacedertUsers("Dilbert", "Dogbert");
}
// -------------------------------------------------------------------------
private void replacedertUsers(String... users) {
List<String> expected = Arrays.asList(users);
Collections.sort(expected);
List<String> actual = jdbcTemplate.queryForList("select name from user", String.clreplaced);
Collections.sort(actual);
replacedertEquals("Users in database;", expected, actual);
}
// -------------------------------------------------------------------------
@Configuration
static clreplaced Config {
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
return //
new EmbeddedDatabaseBuilder().setName(//
"programmatic-tx-mgmt-test-db").addScript(//
"clreplacedpath:/org/springframework/test/context/jdbc/schema.sql").build();
}
}
}
19
Source : TimedTransactionalTestNGSpringContextTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Timed integration tests for
* {@link AbstractTransactionalTestNGSpringContextTests}; used to verify claim
* raised in <a href="https://jira.springframework.org/browse/SPR-6124"
* target="_blank">SPR-6124</a>.
*
* @author Sam Brannen
* @since 3.0
*/
@ContextConfiguration
public clreplaced TimedTransactionalTestNGSpringContextTests extends AbstractTransactionalTestNGSpringContextTests {
@Test
public void testWithoutTimeout() {
replacedertInTransaction(true);
}
// TODO Enable TestNG test with timeout once we have a solution.
@Test(timeOut = 10000, enabled = false)
public void testWithTimeout() {
replacedertInTransaction(true);
}
}
19
Source : DirtiesContextTransactionalTestNGSpringContextTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* <p>
* TestNG based integration test to replacedess the claim in <a
* href="https://opensource.atlreplacedian.com/projects/spring/browse/SPR-3880"
* target="_blank">SPR-3880</a> that a "context marked dirty using
* {@link DirtiesContext @DirtiesContext} in [a] TestNG based test is not
* reloaded in subsequent tests".
* </p>
* <p>
* After careful replacedysis, it turns out that the {@link ApplicationContext} was
* in fact reloaded; however, due to how the test instance was instrumented with
* the {@link TestContextManager} in {@link AbstractTestNGSpringContextTests},
* dependency injection was not being performed on the test instance between
* individual tests. DirtiesContextTransactionalTestNGSpringContextTests
* therefore verifies the expected behavior and correct semantics.
* </p>
*
* @author Sam Brannen
* @since 2.5
*/
@ContextConfiguration
public clreplaced DirtiesContextTransactionalTestNGSpringContextTests extends AbstractTransactionalTestNGSpringContextTests {
private ApplicationContext dirtiedApplicationContext;
private void performCommonreplacedertions() {
replacedertInTransaction(true);
replacedertNotNull(super.applicationContext, "The application context should have been set due to ApplicationContextAware semantics.");
replacedertNotNull(super.jdbcTemplate, "The JdbcTemplate should have been created in setDataSource() via DI for the DataSource.");
}
@Test
@DirtiesContext
public void dirtyContext() {
performCommonreplacedertions();
this.dirtiedApplicationContext = super.applicationContext;
}
@Test(dependsOnMethods = { "dirtyContext" })
public void verifyContextWasDirtied() {
performCommonreplacedertions();
replacedertNotSame(super.applicationContext, this.dirtiedApplicationContext, "The application context should have been 'dirtied'.");
this.dirtiedApplicationContext = super.applicationContext;
}
@Test(dependsOnMethods = { "verifyContextWasDirtied" })
public void verifyContextWasNotDirtied() {
replacedertSame(this.applicationContext, this.dirtiedApplicationContext, "The application context should NOT have been 'dirtied'.");
}
}
19
Source : GenericXmlContextLoaderResourceLocationsTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@ContextConfiguration
clreplaced ClreplacedpathExistentDefaultLocationsTestCase {
}
19
Source : GenericXmlContextLoaderResourceLocationsTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@ContextConfiguration
clreplaced ClreplacedpathNonExistentDefaultLocationsTestCase {
}
19
Source : Spr9799XmlConfigTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests used to replacedess claims raised in
* <a href="https://jira.spring.io/browse/SPR-9799" target="_blank">SPR-9799</a>.
*
* @author Sam Brannen
* @since 3.2
* @see Spr9799AnnotationConfigTests
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced Spr9799XmlConfigTests {
@Test
public void applicationContextLoads() {
// nothing to replacedert: we just want to make sure that the context loads without
// errors.
}
}
19
Source : TransactionalAnnotatedConfigClassWithAtConfigurationTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Concrete implementation of {@link AbstractTransactionalAnnotatedConfigClreplacedTests}
* that uses a true {@link Configuration @Configuration clreplaced}.
*
* @author Sam Brannen
* @since 3.2
* @see TransactionalAnnotatedConfigClreplacedesWithoutAtConfigurationTests
*/
@ContextConfiguration
public clreplaced TransactionalAnnotatedConfigClreplacedWithAtConfigurationTests extends AbstractTransactionalAnnotatedConfigClreplacedTests {
/**
* This is <b>intentionally</b> annotated with {@code @Configuration}.
*
* <p>Consequently, this clreplaced contains standard singleton bean methods
* instead of <i>annotated factory bean methods</i>.
*/
@Configuration
static clreplaced Config {
@Bean
public Employee employee() {
Employee employee = new Employee();
employee.setName("John Smith");
employee.setAge(42);
employee.setCompany("Acme Widgets, Inc.");
return employee;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
return //
new EmbeddedDatabaseBuilder().addScript(//
"clreplacedpath:/org/springframework/test/jdbc/schema.sql").setName(//
getClreplaced().getName()).build();
}
}
@Before
public void compareDataSources() throws Exception {
// NOTE: the two DataSource instances ARE the same!
replacedertSame(dataSourceFromTxManager, dataSourceViaInjection);
}
}
19
Source : TestClass4.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* This name of this clreplaced intentionally does not end with "Test" or "Tests"
* since it should only be run as part of the test suite: {@link Spr8849Tests}.
*
* @author Sam Brannen
* @since 4.2
* @see Spr8849Tests
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced TestClreplaced4 {
@Configuration
@ImportResource("clreplacedpath:/org/springframework/test/context/junit4/spr8849/datasource-config-with-auto-generated-db-name.xml")
static clreplaced Config {
}
@Resource
DataSource dataSource;
@Test
public void dummyTest() {
replacedertNotNull(dataSource);
}
}
19
Source : TestClass3.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* This name of this clreplaced intentionally does not end with "Test" or "Tests"
* since it should only be run as part of the test suite: {@link Spr8849Tests}.
*
* @author Sam Brannen
* @since 4.2
* @see Spr8849Tests
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced TestClreplaced3 {
@Configuration
@ImportResource("clreplacedpath:/org/springframework/test/context/junit4/spr8849/datasource-config-with-auto-generated-db-name.xml")
static clreplaced Config {
}
@Resource
DataSource dataSource;
@Test
public void dummyTest() {
replacedertNotNull(dataSource);
}
}
19
Source : TestClass2.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* This name of this clreplaced intentionally does not end with "Test" or "Tests"
* since it should only be run as part of the test suite: {@link Spr8849Tests}.
*
* @author Mickael Leduque
* @author Sam Brannen
* @since 3.2
* @see Spr8849Tests
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced TestClreplaced2 {
@Configuration
@ImportResource("clreplacedpath:/org/springframework/test/context/junit4/spr8849/datasource-config.xml")
static clreplaced Config {
}
@Resource
DataSource dataSource;
@Test
public void dummyTest() {
replacedertNotNull(dataSource);
}
}
19
Source : TestClass1.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* This name of this clreplaced intentionally does not end with "Test" or "Tests"
* since it should only be run as part of the test suite: {@link Spr8849Tests}.
*
* @author Mickael Leduque
* @author Sam Brannen
* @since 3.2
* @see Spr8849Tests
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced TestClreplaced1 {
@Configuration
@ImportResource("clreplacedpath:/org/springframework/test/context/junit4/spr8849/datasource-config.xml")
static clreplaced Config {
}
@Resource
DataSource dataSource;
@Test
public void dummyTest() {
replacedertNotNull(dataSource);
}
}
19
Source : AutowiredQualifierTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests to verify claims made in <a
* href="https://jira.springframework.org/browse/SPR-6128"
* target="_blank">SPR-6128</a>.
*
* @author Sam Brannen
* @author Chris Beams
* @since 3.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
public clreplaced AutowiredQualifierTests {
@Autowired
private String foo;
@Autowired
@Qualifier("customFoo")
private String customFoo;
@Test
public void test() {
replacedertThat(foo, equalTo("normal"));
replacedertThat(customFoo, equalTo("custom"));
}
}
19
Source : Jsr250LifecycleTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests that investigate the applicability of JSR-250 lifecycle
* annotations in test clreplacedes.
*
* <p>This clreplaced does not really contain actual <em>tests</em> per se. Rather it
* can be used to empirically verify the expected log output (see below). In
* order to see the log output, one would naturally need to ensure that the
* logger category for this clreplaced is enabled at {@code INFO} level.
*
* <h4>Expected Log Output</h4>
* <pre>
* INFO : org.springframework.test.context.junit4.spr4868.LifecycleBean - initializing
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - beforeAllTests()
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - setUp()
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - test1()
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - tearDown()
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - beforeAllTests()
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - setUp()
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - test2()
* INFO : org.springframework.test.context.junit4.spr4868.ExampleTest - tearDown()
* INFO : org.springframework.test.context.junit4.spr4868.LifecycleBean - destroying
* </pre>
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.clreplaced })
@ContextConfiguration
public clreplaced Jsr250LifecycleTests {
private final Log logger = LogFactory.getLog(Jsr250LifecycleTests.clreplaced);
@Configuration
static clreplaced Config {
@Bean
public LifecycleBean lifecycleBean() {
return new LifecycleBean();
}
}
@Autowired
private LifecycleBean lifecycleBean;
@PostConstruct
public void beforeAllTests() {
logger.info("beforeAllTests()");
}
@PreDestroy
public void afterTestSuite() {
logger.info("afterTestSuite()");
}
@Before
public void setUp() throws Exception {
logger.info("setUp()");
}
@After
public void tearDown() throws Exception {
logger.info("tearDown()");
}
@Test
public void test1() {
logger.info("test1()");
replacedertNotNull(lifecycleBean);
}
@Test
public void test2() {
logger.info("test2()");
replacedertNotNull(lifecycleBean);
}
}
19
Source : BeanOverridingDefaultLocationsInheritedTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* JUnit 4 based integration test for verifying support for the
* {@link ContextConfiguration#inheritLocations() inheritLocations} flag of
* {@link ContextConfiguration @ContextConfiguration} indirectly proposed in <a
* href="https://opensource.atlreplacedian.com/projects/spring/browse/SPR-3896"
* target="_blank">SPR-3896</a>.
*
* @author Sam Brannen
* @since 2.5
*/
@ContextConfiguration
public clreplaced BeanOverridingDefaultLocationsInheritedTests extends DefaultLocationsBaseTests {
@Test
@Override
public void verifyEmployeeSetFromBaseContextConfig() {
replacedertNotNull("The employee should have been autowired.", this.employee);
replacedertEquals("The employee bean should have been overridden.", "Yoda", this.employee.getName());
}
}
19
Source : Subclass2AppCtxRuleTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Subclreplaced #2 of {@link BaseAppCtxRuleTests}.
*
* @author Sam Brannen
* @since 4.2
*/
@ContextConfiguration
public clreplaced Subclreplaced2AppCtxRuleTests extends BaseAppCtxRuleTests {
@Autowired
private String baz;
@Test
public void baz() {
replacedertEquals("baz", baz);
}
@Configuration
static clreplaced Config {
@Bean
public String baz() {
return "baz";
}
}
}
19
Source : Subclass1AppCtxRuleTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Subclreplaced #1 of {@link BaseAppCtxRuleTests}.
*
* @author Sam Brannen
* @since 4.2
*/
@ContextConfiguration
public clreplaced Subclreplaced1AppCtxRuleTests extends BaseAppCtxRuleTests {
@Autowired
private String bar;
@Test
public void bar() {
replacedertEquals("bar", bar);
}
@Configuration
static clreplaced Config {
@Bean
public String bar() {
return "bar";
}
}
}
19
Source : ClassNameActiveProfilesResolverTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Michail Nikolaev
* @since 4.0
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@ActiveProfiles(resolver = ClreplacedNameActiveProfilesResolver.clreplaced)
public clreplaced ClreplacedNameActiveProfilesResolverTests {
@Configuration
static clreplaced Config {
}
@Autowired
private ApplicationContext applicationContext;
@Test
public void test() {
replacedertTrue(Arrays.asList(applicationContext.getEnvironment().getActiveProfiles()).contains(getClreplaced().getSimpleName().toLowerCase()));
}
}
19
Source : DefaultLoaderBeanOverridingDefaultConfigClassesInheritedTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests that verify support for configuration clreplacedes in
* the Spring TestContext Framework in conjunction with the
* {@link DelegatingSmartContextLoader}.
*
* @author Sam Brannen
* @since 3.1
*/
@ContextConfiguration
public clreplaced DefaultLoaderBeanOverridingDefaultConfigClreplacedesInheritedTests extends DefaultLoaderDefaultConfigClreplacedesBaseTests {
@Configuration
static clreplaced Config {
@Bean
public Employee employee() {
Employee employee = new Employee();
employee.setName("Yoda");
employee.setAge(900);
employee.setCompany("The Force");
return employee;
}
}
@Test
@Override
public void verifyEmployeeSetFromBaseContextConfig() {
replacedertNotNull("The employee should have been autowired.", this.employee);
replacedertEquals("The employee bean should have been overridden.", "Yoda", this.employee.getName());
}
}
19
Source : BeanOverridingDefaultConfigClassesInheritedTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration tests that verify support for configuration clreplacedes in
* the Spring TestContext Framework.
*
* <p>Configuration will be loaded from {@link DefaultConfigClreplacedesBaseTests.ContextConfiguration}
* and {@link BeanOverridingDefaultConfigClreplacedesInheritedTests.ContextConfiguration}.
*
* @author Sam Brannen
* @since 3.1
*/
@ContextConfiguration
public clreplaced BeanOverridingDefaultConfigClreplacedesInheritedTests extends DefaultConfigClreplacedesBaseTests {
@Configuration
static clreplaced ContextConfiguration {
@Bean
public Employee employee() {
Employee employee = new Employee();
employee.setName("Yoda");
employee.setAge(900);
employee.setCompany("The Force");
return employee;
}
}
@Test
@Override
public void verifyEmployeeSetFromBaseContextConfig() {
replacedertNotNull("The employee should have been autowired.", this.employee);
replacedertEquals("The employee bean should have been overridden.", "Yoda", this.employee.getName());
}
}
19
Source : EarTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Sam Brannen
* @since 3.2.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced EarTests {
@Configuration
static clreplaced EarConfig {
@Bean
public String ear() {
return "ear";
}
}
// -------------------------------------------------------------------------
@Autowired
private ApplicationContext context;
@Autowired
private String ear;
@Test
public void verifyEarConfig() {
replacedertFalse(context instanceof WebApplicationContext);
replacedertNull(context.getParent());
replacedertEquals("ear", ear);
}
}
19
Source : TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Sam Brannen
* @since 3.2.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced TestHierarchyLevelTwoWithBareContextConfigurationInSubclreplacedTests extends TestHierarchyLevelOneWithBareContextConfigurationInSubclreplacedTests {
@Configuration
static clreplaced Config {
@Bean
public String foo() {
return "foo-level-2";
}
@Bean
public String baz() {
return "baz";
}
}
@Autowired
private String foo;
@Autowired
private String bar;
@Autowired
private String baz;
@Autowired
private ApplicationContext context;
@Test
@Override
public void loadContextHierarchy() {
replacedertNotNull("child ApplicationContext", context);
replacedertNotNull("parent ApplicationContext", context.getParent());
replacedertNull("grandparent ApplicationContext", context.getParent().getParent());
replacedertEquals("foo-level-2", foo);
replacedertEquals("bar", bar);
replacedertEquals("baz", baz);
}
}
19
Source : TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Sam Brannen
* @since 3.2.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced TestHierarchyLevelOneWithBareContextConfigurationInSuperclreplacedTests {
@Configuration
static clreplaced Config {
@Bean
public String foo() {
return "foo-level-1";
}
@Bean
public String bar() {
return "bar";
}
}
@Autowired
private String foo;
@Autowired
private String bar;
@Autowired
private ApplicationContext context;
@Test
public void loadContextHierarchy() {
replacedertNotNull("child ApplicationContext", context);
replacedertNull("parent ApplicationContext", context.getParent());
replacedertEquals("foo-level-1", foo);
replacedertEquals("bar", bar);
}
}
19
Source : MetaHierarchyLevelTwoTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Sam Brannen
* @since 4.0.3
*/
@ContextConfiguration
@ActiveProfiles("prod")
public clreplaced MetaHierarchyLevelTwoTests extends MetaHierarchyLevelOneTests {
@Configuration
@Profile("prod")
static clreplaced Config {
@Bean
public String bar() {
return "Prod Bar";
}
}
@Autowired
protected ApplicationContext context;
@Autowired
private String bar;
@Test
public void bar() {
replacedertEquals("Prod Bar", bar);
}
@Test
public void contextHierarchy() {
replacedertNotNull("child ApplicationContext", context);
replacedertNotNull("parent ApplicationContext", context.getParent());
replacedertNull("grandparent ApplicationContext", context.getParent().getParent());
}
}
19
Source : DefaultScriptDetectionXmlSupersedesGroovySpringContextTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Integration test clreplaced that verifies proper detection of a default
* XML config file even though a suitable Groovy script exists.
*
* @author Sam Brannen
* @since 4.1
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced DefaultScriptDetectionXmlSupersedesGroovySpringContextTests {
@Autowired
protected String foo;
@Test
public final void foo() {
replacedertEquals("The foo field should have been autowired.", "Foo", this.foo);
}
}
19
Source : DapTestCommon.java
with BSD 3-Clause "New" or "Revised" License
from Unidata
with BSD 3-Clause "New" or "Revised" License
from Unidata
@ContextConfiguration
@WebAppConfiguration("file:src/test/data")
abstract public clreplaced DapTestCommon extends UnitTestCommon {
// ////////////////////////////////////////////////
// Constants
static final String DEFAULTTREEROOT = "dap4";
static public final String FILESERVER = "file://localhost:8080";
static public final String CONSTRAINTTAG = "dap4.ce";
static public final String ORDERTAG = "ucar.littleendian";
static public final String NOCSUMTAG = "ucar.nochecksum";
static public final String TRANSLATETAG = "ucar.translate";
static public final String TESTTAG = "ucar.testing";
static final String D4TESTDIRNAME = "d4tests";
// Equivalent to the path to the webapp/d4ts for testing purposes
static protected final String DFALTRESOURCEPATH = "/src/test/data/resources";
static protected Clreplaced NC4IOSP = ucar.nc2.jni.netcdf.Nc4Iosp.clreplaced;
// ////////////////////////////////////////////////
// Type decls
static clreplaced Mocker {
public MockHttpServletRequest req = null;
public MockHttpServletResponse resp = null;
public MockServletContext context = null;
public DapController controller = null;
public String url = null;
public String servletname = null;
public DapTestCommon parent = null;
public Mocker(String servletname, String url, DapTestCommon parent) throws Exception {
this(servletname, url, new Dap4Controller(), parent);
}
public Mocker(String servletname, String url, DapController controller, DapTestCommon parent) throws Exception {
this.parent = parent;
this.url = url;
this.servletname = servletname;
if (controller != null)
setController(controller);
String testdir = parent.getResourceRoot();
// There appears to be bug in the spring core.io code
// such that it replacedumes absolute paths start with '/'.
// So, check for windows drive and prepend 'file:/' as a hack.
if (DapUtil.hasDriveLetter(testdir))
testdir = "/" + testdir;
testdir = "file:" + testdir;
this.context = new MockServletContext(testdir);
URI u = HTTPUtil.parseToURI(url);
this.req = new MockHttpServletRequest(this.context, "GET", u.getPath());
this.resp = new MockHttpServletResponse();
req.setMethod("GET");
setup();
}
protected void setController(DapController ct) throws ServletException {
this.controller = ct;
}
/**
* The spring mocker is not very smart.
* Given the url it should be possible
* to initialize a lot of its fields.
* Instead, it requires the user to so do.
* The request elements to set are:
* - servletpath
* - protocol
* - querystring
* - servername
* - serverport
* - contextpath
* - pathinfo
* - servletpath
*/
protected void setup() throws Exception {
this.req.setCharacterEncoding("UTF-8");
this.req.setServletPath("/" + this.servletname);
URI url = HTTPUtil.parseToURI(this.url);
this.req.setProtocol(url.getScheme());
this.req.setQueryString(url.getQuery());
this.req.setServerName(url.getHost());
this.req.setServerPort(url.getPort());
String path = url.getPath();
if (path != null) {
// probably more complex than it needs to be
String prefix = null;
String suffix = null;
if (path.equals("/" + this.servletname) || path.equals("/" + this.servletname + "/")) {
// path is just servlet tag
prefix = "/" + this.servletname;
suffix = "/";
} else {
int i;
String[] pieces = path.split("[/]");
for (i = 0; i < pieces.length; i++) {
// find servletname piece
if (pieces[i].equals(this.servletname))
break;
}
if (// not found
i >= pieces.length)
throw new IllegalArgumentException("DapTestCommon");
prefix = DapUtil.join(pieces, "/", 0, i);
suffix = DapUtil.join(pieces, "/", i + 1, pieces.length);
}
this.req.setContextPath(DapUtil.absolutize(prefix));
this.req.setPathInfo(suffix);
this.req.setServletPath(DapUtil.absolutize(suffix));
}
}
public byte[] execute() throws IOException {
if (this.controller == null)
throw new DapException("Mocker: no controller");
this.controller.handleRequest(this.req, this.resp);
return this.resp.getContentAsByteArray();
}
}
// Mocking Support Clreplaced for HTTPMethod
static public clreplaced MockExecutor implements HTTPMethod.Executor {
protected String resourcepath = null;
public MockExecutor(String resourcepath) {
this.resourcepath = resourcepath;
}
// HttpHost targethost,HttpClient httpclient,HTTPSession session
public HttpResponse execute(HttpRequestBase rq) throws IOException {
URI uri = rq.getURI();
DapController controller = getController(uri);
StandaloneMockMvcBuilder mvcbuilder = MockMvcBuilders.standaloneSetup(controller);
mvcbuilder.setValidator(new TestServlet.NullValidator());
MockMvc mockMvc = mvcbuilder.build();
MockHttpServletRequestBuilder mockrb = MockMvcRequestBuilders.get(uri);
// We need to use only the path part
mockrb.servletPath(uri.getPath());
// Move any headers from rq to mockrb
Header[] headers = rq.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
Header h = headers[i];
mockrb.header(h.getName(), h.getValue());
}
// Since the url has the query parameters,
// they will automatically be parsed and added
// to the rb parameters.
// Finally set the resource dir
mockrb.requestAttr("RESOURCEDIR", this.resourcepath);
// Now invoke the servlet
MvcResult result;
try {
result = mockMvc.perform(mockrb).andReturn();
} catch (Exception e) {
throw new IOException(e);
}
// Collect the output
MockHttpServletResponse res = result.getResponse();
byte[] byteresult = res.getContentAsByteArray();
// Convert to HttpResponse
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, res.getStatus(), "");
if (response == null)
throw new IOException("HTTPMethod.executeMock: Response was null");
Collection<String> keys = res.getHeaderNames();
// Move headers to the response
for (String key : keys) {
List<String> values = res.getHeaders(key);
for (String v : values) {
response.addHeader(key, v);
}
}
ByteArrayEnreplacedy enreplacedy = new ByteArrayEnreplacedy(byteresult);
String sct = res.getContentType();
enreplacedy.setContentType(sct);
response.setEnreplacedy(enreplacedy);
return response;
}
protected DapController getController(URI uri) throws IOException {
String path = uri.getPath();
path = HTTPUtil.canonicalpath(path);
replacedert path.startsWith("/");
String[] pieces = path.split("[/]");
replacedert pieces.length >= 2;
// Path is absolute, so pieces[0] will be empty
// so pieces[1] should determine the controller
DapController controller;
if ("d4ts".equals(pieces[1])) {
controller = new D4TSController();
} else if ("thredds".equals(pieces[1])) {
controller = new Dap4Controller();
} else
throw new IOException("Unknown controller type " + pieces[1]);
return controller;
}
}
static clreplaced TestFilter implements FileFilter {
boolean debug;
boolean strip;
String[] extensions;
public TestFilter(boolean debug, String[] extensions) {
this.debug = debug;
this.strip = strip;
this.extensions = extensions;
}
public boolean accept(File file) {
boolean ok = false;
if (file.isFile() && file.canRead()) {
// Check for proper extension
String name = file.getName();
if (name != null) {
for (String ext : extensions) {
if (name.endsWith(ext))
ok = true;
}
}
if (!ok && debug)
System.err.println("Ignoring: " + file.toString());
}
return ok;
}
static void filterfiles(String path, List<String> matches, String... extensions) {
File testdirf = new File(path);
replacedert (testdirf.canRead());
TestFilter tf = new TestFilter(DEBUG, extensions);
File[] filelist = testdirf.listFiles(tf);
for (int i = 0; i < filelist.length; i++) {
File file = filelist[i];
if (file.isDirectory())
continue;
String fname = DapUtil.canonicalpath(file.getAbsolutePath());
matches.add(fname);
}
}
}
// ////////////////////////////////////////////////
// Static variables
static protected String dap4root = null;
static protected String dap4testroot = null;
static protected String dap4resourcedir = null;
static {
dap4root = locateDAP4Root(threddsroot);
if (dap4root == null)
System.err.println("Cannot locate /dap4 parent dir");
dap4testroot = canonjoin(dap4root, D4TESTDIRNAME);
dap4resourcedir = canonjoin(dap4testroot, DFALTRESOURCEPATH);
}
// ////////////////////////////////////////////////
// Static methods
static protected String getD4TestsRoot() {
return dap4testroot;
}
static protected String getResourceRoot() {
return dap4resourcedir;
}
static String locateDAP4Root(String threddsroot) {
String root = threddsroot;
if (root != null)
root = root + "/" + DEFAULTTREEROOT;
// See if it exists
File f = new File(root);
if (!f.exists() || !f.isDirectory())
root = null;
return root;
}
// ////////////////////////////////////////////////
// Instance variables
protected String d4tsserver = null;
protected String replacedle = "Dap4 Testing";
public DapTestCommon() {
this("DapTest");
}
public DapTestCommon(String name) {
super(name);
this.d4tsserver = TestDir.dap4TestServer;
if (DEBUG)
System.err.println("DapTestCommon: d4tsServer=" + d4tsserver);
}
/**
* Try to get the system properties
*/
protected void setSystemProperties() {
String testargs = System.getProperty("testargs");
if (testargs != null && testargs.length() > 0) {
String[] pairs = testargs.split("[ ]*[,][ ]*");
for (String pair : pairs) {
String[] tuple = pair.split("[ ]*[=][ ]*");
String value = (tuple.length == 1 ? "" : tuple[1]);
if (tuple[0].length() > 0)
System.setProperty(tuple[0], value);
}
}
if (System.getProperty("nodiff") != null)
prop_diff = false;
if (System.getProperty("baseline") != null)
prop_baseline = true;
if (System.getProperty("nogenerate") != null)
prop_generate = false;
if (System.getProperty("debug") != null)
prop_debug = true;
if (System.getProperty("visual") != null)
prop_visual = true;
if (System.getProperty("ascii") != null)
prop_ascii = true;
if (System.getProperty("utf8") != null)
prop_ascii = false;
if (prop_baseline && prop_diff)
prop_diff = false;
prop_controls = System.getProperty("controls", "");
}
// ////////////////////////////////////////////////
// Overrideable methods
// ////////////////////////////////////////////////
// Accessor
public void setreplacedle(String replacedle) {
this.replacedle = replacedle;
}
public String getreplacedle() {
return this.replacedle;
}
// ////////////////////////////////////////////////
// Instance Utilities
public void visual(String header, String captured) {
if (!captured.endsWith("\n"))
captured = captured + "\n";
// Dump the output for visual comparison
System.err.println("\n" + header + ":");
System.err.println("---------------");
System.err.print(captured);
System.err.println("---------------");
System.err.flush();
}
protected void findServer(String path) throws DapException {
String svc = "http://" + this.d4tsserver + "/d4ts";
if (!checkServer(svc))
System.err.println("D4TS Server not reachable: " + svc);
// Since we will be accessing it thru NetcdfDataset, we need to change the schema.
d4tsserver = "dap4://" + d4tsserver + "/d4ts";
}
// ////////////////////////////////////////////////
public String getDAP4Root() {
return this.dap4root;
}
@Override
public String getResourceDir() {
return this.dap4resourcedir;
}
/**
* Unfortunately, mock does not appear to always
* do proper initialization
*/
static protected void mockSetup() {
TdsRequestedDataset.setDatasetManager(new DatasetManager());
}
static protected void testSetup() {
DapController.TESTING = true;
DapCache.dspregistry.register(FileDSP.clreplaced, DSPRegistry.FIRST);
DapCache.dspregistry.register(SynDSP.clreplaced, DSPRegistry.FIRST);
try {
// Always prefer Nc4Iosp over HDF5
NetcdfFile.iospDeRegister(NC4IOSP);
NetcdfFile.registerIOProviderPreferred(NC4IOSP, ucar.nc2.iosp.hdf5.H5iosp.clreplaced);
// Print out the library version
System.err.printf("Netcdf-c library version: %s%n", getCLibraryVersion());
System.err.flush();
} catch (Exception e) {
System.err.println("Cannot load ucar.nc2.jni.netcdf.Nc4Iosp");
}
}
static protected MvcResult perform(String url, MockMvc mockMvc, String respath, String... params) throws Exception {
MockHttpServletRequestBuilder rb = MockMvcRequestBuilders.get(url).servletPath(url);
if (params.length > 0) {
if (params.length % 2 == 1)
throw new Exception("Illegal query params");
for (int i = 0; i < params.length; i += 2) {
if (params[i] != null) {
rb.param(params[i], params[i + 1]);
}
}
}
replacedert respath != null;
String realdir = canonjoin(dap4testroot, respath);
rb.requestAttr("RESOURCEDIR", realdir);
MvcResult result = mockMvc.perform(rb).andReturn();
return result;
}
static void printDir(String path) {
File testdirf = new File(path);
replacedert (testdirf.canRead());
File[] filelist = testdirf.listFiles();
System.err.println("\n*******************");
System.err.printf("Contents of %s:%n", path);
for (int i = 0; i < filelist.length; i++) {
File file = filelist[i];
String fname = file.getName();
System.err.printf("\t%s%s%n", fname, (file.isDirectory() ? "/" : ""));
}
System.err.println("*******************");
System.err.flush();
}
static public String getCLibraryVersion() {
Nc4prototypes nc4 = getCLibrary();
return (nc4 == null ? "Unknown" : nc4.nc_inq_libvers());
}
static public Nc4prototypes getCLibrary() {
try {
Method getclib = NC4IOSP.getMethod("getCLibrary");
return (Nc4prototypes) getclib.invoke(null);
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
return null;
}
}
}
19
Source : GcpMemorystoreHealthTest.java
with Apache License 2.0
from ThalesGroup
with Apache License 2.0
from ThalesGroup
@RunWith(SpringRunner.clreplaced)
@ContextConfiguration
public clreplaced GcpMemorystoreHealthTest {
@MockBean
private GcpMemorystorePlatform gcpMemorystorePlatform;
@Autowired
private GcpMemorystoreHealth gcpMemorystoreHealth;
@Test
public void getHealth() {
doReturn(ApiStatus.OK).doReturn(ApiStatus.ERROR).doReturn(null).doThrow(new RuntimeException()).when(gcpMemorystorePlatform).getApiStatus();
replacedertEquals(SystemHealthState.OK, gcpMemorystoreHealth.getHealth());
replacedertEquals(SystemHealthState.ERROR, gcpMemorystoreHealth.getHealth());
replacedertEquals(SystemHealthState.UNKNOWN, gcpMemorystoreHealth.getHealth());
replacedertEquals(SystemHealthState.UNKNOWN, gcpMemorystoreHealth.getHealth());
}
@Configuration
public static clreplaced GcpMemorystoreHealthTestConfiguration {
@Autowired
private GcpMemorystorePlatform gcpMemorystorePlatform;
@Bean
public GcpMemorystoreHealth gcpMemorystoreHealth() {
return spy(new GcpMemorystoreHealth());
}
}
}
19
Source : GcpComputeHealthTest.java
with Apache License 2.0
from ThalesGroup
with Apache License 2.0
from ThalesGroup
@RunWith(SpringRunner.clreplaced)
@ContextConfiguration
public clreplaced GcpComputeHealthTest {
@MockBean
private GcpComputePlatform gcpComputePlatform;
@Autowired
private GcpComputeHealth gcpComputeHealth;
@Test
public void getHealth() {
doReturn(ApiStatus.OK).doReturn(ApiStatus.ERROR).doReturn(null).doThrow(new RuntimeException()).when(gcpComputePlatform).getApiStatus();
replacedertEquals(SystemHealthState.OK, gcpComputeHealth.getHealth());
replacedertEquals(SystemHealthState.ERROR, gcpComputeHealth.getHealth());
replacedertEquals(SystemHealthState.UNKNOWN, gcpComputeHealth.getHealth());
replacedertEquals(SystemHealthState.UNKNOWN, gcpComputeHealth.getHealth());
}
@Configuration
public static clreplaced GcpComputeHealthTestConfiguration {
@Autowired
private GcpComputePlatform gcpComputePlatform;
@Bean
public GcpComputeHealth gcpComputeHealth() {
return spy(new GcpComputeHealth());
}
}
}
19
Source : AwsEC2SelfAwarenessTest.java
with Apache License 2.0
from ThalesGroup
with Apache License 2.0
from ThalesGroup
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced AwsEC2SelfAwarenessTest {
private static final String RESPONSE = UUID.randomUUID().toString();
@Autowired
private AwsEC2SelfAwareness awsEC2SelfAwareness = new AwsEC2SelfAwareness();
@Test
public void isMe() {
doReturn(RESPONSE).when(awsEC2SelfAwareness).fetchInstanceId();
replacedertTrue(awsEC2SelfAwareness.isMe(RESPONSE));
// replacedertion repeated for testing caching of the ID.
replacedertTrue(awsEC2SelfAwareness.isMe(RESPONSE));
replacedertFalse(awsEC2SelfAwareness.isMe(RESPONSE.substring(RESPONSE.length() - 1)));
verify(awsEC2SelfAwareness, times(1)).fetchInstanceId();
}
@Configuration
static clreplaced TestConfig {
@Bean
AwsEC2SelfAwareness awsEC2SelfAwareness() {
return Mockito.spy(new AwsEC2SelfAwareness());
}
}
}
See More Examples