List of usage examples for org.apache.commons.configuration AbstractConfiguration setProperty
public void setProperty(String key, Object value)
From source file:com.hazelcast.eurekast.one.HazelcastClientTestCase.java
@Test public void testSimpleDiscovery() throws Exception { AbstractConfiguration configInstance = ConfigurationManager.getConfigInstance(); String serviceUrl = "http://localhost:" + serverResource.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH; configInstance.setProperty("eureka.serviceUrl.defaultZone", serviceUrl); configInstance.setProperty("eureka.name", "hazelcast-test"); Application application = new Application(); application.setName("hazelcast-test"); application.addInstance(buildInstanceInfo(5701)); application.addInstance(buildInstanceInfo(5702)); serverResource.addLocalRegionApps("hazelcast-test", application); TestHazelcastFactory factory = new TestHazelcastFactory(); try {// w w w . j a v a 2 s . co m HazelcastInstance hz1 = factory.newHazelcastInstance(); HazelcastInstance hz2 = factory.newHazelcastInstance(); assertClusterSizeEventually(2, hz1); assertClusterSizeEventually(2, hz2); HazelcastInstance client = factory.newHazelcastClient(); assertClusterSizeEventually(2, client); } finally { factory.shutdownAll(); } }
From source file:com.hazelcast.eurekast.one.ExternalRegistrationTestCase.java
@Test public void testSimpleDiscovery() throws Exception { AbstractConfiguration configInstance = ConfigurationManager.getConfigInstance(); String serviceUrl = "http://localhost:" + serverResource.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH; configInstance.setProperty("eureka.serviceUrl.defaultZone", serviceUrl); configInstance.setProperty("eureka.name", "hazelcast-test"); Application application = new Application(); application.setName("hazelcast-test"); application.addInstance(buildInstanceInfo(5701)); application.addInstance(buildInstanceInfo(5702)); serverResource.addLocalRegionApps("hazelcast-test", application); try {/*from w ww . j ava 2s . c o m*/ Config config = new XmlConfigBuilder().build(); DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig(); DiscoveryStrategyConfig strategyConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator() .next(); strategyConfig.addProperty("self-registration", "false"); TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2); HazelcastInstance hz1 = factory.newHazelcastInstance(config); HazelcastInstance hz2 = factory.newHazelcastInstance(config); assertClusterSizeEventually(2, hz1); assertClusterSizeEventually(2, hz2); } finally { Hazelcast.shutdownAll(); } }
From source file:com.netflix.niws.client.http.SecureRestClientKeystoreTest.java
@Test public void testGetKeystoreWithNoClientAuth() throws Exception { // jks format byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1); byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1); File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore"); File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore"); FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore); try {/* w w w .ja v a 2s .c om*/ keystoreFileOut.write(dummyKeystore); } finally { keystoreFileOut.close(); } FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore); try { truststoreFileOut.write(dummyTruststore); } finally { truststoreFileOut.close(); } AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = this.getClass().getName() + ".test2"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, "changeit"); RestClient client = (RestClient) ClientFactory.getNamedClient(name); KeyStore keyStore = client.getKeyStore(); Certificate cert = keyStore.getCertificate("ribbon_key"); assertNotNull(cert); }
From source file:com.netflix.iep.config.ConfigurationTests.java
private TestConfig mkConfig(String prefix, Map<String, String> props) { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); config.clear();//from ww w . ja v a 2 s .c o m for (Map.Entry<String, String> e : props.entrySet()) config.setProperty(e.getKey(), e.getValue()); return Configuration.newProxy(TestConfig.class, prefix); }
From source file:com.netflix.niws.client.http.SecureRestClientKeystoreTest.java
@Test public void testGetKeystoreWithClientAuth() throws Exception { // jks format byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1); byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1); File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore"); File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore"); FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore); try {//from w w w. ja va 2s . c o m keystoreFileOut.write(dummyKeystore); } finally { keystoreFileOut.close(); } FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore); try { truststoreFileOut.write(dummyTruststore); } finally { truststoreFileOut.close(); } AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = this.getClass().getName() + ".test1"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, "changeit"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, tempTruststore.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, "changeit"); RestClient client = (RestClient) ClientFactory.getNamedClient(name); KeyStore keyStore = client.getKeyStore(); Certificate cert = keyStore.getCertificate("ribbon_key"); assertNotNull(cert); }
From source file:com.netflix.config.DynamicPropertyUpdaterTest.java
@Test public void testAddorUpdatePropertyWithColonDelimiter() { AbstractConfiguration.setDefaultListDelimiter(':'); AbstractConfiguration config = new ConcurrentCompositeConfiguration(); config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener())); MyListener.resetCount();// w w w. j a va2 s.c o m config.setProperty("test.host", "test:test1:test2"); assertEquals(1, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host", "test:test1:test2", config); assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size()); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2")); assertEquals(1, MyListener.count); // the config is not set again. when the value is still not changed. config.setProperty("test.host1", "test1:test12"); // changing the new object value , the config.setProperty should be called again. dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config); assertEquals("test1.test12", config.getProperty("test.host1")); assertEquals(3, MyListener.count); }
From source file:com.netflix.config.DynamicPropertyUpdaterTest.java
/** * Test method for {@link com.charter.aesd.archaius.DynamicPropertyUpdater#updateProperties(com.netflix.config.WatchedUpdateResult, org.apache.commons.configuration.Configuration, boolean)}. * @throws InterruptedException /*from w ww. j av a 2 s. c o m*/ */ @Test public void testUpdateProperties() throws InterruptedException { AbstractConfiguration.setDefaultListDelimiter(','); AbstractConfiguration config = new ConcurrentCompositeConfiguration(); config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener())); MyListener.resetCount(); config.setProperty("test", "host,host1,host2"); config.setProperty("test12", "host12"); Map<String, Object> added = Maps.newHashMap(); added.put("test.host", "test,test1"); Map<String, Object> changed = Maps.newHashMap(); changed.put("test", "host,host1"); changed.put("test.host", ""); dynamicPropertyUpdater.updateProperties(WatchedUpdateResult.createIncremental(added, changed, null), config, false); assertEquals("", config.getProperty("test.host")); assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test"))).size()); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test"))).contains("host")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test"))).contains("host1")); assertEquals(5, MyListener.count); }
From source file:com.netflix.config.DynamicPropertyUpdaterTest.java
@Test public void testAddorChangeProperty() { AbstractConfiguration.setDefaultListDelimiter(','); AbstractConfiguration config = new ConcurrentCompositeConfiguration(); config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener())); MyListener.resetCount();/*from w w w . j a va2s. c o m*/ config.setProperty("test.host", "test,test1,test2"); assertEquals(1, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config); assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size()); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2")); assertEquals(1, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config); assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size()); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2")); assertEquals(1, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1", config); assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size()); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1")); assertEquals(2, MyListener.count); dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1,test12", config); assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host1"))).size()); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test1")); assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test12")); assertEquals(3, MyListener.count); config.setProperty("test.host1", "test1.test12"); dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config); assertEquals("test1.test12", config.getProperty("test.host1")); assertEquals(4, MyListener.count); }
From source file:com.netflix.niws.client.http.SecureAcceptAllGetTest.java
@Test public void testPositiveAcceptAllSSLSocketFactory() throws Exception { // test connection succeeds connecting to a random SSL endpoint with allow all SSL factory AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = "GetPostSecureTest" + ".testPositiveAcceptAllSSLSocketFactory"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName, "com.netflix.http4.ssl.AcceptAllSocketFactory"); RestClient rc = (RestClient) ClientFactory.getNamedClient(name); TEST_SERVER.accept();// w w w . ja v a2 s . c om URI getUri = new URI(TEST_SERVICE_URI + "test/"); HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build(); HttpResponse response = rc.execute(request); assertEquals(200, response.getStatus()); }
From source file:com.netflix.adminresources.resources.WebAdminComponent.java
@PostConstruct public void init() { AbstractConfiguration configInstance = ConfigurationManager.getConfigInstance(); if (configInstance.containsKey(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME)) { logger.info("Admin container default page already set to: " + configInstance .getString(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME + ", not overriding.")); return;//from w ww .j a v a2 s . co m } configInstance.setProperty(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME, ADMINRES_WEBADMIN_INDEX_HTML); logger.info("Set the default page for admin container to: " + ADMINRES_WEBADMIN_INDEX_HTML); }