Example usage for java.lang System clearProperty

List of usage examples for java.lang System clearProperty

Introduction

In this page you can find the example usage for java.lang System clearProperty.

Prototype

public static String clearProperty(String key) 

Source Link

Document

Removes the system property indicated by the specified key.

Usage

From source file:org.apache.solr.cloud.FullSolrCloudTest.java

@Override
protected void createServers(int numServers) throws Exception {

    System.setProperty("collection", "control_collection");
    String numShards = System.getProperty(ZkStateReader.NUM_SHARDS_PROP);
    System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
    controlJetty = createJetty(testDir, testDir + "/control/data", "control_shard");
    System.clearProperty("collection");
    if (numShards != null) {
        System.setProperty(ZkStateReader.NUM_SHARDS_PROP, numShards);
    }//from   w  w w .  j a v  a  2 s.  c om
    controlClient = createNewSolrServer(controlJetty.getLocalPort());

    createJettys(numServers, true);

}

From source file:io.servicecomb.foundation.ssl.SSLOptionTest.java

@Test
public void testSSLOptionYamlOption2() throws Exception {
    System.setProperty("ssl.protocols", "TLSv1.2");
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(),
            new NeverStartPollingScheduler());
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(
            new SystemConfiguration());
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");

    SSLOption option = SSLOption.buildFromYaml("server", finalConfig);

    String protocols = option.getProtocols();
    option.setProtocols(protocols);/*w  w w  . j a va  2 s . com*/
    Assert.assertEquals("TLSv1.2", protocols);
    System.clearProperty("ssl.protocols");
}

From source file:org.apache.solr.hadoop.MorphlineGoLiveMiniMRTest.java

@AfterClass
public static void teardownClass() throws Exception {
    System.clearProperty("solr.hdfs.blockcache.global");
    System.clearProperty("solr.hdfs.blockcache.blocksperbank");
    System.clearProperty("solr.hdfs.blockcache.enabled");
    System.clearProperty("hadoop.log.dir");
    System.clearProperty("test.build.dir");
    System.clearProperty("test.build.data");
    System.clearProperty("test.cache.data");

    if (mrCluster != null) {
        mrCluster.stop();//from  w  w w.j  a va  2s. c  o  m
        mrCluster = null;
    }
    if (dfsCluster != null) {
        dfsCluster.shutdown();
        dfsCluster = null;
    }
    FileSystem.closeAll();
}

From source file:org.apache.geode.internal.cache.PersistentPartitionedRegionJUnitTest.java

@Test
public void testValuesAreNotRecoveredForHeapLruRegionsWithRecoverPropertySet() {
    String oldValue = System.getProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME);
    System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "true");

    try {/*  w w w.  j  a v  a  2s .c o m*/
        createLRURegionAndValidateRecovery(false, true, 10, 0);
    } finally {
        if (oldValue != null) {
            System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, oldValue);
        } else {
            System.clearProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME);
        }
    }
}

From source file:com.sun.tools.xjc.addon.xew.XmlElementWrapperPluginTest.java

/**
 * Standard test for XSD examples./* w ww.  j av  a2  s .com*/
 * 
 * @param testName
 *            the prototype of XSD file name / package name
 * @param extraXewOptions
 *            to be passed to plugin
 * @param generateEpisode
 *            generate episode file and check the list of classes included into it
 * @param classesToCheck
 *            expected classes/files in target directory; these files content is checked if it is present in
 *            resources directory; {@code ObjectFactory.java} is automatically included
 */
