In my Integration test, I have @Shared fields that are loaded from fixtures(Fixtures plugin for grails). Those fields are aliases for the fixture beans. Look at the code I have now!
@TestFor(OrganizationUserService)
class OrganizationUserServiceSpec extends Specification {
def fixtureLoader
@Shared
def fixture
@Shared
def activeOrganizationOne
@Shared
def activeChild1
def setup() {
fixture = fixtureLoader.load {
build {
activeOrganizationOne(Organization) {
name = "Active Organization"
active = true
parent = null
}
activeChild1(Organization) {
name = "Active Child One"
active = true
parent = activeOrganizationOne
}
}
activeOrganizationOne = fixture.activeOrganizationOne
activeChild1 = fixture.activeChild1
}
void "deactivateOrganization deactivates an organization and all its children"() {
given:
service.organizationService = new OrganizationService()
service.userService = new UserService()
when:
service.deactivateOrganization(activeOrganizationOne)
//the above method deactivates activeOrganizationOne and activeChild1
//and activeChild1 will have a disableReason = PARENT_DEACTIVATION
then:
!activeOrganizationOne.active
!activeChild1.active
DisableReason.PARENT_DEACTIVATION.toString() == activeChild1.disableReason.toString()
}
}
Surprising it is for me that it works. activeChild1 is found by the service method via GORM request. How is it then the @Shared object in the test class modified?
To explain more, deactivateOrganization gets the childs of the organization using Organization.findAllByParent(org). In which org is the parameter passed to deactivateOrganization. if deactivateOrganization only modifies the objects that are returned from the GORM call, then how does @shared fields in the test catch the change? I didn't refresh anything.
I am on Grails 2.3.11 and running with mongoDB.
I am trying to create a standard on how to right Integration tests. So, I want to know the right way to work with fixtures and Integration tests.
Thanks In Advance;