Ejemplo n.º 1
0
  private static void setDelaySenderRC(final String value) {
    ServiceRequest request = new ServiceRequest();
    JSONObject json =
        new JSONObject(
            new HashMap<String, String>(2) {

              private static final long serialVersionUID = 1L;

              {
                put("value", value);
              }
            });
    request.setBody(json.toString());
    try {
      Status status =
          request.doPut(
              "http://config-ws.remote-admin.intranet/product/afiliados/component/aff-inscription-sender-ws/property/queue.scheduled.delivery.millis?application=test-aff-inscription-consumer-ws",
              MediaType.APPLICATION_JSON_TYPE);
      Assert.assertTrue(
          "A resposta para a chamada ao Remote Config nao foi positiva.",
          status.getStatusCode() < 30000);
    } catch (Exception e) {
      Assert.fail(
          String.format(
              "Erro ao tentar realizar a chamada ao remote config: %s", e.getLocalizedMessage()));
    }
  }
Ejemplo n.º 2
0
 @Override
 public String getStatusMessage(int status) {
   Status s = javax.ws.rs.core.Response.Status.fromStatusCode(status);
   if (s != null) {
     return s.getReasonPhrase();
   }
   return null;
 }
Ejemplo n.º 3
0
 private String shellCall(String command, Status status, Pair<String, String>... params) {
   return gen()
       .payload("{\"command\":\"" + command + "\",\"engine\":\"shell\"}")
       .expectedStatus(status.getStatusCode())
       .post(consoleUri())
       .entity();
 }
Ejemplo n.º 4
0
 public Response withSynchronization(
     final EntitlementCallCompletionCallback<T> callback,
     final long timeoutSec,
     final boolean callCompletion,
     final CallContext callContext)
     throws SubscriptionApiException, AccountApiException, EntitlementApiException {
   final CompletionUserRequestEntitlement waiter =
       callCompletion ? new CompletionUserRequestEntitlement(callContext.getUserToken()) : null;
   try {
     if (waiter != null) {
       killbillHandler.registerCompletionUserRequestWaiter(waiter);
     }
     final T operationValue = callback.doOperation(callContext);
     if (waiter != null && callback.isImmOperation()) {
       waiter.waitForCompletion(timeoutSec * 1000);
     }
     return callback.doResponseOk(operationValue);
   } catch (InterruptedException e) {
     return Response.status(Status.INTERNAL_SERVER_ERROR).build();
   } catch (TimeoutException e) {
     return Response.status(Status.fromStatusCode(408)).build();
   } finally {
     if (waiter != null) {
       killbillHandler.unregisterCompletionUserRequestWaiter(waiter);
     }
   }
 }
Ejemplo n.º 5
0
 protected void test(
     HttpMethodEnum method,
     String eTagHeader,
     String eTagHeaderValue,
     String lmdHeader,
     String lmdHeaderValue,
     Status status) {
   test(method, eTagHeader, eTagHeaderValue, lmdHeader, lmdHeaderValue, status.getStatusCode());
 }
Ejemplo n.º 6
0
 @Test
 public void shouldBeDistinctFromStatus() {
   Stream.of(MoreStatus.values())
       .map(StatusType::getStatusCode)
       .forEach(
           code -> {
             final Status status = Status.fromStatusCode(code);
             assertThat("Duplicate code: " + code, status, is(nullValue()));
           });
 }
 private void executeAndVerifySorting(String sortBy, String sortOrder, Status expectedStatus) {
   given()
       .queryParam("sortBy", sortBy)
       .queryParam("sortOrder", sortOrder)
       .then()
       .expect()
       .statusCode(expectedStatus.getStatusCode())
       .when()
       .get(JOBS_RESOURCE_URL);
 }
 protected void executeAndVerifySorting(String sortBy, String sortOrder, Status expectedStatus) {
   given()
       .queryParam("sortBy", sortBy)
       .queryParam("sortOrder", sortOrder)
       .then()
       .expect()
       .statusCode(expectedStatus.getStatusCode())
       .when()
       .get(CASE_DEFINITION_QUERY_URL);
 }
 protected void executeAndVerifySorting(String sortBy, String sortOrder, Status expectedStatus) {
   given()
       .queryParam("sortBy", sortBy)
       .queryParam("sortOrder", sortOrder)
       .then()
       .expect()
       .statusCode(expectedStatus.getStatusCode())
       .when()
       .get(HISTORIC_DETAIL_RESOURCE_URL);
 }
  protected String doCypherRestCall(
      String endpoint, String script, Status status, Pair<String, String>... params) {
    data.get();
    String parameterString = createParameterString(params);

    String queryString = "{\"query\": \"" + createScript(script) + "\"," + parameterString + "},";

    gen.get()
        .expectedStatus(status.getStatusCode())
        .payload(queryString)
        .description(AsciidocHelper.createCypherSnippet(script));
    return gen.get().post(endpoint).entity();
  }
  protected String doGremlinRestCall(
      String endpoint, String script, Status status, Pair<String, String>... params) {
    data.get();
    String parameterString = createParameterString(params);

    String queryString = "{\"script\": \"" + createScript(script) + "\"," + parameterString + "},";

    gen.get()
        .expectedStatus(status.getStatusCode())
        .payload(queryString)
        .description(formatGroovy(createScript(script)));
    return gen.get().post(endpoint).entity();
  }
  public String doCypherRestCall(
      String endpoint, String scriptTemplate, Status status, String parameterString) {
    data.get();

    String script = createScript(scriptTemplate);
    String queryString = "{\"query\": \"" + script + "\",\"params\":{" + parameterString + "}}";

    String snippet =
        org.neo4j.cypher.internal.compiler.v2_0.prettifier.Prettifier$.MODULE$.apply(script);
    gen()
        .expectedStatus(status.getStatusCode())
        .payload(queryString)
        .description(AsciidocHelper.createAsciiDocSnippet("cypher", snippet));
    return gen().post(endpoint).entity();
  }
