I have a Groovy domain like this:
package fantasy
class Notification {
enum NotificationType {
INVITE_GENERAL, INVITE_CONTEST
}
NotificationType type
String emailTo
User toUser
User fromUser
String message
boolean wasReadByToUser
boolean wasReadByFromUser
boolean fromUserRemoved
Date dateCreated
static constraints = {
type(blank: false)
toUser(nullable: true)
emailTo(email: true, blank: false)
}
static mapping = {
autoTimestamp true
}
}
And I need to access a notification type in a Grails.Groovy/Spock test...
How can I get at the Enum, as I've tried just about everything I can do. Here is my test so far:
package fantasy
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(Notification)
@Mock([Notification, User])
class NotificationSpec extends Specification {
// Notification
Notification notification
// *** Here is my issue *** //
Notification.NotificationType type = Notification.NotificationType.INVITE_CONTEST
// Fields
String emailTo = "fmulder@fox.com"
String message = "Trust No One"
boolean wasReadByUser = false
boolean wasReadByFromUser = false
boolean fromUserRemoved = false
// Date
Date dateCreated
// Mocks
def toUser
def fromUser
def setup() {
toUser = Mock(User)
fromUser = Mock(User)
dateCreated = new Date()
}
def cleanup() {
toUser = null
fromUser = null
dateCreated = null
}
void "test valid entry will validate"() {
setup:
notification = new Notification(
type: type,
emailTo: "danaScully@fox.com",
toUser: toUser,
fromUser: fromUser,
message: message,
wasReadByUser: false,
wasReadByFromUser: false,
fromUserRemoved: false,
dateCreated: dateCreated
).save(failOnError: false, flush: true)
expect:
Notification.count() == 1
notification.validate()
}
}
How can I access that inner Enum?
Aucun commentaire:
Enregistrer un commentaire