Exemplo n.º 1
0
  /** Test an invalid directory name, see if an error occurs */
  @Test
  public void testInvalidDirectory() {
    System.setSecurityManager(new NoExitSecurityManager());
    boolean exceptionThrown = false;

    cobertura = new Cobertura(null);
    try {
      cobertura.executeCobertura();
    } catch (ExitException e) {
      exceptionThrown = true;
      assertEquals(
          "Exit status invalid", OperiasStatus.ERROR_COBERTURA_TASK_CREATION.ordinal(), e.status);
    }

    exceptionThrown = false;

    cobertura = new Cobertura("src/../");
    try {
      cobertura.executeCobertura();
    } catch (ExitException e) {
      exceptionThrown = true;
      assertEquals(
          "Exit status invalid",
          OperiasStatus.ERROR_COBERTURA_TASK_OPERIAS_EXECUTION.ordinal(),
          e.status);
    }

    assertTrue("No exception was thrown", exceptionThrown);

    System.setSecurityManager(null);
  }
Exemplo n.º 2
0
  /**
   * Proper execution of the maven project, but the coverage file was not found, can be test by
   * giving a random non existing output directory
   */
  @Test
  public void testCoverageXMLNotFound() {
    System.setSecurityManager(new NoExitSecurityManager());
    boolean exceptionThrown = false;

    cobertura = new Cobertura("src/test/resources/simpleMavenProject");
    cobertura.setOutputDirectory("target/randomFolder");
    try {
      cobertura.executeCobertura();
    } catch (ExitException e) {
      exceptionThrown = true;
      assertEquals("Exit status invalid", OperiasStatus.COVERAGE_XML_NOT_FOUND.ordinal(), e.status);
    }
    System.setSecurityManager(null);
    assertTrue("No exception was thrown", exceptionThrown);
  }
  @Test
  public void systemPropertiesSecurityManager() {
    GenericApplicationContext ac = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);

    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(TestBean.class);
    bd.getPropertyValues().add("country", "#{systemProperties.country}");
    ac.registerBeanDefinition("tb", bd);

    SecurityManager oldSecurityManager = System.getSecurityManager();
    try {
      System.setProperty("country", "NL");

      SecurityManager securityManager =
          new SecurityManager() {
            @Override
            public void checkPropertiesAccess() {
              throw new AccessControlException("Not Allowed");
            }

            @Override
            public void checkPermission(Permission perm) {
              // allow everything else
            }
          };
      System.setSecurityManager(securityManager);
      ac.refresh();

      TestBean tb = ac.getBean("tb", TestBean.class);
      assertEquals("NL", tb.getCountry());

    } finally {
      System.setSecurityManager(oldSecurityManager);
      System.getProperties().remove("country");
    }
  }
  @BeforeClass
  public static void startMetaStoreServer() throws Exception {

    securityManager = System.getSecurityManager();
    System.setSecurityManager(new NoExitSecurityManager());
    HiveConf metastoreConf = new HiveConf();
    metastoreConf.setClass(
        HiveConf.ConfVars.METASTORE_EXPRESSION_PROXY_CLASS.varname,
        MockPartitionExpressionForMetastore.class,
        PartitionExpressionProxy.class);
    metastoreConf.setBoolVar(HiveConf.ConfVars.METASTORE_TRY_DIRECT_SQL_DDL, false);
    int msPort = MetaStoreUtils.startMetaStore(metastoreConf);
    hiveConf = new HiveConf(TestHiveMetaStoreGetMetaConf.class);
    hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + msPort);
    hiveConf.setVar(HiveConf.ConfVars.PREEXECHOOKS, "");
    hiveConf.setVar(HiveConf.ConfVars.POSTEXECHOOKS, "");
    hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false);
    hiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 10);

    System.setProperty(HiveConf.ConfVars.PREEXECHOOKS.varname, " ");
    System.setProperty(HiveConf.ConfVars.POSTEXECHOOKS.varname, " ");
  }
 @AfterClass
 public static void tearDown() throws Exception {
   LOG.info("Shutting down metastore.");
   System.setSecurityManager(securityManager);
 }