Skip to content

Commit dcf28dd

Browse files
SeunMattmaibin
authored andcommitted
refactor the spring boot persistence mongodb module (eugenp#5829)
* added example code for BAEL-2366 * moved example code for BAEL-2366 * example code for BAEL-1961 * moved example code into integration test * updated the test assertions * refactor the spring boot persistence mongodb module * remove redundant example code * declared the spring boot persistence module in the root pom * fixed issue with non-imported file
1 parent 6b29e94 commit dcf28dd

File tree

13 files changed

+137
-22
lines changed

13 files changed

+137
-22
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
/.idea/
3+
/target/
4+
/spring-boot-persistence.iml
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<artifactId>parent-boot-2</artifactId>
9+
<groupId>com.baeldung</groupId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
<relativePath>../../parent-boot-2</relativePath>
12+
</parent>
13+
14+
<artifactId>spring-boot-persistence-mongodb</artifactId>
15+
<packaging>war</packaging>
16+
<name>spring-boot-persistence-mongodb</name>
17+
<description>This is simple boot application for Spring boot persistence mongodb test</description>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-web</artifactId>
23+
</dependency>
24+
<!-- MongoDB -->
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-data-mongodb</artifactId>
28+
</dependency>
29+
<!-- JUnit Jupiter dependencies -->
30+
<dependency>
31+
<groupId>org.junit.jupiter</groupId>
32+
<artifactId>junit-jupiter-api</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter-engine</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
<!-- JUnit platform launcher -->
41+
<!-- To be able to run tests from IDE directly -->
42+
<dependency>
43+
<groupId>org.junit.platform</groupId>
44+
<artifactId>junit-platform-launcher</artifactId>
45+
<version>${junit-platform.version}</version>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-test</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
</dependencies>
54+
55+
<build>
56+
<finalName>spring-boot-persistence</finalName>
57+
<resources>
58+
<resource>
59+
<directory>src/main/resources</directory>
60+
<filtering>true</filtering>
61+
</resource>
62+
</resources>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-war-plugin</artifactId>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
<profiles>
72+
<profile>
73+
<id>autoconfiguration</id>
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-surefire-plugin</artifactId>
79+
<executions>
80+
<execution>
81+
<phase>integration-test</phase>
82+
<goals>
83+
<goal>test</goal>
84+
</goals>
85+
<configuration>
86+
<excludes>
87+
<exclude>**/*LiveTest.java</exclude>
88+
<exclude>**/*IntegrationTest.java</exclude>
89+
<exclude>**/*IntTest.java</exclude>
90+
</excludes>
91+
</configuration>
92+
</execution>
93+
</executions>
94+
<configuration>
95+
<systemPropertyVariables>
96+
<test.mime>json</test.mime>
97+
</systemPropertyVariables>
98+
</configuration>
99+
</plugin>
100+
</plugins>
101+
</build>
102+
</profile>
103+
</profiles>
104+
105+
106+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringBootPersistenceApplication {
8+
9+
public static void main(String ... args) {
10+
SpringApplication.run(SpringBootPersistenceApplication.class, args);
11+
}
12+
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spring.application.name=spring-boot-persistence
2+
server.port=${PORT:0}
3+
4+
#spring boot mongodb
5+
spring.data.mongodb.host=localhost
6+
spring.data.mongodb.port=27017
7+
spring.data.mongodb.database=springboot-mongo
8+

spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java renamed to persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
import org.junit.Test;
66
import org.junit.runner.RunWith;
77
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.context.SpringBootTest;
89
import org.springframework.test.context.junit4.SpringRunner;
9-
import static org.assertj.core.api.Assertions.assertThat;
1010

11-
import java.util.List;
11+
import static org.assertj.core.api.Assertions.assertThat;
1212

1313

1414
@RunWith(SpringRunner.class)
15+
@SpringBootTest
1516
public class MongoDbAutoGeneratedFieldIntegrationTest {
1617

1718
@Autowired
18-
private UserRepository userRepository;
19+
UserRepository userRepository;
1920

2021
@Test
2122
public void contextLoads() {}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@
479479
<module>persistence-modules/spring-data-cassandra</module>
480480
<module>persistence-modules/spring-data-couchbase-2</module>
481481
<module>persistence-modules/spring-data-redis</module>
482+
<module>persistence-modules/spring-boot-persistence-mongodb</module>
482483

483484
<module>reactor-core</module>
484485
<module>resteasy</module>

spring-boot/src/main/java/com/baeldung/mongodb/Application.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

spring-boot/src/test/java/com/baeldung/mongodb/MongoDbSpringIntegrationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5+
import org.baeldung.boot.Application;
56
import org.junit.jupiter.api.DisplayName;
67
import org.junit.jupiter.api.Test;
78
import org.junit.jupiter.api.extension.ExtendWith;

0 commit comments

Comments
 (0)