@Test public void prototypeCreationIsFastEnough() { if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) { // Skip this test: Trace logging blows the time limit. return; } GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getConstructorArgumentValues().addGenericArgumentValue("#{systemProperties.name}"); rbd.getPropertyValues().add("country", "#{systemProperties.country}"); ac.registerBeanDefinition("test", rbd); ac.refresh(); StopWatch sw = new StopWatch(); sw.start("prototype"); System.getProperties().put("name", "juergen"); System.getProperties().put("country", "UK"); try { for (int i = 0; i < 100000; i++) { TestBean tb = (TestBean) ac.getBean("test"); assertEquals("juergen", tb.getName()); assertEquals("UK", tb.getCountry()); } sw.stop(); } finally { System.getProperties().remove("country"); System.getProperties().remove("name"); } assertTrue( "Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000); }
@Test public void testDefault() { final SystemProperties props = SystemProperties.getDefault(); final String propKey = System.getProperties().keySet().iterator().next().toString(); final String propValue = System.getProperties().getProperty(propKey); assertEquals(propValue, props.get(propKey)); final String envKey = System.getenv().keySet().iterator().next(); final String envValue = System.getenv(envKey); assertEquals(envValue, props.getEnv(envKey)); }
/** * checkEnvのテストケース 異常系:"ASAKUSA_HOME"の設定が不正のケース * * @throws Exception */ @Test public void checkEnvTest04() throws Exception { ConfigurationLoader.init(properties_db, true, false); Map<String, String> m = new HashMap<String, String>(); m.put(Constants.ASAKUSA_HOME, "J:\temp"); m.put( Constants.THUNDER_GATE_HOME, ConfigurationLoader.getEnvProperty(Constants.THUNDER_GATE_HOME)); ConfigurationLoader.setEnv(m); Properties p = System.getProperties(); p.setProperty(Constants.ASAKUSA_HOME, "J:\temp"); p.setProperty(Constants.THUNDER_GATE_HOME, "src/test"); ConfigurationLoader.setSysProp(p); System.setProperties(p); try { ConfigurationLoader.checkEnv(); fail(); } catch (Exception e) { assertTrue(e instanceof Exception); System.out.println(e.getMessage()); e.printStackTrace(); } }
public TestWorkflowDataSourceRepository() throws SQLException, FileNotFoundException { // set the log levels System.setProperty( "java.util.logging.config.file", new File("./src/main/resources/logging.properties").getAbsolutePath()); // first load the example configuration try { System.getProperties().load(new FileInputStream("./src/main/resources/workflow.properties")); } catch (Exception e) { fail(e.getMessage()); } // get a temp directory File tempDir = null; File tempFile; try { tempFile = File.createTempFile("foo", "bar"); tempFile.deleteOnExit(); tempDir = tempFile.getParentFile(); } catch (Exception e) { fail(e.getMessage()); } tmpDirPath = tempDir.getAbsolutePath(); }
@BeforeClass public static void init() throws IOException { File propertyFile = new File("src/test/config/bes_media_file_log_batch_update_unittest.properties"); FileInputStream in = new FileInputStream(propertyFile); properties = new Properties(); properties.load(in); in.close(); System.getProperties().put("log4j.defaultInitOverride", "true"); DOMConfigurator.configure(properties.getProperty("log4j.config.file.path")); }
@Test public void testProps() throws MalformedURLException { MergeableProperties p = new MergeableProperties(); URL url = new URL( "classpath:logstash.properties?deployer.launch.env.keys.appendchar=,&deployer.launch.env.keys=JAVA_OPTIONS&JAVA_OPTIONS=-javaagent:../../target/jacoco-agent.jar=jmx=true,destfile=../../target/willow-deployer/server.exec&deployer.launch.workdir=target/logstash&deployer.launch.workdir.readonly=true"); assertEquals( "deployer.launch.env.keys.appendchar=,&deployer.launch.env.keys=JAVA_OPTIONS&JAVA_OPTIONS=-javaagent:../../target/jacoco-agent.jar=jmx=true,destfile=../../target/willow-deployer/server.exec&deployer.launch.workdir=target/logstash&deployer.launch.workdir.readonly=true", url.getQuery()); p.merge(System.getProperties(), url.toString()); assertEquals("JAVA_OPTIONS,VENDORED_JRUBY", p.get("deployer.launch.env.keys")); }
/** * Test that the constructor reads the system property and set the htmlOutputDirectory correctly. */ @Test public void htmlOutputDirectoryConfiguration() { Configuration configuration = new Configuration(); assertTrue( configuration.getHtmlOutputDirectory().endsWith(Configuration.DEFAULT_HTML_OUTPUT_DIR)); System.setProperty(Configuration.PROPERTY_HTML_OUTPUT_DIR, TEST_OUTPUT_DIR_PATH); configuration = new Configuration(); assertTrue(configuration.getHtmlOutputDirectory().endsWith(TEST_OUTPUT_DIR_PATH)); Properties sysProps = System.getProperties(); sysProps.remove(Configuration.PROPERTY_HTML_OUTPUT_DIR); }
@Test public void prototypeCreationReevaluatesExpressions() { GenericApplicationContext ac = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ac); RootBeanDefinition rbd = new RootBeanDefinition(PrototypeTestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getPropertyValues().add("country", "#{systemProperties.country}"); rbd.getPropertyValues().add("country2", new TypedStringValue("#{systemProperties.country}")); ac.registerBeanDefinition("test", rbd); ac.refresh(); try { System.getProperties().put("name", "juergen1"); System.getProperties().put("country", "UK1"); PrototypeTestBean tb = (PrototypeTestBean) ac.getBean("test"); assertEquals("juergen1", tb.getName()); assertEquals("UK1", tb.getCountry()); assertEquals("UK1", tb.getCountry2()); System.getProperties().put("name", "juergen2"); System.getProperties().put("country", "UK2"); tb = (PrototypeTestBean) ac.getBean("test"); assertEquals("juergen2", tb.getName()); assertEquals("UK2", tb.getCountry()); assertEquals("UK2", tb.getCountry2()); } finally { System.getProperties().remove("name"); System.getProperties().remove("country"); } }
private static void startXmlRpcWorkflowManager() { System.setProperty( "java.util.logging.config.file", new File("./src/main/resources/logging.properties").getAbsolutePath()); try { System.getProperties().load(new FileInputStream("./src/main/resources/workflow.properties")); } catch (Exception e) { fail(e.getMessage()); } try { luceneCatLoc = Files.createTempDirectory("repo").toString(); LOG.log(Level.INFO, "Lucene instance repository: [" + luceneCatLoc + "]"); } catch (Exception e) { fail(e.getMessage()); } if (new File(luceneCatLoc).exists()) { // blow away lucene cat LOG.log(Level.INFO, "Removing workflow instance repository: [" + luceneCatLoc + "]"); try { FileUtils.deleteDirectory(new File(luceneCatLoc)); } catch (IOException e) { fail(e.getMessage()); } } System.setProperty( "workflow.engine.instanceRep.factory", "org.apache.oodt.cas.workflow.instrepo.LuceneWorkflowInstanceRepositoryFactory"); System.setProperty("org.apache.oodt.cas.workflow.instanceRep.lucene.idxPath", luceneCatLoc); try { System.setProperty( "org.apache.oodt.cas.workflow.repo.dirs", "file://" + new File("./src/main/resources/examples").getCanonicalPath()); System.setProperty( "org.apache.oodt.cas.workflow.lifecycle.filePath", new File("./src/main/resources/examples/workflow-lifecycle.xml").getCanonicalPath()); } catch (Exception e) { fail(e.getMessage()); } try { wmgr = new XmlRpcWorkflowManager(WM_PORT); Thread.sleep(MILLIS); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage()); fail(e.getMessage()); } }
private static void stopXmlRpcWorkflowManager() { System.setProperty( "java.util.logging.config.file", new File("./src/main/resources/logging.properties").getAbsolutePath()); try { System.getProperties().load(new FileInputStream("./src/main/resources/workflow.properties")); } catch (Exception e) { fail(e.getMessage()); } System.setProperty( "workflow.engine.instanceRep.factory", "org.apache.oodt.cas.workflow.instrepo.LuceneWorkflowInstanceRepositoryFactory"); System.setProperty("org.apache.oodt.cas.workflow.instanceRep.lucene.idxPath", luceneCatLoc); try { System.setProperty( "org.apache.oodt.cas.workflow.repo.dirs", "file://" + new File("./src/main/resources/examples").getCanonicalPath()); System.setProperty( "org.apache.oodt.cas.workflow.lifecycle.filePath", new File("./src/main/resources/examples/workflow-lifecycle.xml").getCanonicalPath()); } catch (Exception e) { fail(e.getMessage()); } try { wmgr.shutdown(); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage()); fail(e.getMessage()); } /** Sleep before removing to prevent file not found issues. */ try { Thread.sleep(MILLIS); } catch (InterruptedException e) { e.printStackTrace(); } if (new File(luceneCatLoc).exists()) { // blow away lucene cat LOG.log(Level.INFO, "Removing workflow instance repository: [" + luceneCatLoc + "]"); try { FileUtils.deleteDirectory(new File(luceneCatLoc)); } catch (IOException e) { fail(e.getMessage()); } } }
@Test public void systemPropertiesTakePrecedenceOverConfiguredProperties() throws Exception { final String configFileName = "systemPropertiesTakePrecedenceOverConfiguredProperties.properties"; FileUtil.createFile(configFileName, "Theme=example"); System.setProperty("Theme", "othertheme"); try { // Checked via logging: String output = runFitnesseMainWith("-o", "-c", "/root", "-f", configFileName); assertThat(output, containsString("othertheme")); } finally { System.getProperties().remove("Theme"); FileUtil.deleteFile(configFileName); } }
/** * Tests {@link org.jboss.bqt.core.util.PropertiesUtils} * * @throws Exception */ @Test public void test1() throws Exception { // add this step of removing the property because the order of // running is not guaranteed, and if this doesn't run first, // this property is set by other tests Properties props = System.getProperties(); props.remove(ConfigPropertyNames.CONFIG_FILE); System.setProperties(props); System.setProperty("test", "value"); ConfigPropertyLoader _instance = ConfigPropertyLoader.getInstance(); Properties p = _instance.getProperties(); assertNotNull(p); assertTrue(!p.isEmpty()); assertEquals("value", p.getProperty("test")); // $NON-NLS-1$ //$NON-NLS-2$ _instance.setProperty("override", "ovalue"); assertEquals("ovalue", _instance.getProperty("override")); // $NON-NLS-1$ //$NON-NLS-2$ // confirm the loader actually loaded the default-config.properties file assertEquals( "driver", p.getProperty(ConfigPropertyNames.CONNECTION_TYPE)); // $NON-NLS-1$ //$NON-NLS-2$ System.setProperty("username", ""); ConfigPropertyLoader.reset(); _instance = ConfigPropertyLoader.getInstance(); p = _instance.getProperties(); assertNull("should be null after reset", _instance.getProperties().getProperty("override")); assertEquals( "failed to pickup system property", "value", p.getProperty("test")); // $NON-NLS-1$ //$NON-NLS-2$ // confirm the loader actually loaded the default-config.properties file assertEquals( "failed to correctly pickup the User ", "", _instance.getProperty("conn.user")); // $NON-NLS-1$ //$NON-NLS-2$ }
@Test public void test_windowAbsolutePathBeginWithSlashIsValid() throws Exception { final String osProperty = System.getProperties().getProperty("os.name"); if (!osProperty.toLowerCase().contains("windows")) return; System.out.println("Test Windows valid path string."); File f0 = new File("C:/Windows"); File f1 = new File("/C:/Windows"); File f2 = new File("C:\\Windows"); File f3 = new File("/C:\\Windows"); File f4 = new File("\\C:\\Windows"); assertEquals(f0, f1); assertEquals(f0, f2); assertEquals(f0, f3); assertEquals(f0, f4); }
@Test public void testSysPropConf() { Configuration cfg = Configuration.instance(); try { cfg.load(); } catch (ConfigurationException e) { e.printStackTrace(); fail(); } assertNull(cfg.getProperty("name1")); System.setProperty(Configuration.CONF_SYS_P, "src/test/data/conf2.properties"); Configuration cfg2 = Configuration.instance(); try { cfg2.load(); } catch (ConfigurationException e) { e.printStackTrace(); fail(); } assertEquals("value1", cfg2.getProperty("name1")); System.getProperties().remove("tangara.configuration"); }
public CallManagerTest() { if (props == null) { props = new Properties(); try { props.load( new FileInputStream( System.getProperties().getProperty("user.home") + "/flibble-test.properties")); proxyAddress = props.getProperty("proxyAddress"); proxyPort = new Integer(props.getProperty("proxyPort")).intValue(); uriA = props.getProperty("uriA"); uriB = props.getProperty("uriB"); localIp = props.getProperty("localIp"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (callMgr1 == null) { initializeCallManagers(); } }
@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"); } }
@After public void tearDown() { System.getProperties().remove("drools.dialect.java.compiler"); }
@Before public void setUp() { System.getProperties().remove("drools.dialect.java.compiler"); }
@AfterClass public static void teardownClass() { Properties properties = System.getProperties(); properties.remove(Constants.PROP_PROJECT_SCRIPT_MODEL); System.setProperties(properties); }
@After public void after() { System.getProperties().remove("jboss.server.config.user.dir"); System.getProperties().remove("jboss.server.config.dir"); }
private BuildResult doRun( final OutputListenerImpl outputListener, OutputListenerImpl errorListener, BuildListenerImpl listener) { // Capture the current state of things that we will change during execution InputStream originalStdIn = System.in; Properties originalSysProperties = new Properties(); originalSysProperties.putAll(System.getProperties()); File originalUserDir = new File(originalSysProperties.getProperty("user.dir")); Map<String, String> originalEnv = new HashMap<String, String>(System.getenv()); // Augment the environment for the execution System.setIn(getStdin()); processEnvironment.maybeSetProcessDir(getWorkingDir()); for (Map.Entry<String, String> entry : getEnvironmentVars().entrySet()) { processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue()); } Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties(); System.getProperties().putAll(implicitJvmSystemProperties); DefaultStartParameter parameter = new DefaultStartParameter(); parameter.setCurrentDir(getWorkingDir()); parameter.setShowStacktrace(ShowStacktrace.ALWAYS); CommandLineParser parser = new CommandLineParser(); DefaultCommandLineConverter converter = new DefaultCommandLineConverter(); converter.configure(parser); ParsedCommandLine parsedCommandLine = parser.parse(getAllArgs()); BuildLayoutParameters layout = converter.getLayoutConverter().convert(parsedCommandLine); Map<String, String> properties = new HashMap<String, String>(); new LayoutToPropertiesConverter().convert(layout, properties); converter.getSystemPropertiesConverter().convert(parsedCommandLine, properties); new PropertiesToStartParameterConverter().convert(properties, parameter); converter.convert(parsedCommandLine, parameter); DefaultGradleLauncherFactory factory = DeprecationLogger.whileDisabled( new Factory<DefaultGradleLauncherFactory>() { public DefaultGradleLauncherFactory create() { return (DefaultGradleLauncherFactory) GradleLauncher.getFactory(); } }); factory.addListener(listener); GradleLauncher gradleLauncher = factory.newInstance(parameter); gradleLauncher.addStandardOutputListener(outputListener); gradleLauncher.addStandardErrorListener(errorListener); try { return gradleLauncher.run(); } finally { // Restore the environment System.setProperties(originalSysProperties); processEnvironment.maybeSetProcessDir(originalUserDir); for (String envVar : getEnvironmentVars().keySet()) { String oldValue = originalEnv.get(envVar); if (oldValue != null) { processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue); } else { processEnvironment.maybeRemoveEnvironmentVariable(envVar); } } factory.removeListener(listener); System.setIn(originalStdIn); } }
@Test public void genericApplicationContext() throws Exception { GenericApplicationContext ac = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ac); ac.getBeanFactory() .registerScope( "myScope", new Scope() { public Object get(String name, ObjectFactory objectFactory) { return objectFactory.getObject(); } public Object remove(String name) { return null; } public void registerDestructionCallback(String name, Runnable callback) {} public Object resolveContextualObject(String key) { if (key.equals("mySpecialAttr")) { return "42"; } else { return null; } } public String getConversationId() { return null; } }); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); Properties placeholders = new Properties(); placeholders.setProperty("code", "123"); ppc.setProperties(placeholders); ac.addBeanFactoryPostProcessor(ppc); GenericBeanDefinition bd0 = new GenericBeanDefinition(); bd0.setBeanClass(TestBean.class); bd0.getPropertyValues().add("name", "myName"); bd0.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "original")); ac.registerBeanDefinition("tb0", bd0); GenericBeanDefinition bd1 = new GenericBeanDefinition(); bd1.setBeanClass(TestBean.class); bd1.setScope("myScope"); bd1.getConstructorArgumentValues() .addGenericArgumentValue("XXX#{tb0.name}YYY#{mySpecialAttr}ZZZ"); bd1.getConstructorArgumentValues().addGenericArgumentValue("#{mySpecialAttr}"); ac.registerBeanDefinition("tb1", bd1); GenericBeanDefinition bd2 = new GenericBeanDefinition(); bd2.setBeanClass(TestBean.class); bd2.setScope("myScope"); bd2.getPropertyValues().add("name", "{ XXX#{tb0.name}YYY#{mySpecialAttr}ZZZ }"); bd2.getPropertyValues().add("age", "#{mySpecialAttr}"); bd2.getPropertyValues().add("country", "${code} #{systemProperties.country}"); ac.registerBeanDefinition("tb2", bd2); GenericBeanDefinition bd3 = new GenericBeanDefinition(); bd3.setBeanClass(ValueTestBean.class); bd3.setScope("myScope"); ac.registerBeanDefinition("tb3", bd3); GenericBeanDefinition bd4 = new GenericBeanDefinition(); bd4.setBeanClass(ConstructorValueTestBean.class); bd4.setScope("myScope"); ac.registerBeanDefinition("tb4", bd4); GenericBeanDefinition bd5 = new GenericBeanDefinition(); bd5.setBeanClass(MethodValueTestBean.class); bd5.setScope("myScope"); ac.registerBeanDefinition("tb5", bd5); GenericBeanDefinition bd6 = new GenericBeanDefinition(); bd6.setBeanClass(PropertyValueTestBean.class); bd6.setScope("myScope"); ac.registerBeanDefinition("tb6", bd6); System.getProperties().put("country", "UK"); try { ac.refresh(); TestBean tb0 = ac.getBean("tb0", TestBean.class); TestBean tb1 = ac.getBean("tb1", TestBean.class); assertEquals("XXXmyNameYYY42ZZZ", tb1.getName()); assertEquals(42, tb1.getAge()); TestBean tb2 = ac.getBean("tb2", TestBean.class); assertEquals("{ XXXmyNameYYY42ZZZ }", tb2.getName()); assertEquals(42, tb2.getAge()); assertEquals("123 UK", tb2.getCountry()); ValueTestBean tb3 = ac.getBean("tb3", ValueTestBean.class); assertEquals("XXXmyNameYYY42ZZZ", tb3.name); assertEquals(42, tb3.age); assertEquals("123 UK", tb3.country); assertEquals("123 UK", tb3.countryFactory.getObject()); System.getProperties().put("country", "US"); assertEquals("123 UK", tb3.country); assertEquals("123 US", tb3.countryFactory.getObject()); System.getProperties().put("country", "UK"); assertEquals("123 UK", tb3.country); assertEquals("123 UK", tb3.countryFactory.getObject()); assertSame(tb0, tb3.tb); tb3 = (ValueTestBean) SerializationTestUtils.serializeAndDeserialize(tb3); assertEquals("123 UK", tb3.countryFactory.getObject()); ConstructorValueTestBean tb4 = ac.getBean("tb4", ConstructorValueTestBean.class); assertEquals("XXXmyNameYYY42ZZZ", tb4.name); assertEquals(42, tb4.age); assertEquals("123 UK", tb4.country); assertSame(tb0, tb4.tb); MethodValueTestBean tb5 = ac.getBean("tb5", MethodValueTestBean.class); assertEquals("XXXmyNameYYY42ZZZ", tb5.name); assertEquals(42, tb5.age); assertEquals("123 UK", tb5.country); assertSame(tb0, tb5.tb); PropertyValueTestBean tb6 = ac.getBean("tb6", PropertyValueTestBean.class); assertEquals("XXXmyNameYYY42ZZZ", tb6.name); assertEquals(42, tb6.age); assertEquals("123 UK", tb6.country); assertSame(tb0, tb6.tb); } finally { System.getProperties().remove("country"); } }