Beispiel #1
0
  private void editingMultivaluedProperties() {
    String path = "/props/t3/r1";
    Resource r1 = registry.newResource();
    try {
      r1.setContent("r1 content");

      r1.addProperty("p1", "v1");
      r1.addProperty("p1", "v2");
      r1.setProperty("test", "value2");
      r1.setProperty("test2", "value2");
      registry.put(path, r1);

      Resource r1e1 = registry.get(path);
      r1e1.setContent("r1 content");
      r1e1.editPropertyValue("p1", "v1", "v3");

      registry.put(path, r1e1);

      Resource r1e2 = registry.get(path);
      assertFalse("Property is not edited.", r1e2.getPropertyValues("p1").contains("v1"));
      assertTrue("Property is not edited.", r1e2.getPropertyValues("p1").contains("v3"));
      assertTrue("Wrong property is removed.", r1e2.getPropertyValues("p1").contains("v2"));

      deleteResources("/props");
      log.info("editingMultivaluedProperties- Passed");
    } catch (RegistryException e) {

      log.error("editingMultivaluedProperties RegistryException thrown :" + e.getMessage());
      Assert.fail("editingMultivaluedProperties RegistryException thrown :" + e.getMessage());
    }
  }
Beispiel #2
0
  private void multiValuedProperties() {
    String path = "/propTest/r1";
    Resource r1 = registry.newResource();

    try {
      r1.setContent("Some content for r1");

      r1.addProperty("p1", "p1v1");
      r1.addProperty("p1", "p1v2");
      registry.put(path, r1);

      Resource r1b = registry.get(path);
      List propValues = r1b.getPropertyValues("p1");

      assertTrue(
          "Property p1 of /propTest/r1 should contain the value p1v1", propValues.contains("p1v1"));

      assertTrue(
          "Property p1 of /propTest/r1 should contain the value p1v2", propValues.contains("p1v2"));

      deleteResources("/propTest");
      log.info("multiValuedProperties - Passed");
    } catch (RegistryException e) {

      log.error("multiValuedProperties RegistryException thrown :" + e.getMessage());
      Assert.fail("multiValuedProperties RegistryException thrown :" + e.getMessage());
    }
  }
 public boolean getProperty(String path, String key, String value) throws Exception {
   Resource r3 = registry.newResource();
   try {
     r3 = registry.get(path);
   } catch (Exception e) {
     fail(
         (new StringBuilder())
             .append("Couldn't get file from the path :")
             .append(path)
             .toString());
   }
   List propertyValues = r3.getPropertyValues(key);
   Object valueName[] = propertyValues.toArray();
   boolean propertystatus;
   propertystatus = containsString(valueName, value);
   return propertystatus;
 }
  /**
   * method to get stored accounts from registry
   *
   * @param registry Registry
   * @return list of AccountInfo
   * @throws IssueTrackerException thrown if unable to obtain resources from registry
   */
  public static List<AccountInfo> getAccounts(Registry registry) throws IssueTrackerException {

    List<AccountInfo> accounts = new ArrayList<AccountInfo>();
    try {

      // check whether resources exist at the registry path
      if (registry.resourceExists(IssueTrackerConstants.ISSUE_TRACKERS_RESOURCE_PATH)) {

        // get the collection
        Collection collection =
            (Collection) registry.get(IssueTrackerConstants.ISSUE_TRACKERS_RESOURCE_PATH);

        if (null != collection) {

          // get paths of resources in the collection
          String[] paths = collection.getChildren();

          // for each resource construct the corresponding AccountInfo instance and add it to the
          // list
          for (String path : paths) {

            AccountInfo accountInfo = new AccountInfo();
            GenericCredentials credentials = new GenericCredentials();

            if (registry.resourceExists(path)) {
              Resource resource = registry.get(path);

              List<String> accountPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_KEY);
              accountInfo.setKey(accountPropertySet.get(accountPropertySet.size() - 1));

              List<String> urlPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ISSUE_TRACKER_URL);
              String url = urlPropertySet.get(urlPropertySet.size() - 1);

              List<String> usernamePropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_LOGIN_USERNAME);
              String username = usernamePropertySet.get(usernamePropertySet.size() - 1);

              List<String> emailPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_EMAIL);
              String email = emailPropertySet.get(emailPropertySet.size() - 1);

              List<String> uidPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_UID);
              String uid = uidPropertySet.get(uidPropertySet.size() - 1);

              List<String> hasSupportPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.HAS_SUPPORT_ACCOUNT);
              String hasSupport = hasSupportPropertySet.get(usernamePropertySet.size() - 1);

              List<String> passwordPropertySet;

              passwordPropertySet =
                  resource.getPropertyValues(
                      IssueTrackerConstants.ACCOUNT_PASSWORD_HIDDEN_PROPERTY);

              // for users with older accounts hidden password property does not exist. for them,
              // have to get the older property
              // until the account is edited.
              if (null == passwordPropertySet) {
                passwordPropertySet =
                    resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_PASSWORD);
              }

              String password = "";
              if (null != passwordPropertySet) {

                String encryptedPassword = passwordPropertySet.get(passwordPropertySet.size() - 1);

                password =
                    new String(
                        CryptoUtil.getDefaultCryptoUtil()
                            .base64DecodeAndDecrypt(encryptedPassword));
              }
              String isAutoReportingEnabled =
                  resource.getProperty(IssueTrackerConstants.AUTO_REPORTING);

              if (null != isAutoReportingEnabled
                  && IssueTrackerConstants.IS_AUTO_REPORTING_ENABLED.equals(
                      isAutoReportingEnabled)) {
                accountInfo.setAutoReportingEnable(true);

                AutoReportingSettings settings = new AutoReportingSettings();
                String projectName =
                    resource.getProperty(IssueTrackerConstants.AUTO_REPORTING_PROJECT);
                settings.setProjectName(projectName);
                String priority =
                    resource.getProperty(IssueTrackerConstants.AUTO_REPORTING_PRIORITY);
                settings.setPriority(priority);
                String type = resource.getProperty(IssueTrackerConstants.AUTO_REPORTING_ISSUE_TYPE);
                settings.setIssueType(type);
                accountInfo.setAutoReportingSettings(settings);
              } else {
                accountInfo.setAutoReportingEnable(false);
              }

              if (!"".equals(url) && !"".equals(username) && !"".equals(password)) {
                credentials.setUrl(url);
                credentials.setUsername(username);
                credentials.setPassword(password);
                accountInfo.setCredentials(credentials);
                accountInfo.setEmail(email);
                accountInfo.setUid(uid);
                accountInfo.setHasSupportAccount(Boolean.getBoolean(hasSupport));
                accounts.add(accountInfo);
              }
            }
          }
        }
      }
    } catch (RegistryException e) {
      ExceptionHandler.handleException("Error getting resources from registry", e, log);
    } catch (CryptoException e) {
      ExceptionHandler.handleException("Error decrypting password", e, log);
    }

    return accounts;
  }