static void assertXsd(String testName, String[] extraXewOptions, boolean generateEpisode,
        String... classesToCheck) throws Exception {
    String resourceXsd = testName + ".xsd";
    String packageName = testName.replace('-', '_');

    // Force plugin to reinitialize the logger:
    System.clearProperty(XmlElementWrapperPlugin.COMMONS_LOGGING_LOG_LEVEL_PROPERTY_KEY);

    URL xsdUrl = XmlElementWrapperPluginTest.class.getResource(resourceXsd);

    File targetDir = new File(GENERATED_SOURCES_PREFIX);

    targetDir.mkdirs();

    PrintStream loggingPrintStream = new PrintStream(
            new LoggingOutputStream(logger, LoggingOutputStream.LogLevel.INFO, "[XJC] "));

    String[] opts = ArrayUtils.addAll(extraXewOptions, "-no-header", "-extension", "-Xxew", "-d",
            targetDir.getPath(), xsdUrl.getFile());

    String episodeFile = new File(targetDir, "episode.xml").getPath();

    // Episode plugin should be triggered after Xew, see https://github.com/dmak/jaxb-xew-plugin/issues/6
    if (generateEpisode) {
        opts = ArrayUtils.addAll(opts, "-episode", episodeFile);
    }

    assertTrue("XJC compilation failed. Checked console for more info.",
            Driver.run(opts, loggingPrintStream, loggingPrintStream) == 0);

    if (generateEpisode) {
        // FIXME: Episode file actually contains only value objects
        Set<String> classReferences = getClassReferencesFromEpisodeFile(episodeFile);

        if (Arrays.asList(classesToCheck).contains("package-info")) {
            classReferences.add(packageName + ".package-info");
        }

        assertEquals("Wrong number of classes in episode file", classesToCheck.length, classReferences.size());

        for (String className : classesToCheck) {
            assertTrue(className + " class is missing in episode file;",
                    classReferences.contains(packageName + "." + className));
        }
    }

    targetDir = new File(targetDir, packageName);

    Collection<String> generatedJavaSources = new HashSet<String>();

    // *.properties files are ignored:
    for (File targetFile : FileUtils.listFiles(targetDir, new String[] { "java" }, true)) {
        // This is effectively the path of targetFile relative to targetDir:
        generatedJavaSources
                .add(targetFile.getPath().substring(targetDir.getPath().length() + 1).replace('\\', '/'));
    }

    // This class is added and checked by default:
    classesToCheck = ArrayUtils.add(classesToCheck, "ObjectFactory");

    assertEquals("Wrong number of generated classes " + generatedJavaSources + ";", classesToCheck.length,
            generatedJavaSources.size());

    for (String className : classesToCheck) {
        className = className.replace('.', '/') + ".java";

        assertTrue(className + " is missing in target directory", generatedJavaSources.contains(className));
    }

    // Check the contents for those files which exist in resources:
    for (String className : classesToCheck) {
        className = className.replace('.', '/') + ".java";

        File sourceFile = new File(PREGENERATED_SOURCES_PREFIX + packageName, className);

        if (sourceFile.exists()) {
            // To avoid CR/LF conflicts:
            assertEquals("For " + className, FileUtils.readFileToString(sourceFile).replace("\r", ""),
                    FileUtils.readFileToString(new File(targetDir, className)).replace("\r", ""));
        }
    }

    JAXBContext jaxbContext = compileAndLoad(packageName, targetDir, generatedJavaSources);

    URL xmlTestFile = XmlElementWrapperPluginTest.class.getResource(testName + ".xml");

    if (xmlTestFile != null) {
        StringWriter writer = new StringWriter();

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setSchema(schemaFactory.newSchema(xsdUrl));

        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        Object bean = unmarshaller.unmarshal(xmlTestFile);
        marshaller.marshal(bean, writer);

        XMLUnit.setIgnoreComments(true);
        XMLUnit.setIgnoreWhitespace(true);
        Diff xmlDiff = new Diff(IOUtils.toString(xmlTestFile), writer.toString());

        assertXMLEqual("Generated XML is wrong: " + writer.toString(), xmlDiff, true);
    }
}

From source file:com.seleniumtests.it.reporter.TestCustomReporter.java

