Grails2.5.0-针对RESTful服务与spring安全性的集成测试

Grails2.5.0-针对RESTful服务与spring安全性的集成测试,grails,spring-security,Grails,Spring Security,我想测试GrailsWeb应用程序的安全性,确保只有某些角色可以发布,并且给出了正确的响应。我在集成测试中有以下内容: class MyIntegrationSpec extends IntegrationSpec { def grailsApplication def testdataService def setup() { testdataService.addTestData() SpringSecurityUtils.reaut

我想测试GrailsWeb应用程序的安全性,确保只有某些角色可以发布,并且给出了正确的响应。我在集成测试中有以下内容:

class MyIntegrationSpec extends IntegrationSpec {
    def grailsApplication
    def testdataService

    def setup() {
        testdataService.addTestData()
        SpringSecurityUtils.reauthenticate 'user1', null
    }

    def cleanup() {
    }

    void "test case"() {
        given:
        RestBuilder rest = new RestBuilder()

        when:
        RestResponse response = rest.post("http://localhost:8080/${grailsApplication.metadata.'app.name'}/mycontroller/myaction") {
            json([
                    data1: "foo",
                    data2: "bar"
            ])
        }

        then:
        response.status == 200
    }
}
不幸的是,集成测试是在Spring Security启动之前运行的,我得到以下错误:

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8080/myapp/mycontroller/myaction":Connection refused: connect; nested exception is java.net.ConnectException

如何运行集成测试,以便测试用户的体验,尤其是安全性?

web服务器没有启动进行集成测试。Spring应用程序上下文已启动,插件处于活动状态,默认情况下内存中有一个真实的数据库可用,但您可以将其配置为指向服务器等,但不指向web服务器

如果要测试需要运行web服务器的安全性和其他功能,则需要使用功能测试。我用过,它很好,但有点车。我使用了1.2.7版,但我看到现在有了2.0版,所以可能会更好