【发布时间】:2012-07-31 16:09:16
【问题描述】:
虽然下面的测试在一个环境中运行良好,但如何修改测试使其不依赖于哪个服务器 getJson() 服务是否正在运行?
我是否需要创建一个模拟 Spring json 对象以便不管域名是什么(在本例中为 http://myapplication)?
@Test
public void jsonResponse() throws Exception
{
URL oracle = new URL("http://myapplication/newJson.json");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
String json;
while ((inputLine = in.readLine()) != null)
json += inputLine;
in.close();
}
My controller class is defined like :
@Controller
@RequestMapping("myservice")
public class Controller {
@RequestMapping(value = "/newJson.json", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String getJson() {
return "{ test:testJson}";
}
}
【问题讨论】:
标签: java json spring spring-mvc junit