public On<Conjunction<Graph>> to( Iterator<?> values ) { List<Object> valueList = new LinkedList<Object>(); while (values.hasNext()) { Object value = values.next(); valueList.add(value); } return set(getContext().getPropertyFactory().create(propertyName, valueList)); } };
public On<Conjunction<Graph>> to( Iterable<?> values ) { List<Object> valueList = new LinkedList<Object>(); for (Object value : values) { value = convertReferenceValue(value); valueList.add(value); } return set(getContext().getPropertyFactory().create(propertyName, valueList)); }
protected On<Conjunction<Graph>> toValue( Object value ) { return set(getContext().getPropertyFactory().create(propertyName, value)); }
/** * Set a property on a node, starting with the name. The interface returned from this method should be used to specify the * value(s) and the location of the node onto which the property should be set. * * @param propertyName the property name * @return the interface used to specify the values */ public SetValues<Conjunction<Graph>> set( String propertyName ) { Name name = getContext().getValueFactories().getNameFactory().create(propertyName); return set(name); }
public On<Conjunction<Graph>> to( Node node ) { Reference value = (Reference)convertReferenceValue(node); return set(getContext().getPropertyFactory().create(propertyName, value)); }
public On<Conjunction<Graph>> to( Object[] values ) { for (int i = 0, len = values.length; i != len; ++i) { values[i] = convertReferenceValue(values[i]); } return set(getContext().getPropertyFactory().create(propertyName, values)); }
public On<Conjunction<Graph>> to( Location location ) { Reference value = (Reference)convertReferenceValue(location); return set(getContext().getPropertyFactory().create(propertyName, value)); }
public On<Conjunction<Graph>> to( Object value ) { value = convertReferenceValue(value); return set(getContext().getPropertyFactory().create(propertyName, value)); }
public On<Conjunction<Graph>> to( Object firstValue, Object... otherValues ) { firstValue = convertReferenceValue(firstValue); for (int i = 0, len = otherValues.length; i != len; ++i) { otherValues[i] = convertReferenceValue(otherValues[i]); } return set(getContext().getPropertyFactory().create(propertyName, firstValue, otherValues)); }
@Test( expected = InvalidRequestException.class ) public void shouldNotAllowSettingPropertyOnRootNode() { graph.set("propA").to("valueA").on("/"); }
@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 public void shouldProvideInputProperties() throws Exception { this.sequencedProperty = mock(Property.class); graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); graph.set("x").on("/a/b/c").to(true); graph.set("y").on("/a/b/c").to(Arrays.asList(new String[] {"asdf", "xyzzy"})); Node input = graph.getNodeAt("/a/b/c"); StreamSequencerContext sequencerContext = sequencer.createStreamSequencerContext(input, sequencedProperty, seqContext, problems); assertThat(sequencerContext.getInputProperties(), notNullValue()); assertThat(sequencerContext.getInputProperties().isEmpty(), is(false)); assertThat(sequencerContext.getInputProperties().size(), is(3)); // verifyProperty(sequencerContext, "jcr:uuid", /* some UUID */null ); verifyProperty(sequencerContext, "x", true); verifyProperty(sequencerContext, "y", "asdf", "xyzzy"); }
@Test public void shouldSetPropertyValueToPrimitiveTypes() { graph.set("propName").on(validPath).to(3.0F); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", new Float(3.0f))); graph.set("propName").on(validPath).to(1.0D); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", new Double(1.0))); graph.set("propName").on(validPath).to(false); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", Boolean.FALSE)); graph.set("propName").on(validPath).to(3); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", new Integer(3))); graph.set("propName").on(validPath).to(5L); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", new Long(5))); graph.set("propName").on(validPath).to(validPath); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", validPath)); graph.set("propName").on(validPath).to(validPath.getLastSegment().getName()); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", validPath.getLastSegment().getName())); Date now = new Date(); graph.set("propName").on(validPath).to(now); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", now)); DateTime dtNow = context.getValueFactories().getDateFactory().create(now); graph.set("propName").on(validPath).to(dtNow); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", dtNow)); Calendar calNow = Calendar.getInstance(); calNow.setTime(now); graph.set("propName").on(validPath).to(calNow); assertNextRequestSetProperty(Location.create(validPath), createProperty("propName", dtNow)); }
@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")); }
@FixFor( "MODE-1168" ) @Test public void shouldUseCorrectSetterForOverloadedSimpleProperties() { Path configPath = context.getValueFactories().getPathFactory().create("/mode:system"); service = new RepositoryService(configRepositorySource, configWorkspaceName, configPath, context, bus, problems); // Set up the configuration repository ... configRepository.useWorkspace("default"); configRepository.create("/mode:system").and(); configRepository.create("/mode:system/mode:sources").and(); configRepository.create("/mode:system/mode:sources/source A").and(); final String className = FakeRepositorySource.class.getName(); configRepository.set(ModeShapeLexicon.CLASSNAME).on("/mode:system/mode:sources/source A").to(className); configRepository.set(ModeShapeLexicon.CLASSPATH).on("/mode:system/mode:sources/source A").to(""); configRepository.set("overloadedParam").on("/mode:system/mode:sources/source A").to("true"); // Now, start up the service ... service.getAdministrator().start(); // Get the source, which should be configured ... RepositorySource repositorySourceA = service.getRepositoryLibrary().getSource("source A"); assertThat(repositorySourceA, is(instanceOf(FakeRepositorySource.class))); FakeRepositorySource sourceA = (FakeRepositorySource)repositorySourceA; assertThat(sourceA.isBooleanParam(), is(true)); }
@Test public void shouldExecuteSequencerOnExistingNodeAndOutputToExistingNode() throws Exception { // Set up the repository for the test ... graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); graph.create("/d").and().create("/d/e").and(); graph.set("sequencedProperty").on("/a/b/c").to(new ByteArrayInputStream(sampleData.getBytes())); Node nodeC = graph.getNodeAt("/a/b/c"); Node nodeE = graph.getNodeAt("/d/e"); assertThat(nodeC, is(notNullValue())); assertThat(nodeE, is(notNullValue())); assertThat(nodeE.getChildren().size(), is(0)); assertThat(nodeE.getProperties().size(), is(1)); // jcr:uuid // assertThat(nodeE.getProperty("jcr:primaryType").getString(), is("nt:unstructured")); // Set the property that will be sequenced ... // Set up the node changes ... Location location = Location.create(context.getValueFactories().getPathFactory().create("/a/b/c")); Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); // Set up the output directory ... Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>(); outputPaths.add(new RepositoryNodePath(repositorySourceName, repositoryWorkspaceName, "/d/e")); // Generate the output data that the sequencer subclass will produce and that should be saved to the repository ... sequencerOutput.setProperty(path("alpha/beta"), name("isSomething"), true); // Call the sequencer ... sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths, seqContext, problems); }
@Test public void shouldExecuteSequencerOnExistingNodeAndOutputToNonExistingNode() throws Exception { // Set up the repository for the test ... graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); // Set the property that will be sequenced ... graph.set("sequencedProperty").on("/a/b/c").to(new ByteArrayInputStream(sampleData.getBytes())); Node nodeC = graph.getNodeAt("/a/b/c"); assertThat(nodeC, is(notNullValue())); assertNodeDoesNotExist(graph, "/d"); // Set up the node changes ... Location location = Location.create(context.getValueFactories().getPathFactory().create("/a/b/c")); Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); // Set up the output directory ... Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>(); outputPaths.add(new RepositoryNodePath(repositorySourceName, repositoryWorkspaceName, "/d/e")); // Generate the output data that the sequencer subclass will produce and that should be saved to the repository ... sequencerOutput.setProperty(path("alpha/beta"), name("isSomething"), true); // Call the sequencer ... sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths, seqContext, problems); // Check to see that the "/d/e" node has been created ... assertThat(graph.getNodeAt("/d/e"), is(notNullValue())); }
graph.set("sequencedProperty").on("/a/b/c").to(new ByteArrayInputStream(sampleData.getBytes()));
protected void testSequencer( final StreamSequencer sequencer ) throws Throwable { StreamSequencer streamSequencer = new StreamSequencer() { @Override public void sequence( InputStream stream, SequencerOutput output, StreamSequencerContext context ) { sequencer.sequence(stream, output, context); } }; StreamSequencerAdapter adapter = new StreamSequencerAdapter(streamSequencer); graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); graph.create("/d").and().create("/d/e").and(); graph.set("sequencedProperty").on("/a/b/c").to(new ByteArrayInputStream(sampleData.getBytes())); Node inputNode = graph.getNodeAt("/a/b/c"); Location location = Location.create(context.getValueFactories().getPathFactory().create("/a/b/c")); Property sequencedProperty = inputNode.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>(); outputPaths.add(new RepositoryNodePath(repositorySourceName, repositoryWorkspaceName, "/d/e")); sequencerOutput.setProperty(path("alpha/beta"), name("isSomething"), true); adapter.execute(inputNode, "sequencedProperty", nodeChange, outputPaths, seqContext, problems); }
@Test( expected = SequencerException.class ) public void shouldExecuteSequencerOnExistingNodeWithMissingSequencedPropertyAndOutputToExistingNode() throws Exception { // Set up the repository for the test ... graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); graph.create("/d").and().create("/d/e").and(); Node nodeC = graph.getNodeAt("/a/b/c"); Node nodeE = graph.getNodeAt("/d/e"); assertThat(nodeC, is(notNullValue())); assertThat(nodeE, is(notNullValue())); assertThat(nodeE.getChildren().size(), is(0)); assertThat(nodeE.getProperties().size(), is(1)); // jcr:uuid // assertThat(nodeE.getProperty("jcr:primaryType").getString(), is("nt:unstructured")); // Set the property that will be sequenced ... // THIS TEST REQUIRES THIS PROPERTY TO BE NULL OR NON-EXISTANT graph.set("sequencedProperty").on(nodeC.getLocation()).to((String)null); // Set up the node changes ... Location location = Location.create(context.getValueFactories().getPathFactory().create("/a/b/c")); Property sequencedProperty = nodeC.getProperty("sequencedProperty"); NetChange nodeChange = new NetChange(repositoryWorkspaceName, location, EnumSet.of(ChangeType.PROPERTY_CHANGED), null, Collections.singleton(sequencedProperty), null, null, null, false); // Set up the output directory ... Set<RepositoryNodePath> outputPaths = new HashSet<RepositoryNodePath>(); outputPaths.add(new RepositoryNodePath(repositorySourceName, repositoryWorkspaceName, "/d/e")); // Generate the output data that the sequencer subclass will produce and that should be saved to the repository ... sequencerOutput.setProperty(path("alpha/beta"), name("isSomething"), true); // Call the sequencer, which should cause the exception ... sequencer.execute(nodeC, "sequencedProperty", nodeChange, outputPaths, seqContext, problems); }