Exemplo n.º 1
0
 @Test(
     dataProvider = "DP_valid_login",
     dataProviderClass = DataProviderObjects.DP_LoginScenario.class,
     groups = {"SmokeTest"})
 public void avalid_login(String TC_ID, String Order, String Uname, String Pwd, String expected)
     throws Exception {
   SoftAssert assert1 = new SoftAssert();
   Initialize_browser();
   POM_LoginScenario pom_valid = new POM_LoginScenario(driver);
   pom_valid.execute_common_methods_log(Uname, Pwd);
   if (!driver
       .getTitle()
       .equalsIgnoreCase(
           "Buy Books Online | Online Bookstore India | Online Book Shopping | Free Shipping Across India")) {
     log.error(
         "The user has failed to login, the page the user currently is " + driver.getTitle());
     Assert.fail();
     tear_down();
   }
   String actual = pom_valid.get_valid_log_msg();
   assert1.assertEquals(
       actual, expected, "The actual found is" + actual + " The expected is " + expected);
   if (actual.equalsIgnoreCase(expected)) {
     log.info("The validation has passed");
   } else {
     log.error("THe validation has failed");
   }
   pom_valid.click_signout();
   tear_down();
   assert1.assertAll();
 }
 // This method can be used to navigate to specific url
 public void navigateTo(String url) {
   try {
     logger.info("navigating to url--" + url);
     driver.navigate().to(url);
   } catch (Throwable e) {
     logger.error("cannot navigate to url " + url, e);
   }
 }
 // *****************************************************
 // basic method-type, click, double click, drag and drop
 // GetWebElement
 public WebElement getWebElement(By by) {
   try {
     logger.info("finding webelement by " + by);
     return driver.findElement(by);
   } catch (Throwable t) {
     logger.error("could not find webElement by " + by, t);
   }
   return null;
 }
  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testListCreditCard() throws PayPalRESTException {
    logger.info("**** List CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCardHistory creditCards = CreditCard.list(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Retrieved list of credit cards = " + creditCards.getItems());
    Assert.assertTrue(creditCards.getTotalItems() > 0);
  }
  public Properties readPropertiesFile(String path) {
    try {
      logger.info("loading properties file " + path);
      Properties prop = new Properties();
      FileInputStream fis = new FileInputStream(path);

      prop.load(fis);
      return prop;

    } catch (Throwable t) {
      logger.error("File could not be loaded" + path, t);
    }
    return null;
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testGetCreditCard() throws PayPalRESTException {
    logger.info("**** Get CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(
        true, this.creditCard.getId().equalsIgnoreCase(retrievedCreditCard.getId()));
    logger.info("Retrieved Credit Card status = " + retrievedCreditCard.getState());
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void getCreditCardForNull() {
    logger.info("**** Get CreditCard Null ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    try {
      CreditCard.get(TokenHolder.accessToken, null);
    } catch (IllegalArgumentException e) {
      Assert.assertTrue(e != null, "Illegal Argument Exception not thrown for null arguments");
    } catch (PayPalRESTException e) {
      Assert.fail();
    }
  }
 // -------------------------------------------------------
 //	Click Method.
 public void click(By by) {
   try {
     getWebElement(by).click();
   } catch (Throwable t) {
     logger.error("cannot click by " + by, t);
   }
 }
 // close all existing opened browser
 public void closeAllBr() {
   try {
     driver.close();
     driver.quit();
   } catch (Throwable t) {
     logger.error("cannot close browser", t);
   }
 }
Exemplo n.º 10
0
 public void clearAndSendKeys(By by, String toType) {
   try {
     getWebElement(by).clear();
     getWebElement(by).sendKeys(toType);
   } catch (Throwable t) {
     logger.error("cannot type to " + by, t);
   }
 }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testUpdateCreditCard"})
  public void deleteCreditCard() throws PayPalRESTException {
    logger.info("**** Delete CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    retrievedCreditCard.delete(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    try {
      CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 12
0
 public String getTextValue(By by) {
   try {
     // String strTextValue= getWebElement(by).getText();
     strTextValue = getWebElement(by).getText();
   } catch (Throwable t) {
     logger.error("cannot type to " + by, t);
   }
   return strTextValue;
 }
Exemplo n.º 13
0
  // selects by String value
  public void selectByValue(By by, String value) {
    try {

      new Select(getWebElement(by)).selectByValue(value);

    } catch (Throwable t) {
      logger.error("cannot select webelement by " + by, t);
    }
  }
Exemplo n.º 14
0
 public WebDriver getWebDriver(String br) {
   // make sure capabilities is not null
   logger.info("Starting WebDriver");
   // Set the desired capabilities
   capabilities = setDesiredCapabilites(br);
   // To run test Cases on Firefox Browser.
   if (br.equalsIgnoreCase("firefox")) {
     dr = new FirefoxDriver(capabilities);
     return dr;
   }
   return null;
 }
  @Test(groups = "unit")
  public void testCvv2() {
    logger.info("**** Test CreditCard CVV2 ****");
    CreditCard creditCard = createDummyCreditCard();

    // empty CVV2
    creditCard.setCvv2(null);
    Assert.assertEquals(-1, creditCard.getCvv2());

    // valid CVV2
    creditCard.setCvv2(123);
    Assert.assertEquals(123, creditCard.getCvv2());
  }
  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void testUpdateCreditCard() throws PayPalRESTException {
    logger.info("**** Update CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    // set up patch request
    Patch patch = new Patch();
    patch.setOp("replace");
    patch.setPath("/expire_year");
    patch.setValue(new Integer(2020));
    List<Patch> patchRequest = new ArrayList<Patch>();
    patchRequest.add(patch);

    // send patch request
    CreditCard creditCard = new CreditCard();
    creditCard.setId(createdCreditCardId);
    CreditCard retrievedCreditCard = creditCard.update(TokenHolder.accessToken, patchRequest);

    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(2020, retrievedCreditCard.getExpireYear());
  }
Exemplo n.º 17
0
  // will be called in before method
  public void initBeforeMethod() {
    // initialize - all before methods
    logger.info("Starting init method");
    locator = readPropertiesFile(pathLocator);
    // Launch webDriver

    dr = getWebDriver(br);
    driver = new EventFiringWebDriver(dr);
    // maximize
    driver.manage().window().maximize();
    originalWindowHandle = driver.getWindowHandle();
    // implicit wait, pageloadtimeout

    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(PAGELOAD_TIMEOUT, TimeUnit.SECONDS);
    // navigate
    navigateTo(url);
    createObject();
  }
Exemplo n.º 18
0
  /** @param br purpose: set desiredCapanbilities */
  public DesiredCapabilities setDesiredCapabilites(String browserCapability) {
    capabilities = new DesiredCapabilities();

    switch (browserCapability) {
      case "firefox":
        capabilities.setBrowserName("firefox");
        capabilities.setPlatform(Platform.ANY);
        break;

      default:
        try {
          throw new Throwable("no capalities matched");
        } catch (Throwable e) {
          // TODO Auto-generated catch block
          logger.error("no capabilites found", e);
        }
    }
    return capabilities;
  }
 /** Creates summary of the run */
 public void generateReport(List<XmlSuite> xml, List<ISuite> suites, String outdir) {
   try {
     m_out = createWriter(outdir);
   } catch (IOException e) {
     L.error("output file", e);
     return;
   }
   ConfigReader cr = ConfigReader.getInstance();
   builder.setEncoding(cr.getSrouceCodeEncoding());
   builder.addSourceTree(new File(cr.getSourceCodeDir()));
   startHtml(m_out);
   generateSuiteSummaryReport(suites);
   testIds.clear();
   generateMethodSummaryReport(suites);
   testIds.clear();
   generateMethodDetailReport(suites);
   testIds.clear();
   endHtml(m_out);
   m_out.flush();
   m_out.close();
 }
Exemplo n.º 20
0
 protected void dump() {
   LOG.info("===== Test class\n" + m_testClass.getName());
   for (ITestNGMethod m : m_beforeClassMethods) {
     LOG.info("  @BeforeClass " + m);
   }
   for (ITestNGMethod m : m_beforeTestMethods) {
     LOG.info("  @BeforeMethod " + m);
   }
   for (ITestNGMethod m : m_testMethods) {
     LOG.info("    @Test " + m);
   }
   for (ITestNGMethod m : m_afterTestMethods) {
     LOG.info("  @AfterMethod " + m);
   }
   for (ITestNGMethod m : m_afterClassMethods) {
     LOG.info("  @AfterClass " + m);
   }
   LOG.info("======");
 }
  @Test(groups = "integration")
  public void createCreditCardTest() throws PayPalRESTException {
    logger.info("**** Create CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard creditCard = new CreditCard();
    creditCard.setExpireMonth(EXPMONTH);
    creditCard.setExpireYear(EXPYEAR);
    creditCard.setNumber(NUMBER);
    creditCard.setType(TYPE);
    this.creditCard = creditCard.create(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Credit Card created with ID = " + this.creditCard.getId());
    Assert.assertEquals(true, "ok".equalsIgnoreCase(this.creditCard.getState()));
    logger.info("Created Credit Card status = " + this.creditCard.getState());
    createdCreditCardId = this.creditCard.getId();
  }
Exemplo n.º 22
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);
          }
        }
      }
    }
  }
Exemplo n.º 23
0
@RunWith(PowerMockRunner.class)
@PrepareForTest({ConfigParamManager.class, Document.class})
public class ConfigParamManagerTest {
  private Logger logger = Logger.getLogger(ConfigParamManagerTest.class);
  private static String configLocation = "environmentConfig.xml";

  @BeforeClass
  public static void setUp() {
    // PropertyConfigurator.configure(ConfigParamManagerTest.class.getClassLoader().getResource("log4j.properties"));
  }

  @Test
  public void readConfig_A$_XML() throws Exception {
    // 建立私有方法的mock对象
    ConfigParamManager mock =
        PowerMock.createPartialMock(ConfigParamManager.class, "getConfigType");
    // 录制私有方法行为
    PowerMock.expectPrivate(mock, "getConfigType", EasyMock.anyObject(Document.class))
        .andReturn("XML");
    // 回放mock对象行为
    PowerMock.replay(mock);

    EnvConfigBean envConfig = mock.readConfig();
    assertNotNull(envConfig);
    assertEquals("XML", envConfig.getConfigType());
    assertEquals(
        "http://172.16.30.20:8090/xms/",
        ConfigParamMap.getConfigParamMap().get("xms_url").getValue());

    PowerMock.verifyAll();
  }

  @Test
  public void testReadConfig_JDBC() throws Exception {
    // 建立私有方法的mock对象
    ConfigParamManager mock =
        PowerMock.createPartialMock(ConfigParamManager.class, "getConfigType");
    // 录制私有方法行为
    PowerMock.expectPrivate(mock, "getConfigType", EasyMock.anyObject(Document.class))
        .andReturn("JDBC");
    // 回放mock对象行为
    PowerMock.replay(mock);

    EnvConfigBean envConfig = mock.readConfig(configLocation);

    assertNotNull(envConfig);
    assertEquals("JDBC", envConfig.getConfigType());
    assertTrue(envConfig.getJdbc().keySet().size() > 0);
    for (ConfigDataSourceBean csb : envConfig.getJdbc().values()) {
      System.out.println("jdbc config==>" + csb.getName() + " = " + csb.getValue());
    }
    for (ConfigParamBean cpb : ConfigParamMap.getConfigParamMap().values()) {
      System.out.println(
          "jdbc configParam==>"
              + cpb.getName()
              + " || "
              + cpb.getValue()
              + " || "
              + cpb.getSystem());
    }
  }

  @Test
  public void testReadConfig_JNDI() throws Exception {
    // 建立私有方法的mock对象
    ConfigParamManager mock =
        PowerMock.createPartialMock(ConfigParamManager.class, "getConfigType");
    // 录制私有方法行为
    PowerMock.expectPrivate(mock, "getConfigType", EasyMock.anyObject(Document.class))
        .andReturn("JNDI");
    // 回放mock对象行为
    PowerMock.replay(mock);

    EnvConfigBean envConfig = mock.readConfig(configLocation);

    assertNotNull(envConfig);
    assertEquals("JNDI", envConfig.getConfigType());
    assertEquals(0, envConfig.getJndi().keySet().size());
    for (ConfigDataSourceBean csb : envConfig.getJndi().values()) {
      System.out.println("jndi config==>" + csb.getName() + " = " + csb.getValue());
    }
  }

  /** @throws Exception */
  @Test(expected = EnvironmentConfigException.class)
  public void testReadConfig_JNDI_EnvironmentConfigException() throws Exception {
    // 建立私有方法的mock对象
    ConfigParamManager mock =
        PowerMock.createPartialMock(ConfigParamManager.class, "getConfigType");
    // 录制私有方法行为
    PowerMock.expectPrivate(mock, "getConfigType", EasyMock.anyObject(Document.class))
        .andReturn("JNDI");

    // 建立mock对象
    Document mockDocument = EasyMock.createMock(Document.class);
    // Document a = PowerMock.createMock(Document.class);
    // 录制public方法行为
    EasyMock.expect(mockDocument.getElementsByTagName(EasyMock.anyObject(String.class)))
        .andReturn(null);

    // 回放mock对象行为
    PowerMock.replay(mock);
    // 回放mock对象行为
    EasyMock.replay(mockDocument);

    EnvConfigBean envConfig = mock.readConfig(configLocation);

    PowerMock.verifyAll();
    EasyMock.verify(mockDocument);
  }

  @Test
  public void testSetEnvConfigLocation() {
    ConfigParamManager cpm = new ConfigParamManager();
    cpm.setEnvConfigLocation("abc");
    assertEquals("environmentConfig.xml", cpm.getEnvConfigLocation());
  }

  @Test
  public void testCustomerConfigLocation() throws Exception {
    // 建立私有方法的mock对象
    ConfigParamManager mock =
        PowerMock.createPartialMock(ConfigParamManager.class, "getConfigType");
    // 录制私有方法行为
    PowerMock.expectPrivate(mock, "getConfigType", EasyMock.anyObject(Document.class))
        .andReturn("XML");
    // 回放mock对象行为
    PowerMock.replay(mock);
    EnvConfigBean envConfig = mock.readConfig("test/testEnvironmentConfig.xml");

    assertEquals(3, envConfig.getConfigParam().entrySet().size());
    PowerMock.verifyAll();
  }
}
Exemplo n.º 24
0
/**
 * This class represents a test class: - The test methods - The configuration methods (test and
 * method) - The class file
 *
 * @author <a href="mailto:[email protected]">Cedric Beust</a>
 * @author <a href='mailto:[email protected]'>Alexandru Popescu</a>
 */
class TestClass extends NoOpTestClass implements ITestClass {
  /* generated */
  private static final long serialVersionUID = -8077917128278361294L;
  private transient IAnnotationFinder annotationFinder = null;
  // The Strategy used to locate test methods (TestNG, JUnit, etc...)
  private transient ITestMethodFinder testMethodFinder = null;

  private IClass iClass = null;
  private String testName;
  private XmlTest xmlTest;
  private XmlClass xmlClass;

  private static final Logger LOG = Logger.getLogger(TestClass.class);

  protected TestClass(
      IClass cls,
      ITestMethodFinder testMethodFinder,
      IAnnotationFinder annotationFinder,
      RunInfo runInfo,
      XmlTest xmlTest,
      XmlClass xmlClass) {
    init(cls, testMethodFinder, annotationFinder, xmlTest, xmlClass);
  }

  @Override
  public String getTestName() {
    return testName;
  }

  @Override
  public XmlTest getXmlTest() {
    return xmlTest;
  }

  @Override
  public XmlClass getXmlClass() {
    return xmlClass;
  }

  public IAnnotationFinder getAnnotationFinder() {
    return annotationFinder;
  }

  private void init(
      IClass cls,
      ITestMethodFinder testMethodFinder,
      IAnnotationFinder annotationFinder,
      XmlTest xmlTest,
      XmlClass xmlClass) {
    log(3, "Creating TestClass for " + cls);
    iClass = cls;
    m_testClass = cls.getRealClass();
    this.xmlTest = xmlTest;
    this.xmlClass = xmlClass;
    this.testMethodFinder = testMethodFinder;
    this.annotationFinder = annotationFinder;
    initTestClassesAndInstances();
    initMethods();
  }

  private void initTestClassesAndInstances() {
    //
    // TestClasses and instances
    //
    Object[] instances = getInstances(false);
    for (Object instance : instances) {
      if (instance instanceof ITest) {
        testName = ((ITest) instance).getTestName();
        break;
      }
    }
    if (testName == null) {
      testName = iClass.getTestName();
    }
  }

  @Override
  public Object[] getInstances(boolean create) {
    return iClass.getInstances(create);
  }

  @Override
  public long[] getInstanceHashCodes() {
    return iClass.getInstanceHashCodes();
  }

  @Deprecated
  @Override
  public int getInstanceCount() {
    return iClass.getInstanceCount();
  }

  @Override
  public void addInstance(Object instance) {
    iClass.addInstance(instance);
  }

  private void initMethods() {
    ITestNGMethod[] methods = testMethodFinder.getTestMethods(m_testClass, xmlTest);
    m_testMethods = createTestMethods(methods);

    for (Object instance : iClass.getInstances(false)) {
      m_beforeSuiteMethods =
          ConfigurationMethod.createSuiteConfigurationMethods(
              testMethodFinder.getBeforeSuiteMethods(m_testClass),
              annotationFinder,
              true,
              instance);
      m_afterSuiteMethods =
          ConfigurationMethod.createSuiteConfigurationMethods(
              testMethodFinder.getAfterSuiteMethods(m_testClass),
              annotationFinder,
              false,
              instance);
      m_beforeTestConfMethods =
          ConfigurationMethod.createTestConfigurationMethods(
              testMethodFinder.getBeforeTestConfigurationMethods(m_testClass),
              annotationFinder,
              true,
              instance);
      m_afterTestConfMethods =
          ConfigurationMethod.createTestConfigurationMethods(
              testMethodFinder.getAfterTestConfigurationMethods(m_testClass),
              annotationFinder,
              false,
              instance);
      m_beforeClassMethods =
          ConfigurationMethod.createClassConfigurationMethods(
              testMethodFinder.getBeforeClassMethods(m_testClass),
              annotationFinder,
              true,
              instance);
      m_afterClassMethods =
          ConfigurationMethod.createClassConfigurationMethods(
              testMethodFinder.getAfterClassMethods(m_testClass),
              annotationFinder,
              false,
              instance);
      m_beforeGroupsMethods =
          ConfigurationMethod.createBeforeConfigurationMethods(
              testMethodFinder.getBeforeGroupsConfigurationMethods(m_testClass),
              annotationFinder,
              true,
              instance);
      m_afterGroupsMethods =
          ConfigurationMethod.createAfterConfigurationMethods(
              testMethodFinder.getAfterGroupsConfigurationMethods(m_testClass),
              annotationFinder,
              false,
              instance);
      m_beforeTestMethods =
          ConfigurationMethod.createTestMethodConfigurationMethods(
              testMethodFinder.getBeforeTestMethods(m_testClass), annotationFinder, true, instance);
      m_afterTestMethods =
          ConfigurationMethod.createTestMethodConfigurationMethods(
              testMethodFinder.getAfterTestMethods(m_testClass), annotationFinder, false, instance);
    }
  }

  /**
   * Create the test methods that belong to this class (rejects all those that belong to a different
   * class).
   */
  private ITestNGMethod[] createTestMethods(ITestNGMethod[] methods) {
    List<ITestNGMethod> vResult = Lists.newArrayList();
    for (ITestNGMethod tm : methods) {
      ConstructorOrMethod m = tm.getConstructorOrMethod();
      if (m.getDeclaringClass().isAssignableFrom(m_testClass)) {
        for (Object o : iClass.getInstances(false)) {
          log(4, "Adding method " + tm + " on TestClass " + m_testClass);
          vResult.add(
              new TestNGMethod(
                  /* tm.getRealClass(), */ m.getMethod(), annotationFinder, xmlTest, o));
        }
      } else {
        log(4, "Rejecting method " + tm + " for TestClass " + m_testClass);
      }
    }

    return vResult.toArray(new ITestNGMethod[vResult.size()]);
  }

  public ITestMethodFinder getTestMethodFinder() {
    return testMethodFinder;
  }

  private void log(int level, String s) {
    Utils.log("TestClass", level, s);
  }

  protected void dump() {
    LOG.info("===== Test class\n" + m_testClass.getName());
    for (ITestNGMethod m : m_beforeClassMethods) {
      LOG.info("  @BeforeClass " + m);
    }
    for (ITestNGMethod m : m_beforeTestMethods) {
      LOG.info("  @BeforeMethod " + m);
    }
    for (ITestNGMethod m : m_testMethods) {
      LOG.info("    @Test " + m);
    }
    for (ITestNGMethod m : m_afterTestMethods) {
      LOG.info("  @AfterMethod " + m);
    }
    for (ITestNGMethod m : m_afterClassMethods) {
      LOG.info("  @AfterClass " + m);
    }
    LOG.info("======");
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(getClass()).add("name", m_testClass).toString();
  }

  public IClass getIClass() {
    return iClass;
  }
}
public class ClusterEntityHelperImpl extends IEntityManagerHelper {

  public ClusterEntityHelperImpl() {}

  public ClusterEntityHelperImpl(String envFileName) throws Exception {
    super(envFileName);
  }

  Logger logger = Logger.getLogger(this.getClass());

  public ServiceResponse delete(String url, String data) throws Exception {
    // throw new UnsupportedOperationException("Not supported yet.");
    url += "/cluster/" + Util.readClusterName(data) + colo;
    return Util.sendRequest(url);
  }

  public ServiceResponse getEntityDefinition(String url, String data) throws Exception {
    url += "/cluster/" + Util.readClusterName(data);

    return Util.sendRequest(url);
  }

  public ServiceResponse getStatus(String url, String data) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public ServiceResponse getStatus(Util.URLS url, String data) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public ServiceResponse resume(String url, String data) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public ServiceResponse schedule(String url, String data) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public ServiceResponse submitAndSchedule(String url, String data) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public ServiceResponse submitAndSchedule(Util.URLS url, String data) throws Exception {
    return null;
  }

  public ServiceResponse submitEntity(String url, String data) throws Exception {
    // throw new UnsupportedOperationException("Not supported yet.");
    url += "/cluster" + colo;

    return Util.sendRequest(url, data);
  }

  public ServiceResponse suspend(String url, String data) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public ServiceResponse suspend(Util.URLS url, String data) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public ServiceResponse validateEntity(String url, String data) throws Exception {

    return Util.sendRequest(url, data);
  }

  public void validateResponse(String response, APIResult.Status expectedResponse, String filename)
      throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public ServiceResponse submitEntity(Util.URLS url, String data) throws Exception {
    // TODO Auto-generated method stub
    // throw new UnsupportedOperationException("Not supported yet.");
    return submitEntity(this.hostname + url.getValue(), data);
  }

  @Override
  public ServiceResponse schedule(Util.URLS scheduleUrl, String processData) throws Exception {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public ServiceResponse delete(Util.URLS deleteUrl, String data) throws Exception {
    // TODO Auto-generated method stub
    return delete(this.hostname + deleteUrl.getValue(), data);
  }

  @Override
  public ServiceResponse resume(Util.URLS url, String data) throws Exception {
    // TODO Auto-generated method stub
    return null;
  }

  public ProcessInstancesResult getRunningInstance(Util.URLS processRuningInstance, String name)
      throws Exception {
    // TODO Auto-generated method stub
    return null;
  }

  public ProcessInstancesResult getProcessInstanceStatus(String readEntityName, String params) {
    // TODO Auto-generated method stub
    return null;
  }

  public ProcessInstancesResult getProcessInstanceSuspend(String readEntityName, String params) {
    // TODO Auto-generated method stub
    return null;
  }

  public String writeEntityToFile(String entity) throws Exception {
    File file = new File("/tmp/" + Util.readClusterName(entity) + ".xml");
    BufferedWriter bf = new BufferedWriter(new FileWriter(file));
    bf.write(entity);
    bf.close();
    return "/tmp/" + Util.readClusterName(entity) + ".xml";
  }

  @Override
  public String submitEntityViaCLI(String filePath) throws Exception {

    // System.out.println(BASE_COMMAND+ " entity -submit -url "+this.hostname+" -type cluster
    // -file "+filePath);
    return Util.executeCommand(
        BASE_COMMAND
            + " entity -submit -url "
            + this.hostname
            + " -type cluster -file "
            + filePath);
  }

  @Override
  public String validateEntityViaCLI(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -validate -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  @Override
  public String submitAndScheduleViaCLI(String filePath) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -submitAndSchedule -url "
            + this.hostname
            + " -type cluster -file "
            + filePath);
  }

  @Override
  public String scheduleViaCLI(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -schedule -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  @Override
  public String resumeViaCLI(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -resume -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  @Override
  public String getStatusViaCLI(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -status -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  @Override
  public String getEntityDefinitionViaCLI(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -definition -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  @Override
  public String deleteViaCLI(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -delete -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  @Override
  public String suspendViaCLI(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -suspend -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  public String updateViaCLI(String processName, String newProcessFilePath) throws Exception {
    return null;
  }

  public String list() throws Exception {
    return Util.executeCommand(
        BASE_COMMAND + " entity -list -url " + this.hostname + " -type cluster");
  }

  @Override
  public String getDependencies(String entityName) throws Exception {

    return Util.executeCommand(
        BASE_COMMAND
            + " entity -dependency -url "
            + this.hostname
            + " -type cluster -name "
            + entityName);
  }

  @Override
  public ProcessInstancesResult getRunningInstance(String processRuningInstance, String name)
      throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public List<String> getArchiveInfo() throws Exception {

    return Util.getClusterArchiveInfo(this);
  }

  @Override
  public List<String> getStoreInfo() throws Exception {

    return Util.getClusterStoreInfo(this);
  }

  @Override
  public ServiceResponse getEntityDefinition(Util.URLS url, String data) throws Exception {
    return getEntityDefinition(this.hostname + url.getValue(), data);
  }

  @Override
  public ServiceResponse update(String oldEntity, String newEntity) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public String toString(Object object) throws Exception {
    Cluster processObject = (Cluster) object;

    JAXBContext context = JAXBContext.newInstance(Cluster.class);
    Marshaller um = context.createMarshaller();
    StringWriter writer = new StringWriter();
    um.marshal(processObject, writer);
    return writer.toString();
  }

  @Override
  public ProcessInstancesResult getInstanceRerun(String EntityName, String params)
      throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  public ProcessInstancesResult getProcessInstanceKill(String readEntityName, String string)
      throws Exception {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public ProcessInstancesResult getProcessInstanceRerun(String readEntityName, String string)
      throws Exception {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public ProcessInstancesResult getProcessInstanceResume(String readEntityName, String string)
      throws Exception {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public String getProcessInstanceStatusViaCli(
      String EntityName, String start, String end, String colos) throws Exception {
    // TODO Auto-generated method stub
    return null;
  }
}
Exemplo n.º 26
0
public class TestBase {
  protected EventFiringWebDriver driver;
  protected WebDriver dr;
  protected Properties locator;
  protected Properties conf;
  private Logger logger = Logger.getLogger(TestBase.class);
  public final String pathLocator = "src\\test\\resources\\configurations\\Locator.properties";
  private DesiredCapabilities capabilities;
  public final String pathConf = "src\\test\\resources\\configurations\\Conf.properties";
  protected String url;
  protected String br;
  protected String strTextValue = null;
  protected String originalWindowHandle;
  protected HomePage ObjTestHomePage;
  protected ResultPage ObjResultPage;
  public static final long PAGELOAD_TIMEOUT = 45L;
  public static final long IMPLICIT_WAIT = 20L;

  // will be called in before class
  public void initBeforeClass() {
    conf = readPropertiesFile(pathConf);
    url = conf.getProperty("url");
    br = conf.getProperty("browser");
  }
  // will be called in before method
  public void initBeforeMethod() {
    // initialize - all before methods
    logger.info("Starting init method");
    locator = readPropertiesFile(pathLocator);
    // Launch webDriver

    dr = getWebDriver(br);
    driver = new EventFiringWebDriver(dr);
    // maximize
    driver.manage().window().maximize();
    originalWindowHandle = driver.getWindowHandle();
    // implicit wait, pageloadtimeout

    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(PAGELOAD_TIMEOUT, TimeUnit.SECONDS);
    // navigate
    navigateTo(url);
    createObject();
  }
  // close all existing opened browser
  public void closeAllBr() {
    try {
      driver.close();
      driver.quit();
    } catch (Throwable t) {
      logger.error("cannot close browser", t);
    }
  }

  public Properties readPropertiesFile(String path) {
    try {
      logger.info("loading properties file " + path);
      Properties prop = new Properties();
      FileInputStream fis = new FileInputStream(path);

      prop.load(fis);
      return prop;

    } catch (Throwable t) {
      logger.error("File could not be loaded" + path, t);
    }
    return null;
  }
  // Load Browser

  public WebDriver getWebDriver(String br) {
    // make sure capabilities is not null
    logger.info("Starting WebDriver");
    // Set the desired capabilities
    capabilities = setDesiredCapabilites(br);
    // To run test Cases on Firefox Browser.
    if (br.equalsIgnoreCase("firefox")) {
      dr = new FirefoxDriver(capabilities);
      return dr;
    }
    return null;
  }
  /** @param br purpose: set desiredCapanbilities */
  public DesiredCapabilities setDesiredCapabilites(String browserCapability) {
    capabilities = new DesiredCapabilities();

    switch (browserCapability) {
      case "firefox":
        capabilities.setBrowserName("firefox");
        capabilities.setPlatform(Platform.ANY);
        break;

      default:
        try {
          throw new Throwable("no capalities matched");
        } catch (Throwable e) {
          // TODO Auto-generated catch block
          logger.error("no capabilites found", e);
        }
    }
    return capabilities;
  }

  // createing object of all modules to use in test cases. Create object of every class.
  public void createObject() {
    ObjTestHomePage = new HomePage(driver, locator);
    ObjResultPage = new ResultPage(driver, locator);
  }
  // Nullifying all the variables.
  public void nullifyAllVariables() {
    ObjTestHomePage = null;
    ObjResultPage = null;
  }

  // *****************************************************
  // basic method-type, click, double click, drag and drop
  // GetWebElement
  public WebElement getWebElement(By by) {
    try {
      logger.info("finding webelement by " + by);
      return driver.findElement(by);
    } catch (Throwable t) {
      logger.error("could not find webElement by " + by, t);
    }
    return null;
  }

  // -------------------------------------------------------
  //	Click Method.
  public void click(By by) {
    try {
      getWebElement(by).click();
    } catch (Throwable t) {
      logger.error("cannot click by " + by, t);
    }
  }

  // selects by String value
  public void selectByValue(By by, String value) {
    try {

      new Select(getWebElement(by)).selectByValue(value);

    } catch (Throwable t) {
      logger.error("cannot select webelement by " + by, t);
    }
  }

  /*This Method can be used to clear the text field and send the keys after that*/

  public void clearAndSendKeys(By by, String toType) {
    try {
      getWebElement(by).clear();
      getWebElement(by).sendKeys(toType);
    } catch (Throwable t) {
      logger.error("cannot type to " + by, t);
    }
  }

  public String getTextValue(By by) {
    try {
      // String strTextValue= getWebElement(by).getText();
      strTextValue = getWebElement(by).getText();
    } catch (Throwable t) {
      logger.error("cannot type to " + by, t);
    }
    return strTextValue;
  }

  // This method can be used to navigate to specific url
  public void navigateTo(String url) {
    try {
      logger.info("navigating to url--" + url);
      driver.navigate().to(url);
    } catch (Throwable e) {
      logger.error("cannot navigate to url " + url, e);
    }
  }
}
Exemplo n.º 27
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);
        }
      }
    }
  }
Exemplo n.º 28
0
public class CmsUtilTest {

  private CmsUtil util = new CmsUtil();
  CmsCISimple ciSimple = new CmsCISimple();
  private Map<String, String> ciAttributes;

  private static final String CLASS_NAME = null;
  private static final long CI_ID = 100;
  private static final String CI_NAME = "Source";
  private static final String NS_PATH = "/public/main";
  private static final String CI_IMPL = "java.lang";
  private static final String DE_FACTO = "df";
  private static final String DE_JURE = "dj";
  private static final Logger logger = Logger.getLogger(CmsUtilTest.class);

  public CmsUtilTest() {
    this.ciAttributes = new HashMap<String, String>(3);
    this.ciAttributes.put("A", "1");
    this.ciAttributes.put("B", "2");
    this.ciAttributes.put("Z", "26");

    this.ciSimple.setCiClassName(CLASS_NAME);
    this.ciSimple.setCiId(CI_ID);
    this.ciSimple.setCiName(CI_NAME);
    this.ciSimple.setCreated(new Date());
    this.ciSimple.setImpl(CI_IMPL);
    this.ciSimple.setNsPath(NS_PATH);
    this.ciSimple.setCiAttributes(ciAttributes);
  }

  // TODO	@Test
  public void custCiSimpleToCi() {

    CmsCI ci = util.custCISimple2CI(this.ciSimple, DE_FACTO);
  }

  private void dumpCmsCIAttributes(CmsCI ci) {
    for (CmsCIAttribute manifestAttr : ci.getAttributes().values()) {
      System.out.println("~Ci_Dj :" + manifestAttr.getDjValue());
    }
  }

  private void dumpMaps(
      Map<String, String> cloudVars,
      Map<String, String> globalVars,
      Map<String, String> localVars) {
    System.out.println("~CLOUDVARS  " + cloudVars);
    System.out.println("~GLOBALVARS " + globalVars);
    System.out.println("~LOCALVARS  " + localVars);
  }

  @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);
          }
        }
      }
    }
  }

  @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);
        }
      }
    }
  }

  @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);
        }
      }
    }
  }

  @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");
      }
    }
  }

  @Test(priority = 90)
  /**
   * test local var where both Cloud and Global have that variable name and the one we want is from
   * the Cloud
   */
  public void processLocalVarChoiceGlobalVsCloud() {
    // Variables for cloud, global, and locals
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    cloudVars.put("common", "duolc");

    Map<String, String> globalVars = new HashMap<String, String>(3);
    globalVars.put("common", "labolg");

    Map<String, String> localVars = new HashMap<String, String>(3);
    localVars.put("common", "lacol");

    CmsCI ci = new CmsCI();
    ci.setCiId(90);
    ci.setCiName("processLocalVarChoiceGlobalVsCloud");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    int i = 0;
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_CLOUD{common}");
    String nameOfAttribute = "my-one-attr";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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 k>" + djKey + " v->" + djAfter);
      if (djKey.equals(nameOfAttribute)) {
        assertEquals(djAfter, "duolc");
      }
    }
  }

  @Test(priority = 95)
  /** test local var where regex matches in middle not start */
  public void processLocalVarMid() {
    Map<String, String> localVars = new HashMap<String, String>(3);
    localVars.put("mylocal", "123456");

    CmsCI ci = new CmsCI();
    ci.setCiId(95);
    ci.setCiName("processLocalVarMid");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    int i = 0;
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("/preamble/$OO_LOCAL{mylocal}");
    String nameOfAttribute = "my-only-attr";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, 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(nameOfAttribute)) {
        assertEquals(djAfter, "/preamble/123456");
      }
    }
  }

  @Test(priority = 98)
  /** test local var where regex matches in middle not start */
  public void processLocalVarDuo() {
    Map<String, String> localVars = new HashMap<String, String>(3);
    localVars.put("mylocal", "123456");

    CmsCI ci = new CmsCI();
    ci.setCiId(98);
    ci.setCiName("processLocalVarDuo");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    int i = 0;
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("/preamble/$OO_LOCAL{mylocal}/middle/$OO_LOCAL{mylocal}");
    String nameOfAttribute = "my-only-attr";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, 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(nameOfAttribute)) {
        assertEquals(djAfter, "/preamble/123456/middle/123456");
      }
    }
  }

  @Test(priority = 111)
  /** test a composite var , one of each layer */
  public void processLocalVarMixed() {
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    cloudVars.put("myCloud", "987654");
    Map<String, String> globalVars = new HashMap<String, String>(3);
    globalVars.put("myGlobal", "1212");
    Map<String, String> localVars = new HashMap<String, String>(3);
    localVars.put("myLocal", "8989");

    CmsCI ci = new CmsCI();
    ci.setCiId(111);
    ci.setCiName("processLocalVarMixed");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue(
        "/preamble/$OO_CLOUD{myCloud}/middle/$OO_GLOBAL{myGlobal}/sss/$OO_LOCAL{myLocal}");
    String nameOfAttribute = "myMixedAttribute";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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 k>" + djKey + " v->" + djAfter);
      if (djKey.equals(nameOfAttribute)) {
        assertEquals(djAfter, "/preamble/987654/middle/1212/sss/8989");
      }
    }
  }

  @Test(priority = 115)
  /**
   * test multi resolution as in artifacts usage
   * $OO_LOCAL{groupId}:$OO_LOCAL{artifactId}:$OO_LOCAL{extension}
   */
  public void processLocalVarTrips() {

    Map<String, String> localVars = new HashMap<String, String>(3);
    localVars.put("groupId", "esb");
    localVars.put("artifactId", "service");
    localVars.put("extension", "html");

    CmsCI ci = new CmsCI();
    ci.setCiId(115);
    ci.setCiName("processLocalVarTrips");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_LOCAL{groupId}:$OO_LOCAL{artifactId}:$OO_LOCAL{extension}");
    String nameOfAttribute = "myArtifactGav";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, 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(nameOfAttribute)) {
        assertEquals(djAfter, "esb:service:html");
      }
    }
  }

  @Test(priority = 122)
  /** test variable that is not one of our OO_CLOUD/LOCAL/GLOBAL varieties */
  public void processLocalVarNegativeSpelling() {

    Map<String, String> localVars = new HashMap<String, String>(1);
    localVars.put("groupId", "barrrrrr");

    CmsCI ci = new CmsCI();
    ci.setCiId(122);
    ci.setCiName("processLocalVarNegativeSpelling");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_NOOCAL{groupId}"); // typo in place of $OO_LOCAL
    String nameOfAttribute = "irrelevantname";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, 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(nameOfAttribute)) {
        assertEquals(djAfter, "$OO_NOOCAL{groupId}"); // outcome is it stays as it
      }
    }
  }

  @Test(priority = 130, expectedExceptions = CIValidationException.class)
  /** test variable that user did not set, it is exception bad reference */
  public void processLocalVarNegativeMissingLocal() {
    Map<String, String> localVars = new HashMap<String, String>(1);
    localVars.put("aaaaaa", "ignore-me");
    CmsCI ci = new CmsCI();
    ci.setCiId(130);
    ci.setCiName("processLocalVarNegativeMissingLocal");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_LOCAL{this-is-not-resolved}");
    String nameOfAttribute = "trouble";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, localVars);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, localVars);
    dumpCmsCIAttributes(ci);
  }

  @Test(priority = 131, expectedExceptions = CIValidationException.class)
  /** test variable that user did not set, it is exception bad reference */
  public void processLocalVarNegativeMissingLocal2() {
    CmsCI ci = new CmsCI();
    ci.setCiId(132);
    ci.setCiName("processLocalVarNegativeMissingLocal2");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_LOCAL{this-is-not-resolved}");
    String nameOfAttribute = "trouble";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, null); // this time all map empty
    dumpCmsCIAttributes(ci);
  }

  @Test(priority = 132, expectedExceptions = CIValidationException.class)
  /** test variable that user did not set, it is exception bad reference */
  public void processLocalVarNegativeMissingGlobal() {
    CmsCI ci = new CmsCI();
    ci.setCiId(132);
    ci.setCiName("processLocalVarNegativeMissingGlobal");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_GLOBAL{where-is-it}");
    String nameOfAttribute = "nowhere";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, null);
    dumpCmsCIAttributes(ci);
  }

  @Test(priority = 132, expectedExceptions = CIValidationException.class)
  /** test variable that user did not set, it is exception bad reference */
  public void processLocalVarNegativeMissingGlobal2() {
    Map<String, String> globalVars = new HashMap<String, String>(1);
    globalVars.put("cc", "ignore-distraction");
    CmsCI ci = new CmsCI();
    ci.setCiId(132);
    ci.setCiName("processLocalVarNegativeMissingGlobal2");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_GLOBAL{where?}");
    String nameOfAttribute = "nowh---ere";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, globalVars, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, globalVars, null);
    dumpCmsCIAttributes(ci);
  }

  @Test(priority = 133, expectedExceptions = CIValidationException.class)
  /** test variable that user did not set, it is exception bad reference */
  public void processLocalVarNegativeMissingCloud1() {
    Map<String, String> cloudVars = new HashMap<String, String>(1);
    cloudVars.put("bb", "ignore-bb");
    CmsCI ci = new CmsCI();
    ci.setCiId(133);
    ci.setCiName("processLocalVarNegativeMissingCloud1");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_CLOUD{not-cloudy}");
    String nameOfAttribute = "sun";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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, null, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, cloudVars, null, null);
    dumpCmsCIAttributes(ci);
  }

  @Test(priority = 134, expectedExceptions = CIValidationException.class)
  /** test variable that user did not set, it is exception bad reference */
  public void processLocalVarNegativeMissingCloud() {
    CmsCI ci = new CmsCI();
    ci.setCiId(134);
    ci.setCiName("processLocalVarNegativeMissingCloud");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_CLOUD{not-cloudy}");
    String nameOfAttribute = "sun";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, null, null, null);
    dumpCmsCIAttributes(ci);
  }

  @Test(priority = 140)
  /**
   * test multi resolution as in artifacts usage
   * $OO_LOCAL{groupId}:$OO_LOCAL{artifactId}:$OO_LOCAL{extension}
   */
  public void processLocalVarDemo() {
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    cloudVars.put("version", "2.0");
    Map<String, String> globalVars = new HashMap<String, String>(3);
    globalVars.put("version", "$OO_CLOUD{version}");
    Map<String, String> localVars = new HashMap<String, String>(3);
    localVars.put("groupId", "esb");
    localVars.put("artifactId", "service");

    CmsCI ci = new CmsCI();
    ci.setCiId(140);
    ci.setCiName("processLocalVarDemo");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_LOCAL{groupId}:$OO_LOCAL{artifactId}:$OO_GLOBAL{version}");
    String nameOfAttribute = "myArtifactGav";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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 k>" + djKey + " v->" + djAfter);
      if (djKey.equals(nameOfAttribute)) {
        assertEquals(djAfter, "esb:service:2.0");
      }
    }
  }

  @Test(priority = 150)
  /**
   * test variable that user did not set, instead it is empty string "" this is NOT a bad reference
   */
  public void processLocalVarBlankValue() {
    Map<String, String> cloudVars = new HashMap<String, String>(3);
    cloudVars.put("FOO", "");
    CmsCI ci = new CmsCI();
    ci.setCiId(150);
    ci.setCiName("processLocalVarBlankValue");
    Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1);
    CmsCIAttribute attrL = new CmsCIAttribute();
    attrL.setDjValue("$OO_CLOUD{FOO}");
    String nameOfAttribute = "testingABlank";
    attributes.put(nameOfAttribute, attrL);
    ci.setAttributes(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(null, null, null);
    dumpCmsCIAttributes(ci);
    util.processAllVars(ci, cloudVars, null, null);
    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(nameOfAttribute)) {
        assertEquals(djAfter, "", "this is not a empty string as expected");
      }
    }
  }

  @Test
  public void testErrorMessage() {
    String errorMessage =
        "CI tomcat, attribute: pre_shutdown_command has bad local var <DEPLOYCONTEXT> reference! value=null";
    assertEquals(
        util.getErrorMessage("tomcat", "pre_shutdown_command", null, "DEPLOYCONTEXT"),
        errorMessage);
  }
}
public class CreditCardTestCase {

