Java 类com.sun.jersey.api.client.ClientResponse.Status 实例源码

项目:personium-core    文件:AuthzTest.java   
/**
 * LocationヘッダのURLのフラグメントが存在しない場合チェックがfalseを返すこと.
 * @throws UnsupportedEncodingException URLのエラー
 */
@Test
public void LocationヘッダのURLのフラグメントが存在しない場合チェックがfalseを返すこと() throws UnsupportedEncodingException {
    ResponseBuilder rb = Response.status(Status.FOUND).type(MediaType.APPLICATION_JSON_TYPE);
    StringBuilder sbuf = new StringBuilder(UrlUtils.cellRoot("authz") + "?" + OAuth2Helper.Key.ERROR + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.ERROR_DESCRIPTION + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.STATE + "=");
    sbuf.append(URLEncoder.encode("0000000111", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.CODE + "=");
    sbuf.append(URLEncoder.encode("PR503-SV-0002", "utf-8"));
    rb.header(HttpHeaders.LOCATION, sbuf.toString());

    Response res = rb.entity("").build();
    AuthzEndPointResourceMock authz = new AuthzEndPointResourceMock(null, null);
    assertFalse(authz.isSuccessAuthorization(res));
}
项目:personium-core    文件:AuthzEndPointResource.java   
/**
 * ImplicitFlowでの認証時のエラーのうち以下の状況で、ユーザが設定したredirect_uriへのRedirectを実行する. 1.response_typeが不正・未指定 2
 * @param state
 * @return
 * @throws MalformedURLException
 */
private Response returnErrorRedirect(String redirectUri, String error,
        String errorDesp, String state, String code) {
    // 302でレスポンスし、Locationヘッダを返却
    ResponseBuilder rb = Response.status(Status.FOUND)
            .type(MediaType.APPLICATION_JSON_TYPE);
    // Locationヘッダに付加するフラグメント情報をURLエンコードする
    StringBuilder sbuf = new StringBuilder(redirectUri + "#" + OAuth2Helper.Key.ERROR + "=");
    try {
        sbuf.append(URLEncoder.encode(error, "utf-8"));
        sbuf.append("&" + OAuth2Helper.Key.ERROR_DESCRIPTION + "=");
        sbuf.append(URLEncoder.encode(errorDesp, "utf-8"));
        sbuf.append("&" + OAuth2Helper.Key.STATE + "=");
        sbuf.append(URLEncoder.encode(state, "utf-8"));
        sbuf.append("&" + OAuth2Helper.Key.CODE + "=");
        sbuf.append(URLEncoder.encode(code, "utf-8"));
    } catch (UnsupportedEncodingException e) {
        // エンコード種別は固定でutf-8にしているので、ここに来ることはありえない
        log.warn("Failed to URLencode, fragmentInfo of Location header.");
    }
    rb.header(HttpHeaders.LOCATION, sbuf.toString());
    // レスポンスの返却
    return rb.entity("").build();
}
项目:personium-core    文件:AuthzTest.java   
/**
 * LocationヘッダのURLのフラグメントにエラー情報が全て存在する場合チェックがfalseを返すこと.
 * @throws UnsupportedEncodingException URLのエラー
 */
@Test
public void LocationヘッダのURLのフラグメントにエラー情報が全て存在する場合チェックがfalseを返すこと() throws UnsupportedEncodingException {
    ResponseBuilder rb = Response.status(Status.FOUND).type(MediaType.APPLICATION_JSON_TYPE);
    StringBuilder sbuf = new StringBuilder(UrlUtils.cellRoot("authz") + "#" + OAuth2Helper.Key.ERROR + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.ERROR_DESCRIPTION + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.STATE + "=");
    sbuf.append(URLEncoder.encode("0000000111", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.CODE + "=");
    sbuf.append(URLEncoder.encode("PR503-SV-0002", "utf-8"));
    rb.header(HttpHeaders.LOCATION, sbuf.toString());

    Response res = rb.entity("").build();
    AuthzEndPointResourceMock authz = new AuthzEndPointResourceMock(null, null);
    assertFalse(authz.isSuccessAuthorization(res));
}
项目:hadoop    文件:TestRMWebServicesDelegationTokenAuthentication.java   
private void cancelDelegationToken(final String tokenString) throws Exception {

    KerberosTestUtils.doAsClient(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        URL url =
            new URL("http://localhost:8088/ws/v1/cluster/delegation-token");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty(RMWebServices.DELEGATION_TOKEN_HEADER,
          tokenString);
        setupConn(conn, "DELETE", null, null);
        InputStream response = conn.getInputStream();
        assertEquals(Status.OK.getStatusCode(), conn.getResponseCode());
        response.close();
        return null;
      }
    });
  }
