From 60f9b05760bd66c36f6e13f635509165c265beac Mon Sep 17 00:00:00 2001 From: Thomas Risberg Date: Wed, 9 Mar 2011 16:29:12 -0500 Subject: [PATCH] DATADOC-48 added additional tests for cross-store --- spring-data-document-core/.classpath | 28 ++++--- .../.settings/org.eclipse.jdt.core.prefs | 18 ++--- ....eclipse.wst.common.project.facet.core.xml | 10 +-- .../persistence/CrossStoreMongoTests.java | 43 +++++++++-- .../persistence/document/test/Person.java | 76 +++++++++++++++++++ .../persistence/document/test/Resume.java | 33 ++++++++ spring-data-mongodb/.classpath | 6 +- .../.settings/org.eclipse.jdt.core.prefs | 18 ++--- ....eclipse.wst.common.project.facet.core.xml | 10 +-- 9 files changed, 193 insertions(+), 49 deletions(-) create mode 100644 spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Person.java create mode 100644 spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Resume.java diff --git a/spring-data-document-core/.classpath b/spring-data-document-core/.classpath index 6019b8317..1da667f53 100644 --- a/spring-data-document-core/.classpath +++ b/spring-data-document-core/.classpath @@ -1,12 +1,16 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/spring-data-document-core/.settings/org.eclipse.jdt.core.prefs b/spring-data-document-core/.settings/org.eclipse.jdt.core.prefs index 41cf44aec..aa62685f0 100644 --- a/spring-data-document-core/.settings/org.eclipse.jdt.core.prefs +++ b/spring-data-document-core/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ -#Thu Oct 14 10:28:37 EDT 2010 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.5 +#Wed Mar 09 13:51:17 EST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/spring-data-document-core/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-data-document-core/.settings/org.eclipse.wst.common.project.facet.core.xml index f66a2079b..5c9bd7532 100644 --- a/spring-data-document-core/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/spring-data-document-core/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ - - - - - + + + + + diff --git a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/CrossStoreMongoTests.java b/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/CrossStoreMongoTests.java index fb95f51d1..137ea7eaf 100644 --- a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/CrossStoreMongoTests.java +++ b/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/CrossStoreMongoTests.java @@ -10,10 +10,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.document.mongodb.MongoTemplate; import org.springframework.persistence.document.test.Account; import org.springframework.persistence.document.test.MongoPerson; +import org.springframework.persistence.document.test.Person; +import org.springframework.persistence.document.test.Resume; import org.springframework.test.annotation.Rollback; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.transaction.annotation.Transactional; import com.mongodb.DBCollection; @@ -42,10 +43,10 @@ public class CrossStoreMongoTests { this.entityManager = entityManager; } - private void clearData() { - DBCollection col = this.mongoTemplate.getCollection(colName); + private void clearData(String collectionName) { + DBCollection col = this.mongoTemplate.getCollection(collectionName); if (col != null) { - this.mongoTemplate.dropCollection(colName); + this.mongoTemplate.dropCollection(collectionName); } } @@ -53,7 +54,7 @@ public class CrossStoreMongoTests { @Transactional @Rollback(false) public void testUserConstructor() { - clearData(); + clearData(colName); int age = 33; MongoPerson p = new MongoPerson("Thomas", age); Assert.assertEquals(age, p.getAge()); @@ -76,8 +77,8 @@ public class CrossStoreMongoTests { @Test @Transactional @Rollback(false) - public void testCreateJpaEntity() { - clearData(); + public void testCreateMongoToJpaEntityRelationship() { + clearData(colName); Account a = new Account(); a.setName("My Account"); a.setFriendlyName("My Test Acct."); @@ -90,7 +91,7 @@ public class CrossStoreMongoTests { @Test @Transactional - public void testReadJpaEntity() { + public void testReadMongoToJpaEntityRelationship() { DBCollection col = this.mongoTemplate.getCollection(colName); DBCursor dbc = col.find(); Object _id = null; @@ -108,4 +109,30 @@ public class CrossStoreMongoTests { System.out.println(found.getAccount()); } + @Test + @Transactional + @Rollback(false) + public void testCreateJpaToMongoEntityRelationship() { + clearData("resume"); + Person p = new Person("Thomas", 20); + Resume r = new Resume(); + r.addEducation("Skanstulls High School, 1975"); + r.addEducation("Univ. of Stockholm, 1980"); + r.addJob("DiMark, DBA, 1990-2000"); + r.addJob("VMware, Developer, 2007-"); + p.setResume(r); + p.setId(1L); + entityManager.persist(p); + } + + @Test + @Transactional + public void testReadJpaToMongoEntityRelationship() { + Person found = entityManager.find(Person.class, 1L); + System.out.println(found); +// TODO: This part isn't working yet - there is no reference to the Momgo _id stored in the db +// if (found != null) +// System.out.println(found.getResume()); + } + } diff --git a/spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Person.java b/spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Person.java new file mode 100644 index 000000000..070fa11e3 --- /dev/null +++ b/spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Person.java @@ -0,0 +1,76 @@ +package org.springframework.persistence.document.test; + +import javax.persistence.Entity; +import javax.persistence.Id; + +import org.springframework.persistence.RelatedEntity; + +@Entity +public class Person { + + @Id Long id; + + private String name; + + private int age; + + private java.util.Date birthDate; + +// @Document // need to decide what the annotation here should be + @RelatedEntity + public Resume resume; + + public Person() { + } + + public Person(String name, int age) { + this.name = name; + this.age = age; + this.birthDate = new java.util.Date(); + } + + public void birthday() { + ++age; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public java.util.Date getBirthDate() { + return birthDate; + } + + public void setBirthDate(java.util.Date birthDate) { + this.birthDate = birthDate; + } + + public Resume getResume() { + return resume; + } + + public void setResume(Resume resume) { + this.resume = resume; + } + +} diff --git a/spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Resume.java b/spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Resume.java new file mode 100644 index 000000000..dc751afb4 --- /dev/null +++ b/spring-data-mongodb-cross-store/src/test/java/org/springframework/persistence/document/test/Resume.java @@ -0,0 +1,33 @@ +package org.springframework.persistence.document.test; + +import org.springframework.persistence.document.DocumentEntity; + +@DocumentEntity +public class Resume { + + private String education = ""; + + private String jobs = ""; + + public String getEducation() { + return education; + } + + public void addEducation(String education) { + this.education = this.education + (this.education.length() > 0 ? "; " : "") + education; + } + + public String getJobs() { + return jobs; + } + + public void addJob(String job) { + this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job; + } + + @Override + public String toString() { + return "Resume [education=" + education + ", jobs=" + jobs + "]"; + } + +} diff --git a/spring-data-mongodb/.classpath b/spring-data-mongodb/.classpath index 201f4e3fc..40f8440e7 100644 --- a/spring-data-mongodb/.classpath +++ b/spring-data-mongodb/.classpath @@ -4,12 +4,16 @@ - + + + + + diff --git a/spring-data-mongodb/.settings/org.eclipse.jdt.core.prefs b/spring-data-mongodb/.settings/org.eclipse.jdt.core.prefs index cdc6b1939..b3ef56f5a 100644 --- a/spring-data-mongodb/.settings/org.eclipse.jdt.core.prefs +++ b/spring-data-mongodb/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ -#Thu Oct 14 10:28:36 EDT 2010 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.5 +#Wed Mar 09 13:51:37 EST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/spring-data-mongodb/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-data-mongodb/.settings/org.eclipse.wst.common.project.facet.core.xml index f66a2079b..5c9bd7532 100644 --- a/spring-data-mongodb/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/spring-data-mongodb/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ - - - - - + + + + +