Example usage for org.apache.commons.configuration Configuration setProperty

List of usage examples for org.apache.commons.configuration Configuration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration setProperty.

Prototype

void setProperty(String key, Object value);

Source Link

Document

Set a property, this will replace any previously set values.

Usage

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

@Test
public void testBasicCRUD() throws IOException {
    Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test");

    final String key = UUID.randomUUID().toString();
    final String v1 = UUID.randomUUID().toString(), v2 = UUID.randomUUID().toString(),
            v3 = UUID.randomUUID().toString(), v4 = UUID.randomUUID().toString(),
            v5 = UUID.randomUUID().toString();

    assertNull(config.getString(key));/*from   w  ww.j a v a 2 s. co  m*/
    assertEquals(v5, config.getString(key, v5));

    config.setProperty(key, v1);
    assertEquals(v1, config.getString(key, v5));

    config.addProperty(key, v2);
    assertEquals(v1, config.getString(key, v5));
    assertThat(config.getList(key), CoreMatchers.<Object>hasItems(v1, v2));

    config.addProperty(key, v3);
    config.addProperty(key, v4);
    assertEquals(v1, config.getString(key, v5));
    assertThat(config.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4));

    config.clearProperty(key);
    assertNull(config.getString(key));
    assertEquals(v5, config.getString(key, v5));

    config.addProperty(key, v5);
    assertEquals(v5, config.getString(key));

    config.clearProperty(key);
    config.setProperty(key, Arrays.asList(v3, v2, v4, v1, v5));
    assertEquals(v3, config.getString(key));
    assertThat(config.getList(key), CoreMatchers.<Object>hasItems(v3, v2, v4, v1, v5));

}

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

@Test
public void testString() throws Exception {
    Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test");

    final String key = UUID.randomUUID().toString();
    final String val1 = "This is a test value with some spcial ? "
            + "- to check serialization, deserialisation and encoding.",
            val2 = "An extended List, with several, commas, that should stay within, the, same value,";

    assertThat(config.getString(key), nullValue(String.class));

    config.setProperty(key, val1);
    assertThat(config.getString(key), equalTo(val1));
    assertThat(config.getList(key), hasSize(1));

    config.setProperty(key, val2);
    assertThat(config.getString(key), equalTo(val2));
    assertThat(config.getList(key), hasSize(1));
}

From source file:de.hybris.platform.order.CartServiceTest.java

@Test
public void testCustomCartTypeCartFactory() {
    final Configuration config = configurationService.getConfiguration();
    final String configuredCartType = config.getString(JaloSession.CART_TYPE, "Cart");
    config.setProperty(JaloSession.CART_TYPE, "Cart");
    final CartModel standardCart = cartFactory.createCart();
    assertEquals(CartModel.class, standardCart.getClass());

    config.setProperty(JaloSession.CART_TYPE, "InMemoryCart");
    final CartModel inMemoryCart = cartFactory.createCart();
    assertEquals(InMemoryCartModel.class, inMemoryCart.getClass());

    config.setProperty(JaloSession.CART_TYPE, configuredCartType);
}

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

@Test
public void testList() throws Exception {
    Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test");

    final String key = UUID.randomUUID().toString();
    final String val = "An extended List, with several, commas, that should stay within, the, same value,";
    final List<?> list = Lists.transform(Arrays.asList(val.split(",")), new Function<String, String>() {
        @Override/*  ww w  .  j  a v a  2s. c o  m*/
        public String apply(String input) {
            return input.trim();
        }
    });

    assertThat(config.getProperty(key), nullValue());

    config.setProperty(key, list);
    assertThat(config.getList(key), IsIterableContainingInOrder.contains(list.toArray()));
    assertThat(config.getString(key), is(val.split(",")[0].trim()));

    config.setProperty(key, val.split(","));
    assertThat(config.getString(key), is(val.split(",")[0]));
    assertThat(config.getList(key), CoreMatchers.<Object>hasItems(val.split(",")));
    assertThat(config.getStringArray(key), arrayContaining(val.split(",")));
    assertThat(config.getStringArray(key), arrayWithSize(val.split(",").length));
}

From source file:net.sf.maltcms.chromaui.project.spi.project.ChromAUIProject.java

@Override
public void setOutputDir(FileObject f) {
    Configuration ps = getSettings();
    ps.setProperty(ProjectSettings.KEY_OUTPUT_BASEDIR, f.getPath());
}

From source file:ezbake.services.graph.TitanGraphStore.java

/**
 * Creates a new graph instance for the specified graph name. This method is used by LoadingCache.
 *///from   w  ww  .j ava  2s.c  o m
private SecureTitanGraph<AccumuloSecurityToken> newInstanceGraph(String graphName) {
    String graphName1 = graphName;
    if (StringUtils.isEmpty(graphName1)) {
        graphName1 = EzGraphServiceConstants.GLOBAL_GRAPH;
    }

    // first we clone the current configuration, this gives us a deep copy
    final Configuration conf = (Configuration) config.clone();

    // now we override the graph name from the original config with the new
    // specified one
    final Configuration storageConf = conf.subset(GraphDatabaseConfiguration.STORAGE_NAMESPACE);
    storageConf.setProperty(AccumuloStoreManager.TABLE_NAME_KEY, graphName1);

    // finally, create new graph instance and return it
    final SecureTitanGraph<AccumuloSecurityToken> stg = new SecureTitanGraph<>(
            new SecureGraphDatabaseConfiguration(conf));

    return stg;
}

From source file:edu.kit.dama.rest.client.DataManagerPropertiesHelper.java

/**
 * Test access to webDAV server.// w  w  w  .  jav  a 2  s .co m
 * <b>Attention:<b><br/>
 * This method should only chosen if the credentials are not fixed. The chosen
 * authentication is slow but allows you to test several credentials.
 *
 * @param pAuthenticationClass Class used for authentication.
 * @return success
 */
private boolean genericWebDavAccess(String pAuthenticationClass) {
    boolean returnValue = false;
    StagingServiceRESTClient ssrc = new StagingServiceRESTClient(restServerUrl + REST_STAGING_PATH, context);
    try {
        StagingAccessPointConfigurationWrapper allAccessPoints = ssrc
                .getAllAccessPoints(properties.getAccessPoint(), properties.getUserGroup(), context);
        String webDavUrl = ssrc.getAccessPointById(allAccessPoints.getEntities().get(0).getId(), context)
                .getEntities().get(0).getRemoteBaseUrl();
        // Method to overwrite the Webdav configuration class with a custom configuration class
        for (String protocol : new String[] { "http", "https" }) {
            Configuration configuration = ProtocolSettings.getSingleton().getConfiguration(protocol);
            configuration.setProperty("authClass", pAuthenticationClass);
            Iterator iter = configuration.getKeys();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                String value = configuration.getString(key);
                configuration.clearProperty(key);
                configuration.addProperty(protocol + "." + key, value);
            }
            ProtocolSettings.getSingleton().overwriteConfiguration(configuration);
        }
        LOGGER.debug(
                "Overwriting the default configuration with the specific configuration of generic ingest client.");
        AbstractFile af = new AbstractFile(new URL(webDavUrl + "/USERS"));
        af.list();
        AbstractFile createDirectory = af.createDirectory(UUID.randomUUID().toString());
        if (createDirectory.exists()) {
            createDirectory.delete();
            returnValue = true;
        }
    } catch (MalformedURLException | AdalapiException e) {
        LOGGER.error(invalidWebDavSettings, e);
    }
    return returnValue;

}

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

@Test
public void testCuncurrent() throws IOException {
    Configuration con1 = new ZookeeperConfiguration(zkConnection, 5000, "/concurrent/");
    Configuration con2 = new ZookeeperConfiguration(zkConnection, 5000, "/concurrent/");

    final String key = UUID.randomUUID().toString();
    final String v1 = UUID.randomUUID().toString(), v2 = UUID.randomUUID().toString(),
            v3 = UUID.randomUUID().toString(), v4 = UUID.randomUUID().toString(),
            v5 = UUID.randomUUID().toString();

    assertNull(con1.getString(key));/*from   w w w . j  a  v  a  2  s . c om*/
    assertNull(con2.getString(key));
    assertEquals(v5, con1.getString(key, v5));
    assertEquals(v5, con2.getString(key, v5));

    con1.setProperty(key, v1);
    assertEquals(v1, con2.getString(key, v5));
    assertEquals(v1, con1.getString(key, v5));

    con2.addProperty(key, v2);
    assertEquals(v1, con1.getString(key, v5));
    assertEquals(v1, con2.getString(key, v5));
    assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v1, v2));
    assertThat(con1.getList(key), CoreMatchers.<Object>hasItems(v1, v2));

    con2.addProperty(key, v3);
    con1.addProperty(key, v4);
    assertEquals(v1, con2.getString(key, v5));
    assertEquals(v1, con1.getString(key, v5));
    assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4));
    assertThat(con1.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4));

    con2.clearProperty(key);
    assertNull(con2.getString(key));
    assertNull(con1.getString(key));
    assertEquals(v5, con1.getString(key, v5));
    assertEquals(v5, con2.getString(key, v5));

    con1.addProperty(key, v5);
    assertEquals(v5, con2.getString(key));

    con1.clearProperty(key);
    con2.setProperty(key, Arrays.asList(v3, v2, v4, v1, v5));
    assertEquals(v3, con1.getString(key));
    assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v3, v2, v4, v1, v5));

}

From source file:com.ibm.research.govsci.graph.BlueprintsBase.java

/**
 * Full constructor that takes an engine, a url, and a map for a configuration
 * //from   ww  w.  j a va  2 s  .  c o  m
 * Configuration parameters should be the exact names that the database uses. This
 * is mainly for setting very specific parameters for neo4j, but it also works for
 * defining a username and password for connecting to an OreintDB database.
 * 
 * @param engine name of the engine
 * @param dburl url of the database for the engine
 * @param config parameters for the engine
 */
public BlueprintsBase(String engine, String dburl, Map<String, String> config) {
    startConstructor();
    String eng = engine.toLowerCase().trim();
    dbengine = eng;
    log.debug("Requested database: {} url: {}", eng, dburl);
    if (eng.equals(Engine.NEO4J)) {
        log.info("Opening neo4j graph at: {}", dburl);
        kigraph = new Neo4jGraph(dburl, config);
        tgraph = (TransactionalGraph) kigraph;
        igraph = (IndexableGraph) kigraph;
    } else if (eng.equals(Engine.REXSTER)) {
        log.warn("Configuration parameters passed to RexsterGraph - Ignored");
        log.info("Opening rexster graph at: {}", dburl);
        kigraph = new RexsterGraph(dburl);
        igraph = (IndexableGraph) kigraph;
    } else if (eng.equals(Engine.TINKERGRAPH)) {
        if (config != null) {
            log.warn("Configuration parameters passed to TinkerGraph - Ignored");
        }
        log.info("creating new tinkergraph with url: {}", dburl);
        if (dburl == null) {
            kigraph = new TinkerGraph();
        } else {
            kigraph = new TinkerGraph(dburl);
        }
        igraph = (IndexableGraph) kigraph;
    } else if (eng.equals(Engine.NEO4JBATCH)) {
        log.info("Opening neo4j batch graph at: {}", dburl);
        if (config == null) {
            kigraph = new Neo4jBatchGraph(dburl);
        } else {
            kigraph = new Neo4jBatchGraph(dburl, config);
        }
        igraph = (IndexableGraph) kigraph;
    } else if (eng.equals(Engine.ORIENTDB)) {
        String username = null;
        String password = null;
        if (config != null) {
            username = config.get("username");
            password = config.get("password");
        }
        if (username != null && password != null) {
            kigraph = new OrientGraph(dburl, username, password);
        } else {
            kigraph = new OrientGraph(dburl);
        }
        tgraph = (TransactionalGraph) kigraph;
        igraph = (IndexableGraph) kigraph;
    } else if (eng.equals(Engine.TITAN)) {
        Configuration conf = null;
        TitanGraph g;
        if (config != null) {
            conf = new BaseConfiguration();
            for (Entry<String, String> e : config.entrySet()) {
                conf.setProperty(e.getKey(), e.getValue());
            }
        }
        if (conf != null) {
            g = TitanFactory.open(conf);
        } else {
            g = TitanFactory.open(dburl);
        }
        kigraph = (KeyIndexableGraph) g;
        tgraph = (TransactionalGraph) g;
    } else {
        log.error("Undefined database engine: {}", eng);
        System.exit(-1);
    }
    finishConstructor();
}

From source file:de.hybris.platform.order.CartServiceTest.java

@Test
public void testCustomCartTypeCartService() {
    final Configuration config = configurationService.getConfiguration();

    //Old cart is restored at the end of the test, as exceptions occur during HybrisJUnit4Test.finish()...
    final String configuredCartType = config.getString(JaloSession.CART_TYPE, "Cart");
    //cartService.setSessionCart(null);
    cartService.removeSessionCart();//w ww .java2  s.  c  o  m

    config.setProperty(JaloSession.CART_TYPE, "Cart");

    final CartModel standardCart = cartService.getSessionCart();
    assertEquals(CartModel.class, standardCart.getClass());
    cartService.removeSessionCart();

    config.setProperty(JaloSession.CART_TYPE, "InMemoryCart");
    final CartModel inMemoryCart = cartService.getSessionCart();
    assertEquals(InMemoryCartModel.class, inMemoryCart.getClass());

    config.setProperty(JaloSession.CART_TYPE, configuredCartType);
    cartService.removeSessionCart();
}