@Test(groups = { "it" })
public void testJsonCharacterEscape(ITestContext testContext) throws Exception {
    try {/*from w  w w  .  j a v a2 s  . c o  m*/
        System.setProperty("customTestReports", "SUP::json::ti/report.test.vm");

        executeSubTest(new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForEncoding" });

        String detailedReportContent = FileUtils
                .readFileToString(Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(),
                        "testAndSubActions", "SUP-result.json").toFile());

        // check step 1 has been encoded
        Assert.assertTrue(detailedReportContent
                .contains("Step step 1 <>\\\\\"'&\\\\/\\\\nclick button  <>\\\\\"'&\\\\na message <>\\\\\"'&"));

    } finally {
        System.clearProperty("customTestReports");
    }
}

From source file:org.apache.sentry.tests.e2e.solr.db.integration.AbstractSolrSentryTestWithDbProvider.java

public static void unsetSystemProperties() {
    System.clearProperty("solr.xml.persist");
    System.clearProperty("solr.hdfs.blockcache.enabled");
    System.clearProperty("solr.hdfs.home");
    System.clearProperty("solr.authorization.sentry.site");
}

From source file:io.cloudslang.lang.compiler.SlangSourceTest.java

@Test
public void testFromBytesOverrideEncoding() throws Exception {
    // In this scenario, the source file is encoded using a single-byte Western European encoding
    // (instead of UTF-8)
    final String sourceString = "Andr Citron";
    final byte[] sourceFile = sourceString.getBytes("ISO-8859-1");

    // Make sure we can override the default encoding (UTF-8) with a system property
    System.setProperty("cslang.encoding", "ISO-8859-1");
    SlangSource result = SlangSource.fromBytes(sourceFile, name);
    System.clearProperty("cslang.encoding");

    Assert.assertEquals(sourceString, result.getContent());
    Assert.assertEquals(name, result.getName());
}

From source file:com.yahoo.athenz.common.server.db.DataSourceFactoryTest.java

@Test
public void testRetrieveConfigSettingLongInvalid() {
    System.setProperty(ATHENZ_DBPOOL_PROP1, "abc");
    assertEquals(DataSourceFactory.retrieveConfigSetting(ATHENZ_DBPOOL_PROP1, 20L), 20L);
    System.clearProperty(ATHENZ_DBPOOL_PROP1);
}

From source file:hudson.model.DirectoryBrowserSupportTest.java

@Issue("SECURITY-95")
@Test/*from   w  w w. jav a 2 s .  co  m*/
public void contentSecurityPolicy() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    p.setScm(new SingleFileSCM("test.html", "<html><body><h1>Hello world!</h1></body></html>"));
    p.getPublishersList().add(new ArtifactArchiver("*", "", true));
    assertEquals(Result.SUCCESS, p.scheduleBuild2(0).get().getResult());

    HtmlPage page = j.createWebClient().goTo("job/" + p.getName() + "/lastSuccessfulBuild/artifact/test.html");
    for (String header : new String[] { "Content-Security-Policy", "X-WebKit-CSP",
            "X-Content-Security-Policy" }) {
        assertEquals("Header set: " + header, page.getWebResponse().getResponseHeaderValue(header),
                DirectoryBrowserSupport.DEFAULT_CSP_VALUE);
    }

    String propName = DirectoryBrowserSupport.class.getName() + ".CSP";
    String initialValue = System.getProperty(propName);
    try {
        System.setProperty(propName, "");
        page = j.createWebClient().goTo("job/" + p.getName() + "/lastSuccessfulBuild/artifact/test.html");
        for (String header : new String[] { "Content-Security-Policy", "X-WebKit-CSP",
                "X-Content-Security-Policy" }) {
            assertFalse("Header not set: " + header,
                    page.getWebResponse().getResponseHeaders().contains(header));
        }
    } finally {
        if (initialValue == null) {
            System.clearProperty(DirectoryBrowserSupport.class.getName() + ".CSP");
        } else {
            System.setProperty(DirectoryBrowserSupport.class.getName() + ".CSP", initialValue);
        }
    }
}