Fixed Integration Tests for spring-cloud submodules:

* spring-cloud-archaius/basic-config
* spring-cloud-aws
* spring-cloud-bootstrap projects
This commit is contained in:
Ger Roza
2019-04-15 10:00:31 -03:00
parent e41d832038
commit ea06f79651
22 changed files with 97 additions and 41 deletions
@@ -5,21 +5,18 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit4.SpringRunner;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
@RunWith(JUnitPlatform.class)
@ExtendWith(SpringExtension.class)
@RunWith(SpringRunner.class)
@SpringBootTest
public class ArchaiusBasicConfigurationIntegrationTest {
+1 -1
View File
@@ -8,7 +8,7 @@
#### Running the Integration Tests
To run the Integration Tests, we need to have an AWS account and have API keys generated for programmatic access. Edit
To run the Live Tests, we need to have an AWS account and have API keys generated for programmatic access. Edit
the `application.properties` file to add the following properties:
```
@@ -5,9 +5,16 @@ import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
*
* To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access.
*
* Check the README file in this module for more information.
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringCloudAwsApplication.class)
public class SpringContextIntegrationTest {
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
@@ -16,12 +16,19 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.ec2.AmazonEC2;
/**
*
* To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access.
*
* Check the README file in this module for more information.
*
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@TestPropertySource("classpath:application-test.properties")
public class EC2MetadataIntegrationTest {
public class EC2MetadataLiveTest {
private static final Logger logger = LoggerFactory.getLogger(EC2MetadataIntegrationTest.class);
private static final Logger logger = LoggerFactory.getLogger(EC2MetadataLiveTest.class);
private boolean serverEc2;
@@ -14,9 +14,16 @@ import java.sql.Statement;
import static org.assertj.core.api.Assertions.assertThat;
/**
*
* To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access.
*
* Check the README file in this module for more information.
*
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class SpringCloudRDSIntegrationTest {
public class SpringCloudRDSLiveTest {
@Autowired
DataSource dataSource;
@@ -23,10 +23,17 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
/**
*
* To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access.
*
* Check the README file in this module for more information.
*
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@TestPropertySource("classpath:application-test.properties")
public class SpringCloudS3IntegrationTest {
public class SpringCloudS3LiveTest {
@Autowired
private SpringCloudS3 springCloudS3;
@@ -16,10 +16,17 @@ import com.amazonaws.services.sns.model.CreateTopicResult;
import com.baeldung.spring.cloud.aws.SpringCloudAwsTestUtil;
import com.baeldung.spring.cloud.aws.sqs.Greeting;
/**
*
* To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access.
*
* Check the README file in this module for more information.
*
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@TestPropertySource("classpath:application-test.properties")
public class SpringCloudSNSIntegrationTest {
public class SpringCloudSNSLiveTest {
@Autowired
private SNSMessageSender snsMessageSender;
@@ -26,12 +26,19 @@ import java.util.concurrent.CountDownLatch;
import static org.assertj.core.api.Assertions.assertThat;
/**
*
* To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access.
*
* Check the README file in this module for more information.
*
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@TestPropertySource("classpath:application-test.properties")
public class SpringCloudSQSIntegrationTest {
public class SpringCloudSQSLiveTest {
private static final Logger logger = LoggerFactory.getLogger(SpringCloudSQSIntegrationTest.class);
private static final Logger logger = LoggerFactory.getLogger(SpringCloudSQSLiveTest.class);
@Autowired
@Lazy
@@ -1,17 +0,0 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.cloud.bootstrap.config.ConfigApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}
@@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.cloud.bootstrap.discovery.DiscoveryApplication;
/**
*
* This Live Test requires:
* * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`)
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DiscoveryApplication.class)
public class SpringContextIntegrationTest {
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
@@ -98,6 +98,6 @@
</plugins>
</build>
<properties>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>Dalston.RELEASE</spring-cloud-dependencies.version>
</properties>
</project>
@@ -71,7 +71,7 @@ public class GatewayApplication {
InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false);
if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) {
baseUrl = instance.getHomePageUrl();
delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter);
delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter);
if (!span.name.matches(skipPattern)) delegate.report(span);
}
if (!span.name.matches(skipPattern)) delegate.report(span);
@@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.cloud.bootstrap.gateway.GatewayApplication;
/**
*
* This Live Test requires:
* * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`)
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = GatewayApplication.class)
public class SpringContextIntegrationTest {
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
@@ -0,0 +1,2 @@
# This property would be provided by the config service in a real-case scenario
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)
@@ -72,7 +72,7 @@
</dependencyManagement>
<properties>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>Dalston.RELEASE</spring-cloud-dependencies.version>
</properties>
</project>
@@ -12,6 +12,8 @@ import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter;
import org.springframework.cloud.sleuth.zipkin.ZipkinProperties;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import zipkin.Span;
@SpringBootApplication
@@ -42,7 +44,7 @@ public class BookServiceApplication {
InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false);
if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) {
baseUrl = instance.getHomePageUrl();
delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter);
delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter);
if (!span.name.matches(skipPattern)) delegate.report(span);
}
}
@@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.cloud.bootstrap.svcbook.BookServiceApplication;
/**
*
* This Live Test requires:
* * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`)
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BookServiceApplication.class)
public class SpringContextIntegrationTest {
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
@@ -0,0 +1,2 @@
# This property would be provided by the config service in a real-case scenario
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)
@@ -81,7 +81,7 @@
</dependencyManagement>
<properties>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>Dalston.RELEASE</spring-cloud-dependencies.version>
</properties>
</project>
@@ -16,6 +16,7 @@ import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
@@ -52,7 +53,7 @@ public class RatingServiceApplication {
InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false);
if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) {
baseUrl = instance.getHomePageUrl();
delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter);
delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter);
if (!span.name.matches(skipPattern)) delegate.report(span);
}
if (!span.name.matches(skipPattern)) delegate.report(span);
@@ -7,9 +7,16 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.cloud.bootstrap.svcrating.RatingServiceApplication;
/**
*
* This Live Test requires:
* * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`)
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RatingServiceApplication.class)
public class SpringContextIntegrationTest {
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
@@ -0,0 +1,2 @@
# This property would be provided by the config service in a real-case scenario
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)