项目:hadoop    文件:TestRMWebServices.java   
@Test
public void testInvalidUri() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("cluster").path("bogus")
        .accept(MediaType.APPLICATION_JSON).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());

    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestRMWebServices.java   
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("cluster")
        .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
        response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestRMWebappAuthentication.java   
@Test
public void testSimpleAuth() throws Exception {

  rm.start();

  // ensure users can access web pages
  // this should work for secure and non-secure clusters
  URL url = new URL("http://localhost:8088/cluster");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  try {
    conn.getInputStream();
    assertEquals(Status.OK.getStatusCode(), conn.getResponseCode());
  } catch (Exception e) {
    fail("Fetching url failed");
  }

  if (UserGroupInformation.isSecurityEnabled()) {
    testAnonymousKerberosUser();
  } else {
    testAnonymousSimpleUser();
  }

  rm.stop();
}
项目:hadoop    文件:TestRMWebServicesNodes.java   
@Test
public void testNonexistNodeDefault() throws JSONException, Exception {
  rm.registerNode("h1:1234", 5120);
  rm.registerNode("h2:1235", 5121);
  WebResource r = resource();
  try {
    r.path("ws").path("v1").path("cluster").path("nodes")
        .path("node_invalid:99").get(JSONObject.class);

    fail("should have thrown exception on non-existent nodeid");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    verifyNonexistNodeException(message, type, classname);
  } finally {
    rm.stop();
  }
}
项目:hadoop    文件:TestRMWebServicesAppsModification.java   
@Test
public void testSingleAppState() throws Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  String[] mediaTypes =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  for (String mediaType : mediaTypes) {
    RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
    amNodeManager.nodeHeartbeat(true);
    ClientResponse response =
        this
          .constructWebResource("apps", app.getApplicationId().toString(),
            "state").accept(mediaType).get(ClientResponse.class);
    assertEquals(Status.OK, response.getClientResponseStatus());
    if (mediaType.equals(MediaType.APPLICATION_JSON)) {
      verifyAppStateJson(response, RMAppState.ACCEPTED);
    } else if (mediaType.equals(MediaType.APPLICATION_XML)) {
      verifyAppStateXML(response, RMAppState.ACCEPTED);
    }
  }
  rm.stop();
}
项目:personium-core    文件:AuthzTest.java   
/**
 * LocationヘッダのURLのフラグメントにstateが存在しない場合チェックがtrueを返すこと.
 * @throws UnsupportedEncodingException URLのエラー
 */
@Test
public void LocationヘッダのURLのフラグメントにstateが存在しない場合チェックがtrueを返すこと() throws UnsupportedEncodingException {
    ResponseBuilder rb = Response.status(Status.FOUND).type(MediaType.APPLICATION_JSON_TYPE);
    StringBuilder sbuf = new StringBuilder(UrlUtils.cellRoot("authz") + "#" + OAuth2Helper.Key.ERROR + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.ERROR_DESCRIPTION + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.CODE + "=");
    sbuf.append(URLEncoder.encode("PR503-SV-0002", "utf-8"));
    rb.header(HttpHeaders.LOCATION, sbuf.toString());

    Response res = rb.entity("").build();
    AuthzEndPointResourceMock authz = new AuthzEndPointResourceMock(null, null);
    assertTrue(authz.isSuccessAuthorization(res));
}
项目:personium-core    文件:AuthzTest.java   
/**
 * LocationヘッダのURLのフラグメントにerror_descriptionが存在しない場合チェックがtrueを返すこと.
 * @throws UnsupportedEncodingException URLのエラー
 */
