Package ch.inftec.ju.util

Examples of ch.inftec.ju.util.SystemPropertyTempSetter


   * 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


   * 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

//  private DateProvider dateProvider;

  @Override
  public SystemPropertyTempSetter runPreTestActionsInEjbContext(TestRunnerAnnotationHandler handler) throws Exception {
    try (ContainerTestContextSetter s = handler.new ContainerTestContextSetter()) {
      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 (this.drivers.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) {
          WebDriver driver = null;
         
          logger.debug("Creating driver: " + driverType);
          if ("HtmlUnit".equals(driverType)) {
            boolean enableJavaScript = pc.get("ju-testing-ee.selenium.htmlUnit.enableJavascript", Boolean.class);
            driver = new HtmlUnitDriver(enableJavaScript);
          } else if ("Chrome".equals(driverType)) {
            System.setProperty("webdriver.chrome.driver", DriverRule.getChromeDriverExePath().toAbsolutePath().toString());
                driver = new ChromeDriver();
          } else {
            throw new JuRuntimeException(String.format("Unsupported selenium driver type: %s. Check value of property %s"
                , driverType
                , PROP_DRIVER));
          }
         
          this.drivers.put(driverType, driver);
          DriverRule.openDrivers.add(driver);
        }
      }
     
      return new Statement() {
        public void evaluate() throws Throwable {
          try {
            // Run test case for with all drivers
            for (String driverType : drivers.keySet()) {
              logger.info("Running test with WebDriver " + driverType);
              testClass.driver = drivers.get(driverType);
             
              // 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

    Assert.assertEquals("String", props.get("encProperty"));
  }
 
  @Test
  public void canExport_property_toSystemProperties() throws Exception {
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("propYesSysYes", "p1");
      ts.setProperty("propYesSysNo", "p2");
      ts.setProperty("propNoSysYes", "p3");
      ts.setProperty("propNoSysNo", "p4");
     
      PropertiesMojo propertiesMojo = (PropertiesMojo) rule.configureMojo(new PropertiesMojo(), "ju-maven-plugin", new File("src/test/resources/test-poms/propertiesMojoTest-exportSystemProperty/pom.xml"));
      propertiesMojo.execute();
     
      // Check maven property export
View Full Code Here

    }
  }
 
  @Test
  public void canSet_andInterpolate_properties() throws Exception {
    try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
      ts.setProperty("propSys", "p1");
      ts.setProperty("propMav", "p2");
      ts.setProperty("myKey", "p3");
     
      PropertiesMojo propertiesMojo = (PropertiesMojo) rule.configureMojo(new PropertiesMojo(), "ju-maven-plugin", new File("src/test/resources/test-poms/propertiesMojoTest-setAndInterpolateProperty/pom.xml"));
      propertiesMojo.execute();
     
      // Check maven property export
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.