Permalink
Browse files

Adding some test examples

  • Loading branch information...
1 parent e90ee53 commit 744b62cb0e48af7d3051e88e93dff7e1977fedc2 @JarredOlson committed Jul 8, 2011
@@ -0,0 +1,28 @@
+package polyglot.setup
+
+import org.junit.Test
+
+
+class ProjectPositionIntegrationTests extends GroovyTestCase {
+
+ @Test
+ void hibernateFromAnIntegrationTest() {
+ def project = new Project(name: "Project 1", startDate: new Date() -2, endDate: new Date())
+ def position1 = new ProjectPosition(name: "ProjectPosition 1", project: project, startDate: new Date() - 2, endDate: new Date(), hoursPerDay: 8.0)
+ def position2 = new ProjectPosition(name: "ProjectPosition 2", project: project, startDate: new Date() - 2, endDate: new Date(), hoursPerDay: 8.0)
+ /*
+ From an integration test, instead of calling mockDomain as you would from a unit test, you simply save the objects.
+ One drawback is your domain objects have to be valid as far as your domain constraints and database constraints are concerned.
+ Adding failOnError:true to your save call will throw an exception if your object is invalid.
+ */
+ project.save(failOnError:true)
+ position1.save(failOnError:true)
+ position2.save(failOnError:true)
+
+ def hibernateResults = ProjectPosition.findAllByProject(project)
+
+ assert 2 == hibernateResults.size()
+ assert "ProjectPosition 1" == hibernateResults[0].name
+ assert "ProjectPosition 2" == hibernateResults[1].name
+ }
+}
@@ -51,21 +51,27 @@ class ProjectPositionTests extends GrailsUnitTestCase {
}
@Test
- void someMetaClassingStuff() {
- Date date = new Date()
- date.metaClass.someNewCoolMethodThatReturnsMyName = {return "Jarred"}
- assert Date.class == date.getClass()
- assert "Jarred" == date.someNewCoolMethodThatReturnsMyName()
- assert Date.class == date.getClass()
+ void instanceLevelMetaClassingWillOnlyApplyToTheInstanceBeingMetaClassed() {
+ Date date1 = new Date()
+ date1.metaClass.someNewCoolMethodThatReturnsMyName = {return "Jarred"}
+ assert "Jarred" == date1.someNewCoolMethodThatReturnsMyName()
+ assert Date.class == date1.getClass()
+ Date date2 = new Date()
+ try {
+ date2.someNewCoolMethodThatReturnsMyName()
+ fail "should not get here"
+ } catch (Exception ex) {}
}
@Test
- void someMetaClassingStuff2() {
+ void classLevelMetaClassingWillApplyToAllInstanceOfTheTypeBeingMetaClassed() {
Date.metaClass.'static'.someNewCoolMethodThatReturnsMyName = {return "Jarred"}
- Date date = new Date()
- assert Date.class == date.getClass()
- assert "Jarred" == date.someNewCoolMethodThatReturnsMyName()
- assert Date.class == date.getClass()
+
+ Date date1 = new Date()
+ assert "Jarred" == date1.someNewCoolMethodThatReturnsMyName()
+ Date date2 = new Date()
+ assert "Jarred" == date2.someNewCoolMethodThatReturnsMyName()
+ assert Date.class == date1.getClass()
}
@Test

0 comments on commit 744b62c

Please sign in to comment.