org.apache.commons.configuration2.MapConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration2.MapConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HaltedTraverserStrategyTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnDetachedElements() {
    final Graph graph = TinkerFactory.createModern();
    final GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
        put(HaltedTraverserStrategy.HALTED_TRAVERSER_FACTORY, DetachedFactory.class.getCanonicalName());
    }})));
    g.V().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
    g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(DetachedVertexProperty.class, vertexProperty.getClass()));
    g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
    g.V().out().outE().forEachRemaining(edge -> assertEquals(DetachedEdge.class, edge.getClass()));
    g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(DetachedProperty.class, property.getClass()));
    g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
    g.V().out().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
    g.V().out().out().path().forEachRemaining(path -> assertEquals(DetachedPath.class, path.getClass()));
    g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
    g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
    // should handle nested collections
    g.V().out().fold().next().forEach(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
}
 
Example #2
Source File: TestConfigurationDynaBean.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Test the modification of a configuration property stored internally as an array.
 */
@Test
public void testSetArrayValue()
{
    final MapConfiguration configuration = new MapConfiguration(new HashMap<String, Object>());
    configuration.getMap().put("objectArray", new Object[] {"value1", "value2", "value3"});

    final ConfigurationDynaBean bean = new ConfigurationDynaBean(configuration);

    bean.set("objectArray", 1, "New Value 1");
    final Object value = bean.get("objectArray", 1);

    assertNotNull("Returned new value 1", value);
    ObjectAssert.assertInstanceOf("Returned String new value 1", String.class,  value);
    assertEquals("Returned correct new value 1", "New Value 1", value);
}
 
Example #3
Source File: GraphTraversalSourceTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSupportMapBasedStrategies() throws Exception {
    GraphTraversalSource g = EmptyGraph.instance().traversal();
    assertFalse(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
    g = g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
        put("vertices", __.hasLabel("person"));
        put("vertexProperties", __.limit(0));
        put("edges", __.hasLabel("knows"));
    }})));
    assertTrue(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
    g = g.withoutStrategies(SubgraphStrategy.class);
    assertFalse(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
    //
    assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
    g = g.withStrategies(ReadOnlyStrategy.instance());
    assertTrue(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
    g = g.withoutStrategies(ReadOnlyStrategy.class);
    assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
}
 
Example #4
Source File: VertexProgramStrategy.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public Configuration getConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(GRAPH_COMPUTER, this.computer.getGraphComputerClass().getCanonicalName());
    if (-1 != this.computer.getWorkers())
        map.put(WORKERS, this.computer.getWorkers());
    if (null != this.computer.getPersist())
        map.put(PERSIST, this.computer.getPersist().name());
    if (null != this.computer.getResultGraph())
        map.put(RESULT, this.computer.getResultGraph().name());
    if (null != this.computer.getVertices())
        map.put(VERTICES, this.computer.getVertices());
    if (null != this.computer.getEdges())
        map.put(EDGES, this.computer.getEdges());
    map.putAll(this.computer.getConfiguration());
    return new MapConfiguration(map);
}
 
Example #5
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void shouldBuildAnAESPayloadCodecForAESConfig() throws Exception {
    ObjectStorageBlobConfiguration actual = ObjectStorageBlobConfiguration.from(new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(CONFIGURATION_WITHOUT_CODEC)
            .put("objectstorage.payload.codec", PayloadCodecFactory.AES256.name())
            .put("objectstorage.aes256.hexsalt", "12345123451234512345")
            .put("objectstorage.aes256.password", "james is great")
        .build()));
    assertThat(actual.getPayloadCodecFactory()).isEqualTo(PayloadCodecFactory.AES256);
    assertThat(actual.getAesSalt()).contains("12345123451234512345");
    assertThat(actual.getAesPassword()).contains("james is great".toCharArray());
}
 
Example #6
Source File: TinkerGraphComputerProvider.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public GraphTraversalSource traversal(final Graph graph) {
    return graph.traversal().withStrategies(VertexProgramStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
        put(VertexProgramStrategy.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1);
        put(VertexProgramStrategy.GRAPH_COMPUTER, RANDOM.nextBoolean() ?
                GraphComputer.class.getCanonicalName() :
                TinkerGraphComputer.class.getCanonicalName());
    }})));
}
 
