Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 9cfb3e8b0c
...
compare: 737807ce05
  • 3 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
2  .gitignore
@@ -11,4 +11,4 @@ bin
*.ipr
*.iws
out
-demo.*
+demo*
View
6 config/codenarc/codenarc.xml
@@ -40,6 +40,9 @@
</ruleset-ref>
<ruleset-ref path='rulesets/imports.xml'>
+ <rule-config name="MisorderedStaticImports">
+ <property name="comesBefore" value="false"/>
+ </rule-config>
</ruleset-ref>
<ruleset-ref path='rulesets/jdbc.xml'>
@@ -52,6 +55,9 @@
</ruleset-ref>
<ruleset-ref path='rulesets/naming.xml'>
+ <rule-config name="FieldName">
+ <property name="ignoreFieldNames" value="log"/>
+ </rule-config>
</ruleset-ref>
<ruleset-ref path='rulesets/security.xml'>
View
33 src/test/groovy/com/awesomecompany/GormTests.groovy
@@ -3,12 +3,16 @@ package com.awesomecompany
import org.codehaus.groovy.grails.orm.hibernate.validation.HibernateDomainClassValidator
import org.junit.Test
import org.junit.runner.RunWith
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import org.springframework.transaction.annotation.Transactional
+import static com.awesomecompany.TestUtil.*
+
/**
* Created with IntelliJ IDEA.
* User: domix
@@ -20,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional
@ContextConfiguration('/schema/appCtx.xml')
@Transactional
class GormTests {
+ private static final Logger log = LoggerFactory.getLogger(GormTests)
@Autowired
ApplicationContext applicationContext
@@ -27,15 +32,11 @@ class GormTests {
@Test
void shouldSavePerson() {
- def person = new Person(
- firstName: 'Domingo',
- lastName: 'Suarez',
- email: 'domingo.suarez@gmail.com'
- )
+ def person = newDemoPerson()
assert person.save()
- def personInDB = Person.findByEmail('domingo.suarez@gmail.com')
- assert personInDB.firstName == 'Domingo'
+ def personInDB = Person.findByEmail(EMAIL)
+ assert FIRST_NAME == personInDB.firstName
}
@Test
@@ -61,4 +62,22 @@ class GormTests {
assert hasErrors
assert !validPerson
}
+
+ @Test
+ void shouldQueryUsingCriteriaWithOneField() {
+ def person = newDemoPerson()
+
+ assert person.save()
+
+
+ def c = Person.withCriteria(uniqueResult: true) {
+ eq 'email', EMAIL
+ }
+
+ log.debug(c.dump())
+
+ assert c
+ assert FIRST_NAME == c.firstName
+ }
+
}
View
22 src/test/groovy/com/awesomecompany/TestUtil.groovy
@@ -0,0 +1,22 @@
+package com.awesomecompany
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: domix
+ * Date: 14/05/12
+ * Time: 00:56
+ * To change this template use File | Settings | File Templates.
+ */
+class TestUtil {
+ static final String EMAIL = 'domingo.suarez@gmail.com'
+ static final String FIRST_NAME = 'Domingo'
+ static final String LAST_NAME = 'Suarez'
+ static Person newDemoPerson() {
+ new Person(
+ firstName: FIRST_NAME,
+ lastName: LAST_NAME,
+ email: EMAIL
+ )
+ }
+
+}
View
41 ...test/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/XGORMNamespaceHandlerTest.groovy
@@ -7,6 +7,10 @@ import org.junit.runner.RunWith
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import org.springframework.transaction.annotation.Transactional
+import org.slf4j.LoggerFactory
+import org.slf4j.Logger
+
+import static com.awesomecompany.TestUtil.*
/**
* Created with IntelliJ IDEA.
@@ -17,19 +21,42 @@ import org.springframework.transaction.annotation.Transactional
*/
@RunWith(SpringJUnit4ClassRunner)
@ContextConfiguration('/schema/appCtx.xml')
+//@ContextConfiguration('/appCtxDefaultGorm.xml')
@Transactional
class XGORMNamespaceHandlerTest {
+ private static final Logger log = LoggerFactory.getLogger(XGORMNamespaceHandlerTest)
+
@Test
void shouldSavePerson() {
- def person = new Person(
- firstName: 'Domingo',
- lastName: 'Suarez',
- email: 'domingo.suarez@gmail.com'
- )
+ def person = newDemoPerson()
+
+ person.save()
+
+ def people = Person.list()
+ assert people
+ log.debug(people.dump())
+
+ def personInDB = Person.findByEmail(EMAIL)
+ assert personInDB
+ assert personInDB.firstName == FIRST_NAME
+
+ }
+
+ @Test
+ void shouldQueryUsingCriteriaWithOneField() {
+ def person = newDemoPerson()
assert person.save()
- def personInDB = Person.findByEmail('domingo.suarez@gmail.com')
- assert personInDB.firstName == 'Domingo'
+
+
+ def c = Person.withCriteria(uniqueResult: true) {
+ eq 'email', EMAIL
+ }
+
+ log.debug(c.dump())
+
+ assert c
+ assert FIRST_NAME == c.firstName
}
@Test
View
4 src/test/resources/appCtxDefaultGorm.xml
@@ -21,7 +21,7 @@
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.h2.Driver"/>
- <property name="url" value="jdbc:h2:demo"/>
+ <property name="url" value="jdbc:h2:demoRaw"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
@@ -45,7 +45,7 @@
message-source-ref="messageSource">
<property name="hibernateProperties">
<util:map>
- <entry key="hibernate.hbm2ddl.auto" value="create"/>
+ <entry key="hibernate.hbm2ddl.auto" value="create-drop"/>
<entry key="hibernate.show_sql" value="true"/>
<entry key="hibernate.format_sql" value="true"/>
</util:map>
View
5 src/test/resources/log4j.properties
@@ -9,7 +9,6 @@ log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.logger.org=ERROR
-log4j.logger.com.awesomecompany=INFO
-
+log4j.logger.com.awesomecompany=DEBUG
# log4j.logger.org.codehaus.groovy.grails.orm=DEBUG
-log4j.logger.org.springframework.validation=DEBUG
+log4j.logger.org.springframework.validation=DEBUG
View
4 src/test/resources/schema/appCtx.xml
@@ -21,7 +21,7 @@
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.h2.Driver"/>
- <property name="url" value="jdbc:h2:demo"/>
+ <property name="url" value="jdbc:h2:demoSchema"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
@@ -47,7 +47,7 @@
<property name="hibernateProperties">
<util:map>
- <entry key="hibernate.hbm2ddl.auto" value="create"/>
+ <entry key="hibernate.hbm2ddl.auto" value="create-drop"/>
<entry key="hibernate.show_sql" value="true"/>
<entry key="hibernate.format_sql" value="true"/>
</util:map>

No commit comments for this range

Something went wrong with that request. Please try again.