Grails IntegrationSpec IllegalStateException

笑着哭i 提交于 2019-12-10 10:29:58

问题


After upgrading to 2.4.2 from 2.4.0, I am getting an error when I run my integration tests. It shows that the tests passed, however I am getting an IllegalStateException.

    Failure:  |
massemailsystem.UserInformationIntegrationSpec
 |
java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
    at grails.util.Holders.getApplicationContext(Holders.java:97)
    at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)

I tried to analyze the tests and I don't see anything out of the ordinary. Heres the full test. I am testing getting information from an LDAP data source

abstract class DirectoryIntegrationSpec extends IntegrationSpec {

    DirContextOperations getContext(Map attrs) {
        DirContextAdapter d = new DirContextAdapter()
        attrs.each { k, v ->
            if (v != null) {
                d.addAttributeValue(k, v)
            }
        }
        d
    }
}


class UserInformationIntegrationSpec extends DirectoryIntegrationSpec {

    def dataSource

    def setup() {
        new SPRIDEN(pidm: 100, yNumber: 'Y00100', lastName: 'Smith').save(flush: true, failOnError: true)
        new SPBPERS(pidm: 100, prefFirstName: 'Joe', activityDate: new Date(), armedServMedVetInd: 'N').save(flush: true, failOnError: true)
        new SPRTELE(pidm: 100, seqNo: 1, teleCode: 'CE', activityDate: new Date(), primaryInd: 'Y', phoneArea: '330', phoneNumber: '1234567').save(flush: true, failOnError: true)

        new SPRIDEN(pidm: 102, yNumber: 'Y00102', lastName: 'Smith').save(flush: true, failOnError: true)
        new SPRTELE(pidm: 102, seqNo: 1, teleCode: 'CE', activityDate: new Date(), primaryInd: 'Y', phoneArea: '330', phoneNumber: '1234567').save(flush: true, failOnError: true)

        new SPRIDEN(pidm: 103, yNumber: 'Y00103', lastName: 'Smith').save(flush: true, failOnError: true)
    }

    def cleanup() {
    }

    @Unroll
    void "test constructor from LDAP for fake #employeeid"() {
        when:
        def context = getContext([employeeid: employeeid, givenname: firstName, sn: lastName, mail: email])
        UserInformation u = new UserInformation(context, username, dataSource)

        then:
        u.id == id
        u.firstName == prefFirstName
        u.lastName == lastName
        u.email == email
        u.phone == phone
        u.department == department
        u.username == username

        where:
        employeeid | username | id   | firstName | prefFirstName | lastName | email            | phone            | department
        'Y00100'   | 'jsmith' | 100  | 'Joseph'  | 'Joe'         | 'Smith'  | 'jsmith@ysu.edu' | '(330) 123-4567' | null
        "Y00101"   | null     | null | null      | null          | null     | null             | null             | null
        "Y00102"   | 'jsmith' | 102  | 'Joseph'  | 'Joseph'      | 'Smith'  | 'jsmith@ysu.edu' | '(330) 123-4567' | null
        "Y00103"   | 'jsmith' | 103  | 'Joseph'  | 'Joseph'      | 'Smith'  | null             | null             | null
    }
}

Thanks in advance!

EDIT: The test doesn't fail when I run it by itself, only when I run all of my integration tests.


回答1:


Stupid problem on my end here.

The test right before the test was using the @TestFor annotation and extending Specification when it should have been extending IntegrationSpec and not had the annotation at all. I changed this spec from a unit to an integration and I failed to change these things.

What was funny was the test itself worked fine, only tests that ran after it had a problem.



来源:https://stackoverflow.com/questions/24957901/grails-integrationspec-illegalstateexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!