  private static final Logger logger = Logger.getLogger(CreditCardTestCase.class);

  public CreditCard creditCard;

  public static String createdCreditCardId = null;

  public static final String TYPE = "visa";

  public static final String NUMBER = "4329685037393232";

  public static final String FIRSTNAME = "Joe";

  public static final String LASTNAME = "Shopper";

  public static final int EXPMONTH = 11;

  public static final int EXPYEAR = 2018;

  public static final int CVV2 = 874;

  public static final String ID = "12345";

  public static final String EXTERNAL_CUSTOMER_ID = "12345";

  public static final String STATE = "Approved";

  public static final String VALIDUNTIL = "2020";

  public static final Address BILLINGADDRESS = AddressTestCase.createAddress();

  @BeforeTest(groups = "integration")
  public void beforeClass() throws PayPalRESTException {
    File testFile = new File(".", "src/test/resources/sdk_config.properties");
    PayPalResource.initConfig(testFile);
    String clientID = "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM";
    String clientSecret = "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM";
    TokenHolder.accessToken = new OAuthTokenCredential(clientID, clientSecret).getAccessToken();
  }

  public static CreditCard createCreditCard() {
    CreditCard creditCard = new CreditCard();
    creditCard
        .setBillingAddress(BILLINGADDRESS)
        .setExpireMonth(EXPMONTH)
        .setExpireYear(EXPYEAR)
        .setFirstName(FIRSTNAME)
        .setLastName(LASTNAME)
        .setNumber(NUMBER)
        .setType(TYPE)
        .setCvv2(CVV2)
        .setBillingAddress(BILLINGADDRESS)
        .setId(ID)
        .setState(STATE)
        .setValidUntil(VALIDUNTIL);
    return creditCard;
  }