@Test
public void LocationヘッダのURLのフラグメントにerror_descriptionが存在しない場合チェックがtrueを返すこと() throws UnsupportedEncodingException {
    ResponseBuilder rb = Response.status(Status.FOUND).type(MediaType.APPLICATION_JSON_TYPE);
    StringBuilder sbuf = new StringBuilder(UrlUtils.cellRoot("authz") + "#" + OAuth2Helper.Key.ERROR + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.STATE + "=");
    sbuf.append(URLEncoder.encode("0000000111", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.CODE + "=");
    sbuf.append(URLEncoder.encode("PR503-SV-0002", "utf-8"));
    rb.header(HttpHeaders.LOCATION, sbuf.toString());

    Response res = rb.entity("").build();
    AuthzEndPointResourceMock authz = new AuthzEndPointResourceMock(null, null);
    assertTrue(authz.isSuccessAuthorization(res));
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testInvalidAttempt() {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, MAX_APPS + 1);
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId.toString()).path("appattempts")
        .path(appAttemptId.toString())
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
  if (round == 1) {
    assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
    return;
  }
  assertEquals("404 not found expected", Status.NOT_FOUND,
          response.getClientResponseStatus());
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testInvalidContainer() throws Exception {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, 1);
  ContainerId containerId = ContainerId.newContainerId(appAttemptId,
      MAX_APPS + 1);
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId.toString()).path("appattempts")
        .path(appAttemptId.toString()).path("containers")
        .path(containerId.toString())
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
  if (round == 1) {
    assertEquals(
        Status.FORBIDDEN, response.getClientResponseStatus());
    return;
  }
  assertEquals("404 not found expected", Status.NOT_FOUND,
          response.getClientResponseStatus());
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testInvalidUri() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr =
        r.path("ws").path("v1").path("applicationhistory").path("bogus")
          .queryParam("user.name", USERS[round])
          .accept(MediaType.APPLICATION_JSON).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());

    WebServicesTestUtils.checkStringMatch(
      "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr =
        r.path("ws").path("v1").path("applicationhistory")
          .queryParam("user.name", USERS[round])
          .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
      response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
      "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testMultipleAttempts() throws Exception {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId.toString()).path("appattempts")
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  if (round == 1) {
    assertEquals(
        Status.FORBIDDEN, response.getClientResponseStatus());
    return;
  }
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject appAttempts = json.getJSONObject("appAttempts");
  assertEquals("incorrect number of elements", 1, appAttempts.length());
  JSONArray array = appAttempts.getJSONArray("appAttempt");
  assertEquals("incorrect number of elements", 5, array.length());
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testMultipleContainers() throws Exception {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, 1);
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId.toString()).path("appattempts")
        .path(appAttemptId.toString()).path("containers")
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  if (round == 1) {
    assertEquals(
        Status.FORBIDDEN, response.getClientResponseStatus());
    return;
  }
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject containers = json.getJSONObject("containers");
  assertEquals("incorrect number of elements", 1, containers.length());
  JSONArray array = containers.getJSONArray("container");
  assertEquals("incorrect number of elements", 5, array.length());
}
项目:hadoop    文件:TestAMWebServicesJobs.java   
@Test
public void testJobIdNonExist() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs")
        .path("job_0_1234").get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    WebServicesTestUtils.checkStringMatch("exception message",
        "java.lang.Exception: job, job_0_1234, is not found", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
项目:hadoop    文件:TestAMWebServicesJobs.java   
@Test
public void testJobIdInvalid() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs").path("job_foo")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    verifyJobIdInvalid(message, type, classname);
  }
}
项目:personium-core    文件:AuthzTest.java   
/**
 * LocationヘッダのURLのフラグメントにcodeが存在しない場合チェックがtrueを返すこと.
 * @throws UnsupportedEncodingException URLのエラー
 */
@Test
public void LocationヘッダのURLのフラグメントにcodeが存在しない場合チェックがtrueを返すこと() throws UnsupportedEncodingException {
    ResponseBuilder rb = Response.status(Status.FOUND).type(MediaType.APPLICATION_JSON_TYPE);
    StringBuilder sbuf = new StringBuilder(UrlUtils.cellRoot("authz") + "#" + OAuth2Helper.Key.ERROR + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.ERROR_DESCRIPTION + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.STATE + "=");
    sbuf.append(URLEncoder.encode("0000000111", "utf-8"));
    rb.header(HttpHeaders.LOCATION, sbuf.toString());

    Response res = rb.entity("").build();
    AuthzEndPointResourceMock authz = new AuthzEndPointResourceMock(null, null);
    assertTrue(authz.isSuccessAuthorization(res));
}
项目:personium-core    文件:AuthzTest.java   
/**
 * LocationヘッダのURLのフラグメントにerrorが存在しない場合チェックがtrueを返すこと.
 * @throws UnsupportedEncodingException URLのエラー
 */
