protected void printSubgraph( Graph graph, String path ) { if (print) { Subgraph subgraph = graph.getSubgraphOfDepth(Integer.MAX_VALUE).at(path); System.out.println(subgraph); } }
protected void printSubgraph( Graph graph, String path ) { if (print) { Subgraph subgraph = graph.getSubgraphOfDepth(Integer.MAX_VALUE).at(path); System.out.println(subgraph); } }
@Test public void shouldSuccessfullyApplyFunction() { // Create some nodes and get the subgraph of them ... Subgraph subgraph = graph.getSubgraphOfDepth(100).at("/"); int count = countNodes(subgraph); // Determine the number of nodes using a function ... Map<String, Serializable> output = graph.applyFunction(new CountNodesFunction()).to("/"); assertThat(output, is(notNullValue())); assertThat(output.get("nodeCount"), is((Object)new Integer(count))); }
@Test public void shouldAllowSettingRetryLimitOnRepositorySourceUsingNonPrefixedPropertyName() { // Update the configuration and save it ... configuration.repositorySource("Source1") .usingClass(InMemoryRepositorySource.class.getName()) .loadedFromClasspath() .setProperty("retryLimit", 5) .and() .save(); // Verify that the graph has been updated correctly ... ModeShapeConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition(); Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/"); assertThat(subgraph.getNode("/mode:sources"), is(notNullValue())); assertThat(subgraph.getNode("/mode:sources/Source1"), is(notNullValue())); assertThat(subgraph.getNode("/mode:sources/Source1"), hasProperty(ModeShapeLexicon.RETRY_LIMIT, 5)); }
@Test public void shouldAllowSettingDescriptionOnRepositorySourceUsingNonPrefixedPropertyName() { // Update the configuration and save it ... configuration.repositorySource("Source1") .usingClass(InMemoryRepositorySource.class.getName()) .loadedFromClasspath() .setProperty("description", "desc") .and() .save(); // Verify that the graph has been updated correctly ... ModeShapeConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition(); Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/"); assertThat(subgraph.getNode("/mode:sources"), is(notNullValue())); assertThat(subgraph.getNode("/mode:sources/Source1"), is(notNullValue())); assertThat(subgraph.getNode("/mode:sources/Source1"), hasProperty(ModeShapeLexicon.DESCRIPTION, "desc")); }
@Test public void shouldAddValuesToNonExistantProperty() { String initialPath = ""; int depth = 1; int numChildrenPerNode = 1; int numPropertiesPerNode = 1; Stopwatch sw = new Stopwatch(); boolean batch = true; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); graph.addValue("foo").andValue("bar").to("newProperty").on("node1"); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); Subgraph subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1", "The quick brown fox jumped over the moon. What? ")); assertThat(subgraph.getNode("node1"), hasProperty("newProperty", "foo", "bar")); }
@Test public void shouldAllowSettingDescriptionOnRepositorySourceUsingPrefixedPropertyName() { // Update the configuration and save it ... configuration.repositorySource("Source1") .usingClass(InMemoryRepositorySource.class.getName()) .loadedFromClasspath() .setProperty("mode:description", "desc") .and() .save(); // Verify that the graph has been updated correctly ... ModeShapeConfiguration.ConfigurationDefinition content = configuration.getConfigurationDefinition(); Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/"); assertThat(subgraph.getNode("/mode:sources"), is(notNullValue())); assertThat(subgraph.getNode("/mode:sources/Source1"), is(notNullValue())); assertThat(subgraph.getNode("/mode:sources/Source1"), hasProperty(ModeShapeLexicon.DESCRIPTION, "desc")); }
@Test public void shouldNotRemoveValuesFromNonExistantProperty() { String initialPath = ""; int depth = 1; int numChildrenPerNode = 1; int numPropertiesPerNode = 1; Stopwatch sw = new Stopwatch(); boolean batch = true; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); graph.removeValue("The quick brown fox jumped over the moon. What? ").from("noSuchProperty").on("node1"); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); Subgraph subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1", "The quick brown fox jumped over the moon. What? ")); }
@Test public void shouldRemoveValuesFromExistingProperty() { String initialPath = ""; int depth = 1; int numChildrenPerNode = 1; int numPropertiesPerNode = 1; Stopwatch sw = new Stopwatch(); boolean batch = true; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); graph.removeValue("The quick brown fox jumped over the moon. What? ").andValue("bar").from("property1").on("node1"); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); Subgraph subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1")); }
protected void merge( Graph actualGraph, Graph.Batch batch ) { CheckArg.isNotNull(actualGraph, "actualGraph"); // Read the initial content ... Subgraph subgraph = this.initialContent.getSubgraphOfDepth(Integer.MAX_VALUE).at("/"); SubgraphNode desiredNode = subgraph.getRoot(); // Go through all of the areas and ensure the nodes exist ... boolean checkProperties = true; if (desiredNode.getLocation().getPath().isRoot()) { // Don't need to check the root's properties ... checkProperties = false; } Path path = desiredNode.getLocation().getPath(); Node actualNode = actualGraph.getNodeAt(path); matchNode(batch, actualGraph, actualNode, desiredNode, checkProperties, true); }
@Test public void shouldSuccessfullyApplyFunctionUsingBatch() { // Create some nodes and get the subgraph of them ... Subgraph subgraph = graph.getSubgraphOfDepth(100).at("/"); int count = countNodes(subgraph); // Determine the number of nodes using a function ... Results results = graph.batch().applyFunction(new CountNodesFunction()).to("/").execute(); assertThat(results, is(notNullValue())); assertThat(results.getRequests().size(), is(1)); FunctionRequest request = (FunctionRequest)results.getRequests().get(0); assertThat(request.output("nodeCount", PropertyType.LONG, (Long)null, context), is(new Long(count))); }
@Test public void shouldAllowSpecifyingMultipleInputParametersWhenApplyingFunction() { // Create some nodes and get the subgraph of them ... Subgraph subgraph = graph.getSubgraphOfDepth(100).at("/"); int count = countNodes(subgraph); Function function = new CountNodesFunction(); Map<String, Serializable> output = graph.applyFunction(function).withInput("a", "value").and("b", "foo").to("/"); assertThat(output.get("nodeCount"), is((Object)new Integer(count))); }
@SuppressWarnings( "synthetic-access" ) public Subgraph getConfiguration( int depth ) { Graph result = Graph.create(configRepositorySource, context); result.useWorkspace("configSpace"); return result.getSubgraphOfDepth(depth).at("/a/b/Test Repository"); } };
@SuppressWarnings( "synthetic-access" ) public Subgraph getConfiguration( int depth ) { Graph result = Graph.create(configRepositorySource, context); result.useWorkspace(configurationWorkspaceName); return result.getSubgraphOfDepth(depth).at("/a/b/Test Repository"); } };
@Test public void shouldReturnSameStructureForRepeatedReadBranchRequests() { // Verify that the content doesn't change Location root = graph.getCurrentWorkspace().getRoot(); Subgraph subgraph1 = graph.getSubgraphOfDepth(10).at(root); for (int i = 0; i != 4; ++i) { Subgraph subgraph2 = graph.getSubgraphOfDepth(10).at(root); assertEquivalentSubgraphs(subgraph1, subgraph2, true, true); } } }
@Test public void shouldAllowSpecifyingOneInputParametersWhenApplyingFunction() { // Create some nodes and get the subgraph of them ... Subgraph subgraph = graph.getSubgraphOfDepth(100).at("/"); int count = countNodes(subgraph); Function function = new CountNodesFunction(); Map<String, Serializable> output = graph.applyFunction(function).withInput("a", "value").to("/"); assertThat(output.get("nodeCount"), is((Object)new Integer(count))); }
@SuppressWarnings( "synthetic-access" ) public Subgraph getConfiguration( int depth ) { Graph result = Graph.create(source, context); result.useWorkspace("configSpace"); return result.getSubgraphOfDepth(depth).at("/"); } };
protected Subgraph subgraph( boolean refresh ) { if (cachedSubgraph == null || refresh) { Graph graph = getConfigurationGraph(); Path configRootPath = configurationRepository.getPath(); cachedSubgraph = graph.getSubgraphOfDepth(getMaxDepth()).at(configRootPath); } return cachedSubgraph; }
public Subgraph getConfiguration( int depth ) { Subgraph result = null; if (configSource != null) { Graph config = Graph.create(configSource, getExecutionContext()); config.useWorkspace(null); // default workspace result = config.getSubgraphOfDepth(depth).at(source.getName()); } return result; } });
public Subgraph getConfiguration( int depth ) { Graph result = Graph.create(source, context); result.useWorkspace("configSpace"); return result.getSubgraphOfDepth(depth).at("/"); } };