  public static CreditCard createDummyCreditCard() {
    CreditCard creditCard = new CreditCard();
    creditCard.setBillingAddress(BILLINGADDRESS);
    creditCard.setExpireMonth(EXPMONTH);
    creditCard.setExpireYear(EXPYEAR);
    creditCard.setFirstName(FIRSTNAME);
    creditCard.setLastName(LASTNAME);
    creditCard.setNumber(NUMBER);
    creditCard.setType(TYPE);
    creditCard.setCvv2(CVV2);
    creditCard.setBillingAddress(BILLINGADDRESS);
    creditCard.setId(ID);
    creditCard.setExternalCustomerId(EXTERNAL_CUSTOMER_ID);
    creditCard.setState(STATE);
    creditCard.setValidUntil(VALIDUNTIL);
    List<Links> links = new ArrayList<Links>();
    links.add(LinksTestCase.createLinks());
    creditCard.setLinks(links);
    return creditCard;
  }

  @Test(groups = "unit")
  public void testConstruction() {
    CreditCard creditCard = createDummyCreditCard();
    Assert.assertEquals(creditCard.getCvv2(), CVV2);
    Assert.assertEquals(creditCard.getExpireMonth(), EXPMONTH);
    Assert.assertEquals(creditCard.getExpireYear(), EXPYEAR);
    Assert.assertEquals(creditCard.getFirstName(), FIRSTNAME);
    Assert.assertEquals(creditCard.getLastName(), LASTNAME);
    Assert.assertEquals(creditCard.getNumber(), NUMBER);
    Assert.assertEquals(creditCard.getType(), TYPE);
    Assert.assertEquals(creditCard.getBillingAddress().getCity(), AddressTestCase.CITY);
    Assert.assertEquals(creditCard.getId(), ID);
    Assert.assertEquals(creditCard.getExternalCustomerId(), EXTERNAL_CUSTOMER_ID);
    Assert.assertEquals(creditCard.getState(), STATE);
    Assert.assertEquals(creditCard.getValidUntil(), VALIDUNTIL);
    Assert.assertEquals(creditCard.getLinks().size(), 1);
  }

