[BAEL-9497] Fix failing context tests - part 1 (#7719)

* fixed context dependency issue and added LiveContext notes in persistence-modules/spring-data-couchbase-2 module

* fixed Context tests and added notes for spring-cloud-bus/spring-cloud-config-client module

* Added context test in spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/data-flow-server module, mainly due to incompatible dependencies, plus fixed parent pom path in different modules

* fixed context tests for spring-cloud/spring-cloud-task/springcloudtaskbatch module, renamed ContextLiveTest as IntegrationTest, now configured to run with an H2 embedded instance. Moved the run note to the application

* Added SpringContextLiveTests in persistence-modules/spring-data-mongodb module
This commit is contained in:
Ger Roza 2019-09-06 06:19:30 -03:00 committed by Josh Cummings
parent c709251eeb
commit e9e4f63313
19 changed files with 199 additions and 58 deletions

View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
@ -59,6 +60,16 @@
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>${javax.el.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>${javax.el.version}</version>
</dependency>
</dependencies>
<properties>
@ -66,6 +77,7 @@
<spring-data-couchbase.version>2.1.5.RELEASE</spring-data-couchbase.version>
<hibernate-validator.version>5.3.3.Final</hibernate-validator.version>
<joda-time.version>2.9.6</joda-time.version>
<javax.el.version>3.0.0</javax.el.version>
</properties>
</project>

View File

@ -9,6 +9,45 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
/**
* This LiveTest requires:
*
* 1- Couchbase instance running (e.g. with `docker run -d --name db -p 8091-8096:8091-8096 -p 11210-11211:11210-11211 couchbase`)
*
*
* 2- Couchbase configured with (we can use the console in localhost:8091):
*
* 2.1- Buckets: named 'baeldung' and 'baeldung2'
*
* 2.2- Security: users 'baeldung' and 'baeldung2'. Note: in newer versions an empty password is not allowed, then we have to change the passwords in the project)
*
* 2.3- Spacial View: Add new spacial view (in Index tab) in document 'campus_spatial', view 'byLocation' with the following function:
* {@code
* function (doc) {
* if (doc.location &&
* doc._class == "org.baeldung.spring.data.couchbase.model.Campus") {
* emit([doc.location.x, doc.location.y], null);
* }
* }}
*
* 2.4- MapReduce Views: Add new views in document 'campus':
* 2.4.1- view 'all' with function:
* {@code
* function (doc, meta) {
* if(doc._class == "org.baeldung.spring.data.couchbase.model.Campus") {
* emit(meta.id, null);
* }
* }}
*
* 2.4.2- view 'byName' with function:
* {@code
* function (doc, meta) {
* if(doc._class == "org.baeldung.spring.data.couchbase.model.Campus" &&
* doc.name) {
* emit(doc.name, null);
* }
* }}
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })

View File

@ -0,0 +1,26 @@
package com.baeldung.contexttests.mongoconfig;
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.config.MongoConfig;
/**
* This Live test requires:
* * mongodb instance running on the environment
*
* (e.g. `docker run -d -p 27017:27017 --name bael-mongo mongo`)
*
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MongoConfig.class)
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -0,0 +1,26 @@
package com.baeldung.contexttests.mongoreactiveconfig;
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.config.MongoReactiveConfig;
/**
* This Live test requires:
* * mongodb instance running on the environment
*
* (e.g. `docker run -d -p 27017:27017 --name bael-mongo mongo`)
*
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MongoReactiveConfig.class)
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -0,0 +1,26 @@
package com.baeldung.contexttests.simplemongoconfig;
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.config.SimpleMongoConfig;
/**
* This Live test requires:
* * mongodb instance running on the environment
*
* (e.g. `docker run -d -p 27017:27017 --name bael-mongo mongo`)
*
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SimpleMongoConfig.class)
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -1,18 +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.SpringCloudConfigClientApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringCloudConfigClientApplication.class)
public class SpringContextIntegrationTest {
@Test
public void contextLoads() {
}
}

View File

@ -7,6 +7,21 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.SpringCloudConfigClientApplication;
/**
* This LiveTest requires:
* 1- The 'spring-cloud-bus/spring-cloud-config-server' service running, with valid Spring Cloud Config properties, for instance:
* 1.1- `spring.cloud.config.server.git.uri` pointing to a valid URI, which has `user.role` and `user.password` properties configured in a properties file. For example, to achieve this in a dev environment:
* 1.1.1- `cd my/custom/path`
* 1.1.2- `git init .`
* 1.1.3- `echo user.role=Programmer >> application.properties`
* 1.1.4- `echo user.password=d3v3L >> application.properties`
* 1.1.5- `git add .`
* 1.1.6- `git commit -m 'inital commit'`
* 1.1.7- 'spring-cloud-bus/spring-cloud-config-server' with property `spring.cloud.config.server.git.uri=my/custom/path`
*
* Note: This is enough to run the ContextTest successfully, but to get the full functionality shown in the related article, we'll need also a RabbitMQ instance running (e.g. `docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management`)
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringCloudConfigClientApplication.class)
public class SpringContextLiveTest {

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>data-flow-server</artifactId>
@ -12,7 +13,7 @@
<artifactId>parent-boot-1</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-1</relativePath>
<relativePath>../../../parent-boot-1</relativePath>
</parent>
<dependencies>
@ -20,6 +21,16 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-dataflow-server-local</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.compatible.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.compatible.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
@ -42,8 +53,9 @@
</dependencyManagement>
<properties>
<spring-cloud-dataflow-dependencies.version>1.1.0.RELEASE</spring-cloud-dataflow-dependencies.version>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
<spring-cloud-dataflow-dependencies.version>1.3.1.RELEASE</spring-cloud-dataflow-dependencies.version>
<spring-cloud-dependencies.version>Edgware.SR6</spring-cloud-dependencies.version>
<hibernate.compatible.version>5.2.12.Final</hibernate.compatible.version>
</properties>
</project>

View File

@ -0,0 +1,2 @@
#spring.datasource.url=jdbc:h2:mem:dataflow
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

View File

@ -1,16 +0,0 @@
package org.baeldung;
import org.baeldung.spring.cloud.DataFlowServerApplication;
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 = DataFlowServerApplication.class)
public class SpringContextLiveTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@ -0,0 +1 @@
spring.datasource.url=jdbc:h2:mem:dataflow

View File

@ -12,7 +12,7 @@
<artifactId>parent-boot-1</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-1</relativePath>
<relativePath>../../../parent-boot-1</relativePath>
</parent>
<dependencies>

View File

@ -12,7 +12,7 @@
<artifactId>parent-boot-1</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-1</relativePath>
<relativePath>../../../parent-boot-1</relativePath>
</parent>
<dependencies>

View File

@ -12,7 +12,7 @@
<artifactId>parent-boot-1</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-1</relativePath>
<relativePath>../../../parent-boot-1</relativePath>
</parent>
<dependencies>

View File

@ -12,7 +12,7 @@
<artifactId>parent-boot-1</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-1</relativePath>
<relativePath>../../../parent-boot-1</relativePath>
</parent>
<dependencies>

View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung.cloud</groupId>
@ -43,6 +44,11 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-batch</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -14,6 +14,13 @@ import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
/**
* This Application 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`)
*
*/
@SpringBootApplication
@EnableTask
@EnableBatchProcessing

View File

@ -10,18 +10,10 @@ 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 {
@ContextConfiguration(classes = { JobConfiguration.class, TaskDemo.class }, initializers = { ConfigFileApplicationContextInitializer.class })
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {

View File

@ -0,0 +1,11 @@
spring:
datasource:
url: jdbc:h2:mem:springcloud
username: sa
password:
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect