Exemple #1
0
  @Test
  /**
   * substitute cloud , global and local variables where each is simply a variable easy test to pass
   */
  public void processAllVarsTest() {
    String[] cloudValues = new String[] {"cbar", "cfoo", "cbaz"};
    String[] globalValues = new String[] {"gbat", "gfee", "gbiz"};
    String[] localValues = new String[] {"lbaz", "lfuu", "lbuz"};

    // -cloud variables are just the variable name set to upper case
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    for (String val : cloudValues) {
      cloudVars.put(val, val.toUpperCase());
    }
    logger.info("cloud values have been set too: " + cloudVars);

    Map<String, String> globalVars = new HashMap<String, String>(3);
    for (String val : globalValues) {
      globalVars.put(val, val.toUpperCase());
    }
    logger.info("globalVars values have been set too: " + globalVars);

    Map<String, String> localVars = new HashMap<String, String>(3);
    for (String val : localValues) {
      localVars.put(val, val.toUpperCase());
    }
    logger.info("local values have been set too: " + localVars);

    CmsCI ci = new CmsCI();
    ci.setCiId(4444);
    ci.setCiName("processAllVarsTest");
    Map<String, CmsCIAttribute> attributes =
        new LinkedHashMap<String, CmsCIAttribute>(cloudValues.length * 3);
    /// set up the ci with attributes which each need replacing...
    int i = 0;
    for (String cloudVariable : cloudValues) { // 3 cloud vars
      CmsCIAttribute attrC = new CmsCIAttribute();
      attrC.setDjValue("$OO_CLOUD{" + cloudVariable + "}");
      attrC.setAttributeName("pav1");
      attributes.put("cloud_" + (++i), attrC);
    }
    for (String globalVariable : globalValues) { // 3 globals
      CmsCIAttribute attrH = new CmsCIAttribute();
      attrH.setDjValue("$OO_GLOBAL{" + globalVariable + "}");
      attrH.setAttributeName("pav2");

      attributes.put("global_" + (++i), attrH);
    }
    for (String localVariable : localValues) { // 3 locals
      CmsCIAttribute attrI = new CmsCIAttribute();
      attrI.setDjValue("$OO_LOCAL{" + localVariable + "}");
      attrI.setAttributeName("pav3");

      attributes.put("local_" + (++i), attrI);
    }
    ci.setAttributes(attributes);
    logger.info("CI Attributes have been set into the ci, attrs: " + attributes);
    Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes();
    for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) {
      System.out.println("*- b4   |" + e.getKey() + "->" + e.getValue().getDjValue());
    }

    CmsUtil util = new CmsUtil();
    dumpMaps(cloudVars, globalVars, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, cloudVars, globalVars, localVars);
    dumpCmsCIAttributes(ci);

    for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) {
      String djKey = a.getKey();
      String djAfter = a.getValue().getDjValue();
      System.out.println("after>" + djKey + "->" + djAfter);
      if (djKey.startsWith("cloud_")) {
        String expected =
            attributesBefore
                .get(djKey)
                .getDjValue()
                .replace("OO_CLOUD{", "")
                .replace("}", "")
                .toUpperCase();
        assertEquals(djAfter, expected, "did not measure up for key " + djKey);
      } else {
        if (djKey.startsWith("global_")) {
          String expected =
              attributesBefore
                  .get(djKey)
                  .getDjValue()
                  .replace("OO_GLOBAL{", "")
                  .replace("}", "")
                  .toUpperCase();
          assertEquals(djAfter, expected, "did not measure up for key " + djKey);
        } else {
          if (djKey.startsWith("local_")) {
            String expected =
                attributesBefore
                    .get(djKey)
                    .getDjValue()
                    .replace("OO_LOCAL{", "")
                    .replace("}", "")
                    .toUpperCase();
            assertEquals(djAfter, expected, "did not measure up for key " + djKey);
          }
        }
      }
    }
  }
Exemple #2
0
  @Test
  /** test that local variable can refer to a global variable value */
  public void processLocalValueWithGlobalValueResolution() {
    String[] globalValues = new String[] {"ggyp-Global"};

    // - global variables' values are just the variable name set to upper case
    Map<String, String> globalVars = new HashMap<String, String>(3);
    for (String val : globalValues) {
      globalVars.put(val, val.toUpperCase());
    }
    System.out.println("globalVars values have been set to : " + globalVars);

    Map<String, String> localVars = new LinkedHashMap<String, String>(2);
    localVars.put("myLocalScalar", "abcdefg");

    localVars.put(
        "myLocalVariable", // one local variable refers to global
        "$OO_GLOBAL{ggyp-Global}" // is a reference to the global variable
        );
    System.out.println("localVars values have been set too: " + localVars);

    CmsCI ci = new CmsCI();
    ci.setCiId(135791113);
    ci.setCiName("processLocalValueWithGlobalValueResolution");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    /// set up the ci with attributes which each need replacing...
    int i = 0;

    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_LOCAL{myLocalVariable}");
    attrL.setAttributeName("pl11");
    attributes.put("l81_" + (++i), attrL);
    CmsCIAttribute attrL2 = new CmsCIAttribute();
    attrL2.setDjValue("$OO_LOCAL{myLocalScalar}");
    attrL2.setAttributeName("pl22");
    attributes.put("l82_" + (++i), attrL2);

    ci.setAttributes(attributes);
    System.out.println(
        "*****CI Attributes have been set into the ci, attrs: " + attributes.values());
    Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes();
    for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) {
      System.out.println("*- b4   |" + e.getKey() + "->" + e.getValue().getDjValue());
    }

    CmsUtil util = new CmsUtil();
    dumpMaps(null, globalVars, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, new HashMap<String, String>(), globalVars, localVars);
    dumpCmsCIAttributes(ci);

    for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) {
      String djKey = a.getKey();
      String djAfter = a.getValue().getDjValue();
      System.out.println("after>" + djKey + "->" + djAfter);

      if (djKey.startsWith("global_")) {
        String expected =
            attributesBefore
                .get(djKey)
                .getDjValue()
                .replace("OO_GLOBAL{", "")
                .replace("}", "")
                .toUpperCase();
        assertEquals(djAfter, expected, "did not measure up for key " + djKey);
      } else {
        if (djKey.startsWith("local_")) {
          String expected =
              attributesBefore
                  .get(djKey)
                  .getDjValue()
                  .replace("OO_LOCAL{", "")
                  .replace("}", "")
                  .toUpperCase();
          assertEquals(djAfter, expected, "did not measure up for key " + djKey);
        }
      }
    }
  }
Exemple #3
0
  @Test(priority = 89)
  /**
   * test that 1 local variable can refer to a global variable (g2) which in turn refers to a Cloud
   * variable (c2) while another (justX) is both in Cloud and Global variable
   */
  public void processLocalValueWithGlobalAndCloudValueResolution() {
    // Variables for cloud, global, and locals
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    cloudVars.put("justX", "ca");
    cloudVars.put("p2", "cb");

    Map<String, String> globalVars = new HashMap<String, String>(3);
    globalVars.put("justX", "ga");
    globalVars.put("p2", "$OO_CLOUD{p2}");

    Map<String, String> localVars = new HashMap<String, String>(3);
    localVars.put("l1", "$OO_GLOBAL{p2}"); // want 'ca'
    localVars.put("p2", "$OO_GLOBAL{justX}"); // want 'ga' not 'ca'

    CmsCI ci = new CmsCI();
    ci.setCiId(89);
    ci.setCiName("processLocalValueWithGlobalAndCloudValueResolution");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_LOCAL{l1}");
    attrL.setAttributeName("fo");
    attributes.put("firstOne", attrL);

    CmsCIAttribute attrL2 = new CmsCIAttribute();
    attrL2.setDjValue("$OO_LOCAL{p2}");
    attrL2.setAttributeName("SO");
    attributes.put("secondOne", attrL2);

    CmsCIAttribute attrL3 = new CmsCIAttribute();
    attrL3.setDjValue("$OO_GLOBAL{p2}");
    attrL3.setAttributeName("TO");
    attributes.put("thirdOne", attrL3);

    ci.setAttributes(attributes);
    System.out.println(
        "*****CI Attributes have been set into the ci, attrs: " + attributes.values());
    Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes();
    for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) {
      System.out.println("*- b4   |" + e.getKey() + "->" + e.getValue().getDjValue());
    }
    CmsUtil util = new CmsUtil();
    dumpMaps(cloudVars, globalVars, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, cloudVars, globalVars, localVars);
    dumpCmsCIAttributes(ci);

    for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) {
      String djKey = a.getKey();
      String djAfter = a.getValue().getDjValue();
      System.out.println("*after k>" + djKey + " v->" + djAfter);
      if (djKey.equals("firstOne")) {
        assertEquals(djAfter, "cb", "firstOne was not resolved correctly, local>global>cloud");
      }
      if (djKey.equals("secondOne")) {
        assertEquals(djAfter, "ga", "secondOne was not resolved correctly, local>global");
      }
      if (djKey.equals("thirdOne")) {
        assertEquals(djAfter, "cb", "thirdOne was not resolved correctly, global>cloud");
      }
    }
  }
Exemple #4
0
  @Test
  /** test that a global value can refer to a cloud variable */
  public void processGlobalValueWithCloudValueResolution() {
    String[] cloudValues = new String[] {"czat", "czitCCC"};
    String[] globalValues = new String[] {"czit"}; // map to czitCCC in cloud

    // -cloud variables are just the variable name set to upper case
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    for (String val : cloudValues) {
      cloudVars.put(val, val.toUpperCase());
    }
    logger.info("cloud values have been set too: " + cloudVars);

    Map<String, String> globalVars = new HashMap<String, String>(3);
    for (String val : globalValues) {
      globalVars.put(
          val, "$OO_CLOUD{" + val + "CCC}" // is a reference to a cloud variable
          );
    }
    logger.info("globalVars values have been set too: " + globalVars);

    CmsCI ci = new CmsCI();
    ci.setCiId(9876);
    ci.setCiName("processGlobalValueWithCloudValueResolution");
    Map<String, CmsCIAttribute> attributes =
        new LinkedHashMap<String, CmsCIAttribute>(cloudValues.length * 3);
    /// set up the ci with attributes which each need replacing...
    int i = 0;
    for (String cloudVariable : cloudValues) { // 3 cloud vars
      CmsCIAttribute attrC = new CmsCIAttribute();
      attrC.setDjValue("$OO_CLOUD{" + cloudVariable + "}");
      attributes.put("cloud_" + (++i), attrC);
    }
    for (String globalVariable : globalValues) { // 3 globals
      CmsCIAttribute attrG = new CmsCIAttribute();
      attrG.setDjValue("$OO_GLOBAL{" + globalVariable + "}");
      attrG.setAttributeName("djdj");
      attributes.put("global_" + (++i), attrG);
    }

    ci.setAttributes(attributes);
    logger.info("CI Attributes have been set into the ci, attrs: " + attributes);
    Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes();
    for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) {
      System.out.println("*- b4   |" + e.getKey() + "->" + e.getValue().getDjValue());
    }

    CmsUtil util = new CmsUtil();
    dumpMaps(cloudVars, globalVars, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, cloudVars, globalVars, new HashMap<String, String>());
    dumpCmsCIAttributes(ci);

    for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) {
      String djKey = a.getKey();
      String djAfter = a.getValue().getDjValue();
      System.out.println("after>" + djKey + "->" + djAfter);
      if (djKey.startsWith("cloud_")) {
        String expected =
            attributesBefore
                .get(djKey)
                .getDjValue()
                .replace("OO_CLOUD{", "")
                .replace("}", "")
                .toUpperCase();
        assertEquals(djAfter, expected, "did not measure up for key " + djKey);
      } else {
        if (djKey.startsWith("global_")) {
          String expected =
              attributesBefore
                  .get(djKey)
                  .getDjValue()
                  .replace("OO_GLOBAL{", "")
                  .replace("}", "")
                  .toUpperCase();
          assertEquals(djAfter, expected, "did not measure up for key " + djKey);
        }
      }
    }
  }