@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"));
  }
  @Test(
      groups = {"wso2.greg", "wso2.greg.es"},
      description = "Adding subscription to a policy LC state change",
      dependsOnMethods = {"createPolicyAssetWithLC"})
  public void addSubscriptionForLCStateChange() throws JSONException, IOException {

    JSONObject dataObject = new JSONObject();

    dataObject.put("notificationType", "PublisherLifeCycleStateChanged");
    dataObject.put("notificationMethod", "work");

    ClientResponse response =
        genericRestClient.geneticRestRequestPost(
            publisherUrl + "/subscriptions/policy/" + assetId,
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_JSON,
            dataObject.toString(),
            queryParamMap,
            headerMap,
            cookieHeader);

    assertTrue(
        (response.getStatusCode() == Response.Status.OK.getStatusCode()),
        "Wrong status code ,Expected"
            + Response.Status.OK.getStatusCode()
            + "Created ,Received "
            + response.getStatusCode());
  }
 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));
 }
 private ClientResponse uncheckLifeCycleCheckItem(String managerCookieHeader, int itemId) {
   return genericRestClient.geneticRestRequestPost(
       publisherUrl + "/asset/" + assetId + "/update-checklist",
       MediaType.APPLICATION_JSON,
       MediaType.APPLICATION_JSON,
       "{\"checklist\":[{\"index\":" + itemId + ",\"checked\":false}]}",
       queryParamMap,
       headerMap,
       managerCookieHeader);
 }
  @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}"));
  }
 @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");
 }
 @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);
 }
  @Test(
      groups = {"wso2.greg", "wso2.greg.es"},
      description = "Deleting of ratings added using rest api",
      dependsOnMethods = "getRatings")
  public void deleteRatings() throws JSONException, IOException, InterruptedException {

    queryParamMap.clear();

    queryParamMap.put("path", path);

    ClientResponse response =
        genericRestClient.geneticRestRequestDelete(
            registryAPIUrl + generalPath + "/rating",
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_JSON,
            null,
            queryParamMap,
            headerMap,
            sessionCookie);

    assertTrue(
        (response.getStatusCode() == Response.Status.NO_CONTENT.getStatusCode()),
        "Wrong status code ,Expected 204 ,Received " + response.getStatusCode());
  }