Example #7
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@ArgumentsSource(RequiredParameters.class)
void shouldThrowWhenRequiredParameterOmitted(String toOmit) {
    Map<String, Object> configurationWithFilteredKey = Maps.filterKeys(VALID_CONFIGURATION, key -> !toOmit.equals(key));

    assertThat(configurationWithFilteredKey).doesNotContainKeys(toOmit);
    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(new MapConfiguration(configurationWithFilteredKey)))
        .isInstanceOf(ConfigurationException.class);
}
 
Example #8
Source File: ProgramVertexProgramStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public VertexProgram generateProgram(final Graph graph, final Memory memory) {
    final MapConfiguration base = new MapConfiguration(this.configuration);
    PureTraversal.storeState(base, ROOT_TRAVERSAL, TraversalHelper.getRootTraversal(this.getTraversal()).clone());
    base.setProperty(STEP_ID, this.getId());
    if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS))
        TraversalVertexProgram.storeHaltedTraversers(base, memory.get(TraversalVertexProgram.HALTED_TRAVERSERS));
    return VertexProgram.createVertexProgram(graph, base);
}
 
Example #9
Source File: ProgramVertexProgramStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public ProgramVertexProgramStep(final Traversal.Admin traversal, final VertexProgram vertexProgram) {
    super(traversal);
    this.configuration = new HashMap<>();
    final MapConfiguration base = new MapConfiguration(this.configuration);
    vertexProgram.storeState(base);
    this.toStringOfVertexProgram = vertexProgram.toString();
    this.traverserRequirements = vertexProgram.getTraverserRequirements();
}
 
Example #10
Source File: AbstractWarningVerificationStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConfiguration() {
    final Map<String, Object> m = new HashMap<>(2);
    m.put(THROW_EXCEPTION, this.throwException);
    m.put(LOG_WARNING, this.logWarning);
    return new MapConfiguration(m);
}
 
Example #11
Source File: SubgraphStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    if (null != this.vertexCriterion)
        map.put(VERTICES, this.vertexCriterion);
    if (null != this.edgeCriterion)
        map.put(EDGES, this.edgeCriterion);
    if (null != this.vertexPropertyCriterion)
        map.put(VERTEX_PROPERTIES, this.vertexPropertyCriterion);
    map.put(CHECK_ADJACENT_VERTICES, this.checkAdjacentVertices);
    return new MapConfiguration(map);
}
 
Example #12
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@ArgumentsSource(RequiredParameters.class)
void shouldThrowWhenRequiredParameterEmpty(String toEmpty) {
    Map<String, Object> configurationWithFilteredKey = Maps.transformEntries(VALID_CONFIGURATION, (key, value) -> {
        if (toEmpty.equals(key)) {
            return "";
        } else {
            return value;
        }
    });

    assertThat(configurationWithFilteredKey).containsEntry(toEmpty, "");
    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(new MapConfiguration(configurationWithFilteredKey)))
        .isInstanceOf(ConfigurationException.class);
}
 
Example #13
Source File: SeedStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STRATEGY, SeedStrategy.class.getCanonicalName());
    map.put(ID_SEED, this.seed);
    return new MapConfiguration(map);
}
 
Example #14
Source File: HaltedTraverserStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STRATEGY, HaltedTraverserStrategy.class.getCanonicalName());
    map.put(HALTED_TRAVERSER_FACTORY, this.haltedTraverserFactory.getCanonicalName());
    return new MapConfiguration(map);
}
 
Example #15
Source File: ElementIdStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STRATEGY, ElementIdStrategy.class.getCanonicalName());
    map.put(ID_PROPERTY_KEY, this.idPropertyKey);
    map.put(ID_MAKER, this.idMaker);
    return new MapConfiguration(map);
}
 
Example #16
Source File: PartitionStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STRATEGY, PartitionStrategy.class.getCanonicalName());
    map.put(INCLUDE_META_PROPERTIES, this.includeMetaProperties);
    if (null != this.writePartition)
        map.put(WRITE_PARTITION, this.writePartition);
    if (null != this.readPartitions)
        map.put(READ_PARTITIONS, this.readPartitions);
    if (null != this.partitionKey)
        map.put(PARTITION_KEY, this.partitionKey);
    return new MapConfiguration(map);
}
 
Example #17
Source File: TraversalStrategySerializer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
protected TraversalStrategy readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException {
    final Class<TraversalStrategy> clazz = context.readValue(buffer, Class.class, false);
    final Map config = context.readValue(buffer, Map.class, false);

    return new TraversalStrategyProxy(clazz, new MapConfiguration(config));
}
 
