[英]Trouble in integration test finding resource
我正在使用 Grails 1.3.6。 我的服务中有此代码...
if (folder) {
path = "json/${folder}/${page}.json"
} else {
path = "json/${page}.json"
} // if
def file = ApplicationHolder.application.parentContext.getResource(path).getFile();
通常该文件是从 web-app/json 目录中正确检索的,但是当我运行集成测试(通过 grails 测试应用程序)时,上述代码在尝试检索资源时失败(“java.io.FileNotFoundException: ZA2F98ED07A4D5F50F7DE1410D905F1477FZ.FileNotFoundException: ZA2F98ED07A4D5F50F7DE1410D905F1477FZ.FileNotFoundException: ZA2F98ED07A4D5F50F7DE1410D905F1477FZ.FileNotFoundException: ZA2F98ED07A4D905F1477FZ.FileNotFoundException: ZA2F98ED07A4A2C资源 [json/index.json] 无法解析为 URL,因为它不存在”)。 下面是我的集成测试。 我如何告诉它在哪里可以找到资源?
谢谢, - 戴夫
class HomeControllerTests extends GroovyTestCase {
...
void testGetAllJSON() {
def controller = new HomeController()
// Call action without any parameters
controller.index()
def responseStr = controller.response.contentAsString
assertTrue( isValidJSON(responseStr) )
}
这可能是因为测试与 web 应用程序的上下文路径不同。 尝试使用资源标签:
if (folder) {
path = "${resource(dir:'json',file:"${folder}/${page}.json")}"
} else {
path = "${resource(dir:'json',file:"${page}.json")}"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.