clean and upgrade
This commit is contained in:
parent
9c544345b3
commit
86c9b89ed9
|
@ -31,13 +31,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>mongodb-driver-reactivestreams</artifactId>
|
<artifactId>mongodb-driver-reactivestreams</artifactId>
|
||||||
<version>1.9.2</version>
|
<version>${mongodb-reactivestreams.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.projectreactor</groupId>
|
<groupId>io.projectreactor</groupId>
|
||||||
<artifactId>reactor-test</artifactId>
|
<artifactId>reactor-test</artifactId>
|
||||||
<version>3.2.0.RELEASE</version>
|
<version>${projectreactor.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@
|
||||||
<querydsl.version>4.1.4</querydsl.version>
|
<querydsl.version>4.1.4</querydsl.version>
|
||||||
<mysema.maven.version>1.1.3</mysema.maven.version>
|
<mysema.maven.version>1.1.3</mysema.maven.version>
|
||||||
<spring.version>5.1.0.RELEASE</spring.version>
|
<spring.version>5.1.0.RELEASE</spring.version>
|
||||||
|
<mongodb-reactivestreams.version>1.9.2</mongodb-reactivestreams.version>
|
||||||
|
<projectreactor.version>3.2.0.RELEASE</projectreactor.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.data.mongodb.MongoDbFactory;
|
import org.springframework.data.mongodb.MongoDbFactory;
|
||||||
import org.springframework.data.mongodb.MongoTransactionManager;
|
import org.springframework.data.mongodb.MongoTransactionManager;
|
||||||
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
|
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
|
||||||
import org.springframework.data.mongodb.core.convert.CustomConversions;
|
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||||
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
||||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||||
|
|
||||||
|
@ -50,9 +50,9 @@ public class MongoConfig extends AbstractMongoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomConversions customConversions() {
|
public MongoCustomConversions customConversions() {
|
||||||
converters.add(new UserWriterConverter());
|
converters.add(new UserWriterConverter());
|
||||||
return new CustomConversions(converters);
|
return new MongoCustomConversions(converters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -40,11 +40,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import com.baeldung.aggregation.model.StatePopulation;
|
import com.baeldung.aggregation.model.StatePopulation;
|
||||||
import com.baeldung.config.MongoConfig;
|
import com.baeldung.config.MongoConfig;
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
import com.mongodb.util.JSON;
|
import com.mongodb.client.MongoCollection;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = MongoConfig.class)
|
@ContextConfiguration(classes = MongoConfig.class)
|
||||||
|
@ -58,23 +56,22 @@ public class ZipsAggregationLiveTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setupTests() throws Exception {
|
public static void setupTests() throws Exception {
|
||||||
client = new MongoClient();
|
client = new MongoClient();
|
||||||
DB testDB = client.getDB("test");
|
MongoDatabase testDB = client.getDatabase("test");
|
||||||
DBCollection zipsCollection = testDB.getCollection("zips");
|
MongoCollection<Document> zipsCollection = testDB.getCollection("zips");
|
||||||
zipsCollection.drop();
|
zipsCollection.drop();
|
||||||
|
|
||||||
InputStream zipsJsonStream = ZipsAggregationLiveTest.class.getResourceAsStream("/zips.json");
|
InputStream zipsJsonStream = ZipsAggregationLiveTest.class.getResourceAsStream("/zips.json");
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(zipsJsonStream));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(zipsJsonStream));
|
||||||
reader.lines()
|
reader.lines()
|
||||||
.forEach(line -> zipsCollection.insert((DBObject) JSON.parse(line)));
|
.forEach(line -> zipsCollection.insertOne(Document.parse(line)));
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDown() throws Exception {
|
public static void tearDown() throws Exception {
|
||||||
client = new MongoClient();
|
client = new MongoClient();
|
||||||
DB testDB = client.getDB("test");
|
MongoDatabase testDB = client.getDatabase("test");
|
||||||
DBCollection zipsCollection = testDB.getCollection("zips");
|
MongoCollection<Document> zipsCollection = testDB.getCollection("zips");
|
||||||
zipsCollection.drop();
|
zipsCollection.drop();
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,10 +205,9 @@ public class GridFSLiveTest {
|
||||||
DBObject metaData = new BasicDBObject();
|
DBObject metaData = new BasicDBObject();
|
||||||
metaData.put("user", "alex");
|
metaData.put("user", "alex");
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
String id = "";
|
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream("src/main/resources/test.png");
|
inputStream = new FileInputStream("src/main/resources/test.png");
|
||||||
id = gridFsTemplate.store(inputStream, "test.png", "image/png", metaData).toString();
|
gridFsTemplate.store(inputStream, "test.png", "image/png", metaData).toString();
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
logger.error("File not found", ex);
|
logger.error("File not found", ex);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.baeldung.mongotemplate;
|
package com.baeldung.mongotemplate;
|
||||||
|
|
||||||
import com.baeldung.config.MongoConfig;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import com.baeldung.model.EmailAddress;
|
import static org.junit.Assert.assertThat;
|
||||||
import com.baeldung.model.User;
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -17,11 +20,9 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import com.baeldung.config.MongoConfig;
|
||||||
import java.util.List;
|
import com.baeldung.model.EmailAddress;
|
||||||
|
import com.baeldung.model.User;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = MongoConfig.class)
|
@ContextConfiguration(classes = MongoConfig.class)
|
||||||
|
@ -152,7 +153,7 @@ public class DocumentQueryLiveTest {
|
||||||
user.setAge(35);
|
user.setAge(35);
|
||||||
mongoTemplate.insert(user);
|
mongoTemplate.insert(user);
|
||||||
|
|
||||||
final Pageable pageableRequest = new PageRequest(0, 2);
|
final Pageable pageableRequest = PageRequest.of(0, 2);
|
||||||
Query query = new Query();
|
Query query = new Query();
|
||||||
query.with(pageableRequest);
|
query.with(pageableRequest);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.baeldung.mongotemplate;
|
package com.baeldung.mongotemplate;
|
||||||
|
|
||||||
import com.baeldung.config.MongoConfig;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import com.baeldung.model.EmailAddress;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import com.baeldung.model.User;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -20,11 +23,9 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.util.List;
|
import com.baeldung.config.MongoConfig;
|
||||||
|
import com.baeldung.model.EmailAddress;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import com.baeldung.model.User;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = MongoConfig.class)
|
@ContextConfiguration(classes = MongoConfig.class)
|
||||||
|
@ -104,7 +105,7 @@ public class MongoTemplateQueryLiveTest {
|
||||||
user.setAge(35);
|
user.setAge(35);
|
||||||
mongoTemplate.insert(user);
|
mongoTemplate.insert(user);
|
||||||
|
|
||||||
final Pageable pageableRequest = new PageRequest(0, 2);
|
final Pageable pageableRequest = PageRequest.of(0, 2);
|
||||||
Query query = new Query();
|
Query query = new Query();
|
||||||
query.with(pageableRequest);
|
query.with(pageableRequest);
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class UserRepositoryLiveTest {
|
||||||
user.setName("Adam");
|
user.setName("Adam");
|
||||||
mongoOps.insert(user);
|
mongoOps.insert(user);
|
||||||
|
|
||||||
final Pageable pageableRequest = new PageRequest(0, 1);
|
final Pageable pageableRequest = PageRequest.of(0, 1);
|
||||||
|
|
||||||
final Page<User> page = userRepository.findAll(pageableRequest);
|
final Page<User> page = userRepository.findAll(pageableRequest);
|
||||||
List<User> users = page.getContent();
|
List<User> users = page.getContent();
|
||||||
|
|
Loading…
Reference in New Issue