Example #18
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void shouldFailIfCodecKeyIsIncorrect() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(CONFIGURATION_WITHOUT_CODEC)
            .put("objectstorage.payload.codec", "aes255")
            .build());
    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(configuration)).isInstanceOf(ConfigurationException.class);
}
 
Example #19
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void shouldFailForAESCodecWhenSaltKeyIsMissing() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(CONFIGURATION_WITHOUT_CODEC)
            .put("objectstorage.payload.codec", PayloadCodecFactory.AES256.name())
            .put("objectstorage.aes256.password", "james is great")
            .build());
    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(configuration)).isInstanceOf(IllegalStateException.class);
}
 
Example #20
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void shouldFailForAESCodecWhenSaltKeyIsEmpty() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(CONFIGURATION_WITHOUT_CODEC)
            .put("objectstorage.payload.codec", PayloadCodecFactory.AES256.name())
            .put("objectstorage.aes256.hexsalt", "")
            .put("objectstorage.aes256.password", "james is great")
            .build());
    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(configuration)).isInstanceOf(IllegalStateException.class);
}
 
Example #21
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void shouldFailForAESCodecWhenPasswordKeyIsMissing() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(CONFIGURATION_WITHOUT_CODEC)
            .put("objectstorage.payload.codec", PayloadCodecFactory.AES256.name())
            .put("objectstorage.aes256.hexsalt", "12345123451234512345")
            .build());

    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(configuration)).isInstanceOf(IllegalStateException.class);
}
 
Example #22
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void shouldFailForAESCodecWhenPasswordKeyIsEmpty() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(CONFIGURATION_WITHOUT_CODEC)
            .put("objectstorage.payload.codec", PayloadCodecFactory.AES256.name())
            .put("objectstorage.aes256.hexsalt", "12345123451234512345")
            .put("objectstorage.aes256.password", "")
            .build());

    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(configuration)).isInstanceOf(IllegalStateException.class);
}
 
Example #23
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void shouldThrowWhenUnknownProvider() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .put("objectstorage.payload.codec", PayloadCodecFactory.DEFAULT.name())
            .put("objectstorage.provider", "unknown")
            .put("objectstorage.namespace", "foo")
            .build());

    assertThatThrownBy(() -> ObjectStorageBlobConfiguration.from(configuration))
        .isInstanceOf(ConfigurationException.class)
        .hasMessage("Unknown object storage provider: unknown");
}
 
Example #24
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldParseNameSpaceWhenSpecified() throws Exception {
    String bucketNameAsString = "my-bucket";
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(VALID_CONFIGURATION)
            .put("objectstorage.namespace", bucketNameAsString)
            .build());

     assertThat(ObjectStorageBlobConfiguration.from(configuration).getNamespace())
        .contains(BucketName.of(bucketNameAsString));
}
 
Example #25
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldNotContainsNamespaceWhenDontSpecify() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(VALID_CONFIGURATION)
            .build());

     assertThat(ObjectStorageBlobConfiguration.from(configuration).getNamespace())
        .isEmpty();
}
 
Example #26
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldParseBucketPrefixWhenSpecified() throws Exception {
    String bucketPrefix = "defaultPrefix";
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(VALID_CONFIGURATION)
            .put("objectstorage.bucketPrefix", bucketPrefix)
            .build());

     assertThat(ObjectStorageBlobConfiguration.from(configuration).getBucketPrefix())
        .contains(bucketPrefix);
}
 
Example #27
Source File: ObjectStorageBlobConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldReturnEmptyWhenDontSpecifyBucketPrefix() throws Exception {
    MapConfiguration configuration = new MapConfiguration(
        ImmutableMap.<String, Object>builder()
            .putAll(VALID_CONFIGURATION)
            .build());

     assertThat(ObjectStorageBlobConfiguration.from(configuration).getBucketPrefix())
        .isEmpty();
}
 
Example #28
Source File: TestSubsetConfigurationEvents.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    return (SubsetConfiguration)new MapConfiguration(new HashMap<String, Object>()).subset("test");
}
 
Example #29
Source File: MapConfigurationBuilder.java    From james-project with Apache License 2.0 4 votes vote down vote up
public MapConfiguration build() {
    return new MapConfiguration(config.build());
}
 
Example #30
Source File: TestMapConfigurationEvents.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    return new MapConfiguration(new HashMap<String, Object>());
}