private JSONObject getAsset(String assetId, String assetType) throws JSONException {
   Map<String, String> assetTypeParamMap = new HashMap<String, String>();
   assetTypeParamMap.put("type", assetType);
   ClientResponse clientResponse =
       getAssetById(publisherUrl, genericRestClient, cookieHeader, assetId, queryParamMap);
   return new JSONObject(clientResponse.getEntity(String.class));
 }
  /**
   * Creates the tickets.
   *
   * @param assignedToUser the assigned to user
   * @param subjectId the subject id
   * @param title the title
   * @param content the content
   * @return the JSON object
   * @throws Exception the exception
   */
  public JSONObject createTickets(
      String assignedToUser, String subjectId, String title, String content) throws Exception {
    logger.info("Executing Create ticket username: "******"/")) {
      url.append("/");
    }
    url.append("createStandardTicket");

    String templateObject = getJSON(assignedToUser, subjectId, title, content);

    BasicAuthorizationSLClient client = new BasicAuthorizationSLClient(username, apiKey);
    ClientResponse clientResponse = client.executePOST(url.toString(), templateObject);
    String response = clientResponse.getEntity(String.class);
    logger.info(
        "Executed create Ticket: clientResponse: "
            + clientResponse.getStatusCode()
            + ", response: "
            + response);

    if (clientResponse.getStatusCode() == 200) {
      JSONObject json = new JSONObject(response);
      logger.debug("Create Ticket: JSON Response: " + response);
      return json;
    }

    throw new Exception(
        "Could not create Ticket: Code: "
            + clientResponse.getStatusCode()
            + ", Reason: "
            + response);
  }
