我想测试我的安全the服务如下:
有人能给我一些提示吗?我不知道如何访问grails安全服务,以及如何在登录和不登录时对我的控制器运行测试。此外,我需要一些模拟服务器或其他东西来测试我的控制器或?
对不起,我对这个话题非常陌生,但我想在失去对我的new服务的控制之前,朝着正确的方向前进。
谢谢你的帮助!
发布于 2011-08-17 14:30:31
我们使用REST客户机插件和功能测试插件来测试我们的所有web服务。
例如..。
void testCreateTag() {
def name = 'Test Name'
def jsonText = """
{
"class":"Tag",
"name":"${name}"
}
"""
post('/api/tag') {
headers['x-user-external-id'] = securityUser.externalId
headers['x-user-api-key'] = securityUser.apiKey
headers['Content-type'] = 'application/json'
body {
jsonText
}
}
def model = this.response.contentAsString
def map = JSON.parse(model)
assertNotNull(map.attributes.id)
Tag.withNewSession {
def tag = Tag.get(map.attributes.id)
assertNotNull(tag)
assertEquals(name, tag.name)
}
}发布于 2012-10-04 15:53:16
我有类似的代码,它使用内置的(groovy1.8) JsonSlurper,我认为它可能更可靠,只需要功能测试插件,而不需要REST客户端插件。
String baseUrlString = 'http://localhost:8080/**YOURAPP**'
baseURL = baseUrlString
post('/j_spring_security_check?')
assertStatus 200
assertContentDoesNotContain('Access Denied')
get("/*your test URL*/")
def jsonObj = new JsonSlurper().parseText(this.response.contentAsString)
assertEquals(jsonObj.your.object.model, **yourContent**)https://stackoverflow.com/questions/7093696
复制相似问题