Skip to content

Commit bcbacf9

Browse files
author
Thomas Risberg
committed
DATADOC-48 added more complexity to test
1 parent c5c8a78 commit bcbacf9

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/CrossStoreMongoTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.junit.runner.RunWith;
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.data.document.mongodb.MongoTemplate;
11+
import org.springframework.data.document.persistence.test.Address;
1112
import org.springframework.data.document.persistence.test.Person;
1213
import org.springframework.data.document.persistence.test.Resume;
1314
import org.springframework.test.annotation.Rollback;
@@ -52,6 +53,8 @@ private void clearData(String collectionName) {
5253
public void testCreateJpaToMongoEntityRelationship() {
5354
clearData(Person.class.getName());
5455
Person p = new Person("Thomas", 20);
56+
Address a = new Address(12, "MAin St.", "Boston", "MA", "02101");
57+
p.setAddress(a);
5558
Resume r = new Resume();
5659
r.addEducation("Skanstulls High School, 1975");
5760
r.addEducation("Univ. of Stockholm, 1980");

spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/test/Person.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ public class Person {
1818
private java.util.Date birthDate;
1919

2020
@RelatedDocument
21-
public Resume resume;
21+
private Address address;
22+
23+
@RelatedDocument
24+
private Resume resume;
2225

2326
public Person() {
2427
}
@@ -73,4 +76,12 @@ public void setResume(Resume resume) {
7376
this.resume = resume;
7477
}
7578

79+
public Address getAddress() {
80+
return address;
81+
}
82+
83+
public void setAddress(Address address) {
84+
this.address = address;
85+
}
86+
7687
}

spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/test/Resume.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
import org.apache.commons.logging.Log;
44
import org.apache.commons.logging.LogFactory;
5+
import org.bson.types.ObjectId;
6+
import org.springframework.data.annotation.Id;
7+
import org.springframework.data.document.mongodb.mapping.Document;
58

6-
//@DocumentEntity
9+
@Document
710
public class Resume {
811

912
private static final Log LOGGER = LogFactory.getLog(Resume.class);
1013

14+
@Id
15+
private ObjectId id;
16+
1117
private String education = "";
1218

1319
private String jobs = "";
1420

21+
public String getId() {
22+
return id.toString();
23+
}
24+
1525
public String getEducation() {
1626
return education;
1727
}

spring-data-mongodb-cross-store/src/test/resources/META-INF/spring/applicationContext.xml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns:tx="http://www.springframework.org/schema/tx"
5-
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
6-
xmlns:context="http://www.springframework.org/schema/context"
7-
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:tx="http://www.springframework.org/schema/tx"
5+
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
6+
xmlns:context="http://www.springframework.org/schema/context"
7+
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
8+
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
9+
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
810
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
9-
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
10-
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
11+
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
12+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
1113

1214
<context:spring-configured/>
1315

1416
<context:component-scan base-package="org.springframework.persistence.test">
1517
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
1618
</context:component-scan>
1719

20+
<mongo:mapping-converter/>
21+
1822
<!-- Mongo config -->
1923
<bean id="mongo" class="org.springframework.data.document.mongodb.MongoFactoryBean">
2024
<property name="host" value="localhost"/>
@@ -24,6 +28,8 @@
2428
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
2529
<constructor-arg name="mongo" ref="mongo"/>
2630
<constructor-arg name="databaseName" value="test"/>
31+
<constructor-arg name="defaultCollectionName" value="cross-store"/>
32+
<constructor-arg name="mongoConverter" ref="mappingConverter"/>
2733
</bean>
2834

2935
<bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator"/>

0 commit comments

Comments
 (0)