Exemplo n.º 3
0
  public void testcreateblog2() {
    System.out.println("Test Case to Create a Blog");
    Resource resource1 = client.resource(url);
    System.out.println("URL: " + url);
    JSONObject sendobject = new JSONObject();
    try {
      sendobject.put("subject", "sjsu_cmpe202");
      sendobject.put("description", "XML");
      sendobject.put("userid", "Shaunak");
      sendobject.put("timestamp", "11:53");

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    String jsonStringObj = sendobject.toString();
    System.out.println("Create : " + jsonStringObj);
    ClientResponse created =
        resource1
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .post(jsonStringObj);
    System.out.println(created.getStatusCode());
    System.out.println(created.getEntity(String.class));
  }
  @Test(
      groups = {"wso2.greg", "wso2.greg.es"},
      description = "Adding ratings added using rest api")
  public void addRatings() throws JSONException, IOException, InterruptedException {

    queryParamMap.clear();

    queryParamMap.put("path", path);
    queryParamMap.put("value", "4");

    ClientResponse response =
        genericRestClient.geneticRestRequestPost(
            registryAPIUrl + generalPath + "rate",
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_JSON,
            null,
            queryParamMap,
            headerMap,
            sessionCookie);

    assertTrue(
        (response.getStatusCode() == Response.Status.OK.getStatusCode()),
        "Wrong status code ,Expected 200 OK ,Received " + response.getStatusCode());

    assertTrue(response.getEntity(String.class).equals("4.0"));
  }
 private JSONObject getLifeCycleState(String assetId, String assetType) throws JSONException {
   Map<String, String> assetTypeParamMap = new HashMap<String, String>();
   assetTypeParamMap.put("type", assetType);
   assetTypeParamMap.put("lifecycle", lifeCycleName);
   ClientResponse response =
       genericRestClient.geneticRestRequestGet(
           publisherUrl + "/asset/" + assetId + "/state", queryParamMap, headerMap, cookieHeader);
   return new JSONObject(response.getEntity(String.class));
 }
 @Test(
     groups = {"wso2.greg", "wso2.greg.es"},
     description = "create a policy with a LC attached.")
 public void createPolicyAssetWithLC()
     throws JSONException, InterruptedException, IOException,
         CustomLifecyclesChecklistAdminServiceExceptionException {
   queryParamMap.put("type", "policy");
   String policyTemplate = readFile(resourcePath + "json" + File.separator + "policy-sample.json");
   assetName = "UTPolicy.xml";
   String dataBody =
       String.format(
           policyTemplate,
           "https://raw.githubusercontent.com/wso2/wso2-qa-artifacts/master/automation-artifacts/greg/policy/UTPolicy.xml",
           assetName,
           "1.0.0");
   ClientResponse response =
       genericRestClient.geneticRestRequestPost(
           publisherUrl + "/assets",
           MediaType.APPLICATION_JSON,
           MediaType.APPLICATION_JSON,
           dataBody,
           queryParamMap,
           headerMap,
           cookieHeader);
   JSONObject obj = new JSONObject(response.getEntity(String.class));
   Assert.assertTrue(
       (response.getStatusCode() == 201),
       "Wrong status code ,Expected 201 Created ,Received " + response.getStatusCode());
   String resultName = obj.get("overview_name").toString();
   Assert.assertEquals(resultName, assetName);
   searchPolicyAsset();
   // attach a LC to the wsdl
   lifeCycleAdminServiceClient.addAspect(path, lifeCycleName);
   Assert.assertNotNull(
       assetId, "Empty asset resource id available" + response.getEntity(String.class));
   Assert.assertTrue(
       this.getAsset(assetId, "policy").get("lifecycle").equals(lifeCycleName),
       "LifeCycle not assigned to given asset");
 }
Exemplo n.º 7
0
  @Test
  public void getRolesList() throws Exception {
    Role role = roleGenerator.createUniqueInstance();
    setup(role);

    Resource resource = client.resource(rolesURI).accept(MediaType.APPLICATION_XML);

    ClientResponse response = resource.get();
    assertEquals(200, response.getStatusCode());

    RolesDto entity = response.getEntity(RolesDto.class);
    assertNotNull(entity);
    assertNotNull(entity.getCollection());
    assertEquals(entity.getCollection().size(), 1);
  }
 private void setTestEnvironment() throws XPathExpressionException, JSONException {
   ClientResponse response =
       authenticate(
           publisherUrl,
           genericRestClient,
           automationContext.getSuperTenant().getTenantAdmin().getUserName(),
           automationContext.getSuperTenant().getTenantAdmin().getPassword());
   JSONObject obj = new JSONObject(response.getEntity(String.class));
   assertTrue(
       (response.getStatusCode() == 200),
       "Wrong status code ,Expected 200 OK ,Received " + response.getStatusCode());
   jSessionId = obj.getJSONObject("data").getString("sessionId");
   cookieHeader = "JSESSIONID=" + jSessionId;
   assertNotNull(jSessionId, "Invalid JSessionID received");
 }
 /**
  * This method get all the wsdls in publisher and select the one created by createWSDLAssetWithLC
  * method.
  *
  * @throws JSONException
  */
 public void searchPolicyAsset() throws JSONException {
   Map<String, String> queryParamMap = new HashMap<>();
   queryParamMap.put("type", "policy");
   ClientResponse clientResponse =
       searchAssetByQuery(publisherUrl, genericRestClient, cookieHeader, queryParamMap);
   JSONObject obj = new JSONObject(clientResponse.getEntity(String.class));
   JSONArray jsonArray = obj.getJSONArray("list");
   for (int i = 0; i < jsonArray.length(); i++) {
     String name = (String) jsonArray.getJSONObject(i).get("name");
     if (assetName.equals(name)) {
       assetId = (String) jsonArray.getJSONObject(i).get("id");
       path = (String) jsonArray.getJSONObject(i).get("path");
       break;
     }
   }
 }
Exemplo n.º 10
0
  public void testInvalidServerMessageBodyReaderRelativeURI() {
    final String creation =
        getCreation(OslcMediaType.APPLICATION_RDF_XML, Constants.TEST_DOMAIN, Constants.TYPE_TEST);

    final OslcRestClient oslcRestClient =
        new OslcRestClient(PROVIDERS, creation, OslcMediaType.APPLICATION_RDF_XML);

    final ClientResponse clientResponse =
        oslcRestClient.addOslcResourceReturnClientResponse(INVALID_RELATIVE_URI);

    final Error error = clientResponse.getEntity(Error.class);

    assertNotNull(error);

    assertEquals(String.valueOf(HttpURLConnection.HTTP_BAD_REQUEST), error.getStatusCode());
    assertNotNull(error.getMessage());
  }
  @Test(
      groups = {"wso2.greg", "wso2.greg.es"},
      description = "Getting ratings added using rest api",
      dependsOnMethods = "addRatings")
  public void getRatings() throws JSONException, IOException, InterruptedException {

    queryParamMap.clear();

    queryParamMap.put("path", path);

    ClientResponse response =
        genericRestClient.geneticRestRequestGet(
            registryAPIUrl + generalPath + "/rating", queryParamMap, headerMap, null);

    assertTrue(
        (response.getStatusCode() == Response.Status.OK.getStatusCode()),
        "Wrong status code ,Expected 200 OK ,Received " + response.getStatusCode());

    assertTrue(response.getEntity(String.class).equals("{\"average\":4.0,\"myRating\":4}"));
  }
  public static void main(String[] args) {

    String baseHTTPURI = "http://localhost:8181/oslc4jsimulink";
    String projectId = "model11";

    String simulinkConstBlockValueParameterURI =
        baseHTTPURI + "/services/" + projectId + "/parameters/Constant::Value";

    // get the parameter value / perform a GET
    System.out.println("Performing HTTP GET on resource " + simulinkConstBlockValueParameterURI);
    ClientResponse clientGETResponse =
        getOslcRestClient(simulinkConstBlockValueParameterURI).getOslcResource();
    SimulinkParameter simulinkParameter = clientGETResponse.getEntity(SimulinkParameter.class);
    System.out.println(
        "Value of parameter resource "
            + simulinkConstBlockValueParameterURI
            + ": "
            + simulinkParameter.getValue());
    String resource1ETagFromGET = getETagFromResponse(clientGETResponse);
    System.out.println(
        "ETag of resource " + simulinkConstBlockValueParameterURI + ": " + resource1ETagFromGET);
  }
 @Test(
     groups = {"wso2.greg", "wso2.greg.es"},
     description = "Change LC state on Policy",
     dependsOnMethods = {
       "createPolicyAssetWithLC",
       "addSubscriptionForLCStateChange",
       "checkLCCheckItemsOnPolicy",
       "uncheckLCCheckItemsOnPolicy"
     })
 public void changeLCStatePolicy() throws JSONException, IOException {
   ClientResponse response =
       genericRestClient.geneticRestRequestPost(
           publisherUrl + "/assets/" + assetId + "/state",
           MediaType.APPLICATION_FORM_URLENCODED,
           MediaType.APPLICATION_JSON,
           "nextState=Testing&comment=Completed",
           queryParamMap,
           headerMap,
           cookieHeader);
   JSONObject obj = new JSONObject(response.getEntity(String.class));
   String status = obj.get("status").toString();
   Assert.assertEquals(status, stateChangeMessage);
 }