  @Test(groups = "unit")
  public void testCvv2() {
    logger.info("**** Test CreditCard CVV2 ****");
    CreditCard creditCard = createDummyCreditCard();

    // empty CVV2
    creditCard.setCvv2(null);
    Assert.assertEquals(-1, creditCard.getCvv2());

    // valid CVV2
    creditCard.setCvv2(123);
    Assert.assertEquals(123, creditCard.getCvv2());
  }

  @Test(groups = "integration")
  public void createCreditCardTest() throws PayPalRESTException {
    logger.info("**** Create CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard creditCard = new CreditCard();
    creditCard.setExpireMonth(EXPMONTH);
    creditCard.setExpireYear(EXPYEAR);
    creditCard.setNumber(NUMBER);
    creditCard.setType(TYPE);
    this.creditCard = creditCard.create(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Credit Card created with ID = " + this.creditCard.getId());
    Assert.assertEquals(true, "ok".equalsIgnoreCase(this.creditCard.getState()));
    logger.info("Created Credit Card status = " + this.creditCard.getState());
    createdCreditCardId = this.creditCard.getId();
  }

  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testGetCreditCard() throws PayPalRESTException {
    logger.info("**** Get CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(
        true, this.creditCard.getId().equalsIgnoreCase(retrievedCreditCard.getId()));
    logger.info("Retrieved Credit Card status = " + retrievedCreditCard.getState());
  }

  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void testUpdateCreditCard() throws PayPalRESTException {
    logger.info("**** Update CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    // set up patch request
    Patch patch = new Patch();
    patch.setOp("replace");
    patch.setPath("/expire_year");
    patch.setValue(new Integer(2020));
    List<Patch> patchRequest = new ArrayList<Patch>();
    patchRequest.add(patch);

    // send patch request
    CreditCard creditCard = new CreditCard();
    creditCard.setId(createdCreditCardId);
    CreditCard retrievedCreditCard = creditCard.update(TokenHolder.accessToken, patchRequest);

    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    Assert.assertEquals(2020, retrievedCreditCard.getExpireYear());
  }

  @Test(
      groups = "integration",
      dependsOnMethods = {"testUpdateCreditCard"})
  public void deleteCreditCard() throws PayPalRESTException {
    logger.info("**** Delete CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    retrievedCreditCard.delete(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    try {
      CreditCard.get(TokenHolder.accessToken, createdCreditCardId);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  @Test(
      groups = "integration",
      dependsOnMethods = {"createCreditCardTest"})
  public void testListCreditCard() throws PayPalRESTException {
    logger.info("**** List CreditCard ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    CreditCardHistory creditCards = CreditCard.list(TokenHolder.accessToken);
    logger.info("Request = " + CreditCard.getLastRequest());
    logger.info("Response = " + CreditCard.getLastResponse());
    logger.info("Retrieved list of credit cards = " + creditCards.getItems());
    Assert.assertTrue(creditCards.getTotalItems() > 0);
  }

  @Test(
      groups = "integration",
      dependsOnMethods = {"testGetCreditCard"})
  public void getCreditCardForNull() {
    logger.info("**** Get CreditCard Null ****");
    logger.info("Generated Access Token = " + TokenHolder.accessToken);

    try {
      CreditCard.get(TokenHolder.accessToken, null);
    } catch (IllegalArgumentException e) {
      Assert.assertTrue(e != null, "Illegal Argument Exception not thrown for null arguments");
    } catch (PayPalRESTException e) {
      Assert.fail();
    }
  }

  @Test
  public void testCreditCardUnknownFileConfiguration() {
    try {
      CreditCard.initConfig(new File("unknown.properties"));
    } catch (PayPalRESTException e) {
      Assert.assertEquals(e.getCause().getClass().getSimpleName(), "FileNotFoundException");
    }
  }

  @Test
  public void testCreditCardInputStreamConfiguration() {
    try {
      File testFile = new File(".", "src/test/resources/sdk_config.properties");
      FileInputStream fis = new FileInputStream(testFile);
      CreditCard.initConfig(fis);
    } catch (PayPalRESTException e) {
      Assert.fail("[sdk_config.properties] stream loading failed");
    } catch (FileNotFoundException e) {
      Assert.fail("[sdk_config.properties] file is not available");
    }
  }

  @Test
  public void testCreditCardPropertiesConfiguration() {
    try {
      File testFile = new File(".", "src/test/resources/sdk_config.properties");
      Properties props = new Properties();
      FileInputStream fis = new FileInputStream(testFile);
      props.load(fis);
      CreditCard.initConfig(props);
    } catch (FileNotFoundException e) {
      Assert.fail("[sdk_config.properties] file is not available");
    } catch (IOException e) {
      Assert.fail("[sdk_config.properties] file is not loaded into properties");
    }
  }

  @Test
  public void testTOJSON() {
    CreditCard creditCard = createCreditCard();
    Assert.assertEquals(creditCard.toJSON().length() == 0, false);
  }

  @Test
  public void testTOString() {
    CreditCard creditCard = createCreditCard();
    Assert.assertEquals(creditCard.toString().length() == 0, false);
  }
}
 public SystemAdminUsersPageTest() {
   log = Logger.getLogger(SystemAdminUsersPageTest.class);
 }