public void verifyPolicy() throws GovernanceException {
   PolicyManager policyManager = new PolicyManager(governance);
   Policy[] policies = policyManager.getAllPolicies();
   boolean resourceFound = false;
   for (Policy policy : policies) {
     if (policy.getQName().getLocalPart().equals("EncrOnlyAnonymous.xml")) {
       resourceFound = true;
     }
   }
   Assert.assertTrue(resourceFound);
 }
 public void createPolicy(String policy_url) throws GovernanceException {
   PolicyManager policyManager = new PolicyManager(governance);
   Policy policy = null;
   try {
     policy = policyManager.newPolicy(policy_url);
     policy.addAttribute("creator", "Aaaa");
     policy.addAttribute("version", "1.0.0");
     policyManager.addPolicy(policy);
   } catch (GovernanceException e) {
     log.error("Failed to add Policy:" + e);
     throw new GovernanceException("Failed to add Policy :" + e);
   }
 }
 private void addPolicy() throws RegistryException, IOException {
   PolicyManager policyManager = new PolicyManager(governance);
   String policyFilePath =
       ProductConstant.getResourceLocations(ProductConstant.GREG_SERVER_NAME)
           + File.separator
           + "policy"
           + File.separator;
   Policy policy =
       policyManager.newPolicy(
           FileManager.readFile(policyFilePath + "UTPolicy.xml").getBytes(), "UTPolicy.xml");
   policyManager.addPolicy(policy);
   policy = policyManager.getPolicy(policy.getId());
   Resource resource = governance.get(policy.getPath());
   resource.addProperty("abcxyzpqr", "40");
   governance.put(policy.getPath(), resource);
 }
 @AfterClass(
     groups = "wso2.greg",
     alwaysRun = true,
     description = "cleaning up the artifacts added")
 public void tearDown() throws GovernanceException {
   policyManager.removePolicy(policy.getId());
   policy = null;
   policyManager = null;
   infoServiceAdminclient = null;
   governanceRegistry = null;
 }
  /** tags verification */
  @Test(groups = "wso2.greg", description = "tags verification")
  public void testAddPolicy()
      throws RemoteException, ResourceAdminServiceExceptionException, GovernanceException,
          MalformedURLException {

    policy =
        policyManager.newPolicy(
            "https://svn.wso2.org/repos/wso2/carbon/platform/trunk/"
                + "platform-integration/platform-automated-test-suite/"
                + "org.wso2.carbon.automation.test.repo/src/main/"
                + "resources/artifacts/GREG/policy/policy.xml");

    policy.addAttribute("version", "1.0.0");
    policy.addAttribute("author", "Aparna");
    policy.addAttribute("description", "added policy using url");
    policyManager.addPolicy(policy);

    assertFalse(policy.getId().isEmpty());
    assertNotNull(policy);
    assertTrue(policy.getAttribute("author").contentEquals("Aparna"));
  }
  @Test(groups = "wso2.greg", description = "tags Verification", dependsOnMethods = "testAddPolicy")
  public void testTagsVerification()
      throws AxisFault, GovernanceException, RegistryException, RegistryExceptionException {

    final String policyPath = "/_system/governance" + policy.getPath();

    infoServiceAdminclient.addTag("my tag", policyPath, sessionCookie);
    TagBean tagBean = infoServiceAdminclient.getTags(policyPath, sessionCookie);

    Tag[] tags = tagBean.getTags();
    boolean status = false;
    for (Tag tmpTag : tags) {
      if (tmpTag.getTagName().contentEquals("my tag")) {
        status = true;
      }
    }
    assertTrue(status, "verifying the tag creation");
  }