Merge pull request #6769 from rozagerardo/geroza/BAEL-14071_Fix-tests-in-spring-cloud-projects-part-3

[BAEL-14071] fix tests in spring-cloud projects - part 3
This commit is contained in:
Loredana Crusoveanu 2019-04-21 13:24:41 +03:00 committed by GitHub
commit 491290cb39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 275 additions and 51 deletions

View File

@ -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 {

View File

@ -0,0 +1,20 @@
package com.baeldung.spring.cloud.archaius.dynamosources;
import org.junit.Test;
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:
* * start a dynamodb instance locally on port 8000(e.g. with the following command `docker run -p 8000:8000 --name bael-dynamodb amazon/dynamodb-local`)
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DynamoSourcesApplication.class)
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -1,17 +1,15 @@
package org.baeldung;
package com.baeldung.spring.cloud.archaius.jdbconfig;
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)
@SpringBootTest(classes = JdbcSourcesApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}
}

View File

@ -0,0 +1,20 @@
package com.baeldung.spring.cloud.archaius.zookeeperconfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* This Live tTest requires:
* * A Zookeeper instance running locally on port 2181 (e.g. using `docker run --name bael-zookeeper -p 2181:2181 --restart always zookeeper`)
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ZookeeperConfigApplication.class)
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

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:
```

View File

@ -0,0 +1,22 @@
package com.baeldung.spring.cloud.aws;
import org.junit.Test;
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 SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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() {

View File

@ -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>

View File

@ -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);

View File

@ -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() {

View File

@ -0,0 +1,2 @@
# This property would be provided by the config service in a real-case scenario
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -0,0 +1,2 @@
# This property would be provided by the config service in a real-case scenario
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)

View File

@ -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>

View File

@ -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);

View File

@ -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() {

View File

@ -0,0 +1,2 @@
# This property would be provided by the config service in a real-case scenario
spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.)

View File

@ -0,0 +1,15 @@
package com.baeldung.spring.cloudfunction.aws;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CloudFunctionAwsApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.spring.cloud.kubernetes.travelagency;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -1,4 +1,5 @@
package com.baeldung.spring.cloud.aws;
package com.baeldung.cloud.openfeign;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -6,10 +7,10 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringCloudAwsApplication.class)
@SpringBootTest(classes = ExampleApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}
}

View File

@ -3,11 +3,11 @@ logging:
org:
springframework:
cloud:
task=DEBUG
task: DEBUG
spring:
application:
name=helloWorld
name: helloWorld
datasource:
url: jdbc:mysql://localhost:3306/springcloud?useSSL=false
username: root

View File

@ -1,17 +0,0 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.task.JobConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = JobConfiguration.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -0,0 +1,29 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.task.JobConfiguration;
import com.baeldung.task.TaskDemo;
/**
* This Live Test requires:
* * a MySql instance running, that allows a root user with no password, and with a database named
*
* (e.g. with the following command `docker run -p 3306:3306 --name bael-mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_DATABASE=springcloud mysql:latest`)
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootApplication
@ContextConfiguration(classes = { JobConfiguration.class, TaskDemo.class }, initializers = {
ConfigFileApplicationContextInitializer.class })
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -0,0 +1,15 @@
package org.baeldung.spring.cloud.vaultsample;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VaultSampleApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -34,6 +34,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>

View File

@ -0,0 +1,16 @@
package com.baeldung.spring.cloud.helloworld;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = HelloWorldApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.spring.cloud.zuulratelimitdemo.controller;
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.zuulratelimitdemo.ZuulRatelimitDemoApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ZuulRatelimitDemoApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}