以下のテストは 1 つの環境で正常に動作しますが、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}";
}
}