Package ch.inftec.ju.util

Examples of ch.inftec.ju.util.SystemPropertyTempSetter


  @Test
  public void canOpenGoogle_andSearchForCheese_usingChrome() {
    JuAssumeUtils.chromeIsAvailable();
    JuAssumeUtils.internetIsAvailable();
   
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("ju-testing-ee.selenium.driver", "Chrome");
     
      TestUtils.runJUnitTests(GoogleSeleniumTest.class);
    }   
  }
View Full Code Here


 
  @Test
  public void canOpenGoogle_andSearchForCheese_usingHtmlUnit() {
    JuAssumeUtils.internetIsAvailable();
   
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("ju-testing-ee.selenium.driver", "HtmlUnit");
      ts.setProperty("ju-testing-ee.selenium.htmlUnit.enableJavascript", "false");
     
      TestUtils.runJUnitTests(GoogleSeleniumTest.class);
    }   
  }
View Full Code Here

  @Test
  public void canOpenGoogle_andSearchForCheese_usingHtmlUnitAndChrome() {
    JuAssumeUtils.chromeIsAvailable();
    JuAssumeUtils.internetIsAvailable();
   
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("ju-testing-ee.selenium.driver", "HtmlUnit,Chrome");
      ts.setProperty("ju-testing-ee.selenium.htmlUnit.enableJavascript", "false");
     
      TestUtils.runJUnitTests(GoogleSeleniumTest.class);
    }
  }
