@Test public void shouldGetPropertiesByNameOnNode() { setPropertiesToReadOn(Location.create(validPath), validIdProperty1, validIdProperty2); Map<Name, Property> propsByName = graph.getPropertiesByName().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath), validIdProperty1, validIdProperty2); assertNoMoreRequests(); assertThat(propsByName.get(validIdProperty1.getName()), is(validIdProperty1)); assertThat(propsByName.get(validIdProperty2.getName()), is(validIdProperty2)); setPropertiesToReadOn(Location.create(validPath)); propsByName = graph.getPropertiesByName().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath)); assertNoMoreRequests(); assertThat(propsByName.isEmpty(), is(true)); }
protected void assertReference( String fromNodePath, String propertyName, String... toNodePath ) { Object[] values = graph.getProperty(propertyName).on(fromNodePath).getValuesAsArray(); assertThat(values.length, is(toNodePath.length)); for (int i = 0; i != values.length; ++i) { Object value = values[i]; assertThat(value, is(instanceOf(Reference.class))); Reference ref = (Reference)value; assertThat(graph.resolve(ref).getLocation().getPath(), is(graph.getNodeAt(toNodePath[i]).getLocation().getPath())); } }
@Test public void shouldSetMultiplePropertiesAtOnce() { Property p1 = createProperty("propName1", new Float(3.0f)); Property p2 = createProperty("propName2", new Double(1.0)); Property p3 = createProperty("propName3", "String value"); graph.batch().set(p1, p2, p3).on(validPath).execute(); assertNextRequestUpdateProperties(Location.create(validPath), p1, p2, p3); }
@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 shouldGetPropertiesOnNode() { setPropertiesToReadOn(Location.create(validPath), validIdProperty1, validIdProperty2); Collection<Property> props = graph.getProperties().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath), validIdProperty1, validIdProperty2); assertNoMoreRequests(); assertThat(props, hasItems(validIdProperty1, validIdProperty2)); setPropertiesToReadOn(Location.create(validPath)); props = graph.getProperties().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath)); assertNoMoreRequests(); assertThat(props.size(), is(0)); }
@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")); }
@Test public void shouldGetPropertyOnNode() { setPropertiesToReadOn(Location.create(validPath), validIdProperty1, validIdProperty2); graph.getProperty(validIdProperty2.getName()).on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperty(Location.create(validPath), validIdProperty2); assertNoMoreRequests(); setPropertiesToReadOn(Location.create(validPath), validIdProperty1, validIdProperty2); graph.getProperty(validIdProperty2.getName().getString(context.getNamespaceRegistry())).on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperty(Location.create(validPath), validIdProperty2); assertNoMoreRequests(); }
@Test( expected = AssertionError.class ) public void shouldPropertyCheckReadPropertiesUsingTestHarness2() { graph.getProperties().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath), validIdProperty1, validIdProperty2); // wrong! }
@Test( expected = AssertionError.class ) public void shouldPropertyCheckReadPropertiesUsingTestHarness1() { setPropertiesToReadOn(Location.create(validPath), validIdProperty1); graph.getProperties().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath), validIdProperty1, validIdProperty2); // wrong! }
@Test public void shouldNotCombineNonAdjacentSetPropertyCalls() { Property p1 = createProperty("propName1", new Float(3.0f)); Property p2 = createProperty("propName2", new Double(1.0)); Property p3 = createProperty("propName3", "String value"); graph.batch().set(p1).on(validPath).and().set(p2).on(validPath).and().set(p3).on(validUuid).execute(); extractRequestsFromComposite(); assertNextRequestUpdateProperties(Location.create(validPath), p1, p2); assertNextRequestSetProperty(Location.create(validUuid), p3); }
@Test public void shouldSetPropertyWithEitherOnOrToMethodsCalledFirst() { graph.set("propName").on(validPath).to(3.0f); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", 3.0f)); graph.set("propName").to(3.0f).on(validPath); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", 3.0f)); }
@Test( expected = InvalidRequestException.class ) public void shouldNotAllowSettingPropertyOnRootNode() { graph.set("propA").to("valueA").on("/"); }
@Test public void shouldCombineAdjacentSetPropertyCalls() { Property p1 = createProperty("propName1", new Float(3.0f)); Property p2 = createProperty("propName2", new Double(1.0)); Property p3 = createProperty("propName3", "String value"); graph.batch().set(p1).on(validPath).and().set(p2).on(validPath).and().set(p3).on(validPath).execute(); assertNextRequestUpdateProperties(Location.create(validPath), p1, p2, p3); }
/** * {@inheritDoc} * * @see org.modeshape.graph.io.Destination#setProperties(org.modeshape.graph.property.Path, java.lang.Iterable) */ public void setProperties( Path path, Iterable<Property> properties ) { if (properties == null) return; batch.set(properties).on(path); }
@Test public void shouldFailToReadPropertyThatDoesNotExistOnExistingNode() { // Read each node that is a child of the root... for (Location childLocation : graph.getChildren().of("/")) { // Find a name for a non-existing property ... String nonExistentPropertyName = "ab39dbyfg739_adf7bg"; // For each node ... Property property = graph.getProperty(nonExistentPropertyName).on(childLocation); // will throw exception assertThat(property, is(nullValue())); } }
@Test public void shouldSetPropertyOnRootNode() { graph.set("propA").to("valueA").on("/"); // Now look up the node ... Node root = graph.getNodeAt("/"); assertThat(root, is(notNullValue())); assertThat(root, hasProperty(ModeShapeLexicon.UUID, getRootNodeUuid())); assertThat(root, hasProperty("propA", "valueA")); }
@Test public void shouldCreateNodesWithBatch() { graph.batch().create(validPath, validIdProperty1).and().remove("prop").on(validPathString).execute(); graph.batch().move(validPath).and(validPath).into(validPathString).and().create(validPath).and().execute(); graph.batch().createUnder(validLocation).nodeNamed("someName").and().delete(validLocation).execute(); }
/** * {@inheritDoc} * * @see org.modeshape.graph.io.Destination#setProperties(org.modeshape.graph.property.Path, * org.modeshape.graph.property.Property[]) */ public void setProperties( Path path, Property... properties ) { if (properties == null) return; batch.set(properties).on(path); }
@Test( expected = PathNotFoundException.class ) public void shouldFailToReadPropertyOnNodeThatDoesNotExist() { // Look up the child that should not exist, and this should throw an exception ... Path nonExistantChildName = findPathToNonExistentNodeUnder("/"); graph.getProperty("jcr:uuid").on(nonExistantChildName); }