Gam*_*mbo 6 rest grails integration-testing
我想测试我的安全Web服务以下内容:
有人可以给我一些提示如何做到这一点?我不知道如何访问grails安全服务以及在登录时何时对我的控制器运行测试.我还需要一些模拟服务器或其他东西来测试我的控制器或?
对不起,我对这个话题很新,但我想在失去对webservices的控制权之前走向正确的方向.
谢谢您的帮助!
我们使用REST Client插件和功能测试插件来测试我们所有的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)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3207 次 |
| 最近记录: |