View Full Code Here

    JuUtils.clearPropertyChain();
  }
 
  @Test
  public void supports_unencryptedPassword() {
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("ju-util.propertyChain.encryption.password", "secretPassword");
     
      ConnectionInfoImpl ci = new ConnectionInfoImpl();
      ci.setPassword("cCULeUjKiLfBwEgCOKC1g3BasxVDF85c");
     
      Assert.assertEquals("cCULeUjKiLfBwEgCOKC1g3BasxVDF85c", ci.getPassword());
View Full Code Here

    }
  }
 
  @Test
  public void supports_encryptedPassword() {
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("ju-util.propertyChain.encryption.password", "secretPassword");
     
      ConnectionInfoImpl ci = new ConnectionInfoImpl();
      ci.setPassword("ENC(cCULeUjKiLfBwEgCOKC1g3BasxVDF85c)");
     
      Assert.assertEquals("secretVal", ci.getPassword());
View Full Code Here

   * a SystemPropertyTempSetter that can be used to reset the properties.
   * @param testEnvAnnos List of JuTestEnv annotations containing systemProperties settings
   * @return SystemPropertyTempSetter that must be closed as soon as the test context is left
   */
  public static SystemPropertyTempSetter setTestEnvProperties(List<AnnotationInfo<JuTestEnv>> testEnvAnnos) {
    @SuppressWarnings("resource") // We'll close it in another method...
    SystemPropertyTempSetter tempSetter = new SystemPropertyTempSetter();
   
    try {
      for (AnnotationInfo<JuTestEnv> testEnvInfo : testEnvAnnos) {
        logger.debug("Processing Annotation (Setting system property): {}", testEnvInfo);
       
        for (String keyValStr : testEnvInfo.getAnnotation().systemProperties()) {
          if (!StringUtils.isEmpty(keyValStr) && keyValStr.contains("=")) {
            int ind = keyValStr.indexOf("=");
            String key = keyValStr.substring(0, ind);
            String val = keyValStr.length() > ind - 1
                ? keyValStr.substring(ind + 1)
                : "";
           
            logger.debug("Setting system property for test context: {}={}", key, val);
            tempSetter.setProperty(key, val);
          } else {
            throw new JuRuntimeException("SystemProperty String must be of type key=val, but was: %s", keyValStr);
          }
        }
      }
    } catch (Exception ex) {
      // When an exception occurrs, make sure we reset the properties to their original values
      tempSetter.close();
      throw ex;
    }
   
    return tempSetter;
  }
View Full Code Here

//  @Inject
//  private DateProvider dateProvider;
 
  @Override
  public SystemPropertyTempSetter runPreTestActionsInEjbContext(TestRunnerAnnotationHandler handler) throws Exception {
    SystemPropertyTempSetter tempSetter = handler.initContainerTestEnv();
   
    try (TxHandler txHandler = new TxHandler(this.tx, true)) {
      // Execute post test annotations (dataset exporting, data verifying)
      handler.executePreTestAnnotations(new JuEmUtil(this.em));
      txHandler.commit(); // Commit after data verifying / exporting
    } catch (Exception ex) {
      // Reset properties in case of an exception
      tempSetter.close();
      throw ex;
    }
   
    return tempSetter;
  }
View Full Code Here

    @Override
    protected void doEvaluation(TestRunnerFacade facade, TestRunnerContext context) throws Throwable {
      TestRunnerAnnotationHandler handler = new TestRunnerAnnotationHandler(method, description, context);
     
      // Run the pre actions
      SystemPropertyTempSetter tempSetter = facade.runPreTestActionsInEjbContext(handler);
     
      try {
        // Run the test statement first. We'll only run the verifiers if the test statement succeeds
        testStatement.evaluate();
       
View Full Code Here

  public Statement apply(final Statement base, Description description) {
    // Handle JuTestEnv annotations
    Method method = TestUtils.getTestMethod(description);
    List<AnnotationInfo<JuTestEnv>> testEnvAnnos = ReflectUtils.getAnnotationsWithInfo(method, JuTestEnv.class, false, true, true);
    Collections.reverse(testEnvAnnos);
    final SystemPropertyTempSetter tempSetter = DbTestAnnotationHandler.setTestEnvProperties(testEnvAnnos);
   
    try {
      PropertyChain pc = JuUtils.getJuPropertyChain();
     
      if (DriverRule.driverHandlers.isEmpty()) {
        // Get from the properties which drivers we should use to run the tests
        String drivers[] = JuStringUtils.split(pc.get(PROP_DRIVER, true), ",", true);
        Assert.assertTrue(String.format("No drivers specified in property %s", DriverRule.PROP_DRIVER), drivers.length > 0);
       
        logger.debug("Initialize WebDrivers: " + Arrays.toString(drivers));
        for (String driverType : drivers) {
          logger.debug("Creating driver: " + driverType);
         
          if ("HtmlUnit".equals(driverType)) {
            DriverRule.driverHandlers.add(new HtmlUnitDriverHandler());
          } else if ("Chrome".equals(driverType)) {
            DriverRule.driverHandlers.add(new ChromeDriverHandler());
          } else {
            throw new JuRuntimeException(String.format("Unsupported selenium driver type: %s. Check value of property %s"
                , driverType
                , PROP_DRIVER));
          }
        }
      }
     
      return new Statement() {
        public void evaluate() throws Throwable {
          try {
            // Run test case for with all drivers.
            // We cannot use a for-iterator here as the closeAll method gets called when the for
            // method tries to loop again, resulting in a ConcurrentModificationException.
            for (int i = 0; i < driverHandlers.size(); i++) {
              DriverHandler driverHandler = driverHandlers.get(0);
              try (DriverHandler.DriverHandlerCreator driverCreator = driverHandler.newDriverHandlerCreator()) {
                logger.info("Running test with WebDriver " + driverCreator);
                testClass.driver = driverCreator.getDriver();

                // If the evaluation fails, it will break our loop, i.e. if we want to run drivers
                // d1 and d2 and in d1, we have an exception, d2 won't be executed at all...
                base.evaluate();
              }
            }
          } finally {
            tempSetter.close();
          }
        }
      };
    } catch (Exception ex) {
      tempSetter.close();
      throw ex;
    }
  }
View Full Code Here

  @Rule
  public MojoRule rule = new MojoRule();
 
  @Test
  public void canConfigureMojo_fromPom() throws Exception {
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("ju.mojoProp", "origValue");
     
      PropertiesMojo propertiesMojo = (PropertiesMojo) rule.configureMojo(new PropertiesMojo(), "ju-maven-plugin", new File("src/test/resources/test-poms/propertiesMojoTest/pom.xml"));
      propertiesMojo.execute();
     
      Assert.assertEquals("mojoVal", propertiesMojo.getProject().getProperties().get("ju.mojoProp"));
View Full Code Here

TOP

Related Classes of ch.inftec.ju.util.SystemPropertyTempSetter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.