Ejemplo n.º 13
0
  /**
   * Test the ACL resource.
   *
   * @throws JSONException
   */
  @Test
  public void testAclResource() {
    // Login acl1
    clientUtil.createUser("acl1");
    String acl1Token = clientUtil.login("acl1");

    // Login acl2
    clientUtil.createUser("acl2");
    String acl2Token = clientUtil.login("acl2");

    // Create a document
    JsonObject json =
        target()
            .path("/document")
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .put(
                Entity.form(
                    new Form()
                        .param("title", "My super title document 1")
                        .param("language", "eng")
                        .param("create_date", Long.toString(new Date().getTime()))),
                JsonObject.class);
    String document1Id = json.getString("id");

    // Get the document as acl1
    json =
        target()
            .path("/document/" + document1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .get(JsonObject.class);
    Assert.assertEquals(document1Id, json.getString("id"));
    JsonArray acls = json.getJsonArray("acls");
    Assert.assertEquals(2, acls.size());

    // Get the document as acl2
    Response response =
        target()
            .path("/document/" + document1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token)
            .get();
    Assert.assertEquals(Status.FORBIDDEN, Status.fromStatusCode(response.getStatus()));

    // Add an ACL READ for acl2 with acl1
    json =
        target()
            .path("/acl")
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .put(
                Entity.form(
                    new Form()
                        .param("source", document1Id)
                        .param("perm", "READ")
                        .param("username", "acl2")),
                JsonObject.class);
    String acl2Id = json.getString("id");

    // Add an ACL WRITE for acl2 with acl1
    json =
        target()
            .path("/acl")
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .put(
                Entity.form(
                    new Form()
                        .param("source", document1Id)
                        .param("perm", "WRITE")
                        .param("username", "acl2")),
                JsonObject.class);

    // Add an ACL WRITE for acl2 with acl1 (again)
    json =
        target()
            .path("/acl")
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .put(
                Entity.form(
                    new Form()
                        .param("source", document1Id)
                        .param("perm", "WRITE")
                        .param("username", "acl2")),
                JsonObject.class);

    // Get the document as acl1
    json =
        target()
            .path("/document/" + document1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .get(JsonObject.class);
    Assert.assertEquals(document1Id, json.getString("id"));
    acls = json.getJsonArray("acls");
    Assert.assertEquals(4, acls.size());

    // Get the document as acl2
    json =
        target()
            .path("/document/" + document1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token)
            .get(JsonObject.class);
    Assert.assertEquals(document1Id, json.getString("id"));
    acls = json.getJsonArray("acls");
    Assert.assertEquals(4, acls.size());

    // Delete the ACL WRITE for acl2 with acl2
    target()
        .path("/acl/" + document1Id + "/WRITE/" + acl2Id)
        .request()
        .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token)
        .delete();

    // Delete the ACL READ for acl2 with acl2
    target()
        .path("/acl/" + document1Id + "/READ/" + acl2Id)
        .request()
        .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token)
        .delete();

    // Delete the ACL READ for acl2 with acl1
    target()
        .path("/acl/" + document1Id + "/READ/" + acl2Id)
        .request()
        .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
        .delete();

    // Get the document as acl1
    json =
        target()
            .path("/document/" + document1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .get(JsonObject.class);
    Assert.assertEquals(document1Id, json.getString("id"));
    acls = json.getJsonArray("acls");
    Assert.assertEquals(2, acls.size());
    String acl1Id = acls.getJsonObject(0).getString("id");

    // Get the document as acl2
    response =
        target()
            .path("/document/" + document1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token)
            .get();
    Assert.assertEquals(Status.FORBIDDEN, Status.fromStatusCode(response.getStatus()));

    // Delete the ACL READ for acl1 with acl1
    response =
        target()
            .path("/acl/" + document1Id + "/READ/" + acl1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .delete();
    Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));

    // Delete the ACL WRITE for acl1 with acl1
    response =
        target()
            .path("/acl/" + document1Id + "/WRITE/" + acl1Id)
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .delete();
    Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));

    // Search target list
    json =
        target()
            .path("/acl/target/search")
            .queryParam("search", "acl")
            .request()
            .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token)
            .get(JsonObject.class);
    JsonArray users = json.getJsonArray("users");
    Assert.assertEquals(2, users.size());
  }
Ejemplo n.º 14
0
 public Response toResponse(Status status, String jsonResponse) {
   return toResponse(status.getStatusCode(), jsonResponse);
 }
 public OrganisaatioResourceException(Status status, String message, String key) {
   this(status.getStatusCode(), new ErrorMessage(message, key));
 }
Ejemplo n.º 16
0
 public CustomException(Status status, String message) {
   this(status.getStatusCode(), message);
 }
 public OrganisaatioResourceException(Status status, Object message) {
   this(status.getStatusCode(), message);
 }
Ejemplo n.º 18
0
 public Response toResponse(Status status, E e) {
   return toResponse(status.getStatusCode(), e);
 }