@Test
public void LocationヘッダのURLのフラグメントにerrorが存在しない場合チェックがtrueを返すこと() throws UnsupportedEncodingException {
    ResponseBuilder rb = Response.status(Status.FOUND).type(MediaType.APPLICATION_JSON_TYPE);
    StringBuilder sbuf = new StringBuilder(UrlUtils.cellRoot("authz") + "#");
    sbuf.append("&" + OAuth2Helper.Key.ERROR_DESCRIPTION + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.STATE + "=");
    sbuf.append(URLEncoder.encode("0000000111", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.CODE + "=");
    sbuf.append(URLEncoder.encode("PR503-SV-0002", "utf-8"));
    rb.header(HttpHeaders.LOCATION, sbuf.toString());

    Response res = rb.entity("").build();
    AuthzEndPointResourceMock authz = new AuthzEndPointResourceMock(null, null);
    assertTrue(authz.isSuccessAuthorization(res));
}
项目:hadoop    文件:TestAMWebServices.java   
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("mapreduce")
        .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
        response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestHsWebServices.java   
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("history")
        .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
        response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestHsWebServicesJobs.java   
@Test
public void testJobIdNonExist() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("history").path("mapreduce").path("jobs")
        .path("job_0_1234").get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    WebServicesTestUtils.checkStringMatch("exception message",
        "java.lang.Exception: job, job_0_1234, is not found", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
项目:hadoop    文件:TestHsWebServicesJobs.java   
@Test
public void testJobIdInvalid() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("history").path("mapreduce").path("jobs")
        .path("job_foo").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    verifyJobIdInvalid(message, type, classname);

  }
}
项目:hadoop    文件:TestHsWebServicesJobs.java   
@Test
public void testJobIdInvalidDefault() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("history").path("mapreduce").path("jobs")
        .path("job_foo").get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    verifyJobIdInvalid(message, type, classname);
  }
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryStateInvalid() throws JSONException, Exception {
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("state", "InvalidState")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringContains(
          "exception message",
          "org.apache.hadoop.mapreduce.v2.api.records.JobState.InvalidState",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "IllegalArgumentException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "java.lang.IllegalArgumentException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryLimitInvalid() throws JSONException, Exception {
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("limit", "-1")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils.checkStringMatch("exception message",
      "java.lang.Exception: limit value must be greater then 0", message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryStartTimeInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("startedTimeBegin", "efsd")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringMatch(
          "exception message",
          "java.lang.Exception: Invalid number format: For input string: \"efsd\"",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryStartTimeEndInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("startedTimeEnd", "efsd")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringMatch(
          "exception message",
          "java.lang.Exception: Invalid number format: For input string: \"efsd\"",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryStartTimeNegative() throws JSONException, Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("startedTimeBegin", String.valueOf(-1000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringMatch("exception message",
          "java.lang.Exception: startedTimeBegin must be greater than 0",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryStartTimeEndNegative() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("startedTimeEnd", String.valueOf(-1000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils.checkStringMatch("exception message",
      "java.lang.Exception: startedTimeEnd must be greater than 0", message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryFinishTimeEndNegative() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("finishedTimeEnd", String.valueOf(-1000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils.checkStringMatch("exception message",
      "java.lang.Exception: finishedTimeEnd must be greater than 0", message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryFinishTimeBeginNegative() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("finishedTimeBegin", String.valueOf(-1000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils.checkStringMatch("exception message",
      "java.lang.Exception: finishedTimeBegin must be greater than 0",
      message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryFinishTimeInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("finishedTimeBegin", "efsd")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringMatch(
          "exception message",
          "java.lang.Exception: Invalid number format: For input string: \"efsd\"",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryFinishTimeEndInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("finishedTimeEnd", "efsd")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils
      .checkStringMatch(
          "exception message",
          "java.lang.Exception: Invalid number format: For input string: \"efsd\"",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestNMWebServicesApps.java   
@Test
public void testNodeAppsUserEmpty() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  try {
    r.path("ws").path("v1").path("node").path("apps").queryParam("user", "")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();

    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    WebServicesTestUtils
        .checkStringMatch(
            "exception message",
            "java.lang.Exception: Error: You must specify a non-empty string for the user",
            message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "BadRequestException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
  }
}
项目:hadoop    文件:TestNMWebServicesApps.java   
@Test
public void testNodeAppsStateInvalid() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  try {
    r.path("ws").path("v1").path("node").path("apps")
        .queryParam("state", "FOO_STATE").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();

    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    verifyStateInvalidException(message, type, classname);
  }
}
项目:hadoop    文件:TestNMWebServicesApps.java   
@Test
public void testNodeAppsStateInvalidDefault() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  try {
    r.path("ws").path("v1").path("node").path("apps")
        .queryParam("state", "FOO_STATE").get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();

    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject msg = response.getEntity(JSONObject.class);
    JSONObject exception = msg.getJSONObject("RemoteException");
    assertEquals("incorrect number of elements", 3, exception.length());
    String message = exception.getString("message");
    String type = exception.getString("exception");
    String classname = exception.getString("javaClassName");
    verifyStateInvalidException(message, type, classname);
  }
}
项目:hadoop    文件:TestNMWebServicesApps.java   
@Test
public void testNodeAppsStateInvalidXML() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  try {
    r.path("ws").path("v1").path("node").path("apps")
        .queryParam("state", "FOO_STATE").accept(MediaType.APPLICATION_XML)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();

    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
    String msg = response.getEntity(String.class);

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(msg));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("RemoteException");
    Element element = (Element) nodes.item(0);
    String message = WebServicesTestUtils.getXmlString(element, "message");
    String type = WebServicesTestUtils.getXmlString(element, "exception");
    String classname = WebServicesTestUtils.getXmlString(element,
        "javaClassName");
    verifyStateInvalidException(message, type, classname);
  }
}