Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor: use GrailsClassUtil and GrailsDomainConfigurationUtil to ev…
…aluate domain model
  • Loading branch information
ohneda committed Jul 4, 2011
1 parent 864deb0 commit 3f4f910
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
Expand Up @@ -5,6 +5,8 @@ import java.lang.reflect.Field;
import org.msgpack.template.BeansFieldEntry;
import org.msgpack.template.FieldOption;
import org.msgpack.template.FieldOptionReader;
import static org.codehaus.groovy.grails.commons.GrailsClassUtils.*
import static org.codehaus.groovy.grails.commons.GrailsDomainConfigurationUtil.*

@Singleton
public class DomainModelFieldOptionReader implements FieldOptionReader {
Expand All @@ -17,11 +19,13 @@ public class DomainModelFieldOptionReader implements FieldOptionReader {
return FieldOption.OPTIONAL
}

if(targetClass.constraints."${entry.name}"?.nullable){
def constraints = evaluateConstraints(targetClass)
if(constraints?."${entry.name}"?.nullable){
return FieldOption.OPTIONAL
}

if(targetClass.transients.contains(entry.name)){
def transients = getStaticPropertyValue(targetClass, 'transients')
if(transients?.contains(entry.name)){
return FieldOption.IGNORE
}

Expand Down
Expand Up @@ -81,25 +81,6 @@ class DomainModelFieldOptionReaderSpec extends IntegrationSpec {
'isPublic' | FieldOption.DEFAULT
}

def 'a collection field is treated as Optional even if it has no constraints'(){

given:
def field = mock(BeansFieldEntry)
field.name.returns(fieldName).stub()
FieldOption result
play{
result = reader.read( msgpack.Message, field, FieldOption.DEFAULT )
}

expect:
result == option

where:
fieldName | option
'props' | FieldOption.OPTIONAL
'comments' | FieldOption.OPTIONAL
}

def 'id field and version field, which is added by grails, is treated as Optional'(){

given:
Expand Down

0 comments on commit 3f4f910

Please sign in to comment.