DNA SVN: r478 - trunk/dna-common/src/test/java/org/jboss/dna/common/util.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-28 15:46:55 -0400 (Thu, 28 Aug 2008)
New Revision: 478
Added:
trunk/dna-common/src/test/java/org/jboss/dna/common/util/JcrUtilTest.java
Log:
JcrUtils - createPathWithIndex ans createPath without index
Added: trunk/dna-common/src/test/java/org/jboss/dna/common/util/JcrUtilTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/JcrUtilTest.java (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/JcrUtilTest.java 2008-08-28 19:46:55 UTC (rev 478)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.util;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+/**
+ * @author Serge Pagop
+ *
+ */
+public class JcrUtilTest {
+
+ /**
+ * Test method for {@link org.jboss.dna.common.util.JcrUtil#createPathWithIndex(java.lang.String, int)}.
+ */
+ @Test
+ public void shouldCreatePathWithIndex() {
+ int index = 1;
+ String path = JcrUtil.createPathWithIndex("/a/b/c", 1);
+ char c = path.charAt(path.indexOf("[") + 1);
+ assertTrue( c == Integer.toString(index).charAt(0));
+ }
+
+ /**
+ * Test method for {@link org.jboss.dna.common.util.JcrUtil#createPath(java.lang.String)}.
+ */
+ @Test
+ public void shouldCreatePath() {
+ String path = JcrUtil.createPath("/a/b/c");
+ assertTrue(path.length() > 0);
+ assertThat(path, is(new String("/a/b/c")));
+ }
+
+}
15 years, 9 months
DNA SVN: r477 - trunk/dna-common/src/main/java/org/jboss/dna/common/util.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-28 15:46:29 -0400 (Thu, 28 Aug 2008)
New Revision: 477
Added:
trunk/dna-common/src/main/java/org/jboss/dna/common/util/JcrUtil.java
Log:
JcrUtils - createPathWithIndex ans createPath without index
Added: trunk/dna-common/src/main/java/org/jboss/dna/common/util/JcrUtil.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/JcrUtil.java (rev 0)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/JcrUtil.java 2008-08-28 19:46:29 UTC (rev 477)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.util;
+
+/**
+ * @author Serge Pagop
+ *
+ */
+public class JcrUtil {
+
+ /**
+ * Create a path for the tree with index.
+ *
+ * @param path the path.
+ * @param index the index begin with 1.
+ * @return the string
+ * @throws IllegalArgumentException if the path is null, blank or empty, or if the index is not a positive value
+ */
+ public static String createPathWithIndex( String path,
+ int index ) {
+ ArgCheck.isNotEmpty(path, "path");
+ ArgCheck.isPositive(index, "index");
+ return path + "[" + index + "]";
+ }
+
+ /**
+ * Create a path for the tree without index.
+ *
+ * @param path - the path.
+ * @return the string
+ * @throws IllegalArgumentException if the path is null, blank or empty
+ */
+ public static String createPath( String path ) {
+ ArgCheck.isNotEmpty(path, "path");
+ return path;
+ }
+
+ private JcrUtil() {
+ // prevent construction
+ }
+
+}
15 years, 9 months
DNA SVN: r476 - in trunk: extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-27 10:41:52 -0400 (Wed, 27 Aug 2008)
New Revision: 476
Added:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
Log:
DNA-212 - Create test for the federation connector that uses all the components of the connector
http://jira.jboss.com/jira/browse/DNA-212
Added an integration test that puts the FederatedRepositorySource (and its components) through some paces. More tests will be required, as more is done to merge nodes.
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-27 14:41:52 UTC (rev 476)
@@ -33,13 +33,17 @@
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
-import org.jboss.dna.spi.graph.InvalidPathException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathNotFoundException;
import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.ActsOnPath;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.DeleteBranchCommand;
import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.SetPropertiesCommand;
import org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor;
import org.jboss.dna.spi.graph.commands.executor.CommandExecutor;
import org.jboss.dna.spi.graph.impl.BasicSingleValueProperty;
@@ -315,12 +319,10 @@
@Override
public void execute( GetChildrenCommand command ) throws RepositorySourceException {
Path targetPath = command.getPath();
+ Map<Name, Property> properties = getProperties(command);
+ if (properties == null) return;
+ // Iterate through all of the properties, looking for any paths that are children of the path ...
Map<Path, Map<Name, Property>> data = repository.getData();
- if (data.get(targetPath) == null) {
- command.setError(new InvalidPathException("Non-existant node: " + targetPath));
- return;
- }
- // Iterate through all of the properties, looking for any paths that are children of the path ...
List<Path.Segment> childSegments = new LinkedList<Path.Segment>();
for (Path path : data.keySet()) {
if (!path.isRoot() && path.getParent().equals(targetPath)) {
@@ -330,8 +332,8 @@
// This does not store children order, so sort ...
Collections.sort(childSegments);
for (Path.Segment childSegment : childSegments) {
- Map<Name, Property> properties = repository.getData().get(targetPath);
- Property uuidProperty = properties.get(uuidPropertyName);
+ Map<Name, Property> childProperties = repository.getData().get(targetPath);
+ Property uuidProperty = childProperties.get(uuidPropertyName);
command.addChild(childSegment,
uuidProperty == null ? new BasicSingleValueProperty(uuidPropertyName, UUID.randomUUID()) : uuidProperty);
}
@@ -344,18 +346,82 @@
*/
@Override
public void execute( GetPropertiesCommand command ) throws RepositorySourceException {
+ Map<Name, Property> properties = getProperties(command);
+ if (properties == null) return;
+ for (Property property : properties.values()) {
+ if (!property.getName().equals(this.uuidPropertyName)) {
+ command.setProperty(property);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.CreateNodeCommand)
+ */
+ @Override
+ public void execute( CreateNodeCommand command ) throws RepositorySourceException {
Path targetPath = command.getPath();
+ ExecutionContext context = getExecutionContext();
+ repository.create(context, targetPath.getString(context.getNamespaceRegistry()));
Map<Name, Property> properties = repository.getData().get(targetPath);
- if (properties == null) {
- command.setError(new InvalidPathException("Non-existant node: " + targetPath));
- return;
+ assert properties != null;
+ for (Property property : command.getProperties()) {
+ if (!property.getName().equals(this.uuidPropertyName)) {
+ properties.put(property.getName(), property);
+ }
}
- for (Property property : properties.values()) {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.SetPropertiesCommand)
+ */
+ @Override
+ public void execute( SetPropertiesCommand command ) throws RepositorySourceException {
+ Map<Name, Property> properties = getProperties(command);
+ if (properties == null) return;
+ for (Property property : command.getProperties()) {
if (!property.getName().equals(this.uuidPropertyName)) {
- command.setProperty(property);
+ properties.put(property.getName(), property);
}
}
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.DeleteBranchCommand)
+ */
+ @Override
+ public void execute( DeleteBranchCommand command ) throws RepositorySourceException {
+ // Iterate through all of the dataq, looking for any paths that are children of the path ...
+ Path targetPath = command.getPath();
+ Map<Path, Map<Name, Property>> data = repository.getData();
+ for (Path path : data.keySet()) {
+ if (!path.isRoot() && path.isAtOrBelow(targetPath)) {
+ data.remove(path);
+ }
+ }
+ }
+
+ protected <T extends ActsOnPath & GraphCommand> Map<Name, Property> getProperties( T command ) {
+ Path targetPath = command.getPath();
+ Map<Name, Property> properties = repository.getData().get(targetPath);
+ if (properties == null) {
+ Path ancestor = targetPath.getParent();
+ while (ancestor != null) {
+ if (repository.getData().get(targetPath) != null) break;
+ ancestor = ancestor.getParent();
+ }
+ if (ancestor == null) ancestor = getExecutionContext().getValueFactories().getPathFactory().createRootPath();
+ command.setError(new PathNotFoundException(targetPath, ancestor));
+ return null;
+ }
+ return properties;
+ }
}
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-27 14:41:52 UTC (rev 476)
@@ -107,7 +107,7 @@
public static final String DNA_CACHE_SEGMENT = "dna:cache";
public static final String DNA_PROJECTIONS_SEGMENT = "dna:projections";
public static final String PROJECTION_RULES_CONFIG_PROPERTY_NAME = "dna:projectionRules";
- public static final String CACHE_POLICY_TIME_TO_LIVE_CONFIG_PROPERTY_NAME = "dna:timeToLive";
+ public static final String CACHE_POLICY_TIME_TO_LIVE_CONFIG_PROPERTY_NAME = "dna:timeToCache";
private String repositoryName;
private String sourceName;
@@ -271,9 +271,7 @@
}
/**
- * Get the projection rule definitions used for the {@link #getConfigurationSourceName() configuration source}. The
- * {@link #DEFAULT_CONFIGURATION_SOURCE_PATH default path} is mapped into the <code>/dna:system</code> branch of the
- * repository.
+ * Get the path in the source that will be subgraph below the <code>/dna:system</code> branch of the repository.
* <p>
* This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
* </p>
@@ -287,9 +285,7 @@
}
/**
- * Get the projection rule definitions used for the {@link #getConfigurationSourceName() configuration source}. The
- * {@link #DEFAULT_CONFIGURATION_SOURCE_PATH default path} is mapped into the <code>/dna:system</code> branch of the
- * repository.
+ * Set the path in the source that will be subgraph below the <code>/dna:system</code> branch of the repository.
* <p>
* This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
* </p>
@@ -310,6 +306,7 @@
if (this.configurationSourcePath == pathInSourceToConfigurationRoot || this.configurationSourcePath != null
&& this.configurationSourcePath.equals(pathInSourceToConfigurationRoot)) return;
this.configurationSourcePath = pathInSourceToConfigurationRoot != null ? pathInSourceToConfigurationRoot : DEFAULT_CONFIGURATION_SOURCE_PATH;
+ changeRepositoryConfig();
}
/**
@@ -824,7 +821,15 @@
getProjectionCommand.getPath(),
getProjectionCommand.getPropertiesByName(),
problems);
- if (projection != null) sourceProjections.add(projection);
+ if (projection != null) {
+ Logger logger = context.getLogger(getClass());
+ if (logger.isTraceEnabled()) {
+ logger.trace("Adding projection to federated repository {1}: {2}",
+ getRepositoryName(),
+ projection);
+ }
+ sourceProjections.add(projection);
+ }
}
}
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java 2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java 2008-08-27 14:41:52 UTC (rev 476)
@@ -430,7 +430,7 @@
first = false;
}
sb.append(" }");
- return super.toString();
+ return sb.toString();
}
/**
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-27 14:41:52 UTC (rev 476)
@@ -21,6 +21,7 @@
*/
package org.jboss.dna.connector.federation.executor;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -380,7 +381,7 @@
break;
}
}
- if (foundNonEmptyContribution) return null;
+ if (!foundNonEmptyContribution) return null;
if (logger.isTraceEnabled()) {
logger.trace("Loaded {0} from sources, resulting in these contributions:", path);
int i = 0;
@@ -533,8 +534,9 @@
final Path path = mergedNode.getPath();
NodeConflictBehavior conflictBehavior = NodeConflictBehavior.UPDATE;
- BasicCreateNodeCommand newNode = new BasicCreateNodeCommand(path, mergedNode.getProperties(), conflictBehavior);
- newNode.setProperty(new BasicSingleValueProperty(this.uuidPropertyName, mergedNode.getUuid()));
+ Collection<Property> properties = new ArrayList<Property>(mergedNode.getPropertiesByName().size() + 1);
+ properties.add(new BasicSingleValueProperty(this.uuidPropertyName, mergedNode.getUuid()));
+ BasicCreateNodeCommand newNode = new BasicCreateNodeCommand(path, properties, conflictBehavior);
List<Segment> children = mergedNode.getChildren();
GraphCommand[] intoCache = new GraphCommand[1 + children.size()];
int i = 0;
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java 2008-08-27 14:41:52 UTC (rev 476)
@@ -0,0 +1,350 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.federation;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.stub;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import javax.naming.Context;
+import javax.security.auth.callback.CallbackHandler;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositorySource;
+import org.jboss.dna.spi.connector.SimpleRepository;
+import org.jboss.dna.spi.connector.SimpleRepositorySource;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathNotFoundException;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetChildrenCommand;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetPropertiesCommand;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * This JUnit test constructs a federated repository of multiple repository sources, and is basically a lightweight integration
+ * test that uses all of the actual components of a {@link FederatedRepository} but using mock or fake components for other
+ * systems.
+ *
+ * @author Randall Hauch
+ */
+public class FederatedRepositorySourceIntegrationTest {
+
+ private FederatedRepositorySource source;
+ private String sourceName;
+ private String username;
+ private String credentials;
+ private String executionContextFactoryJndiName;
+ private String repositoryConnectionFactoryJndiName;
+ private String configurationSourceName;
+ private String securityDomain;
+ private SimpleRepository config;
+ private SimpleRepositorySource configSource;
+ private SimpleRepository cache;
+ private SimpleRepositorySource cacheSource;
+ private SimpleRepository repository1;
+ private SimpleRepositorySource source1;
+ private SimpleRepository repository2;
+ private SimpleRepositorySource source2;
+ private ExecutionContext context;
+ private RepositorySource[] sources;
+ @Mock
+ private Context jndiContext;
+ @Mock
+ private RepositoryConnectionFactory connectionFactory;
+ @Mock
+ private ExecutionContextFactory executionContextFactory;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ // Set up the environment (ExecutionContext, JNDI, security, etc.)
+ context = new BasicExecutionContext();
+ context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
+ executionContextFactoryJndiName = "context factory jndi name";
+ repositoryConnectionFactoryJndiName = "repository connection factory jndi name";
+ configurationSourceName = "configuration source name";
+ securityDomain = "security domain";
+ stub(jndiContext.lookup(executionContextFactoryJndiName)).toReturn(executionContextFactory);
+ stub(jndiContext.lookup(repositoryConnectionFactoryJndiName)).toReturn(connectionFactory);
+ stub(executionContextFactory.create(eq(securityDomain), anyCallbackHandler())).toReturn(context);
+
+ // Set up the federated repository source ...
+ source = new FederatedRepositorySource("Test Repository");
+ sourceName = "federated source";
+ username = "valid username";
+ credentials = "valid password";
+ source.setName(sourceName);
+ source.setUsername(username);
+ source.setPassword(credentials);
+ source.setConfigurationSourceName(configurationSourceName);
+ source.setConfigurationSourcePath("/repos/RepoX");
+ source.setRepositoryConnectionFactoryJndiName(repositoryConnectionFactoryJndiName);
+ source.setExecutionContextFactoryJndiName(executionContextFactoryJndiName);
+ source.setContext(jndiContext);
+ source.setSecurityDomain(securityDomain);
+
+ // Set up the configuration repository with its content ...
+ config = SimpleRepository.get("Configuration Repository");
+ configSource = new SimpleRepositorySource();
+ configSource.setRepositoryName(config.getRepositoryName());
+ configSource.setName(configurationSourceName);
+
+ // Set up the cache repository ...
+ cache = SimpleRepository.get("Cache");
+ cacheSource = new SimpleRepositorySource();
+ cacheSource.setRepositoryName(cache.getRepositoryName());
+ cacheSource.setName("cache source");
+
+ // Set up the first source repository ...
+ repository1 = SimpleRepository.get("source 1");
+ source1 = new SimpleRepositorySource();
+ source1.setRepositoryName(repository1.getRepositoryName());
+ source1.setName("source 1");
+
+ // Set up the second source repository ...
+ repository2 = SimpleRepository.get("source 2");
+ source2 = new SimpleRepositorySource();
+ source2.setRepositoryName(repository2.getRepositoryName());
+ source2.setName("source 2");
+
+ // Set up the connection factory to return connections to the sources ...
+ sources = new RepositorySource[] {spy(configSource), spy(cacheSource), spy(source1), spy(source2)};
+ for (final RepositorySource source : sources) {
+ stub(connectionFactory.createConnection(source.getName())).toAnswer(new Answer<RepositoryConnection>() {
+ public RepositoryConnection answer( InvocationOnMock invocation ) throws Throwable {
+ return source.getConnection();
+ }
+ });
+ }
+ }
+
+ protected static CallbackHandler anyCallbackHandler() {
+ return argThat(new ArgumentMatcher<CallbackHandler>() {
+ @Override
+ public boolean matches( Object callback ) {
+ return callback != null;
+ }
+ });
+ }
+
+ protected void set( SimpleRepository repository,
+ String path,
+ String propertyName,
+ Object... values ) {
+ repository.setProperty(context, path, propertyName, values);
+ }
+
+ protected void assertNonExistant( RepositorySource source,
+ String path ) throws Exception {
+ RepositoryConnection connection = null;
+ Path pathObj = context.getValueFactories().getPathFactory().create(path);
+ try {
+ connection = source.getConnection();
+ BasicGetChildrenCommand command = new BasicGetChildrenCommand(pathObj);
+ connection.execute(context, command);
+ assertThat(command.hasError(), is(true));
+ assertThat(command.getError(), instanceOf(PathNotFoundException.class));
+ } finally {
+ if (connection != null) connection.close();
+ }
+ }
+
+ protected void assertChildren( RepositorySource source,
+ String path,
+ String... children ) throws Exception {
+ RepositoryConnection connection = null;
+ Path pathObj = context.getValueFactories().getPathFactory().create(path);
+ try {
+ connection = source.getConnection();
+ BasicGetChildrenCommand command = new BasicGetChildrenCommand(pathObj);
+ connection.execute(context, command);
+ assertThat(command.hasError(), is(false));
+ if (children == null || children.length == 0) {
+ assertThat(command.getChildren().isEmpty(), is(true));
+ } else {
+ Path.Segment[] segments = new Path.Segment[children.length];
+ int i = 0;
+ for (String child : children) {
+ segments[i++] = context.getValueFactories().getPathFactory().createSegment(child);
+ }
+ assertThat(command.getChildren(), hasItems(segments));
+ }
+ } finally {
+ if (connection != null) connection.close();
+ }
+ }
+
+ protected void assertProperty( RepositorySource source,
+ String path,
+ String propertyName,
+ Object... values ) throws Exception {
+ RepositoryConnection connection = null;
+ Path pathObj = context.getValueFactories().getPathFactory().create(path);
+ try {
+ connection = source.getConnection();
+ BasicGetPropertiesCommand command = new BasicGetPropertiesCommand(pathObj);
+ connection.execute(context, command);
+ assertThat(command.hasError(), is(false));
+ Name name = context.getValueFactories().getNameFactory().create(propertyName);
+ Property property = command.getPropertiesByName().get(name);
+ assertThat(property.getValuesAsArray(), is(values));
+ } finally {
+ if (connection != null) connection.close();
+ }
+ }
+
+ @Test
+ public void shouldReturnCorrectConnectionForEachRepositorySource() throws Exception {
+ for (final RepositorySource source : sources) {
+ // Get a connection from the factory ...
+ RepositoryConnection connection = connectionFactory.createConnection(source.getName());
+ assertThat(connection, is(notNullValue()));
+ // And check that the connection is for the correct source ...
+ assertThat(connection.getSourceName(), is(source.getName()));
+ // And close the connection (no need to do this in a finally, since it's a SimpleRepository)
+ connection.close();
+ }
+ // Now, assert that each source created one connection ...
+ for (final RepositorySource source : sources) {
+ verify(source, times(1)).getConnection();
+ }
+ }
+
+ @Test
+ public void shouldProvideReadAccessToContentFederatedFromOneSourceThatMatchesTheContentFromTheSource() throws Exception {
+ // Set up the configuration to use a single sources.
+ set(config, "/repos/RepoX/dna:federation/", "dna:timeToCache", 100000);
+ set(config, "/repos/RepoX/dna:federation/dna:cache/cache source/", "dna:projectionRules", "/ => /");
+ set(config, "/repos/RepoX/dna:federation/dna:projections/source 1/", "dna:projectionRules", "/ => /s1");
+
+ // Set up the content in the first source ...
+ set(repository1, "/s1/a/a/a", "desc", "description for /a/a/a");
+ set(repository1, "/s1/a/a/b", "desc", "description for /a/a/b");
+ set(repository1, "/s1/a/a/c", "desc", "description for /a/a/c");
+ set(repository1, "/s1/a/b/a", "desc", "description for /a/b/a");
+ set(repository1, "/s1/a/b/b", "desc", "description for /a/b/b");
+ set(repository1, "/s1/a/b/c", "desc", "description for /a/b/c");
+ set(repository1, "/s1/b/a", "desc", "description for /b/a");
+ set(repository1, "/s1/b/b", "desc", "description for /b/b");
+ set(repository1, "/s1/b/c", "desc", "description for /b/c");
+
+ // Create a connection to the federated repository. Doing so will read the config information.
+ RepositoryConnection fedConnection = source.getConnection();
+ assertThat(fedConnection, is(notNullValue()));
+ assertChildren(source, "/", "a", "b");
+ assertChildren(source, "/a/", "a", "b");
+ assertChildren(source, "/a/a", "a", "b", "c");
+ assertChildren(source, "/a/a/a");
+ assertChildren(source, "/a/a/b");
+ assertChildren(source, "/a/a/c");
+ assertChildren(source, "/a/b", "a", "b", "c");
+ assertChildren(source, "/a/b/a");
+ assertChildren(source, "/a/b/b");
+ assertChildren(source, "/a/b/c");
+ assertChildren(source, "/b", "a", "b", "c");
+ assertChildren(source, "/b/a");
+ assertChildren(source, "/b/b");
+ assertChildren(source, "/b/c");
+ }
+
+ @Test
+ public void shouldProvideReadAccessToContentFederatedFromMultipleSources() throws Exception {
+ // Set up the configuration to use multiple sources.
+ set(config, "/repos/RepoX/dna:federation/", "dna:timeToCache", 100000);
+ set(config, "/repos/RepoX/dna:federation/dna:cache/cache source/", "dna:projectionRules", "/ => /");
+ set(config, "/repos/RepoX/dna:federation/dna:projections/source 1/", "dna:projectionRules", "/ => /s1");
+ set(config, "/repos/RepoX/dna:federation/dna:projections/source 2/", "dna:projectionRules", "/ => /s2");
+
+ // Set up the content in the first source ...
+ set(repository1, "/s1/a/a/a", "desc", "description for /a/a/a");
+ set(repository1, "/s1/a/a/b", "desc", "description for /a/a/b");
+ set(repository1, "/s1/a/a/c", "desc", "description for /a/a/c");
+ set(repository1, "/s1/a/b/a", "desc", "description for /a/b/a");
+ set(repository1, "/s1/a/b/b", "desc", "description for /a/b/b");
+ set(repository1, "/s1/a/b/c", "desc", "description for /a/b/c");
+ set(repository1, "/s1/b/a", "desc", "description for /b/a");
+ set(repository1, "/s1/b/b", "desc", "description for /b/b");
+ set(repository1, "/s1/b/c", "desc", "description for /b/c");
+
+ // Set up the content in the first source ...
+ set(repository2, "/s2/x/x/x", "desc", "description for /x/x/x");
+ set(repository2, "/s2/x/x/y", "desc", "description for /x/x/y");
+ set(repository2, "/s2/x/x/z", "desc", "description for /x/x/z");
+ set(repository2, "/s2/x/y/x", "desc", "description for /x/y/x");
+ set(repository2, "/s2/x/y/y", "desc", "description for /x/y/y");
+ set(repository2, "/s2/x/y/z", "desc", "description for /x/y/z");
+ set(repository2, "/s2/y/x", "desc", "description for /y/x");
+ set(repository2, "/s2/y/y", "desc", "description for /y/y");
+ set(repository2, "/s2/y/z", "desc", "description for /y/z");
+
+ // Create a connection to the federated repository. Doing so will read the config information.
+ RepositoryConnection fedConnection = source.getConnection();
+ assertThat(fedConnection, is(notNullValue()));
+ assertChildren(source, "/", "a", "b", "x", "y");
+ assertChildren(source, "/a/", "a", "b");
+ assertChildren(source, "/a/a", "a", "b", "c");
+ assertChildren(source, "/a/a/a");
+ assertChildren(source, "/a/a/b");
+ assertChildren(source, "/a/a/c");
+ assertChildren(source, "/a/b", "a", "b", "c");
+ assertChildren(source, "/a/b/a");
+ assertChildren(source, "/a/b/b");
+ assertChildren(source, "/a/b/c");
+ assertChildren(source, "/b", "a", "b", "c");
+ assertChildren(source, "/b/a");
+ assertChildren(source, "/b/b");
+ assertChildren(source, "/b/c");
+ assertChildren(source, "/x/", "x", "y");
+ assertChildren(source, "/x/x", "x", "y", "z");
+ assertChildren(source, "/x/x/x");
+ assertChildren(source, "/x/x/y");
+ assertChildren(source, "/x/x/z");
+ assertChildren(source, "/x/y", "x", "y", "z");
+ assertChildren(source, "/x/y/x");
+ assertChildren(source, "/x/y/y");
+ assertChildren(source, "/x/y/z");
+ assertChildren(source, "/y", "x", "y", "z");
+ assertChildren(source, "/y/x");
+ assertChildren(source, "/y/y");
+ assertChildren(source, "/y/z");
+ }
+
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 9 months
DNA SVN: r475 - trunk.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-26 21:24:11 -0400 (Tue, 26 Aug 2008)
New Revision: 475
Modified:
trunk/pom.xml
Log:
Added Alexandre and Ben as developers
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-08-26 21:12:04 UTC (rev 474)
+++ trunk/pom.xml 2008-08-27 01:24:11 UTC (rev 475)
@@ -84,6 +84,24 @@
</roles>
<timezone>+1</timezone>
</developer>
+ <developer>
+ <name>Alexandre Porcelli</name>
+ <id>porcelli</id>
+ <email>porcelli(a)devexp.com.br</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>-3</timezone>
+ </developer>
+ <developer>
+ <name>Ben Abernathy</name>
+ <id>babernat</id>
+ <email>ben.abernathy(a)gmail.com</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>+2</timezone>
+ </developer>
</developers>
<contributors>
<contributor>
15 years, 9 months
DNA SVN: r474 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-26 17:12:04 -0400 (Tue, 26 Aug 2008)
New Revision: 474
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
DNA-178: Just another checkpoint closer...
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import javax.jcr.Item;
+
+/**
+ * @author jverhaeg
+ */
+abstract class AbstractJcrItem implements Item {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isModified()
+ */
+ public final boolean isModified() {
+ // TODO: Update when level 2
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNew()
+ */
+ public final boolean isNew() {
+ // TODO: Update when level 2
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#refresh(boolean)
+ */
+ public void refresh( boolean keepChanges ) {
+ // TODO: Update when level 2
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#remove()
+ */
+ public void remove() {
+ // TODO: Update when level 2
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#save()
+ */
+ public void save() {
+ // TODO: Update when level 2
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -22,9 +22,14 @@
package org.jboss.dna.jcr;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.UUID;
+import java.util.Map.Entry;
import javax.jcr.Item;
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
@@ -33,6 +38,7 @@
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.lock.Lock;
import javax.jcr.nodetype.NodeDefinition;
@@ -41,20 +47,21 @@
import javax.jcr.version.VersionHistory;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
-import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.impl.BasicPathSegment;
/**
* @author jverhaeg
*/
@NotThreadSafe
-abstract class AbstractJcrNode implements Node {
+abstract class AbstractJcrNode extends AbstractJcrItem implements Node {
private final Session session;
private Set<Property> properties;
+ private Map<Name, Integer> childCountsByName;
+ private UUID uuid;
- // private List<Segment> children;
-
AbstractJcrNode( Session session ) {
assert session != null;
this.session = session;
@@ -65,8 +72,8 @@
*
* @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
*/
- public void accept( ItemVisitor visitor ) {
- throw new UnsupportedOperationException();
+ public void accept( ItemVisitor visitor ) throws RepositoryException {
+ visitor.visit(this);
}
/**
@@ -145,10 +152,16 @@
/**
* {@inheritDoc}
*
+ * @throws IllegalArgumentException if <code>depth</code> is negative.
* @see javax.jcr.Item#getAncestor(int)
*/
- public Item getAncestor( int depth ) {
- throw new UnsupportedOperationException();
+ public final Item getAncestor( int depth ) throws RepositoryException {
+ ArgCheck.isNonNegative(depth, "depth");
+ Node ancestor = this;
+ while (--depth >= 0) {
+ ancestor = ancestor.getParent();
+ }
+ return ancestor;
}
/**
@@ -160,6 +173,13 @@
throw new UnsupportedOperationException();
}
+ private Map<Name, Integer> getChildCountsByName() {
+ if (childCountsByName == null) {
+ childCountsByName = new HashMap<Name, Integer>();
+ }
+ return childCountsByName;
+ }
+
/**
* {@inheritDoc}
*
@@ -181,21 +201,16 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getDepth()
- */
- public int getDepth() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Node#getIndex()
*/
public int getIndex() {
throw new UnsupportedOperationException();
}
+ final UUID getInternalUuid() {
+ return uuid;
+ }
+
/**
* {@inheritDoc}
*
@@ -219,7 +234,7 @@
*
* @see javax.jcr.Node#getNode(java.lang.String)
*/
- public Node getNode( String relPath ) {
+ public final Node getNode( String relativePath ) {
throw new UnsupportedOperationException();
}
@@ -238,16 +253,55 @@
* @see javax.jcr.Node#getNodes(java.lang.String)
*/
public NodeIterator getNodes( String namePattern ) {
- throw new UnsupportedOperationException();
- }
+ ArgCheck.isNotEmpty(namePattern, "namePattern");
+ String[] disjuncts = namePattern.split("\\|");
+ List<Segment> nodes = new ArrayList<Segment>();
+ for (String disjunct : disjuncts) {
+ String pattern = disjunct.trim();
+ ArgCheck.isNotEmpty(pattern, "namePattern");
+ String ndxPattern;
+ int endNdx = pattern.length() - 1;
+ if (pattern.charAt(endNdx) == ']') {
+ int ndx = pattern.indexOf('[');
+ ndxPattern = pattern.substring(ndx + 1, endNdx);
+ pattern = pattern.substring(0, ndx);
+ } else ndxPattern = null;
+ for (Entry<Name, Integer> entry : getChildCountsByName().entrySet()) {
+ if (entry.getKey().getString().matches(pattern)) {
+ if (ndxPattern != null && !entry.getValue().toString().matches(ndxPattern)) continue;
+ if (entry.getValue() > 1) nodes.add(new BasicPathSegment(entry.getKey(), entry.getValue()));
+ else nodes.add(new BasicPathSegment(entry.getKey()));
+ }
+ }
+ }
+ return new NodeIterator() {
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#getPath()
- */
- public String getPath() {
- throw new UnsupportedOperationException();
+ public Node nextNode() {
+ return null;
+ }
+
+ public long getPosition() {
+ return 0;
+ }
+
+ public long getSize() {
+ return 0;
+ }
+
+ public void skip( long skipNum ) {
+ }
+
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ return null;
+ }
+
+ public void remove() {
+ }
+ };
}
/**
@@ -291,13 +345,11 @@
*
* @see javax.jcr.Node#getProperty(java.lang.String)
*/
- public Property getProperty( String relativePath ) throws RepositoryException {
+ public final Property getProperty( String relativePath ) throws RepositoryException {
ArgCheck.isNotEmpty(relativePath, "relativePath");
// TODO: Handle multi-segment paths
for (Property property : properties) {
- if (relativePath.equals(property.getName())) {
- return property;
- }
+ if (relativePath.equals(property.getName())) return property;
}
return null;
}
@@ -316,7 +368,7 @@
*
* @see javax.jcr.Item#getSession()
*/
- public Session getSession() {
+ public final Session getSession() {
return session;
}
@@ -325,10 +377,15 @@
*
* @see javax.jcr.Node#getUUID()
*/
- public String getUUID() throws RepositoryException {
- // TODO: Check if node is referenceable
- Property prop = getProperty(DnaLexicon.UUID.getString());
- return (prop == null ? null : prop.getString());
+ public final String getUUID() throws RepositoryException {
+ // Check if node is referenceable
+ Property mixinsProp = getProperty("jcr:mixinTypes");
+ if (mixinsProp != null) {
+ for (Value value : mixinsProp.getValues()) {
+ if ("mix:referenceable".equals(value.getString())) return getProperty("jcr:uuid").getString();
+ }
+ }
+ throw new UnsupportedRepositoryOperationException();
}
/**
@@ -406,28 +463,10 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#isModified()
- */
- public boolean isModified() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#isNew()
- */
- public boolean isNew() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Item#isNode()
*/
- public boolean isNode() {
- throw new UnsupportedOperationException();
+ public final boolean isNode() {
+ return true;
}
/**
@@ -445,7 +484,7 @@
* @see javax.jcr.Item#isSame(javax.jcr.Item)
*/
public boolean isSame( Item otherItem ) {
- throw new UnsupportedOperationException();
+ return false;
}
/**
@@ -481,24 +520,6 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#refresh(boolean)
- */
- public void refresh( boolean keepChanges ) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Node#removeMixin(java.lang.String)
*/
public void removeMixin( String mixinName ) {
@@ -546,21 +567,22 @@
throw new UnsupportedOperationException();
}
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#save()
- */
- public void save() {
- throw new UnsupportedOperationException();
+ final void setChildren( List<Segment> children ) {
+ assert children != null;
+ for (Segment seg : children) {
+ Name name = seg.getName();
+ Integer count = getChildCountsByName().get(name);
+ if (count == null) getChildCountsByName().put(name, 1);
+ else getChildCountsByName().put(name, count + 1);
+ }
}
- void setChildren( List<Segment> children ) {
- assert children != null;
- // this.children = children;
+ final void setInternalUuid( UUID uuid ) {
+ assert uuid != null;
+ this.uuid = uuid;
}
- void setProperties( Set<Property> properties ) {
+ final void setProperties( Set<Property> properties ) {
assert properties != null;
this.properties = properties;
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -39,7 +39,7 @@
* @author jverhaeg
*/
@NotThreadSafe
-abstract class AbstractJcrProperty implements Property {
+abstract class AbstractJcrProperty extends AbstractJcrItem implements Property {
private final Node node;
private final ExecutionContext executionContext;
@@ -59,247 +59,189 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getDefinition()
+ * @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
*/
- public PropertyDefinition getDefinition() {
- throw new UnsupportedOperationException();
+ public void accept( ItemVisitor visitor ) throws RepositoryException {
+ visitor.visit(this);
}
- ExecutionContext getExecutionContext() {
- return executionContext;
- }
-
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getNode()
+ * @throws IllegalArgumentException if <code>depth</code> is negative.
+ * @see javax.jcr.Item#getAncestor(int)
*/
- public Node getNode() {
- return node;
+ public final Item getAncestor( int depth ) throws RepositoryException {
+ return (depth == 0 ? this : node.getAncestor(depth - 1));
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getValues()
+ * @see javax.jcr.Property#getDefinition()
*/
- public Value[] getValues() {
+ public PropertyDefinition getDefinition() {
throw new UnsupportedOperationException();
}
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#setValue(javax.jcr.Value)
- */
- public void setValue( Value value ) {
- throw new UnsupportedOperationException();
+ final ExecutionContext getExecutionContext() {
+ return executionContext;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(javax.jcr.Value[])
+ * @see javax.jcr.Property#getNode()
*/
- public void setValue( Value[] values ) {
- throw new UnsupportedOperationException();
+ final public Node getNode() {
+ return node;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.lang.String)
+ * @see javax.jcr.Item#getName()
*/
- public void setValue( String value ) {
- throw new UnsupportedOperationException();
+ public final String getName() {
+ return name.getString();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.lang.String[])
+ * @see javax.jcr.Item#getParent()
*/
- public void setValue( String[] values ) {
- throw new UnsupportedOperationException();
+ public final Node getParent() {
+ return node;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.io.InputStream)
+ * @see javax.jcr.Item#getPath()
*/
- public void setValue( InputStream value ) {
- throw new UnsupportedOperationException();
+ public String getPath() throws RepositoryException {
+ return node.getPath() + '/' + getName();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(long)
+ * @see javax.jcr.Item#getSession()
*/
- public void setValue( long value ) {
- throw new UnsupportedOperationException();
+ public final Session getSession() throws RepositoryException {
+ return node.getSession();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(double)
+ * @see javax.jcr.Item#isNode()
*/
- public void setValue( double value ) {
- throw new UnsupportedOperationException();
+ public final boolean isNode() {
+ return false;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.util.Calendar)
+ * @see javax.jcr.Item#isSame(javax.jcr.Item)
*/
- public void setValue( Calendar value ) {
- throw new UnsupportedOperationException();
+ public boolean isSame( Item otherItem ) throws RepositoryException {
+ if (otherItem instanceof Property) {
+ Property otherProp = (Property)otherItem;
+ return (getName().equals(otherProp.getName()) && getNode().isSame(otherProp.getNode()));
+ }
+ return false;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(boolean)
+ * @see javax.jcr.Property#setValue(javax.jcr.Value)
*/
- public void setValue( boolean value ) {
+ public void setValue( Value value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(javax.jcr.Node)
+ * @see javax.jcr.Property#setValue(javax.jcr.Value[])
*/
- public void setValue( Node value ) {
+ public void setValue( Value[] values ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
+ * @see javax.jcr.Property#setValue(java.lang.String)
*/
- public void accept( ItemVisitor visitor ) {
+ public void setValue( String value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getAncestor(int)
+ * @see javax.jcr.Property#setValue(java.lang.String[])
*/
- public Item getAncestor( int depth ) {
+ public void setValue( String[] values ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getDepth()
+ * @see javax.jcr.Property#setValue(java.io.InputStream)
*/
- public int getDepth() {
+ public void setValue( InputStream value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getName()
+ * @see javax.jcr.Property#setValue(long)
*/
- public String getName() {
- return name.getString();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#getParent()
- */
- public Node getParent() {
+ public void setValue( long value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getPath()
+ * @see javax.jcr.Property#setValue(double)
*/
- public String getPath() {
+ public void setValue( double value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getSession()
+ * @see javax.jcr.Property#setValue(java.util.Calendar)
*/
- public Session getSession() throws RepositoryException {
- return node.getSession();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#isModified()
- */
- public boolean isModified() {
+ public void setValue( Calendar value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#isNew()
+ * @see javax.jcr.Property#setValue(boolean)
*/
- public boolean isNew() {
+ public void setValue( boolean value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#isNode()
+ * @see javax.jcr.Property#setValue(javax.jcr.Node)
*/
- public boolean isNode() {
+ public void setValue( Node value ) {
throw new UnsupportedOperationException();
}
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#isSame(javax.jcr.Item)
- */
- public boolean isSame( Item otherItem ) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#refresh(boolean)
- */
- public void refresh( boolean keepChanges ) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#save()
- */
- public void save() {
- throw new UnsupportedOperationException();
- }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -21,11 +21,13 @@
*/
package org.jboss.dna.jcr;
+import java.util.UUID;
import javax.jcr.Node;
-import javax.jcr.Property;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Name;
/**
* @author jverhaeg
@@ -33,20 +35,35 @@
@NotThreadSafe
final class JcrNode extends AbstractJcrNode {
- JcrNode( Session session ) {
+ private final UUID parentUuid;
+ private final Name name;
+
+ JcrNode( Session session,
+ UUID parentUuid,
+ Name name ) {
super(session);
+ assert parentUuid != null;
+ assert name != null;
+ this.parentUuid = parentUuid;
+ this.name = name;
}
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() throws RepositoryException {
+ return getParent().getDepth() + 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Item#getName()
*/
- public String getName() throws RepositoryException {
- Property prop = getProperty("jcr:name");
- assert prop != null;
- assert prop.getValue() != null;
- return prop.getValue().getString();
+ public String getName() {
+ return name.getString();
}
/**
@@ -54,7 +71,30 @@
*
* @see javax.jcr.Item#getParent()
*/
- public Node getParent() {
- throw new UnsupportedOperationException();
+ public Node getParent() throws RepositoryException {
+ return getSession().getNodeByUUID(parentUuid.toString());
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getPath()
+ */
+ public String getPath() throws RepositoryException {
+ Node parent = getParent();
+ StringBuilder builder = new StringBuilder(parent.getPath());
+ assert builder.length() > 0;
+ if (builder.charAt(builder.length() - 1) != '/') {
+ builder.append('/');
+ }
+ String name = getName();
+ builder.append(name);
+ NodeIterator iter = parent.getNodes(name);
+ if (iter.getSize() > 1) {
+ builder.append('[');
+ builder.append(getIndex());
+ builder.append(']');
+ }
+ return builder.toString();
+ }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -22,6 +22,7 @@
package org.jboss.dna.jcr;
import java.io.InputStream;
+import java.io.Reader;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
@@ -32,6 +33,7 @@
import javax.jcr.ValueFormatException;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.ValueFactories;
/**
@@ -63,11 +65,19 @@
} else if (value instanceof Long) {
jcrValue = new JcrValue<Long>(valueFactories, PropertyType.LONG, (Long)value);
} else if (value instanceof UUID) {
- jcrValue = new JcrValue<UUID>(valueFactories, PropertyType.STRING, (UUID)value);
+ jcrValue = new JcrValue<UUID>(valueFactories, PropertyType.REFERENCE, (UUID)value);
} else if (value instanceof String) {
jcrValue = new JcrValue<String>(valueFactories, PropertyType.STRING, (String)value);
+ } else if (value instanceof Name) {
+ jcrValue = new JcrValue<Name>(valueFactories, PropertyType.NAME, (Name)value);
+ } else if (value instanceof Path) {
+ jcrValue = new JcrValue<Path>(valueFactories, PropertyType.PATH, (Path)value);
+ } else if (value instanceof InputStream) {
+ jcrValue = new JcrValue<InputStream>(valueFactories, PropertyType.BINARY, (InputStream)value);
+ } else if (value instanceof Reader) {
+ jcrValue = new JcrValue<Reader>(valueFactories, PropertyType.BINARY, (Reader)value);
} else {
- jcrValue = new JcrValue<Object>(valueFactories, PropertyType.BINARY, value);
+ jcrValue = new JcrValue<Object>(getExecutionContext().getValueFactories(), PropertyType.BINARY, value);
}
}
@@ -92,6 +102,15 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() throws RepositoryException {
+ return getParent().getDepth() + 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() throws RepositoryException {
@@ -160,4 +179,69 @@
public Value getValue() {
return jcrValue;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValues()
+ */
+ public Value[] getValues() throws ValueFormatException {
+ throw new ValueFormatException();
+ }
+ //
+ // /**
+ // * {@inheritDoc}
+ // *
+ // * @throws IllegalArgumentException if <code>value</code> is <code>null</code>.
+ // * @see javax.jcr.Property#setValue(javax.jcr.Value)
+ // */
+ // @SuppressWarnings( "fallthrough" )
+ // public void setValue( Value value ) throws RepositoryException {
+ // ArgCheck.isNotNull(value, "value");
+ // // TODOx: Check node type constraint
+ // try {
+ // jcrValue = JcrValue.class.cast(value);
+ // } catch (ClassCastException error) {
+ // // TODOx: not sure if this is even possible
+ // ValueFactories valueFactories = getExecutionContext().getValueFactories();
+ // int type = value.getType();
+ // switch (type) {
+ // case PropertyType.BINARY: {
+ // jcrValue = new JcrValue<InputStream>(valueFactories, type, value.getStream());
+ // break;
+ // }
+ // case PropertyType.BOOLEAN: {
+ // jcrValue = new JcrValue<Boolean>(valueFactories, type, value.getBoolean());
+ // break;
+ // }
+ // case PropertyType.DATE: {
+ // jcrValue = new JcrValue<Calendar>(valueFactories, type, value.getDate());
+ // break;
+ // }
+ // case PropertyType.DOUBLE: {
+ // jcrValue = new JcrValue<Double>(valueFactories, type, value.getDouble());
+ // break;
+ // }
+ // case PropertyType.LONG: {
+ // jcrValue = new JcrValue<Long>(valueFactories, type, value.getLong());
+ // break;
+ // }
+ // case PropertyType.REFERENCE: {
+ // try {
+ // jcrValue = new JcrValue<UUID>(valueFactories, type, UUID.fromString(value.getString()));
+ // } catch (IllegalArgumentException fallsThroughToString) {
+ // }
+ // }
+ // case PropertyType.NAME:
+ // case PropertyType.PATH:
+ // case PropertyType.STRING: {
+ // jcrValue = new JcrValue<String>(valueFactories, type, value.getString());
+ // break;
+ // }
+ // default: {
+ // throw new AssertionError("Unsupported PropertyType: " + value.getType());
+ // }
+ // }
+ // }
+ // }
}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.Iterator;
+import java.util.Set;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+class JcrPropertyIterator implements PropertyIterator {
+
+ private final Set<Property> properties;
+ private final Iterator<Property> iterator;
+ private long index = 0L;
+
+ JcrPropertyIterator( Set<Property> properties ) {
+ assert properties != null;
+ this.properties = properties;
+ iterator = properties.iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.PropertyIterator#nextProperty()
+ */
+ public Property nextProperty() {
+ Property property = iterator.next();
+ index++;
+ return property;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return index;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return properties.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long count ) {
+ ArgCheck.isNonNegative(count, "count");
+ while (--count >= 0) {
+ iterator.next();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ return nextProperty();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ iterator.remove();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.UUID;
import java.util.WeakHashMap;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
@@ -253,7 +254,7 @@
// Create session
try {
return new JcrSession(this, execContext, workspaceName, connectionFactory.createConnection(workspaceName),
- new WeakHashMap<String, WeakReference<Node>>());
+ new WeakHashMap<UUID, WeakReference<Node>>());
} catch (InterruptedException error) {
throw new RepositoryException(error);
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -39,6 +39,15 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Item#getName()
*/
public String getName() {
@@ -53,4 +62,13 @@
public Node getParent() throws ItemNotFoundException {
throw new ItemNotFoundException();
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getPath()
+ */
+ public String getPath() {
+ return "/";
+ }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -49,6 +49,7 @@
import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.UuidFactory;
import org.jboss.dna.spi.graph.Path.Segment;
import org.jboss.dna.spi.graph.commands.GraphCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
@@ -64,7 +65,7 @@
private final Repository repository;
private final ExecutionContext executionContext;
private RepositoryConnection connection;
- private final Map<String, WeakReference<Node>> uuid2NodeMap;
+ private final Map<UUID, WeakReference<Node>> nodesByUuid;
private boolean isLive;
private Workspace workspace;
private JcrRootNode rootNode;
@@ -73,16 +74,16 @@
ExecutionContext executionContext,
String workspaceName,
RepositoryConnection connection,
- Map<String, WeakReference<Node>> uuid2NodeMap ) throws RepositoryException {
+ Map<UUID, WeakReference<Node>> nodesByUuid ) throws RepositoryException {
assert repository != null;
assert executionContext != null;
assert workspaceName != null;
assert connection != null;
- assert uuid2NodeMap != null;
+ assert nodesByUuid != null;
this.repository = repository;
this.executionContext = executionContext;
this.connection = connection;
- this.uuid2NodeMap = uuid2NodeMap;
+ this.nodesByUuid = nodesByUuid;
this.isLive = true;
// Following must be initialized after session's state is initialized
this.workspace = new JcrWorkspace(this, workspaceName);
@@ -210,7 +211,8 @@
BasicGetNodeCommand getNodeCommand = new BasicGetNodeCommand(parentPath);
execute(getNodeCommand);
// First search for a child with the last name in the path
- Name name = path.getLastSegment().getName();
+ Segment lastSeg = path.getLastSegment();
+ Name name = lastSeg.getName();
for (Segment seg : getNodeCommand.getChildren()) {
if (seg.getName().equals(name)) {
return getNode(path);
@@ -218,9 +220,8 @@
}
// If a node isn't found & last segment contains no index, get parent node & search for a property with the last name in
// the path
- Segment seg = path.getLastSegment();
- if (!seg.hasIndex()) {
- return getNode(parentPath).getProperty(seg.getString());
+ if (!lastSeg.hasIndex()) {
+ return getNode(parentPath).getProperty(lastSeg.getString());
}
// If a property isn't found, throw a PathNotFoundException
throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
@@ -267,10 +268,11 @@
BasicGetNodeCommand command = new BasicGetNodeCommand(path);
execute(command);
// First check if node already exists. We don't need to check for changes since that will be handled by an observer
- org.jboss.dna.spi.graph.Property dnaUuidProp = command.getPropertiesByName().get(DnaLexicon.UUID);
+ org.jboss.dna.spi.graph.Property dnaUuidProp = command.getPropertiesByName().get(executionContext.getValueFactories().getNameFactory().create("jcr:uuid"));
+ if (dnaUuidProp == null) dnaUuidProp = command.getPropertiesByName().get(DnaLexicon.UUID);
if (dnaUuidProp != null) {
- String uuid = executionContext.getValueFactories().getStringFactory().create(dnaUuidProp.getValues()).next();
- WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+ UUID uuid = executionContext.getValueFactories().getUuidFactory().create(dnaUuidProp.getValues()).next();
+ WeakReference<Node> ref = nodesByUuid.get(uuid);
if (ref != null) {
Node node = ref.get();
if (node != null) {
@@ -279,7 +281,11 @@
}
}
// If not create a new one & populate it
- JcrNode node = new JcrNode(this);
+ JcrNode node;
+ Path parentPath = path.getParent();
+ if (parentPath.isRoot()) node = new JcrNode(this, ((JcrRootNode)getRootNode()).getInternalUuid(),
+ path.getLastSegment().getName());
+ else node = new JcrNode(this, ((JcrNode)getNode(parentPath)).getInternalUuid(), path.getLastSegment().getName());
populateNode(node, command);
return node;
}
@@ -437,7 +443,7 @@
}
private void populateNode( AbstractJcrNode node,
- BasicGetNodeCommand getNodeCommand ) throws RepositoryException {
+ BasicGetNodeCommand getNodeCommand ) {
// TODO: What do we do to validate node against its primary type?
assert node != null;
assert getNodeCommand != null;
@@ -445,20 +451,23 @@
node.setChildren(getNodeCommand.getChildren());
// Create JCR properties for corresponding DNA properties
Set<Property> properties = new HashSet<Property>();
- boolean uuidFound = false;
+ UUID uuid = null;
+ Name jcrUuidName = executionContext.getValueFactories().getNameFactory().create("jcr:uuid");
+ UuidFactory uuidFactory = executionContext.getValueFactories().getUuidFactory();
for (org.jboss.dna.spi.graph.Property dnaProp : getNodeCommand.getProperties()) {
- if (DnaLexicon.UUID.equals(dnaProp.getName())) {
- uuidFound = true;
+ Name name = dnaProp.getName();
+ if (uuid == null && DnaLexicon.UUID.equals(name)) uuid = uuidFactory.create(dnaProp.getValues()).next();
+ else {
+ if (jcrUuidName.equals(name)) uuid = uuidFactory.create(dnaProp.getValues()).next();
+ properties.add(new JcrProperty(node, executionContext, name, dnaProp.getValues().next()));
}
- properties.add(new JcrProperty(node, executionContext, dnaProp.getName(), dnaProp.getValues().next()));
}
- // Ensure a UUID property exists
- if (!uuidFound) {
- properties.add(new JcrProperty(node, executionContext, DnaLexicon.UUID, UUID.randomUUID()));
- }
node.setProperties(properties);
- // Setup node to be retrieved by UUID
- uuid2NodeMap.put(node.getUUID(), new WeakReference<Node>(node));
+ // Set node's UUID, creating one if necessary
+ if (uuid == null) uuid = UUID.randomUUID();
+ node.setInternalUuid(uuid);
+ // Setup node to be retrieved by DNA UUID
+ nodesByUuid.put(node.getInternalUuid(), new WeakReference<Node>(node));
}
/**
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.Session;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author jverhaeg
+ */
+public class AbstractJcrItemTest {
+
+ private AbstractJcrItem item;
+
+ @Before
+ public void before() {
+ item = new AbstractJcrItem() {
+
+ public void accept( ItemVisitor visitor ) {
+ }
+
+ public Item getAncestor( int depth ) {
+ return null;
+ }
+
+ public int getDepth() {
+ return 0;
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public Node getParent() {
+ return null;
+ }
+
+ public String getPath() {
+ return null;
+ }
+
+ public Session getSession() {
+ return null;
+ }
+
+ public boolean isNode() {
+ return false;
+ }
+
+ public boolean isSame( Item otherItem ) {
+ return false;
+ }
+ };
+ }
+
+ @Test
+ public void shouldNotBeNew() throws Exception {
+ assertThat(item.isNew(), is(false));
+ }
+
+ @Test
+ public void shouldNotBeModified() throws Exception {
+ assertThat(item.isModified(), is(false));
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowRefresh() throws Exception {
+ item.refresh(false);
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowRemove() throws Exception {
+ item.remove();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowSave() throws Exception {
+ item.save();
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -26,10 +26,12 @@
import static org.mockito.Mockito.stub;
import java.util.HashSet;
import java.util.Set;
+import java.util.UUID;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
-import org.jboss.dna.spi.DnaLexicon;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -52,6 +54,10 @@
properties = new HashSet<Property>();
node = new AbstractJcrNode(session) {
+ public int getDepth() {
+ return 0;
+ }
+
public String getName() {
return null;
}
@@ -59,14 +65,29 @@
public Node getParent() {
return null;
}
+
+ public String getPath() {
+ return null;
+ }
};
node.setProperties(properties);
}
+ @Test
+ public void shouldAllowVisitation() throws Exception {
+ ItemVisitor visitor = Mockito.mock(ItemVisitor.class);
+ node.accept(visitor);
+ Mockito.verify(visitor).visit(node);
+ }
+
@Test( expected = AssertionError.class )
public void shouldNotAllowNoSession() throws Exception {
new AbstractJcrNode(null) {
+ public int getDepth() {
+ return 0;
+ }
+
public String getName() {
return null;
}
@@ -74,21 +95,33 @@
public Node getParent() {
return null;
}
+
+ public String getPath() {
+ return null;
+ }
};
}
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeAncestorDepth() throws Exception {
+ node.getAncestor(-1);
+ }
+
@Test
+ public void shouldProvideAncestor() throws Exception {
+ assertThat(node.getAncestor(0), is((Item)node));
+ }
+
+ @Test
public void shouldProvideSession() throws Exception {
assertThat(node.getSession(), is(session));
}
@Test
- public void shouldProvideUuid() throws Exception {
- Property property = Mockito.mock(Property.class);
- stub(property.getName()).toReturn(DnaLexicon.UUID.getString());
- stub(property.getString()).toReturn("uuid");
- properties.add(property);
- assertThat(node.getUUID(), is("uuid"));
+ public void shouldProvideInternalUuid() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ node.setInternalUuid(uuid);
+ assertThat(node.getInternalUuid(), is(uuid));
}
@Test
@@ -98,4 +131,9 @@
properties.add(property);
assertThat(node.getProperty("test"), is(property));
}
+
+ @Test
+ public void shouldBeANode() {
+ assertThat(node.isNode(), is(true));
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -26,7 +26,11 @@
import static org.mockito.Mockito.stub;
import java.io.InputStream;
import java.util.Calendar;
+import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ItemVisitor;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Session;
import javax.jcr.Value;
import org.jboss.dna.spi.ExecutionContext;
@@ -56,6 +60,13 @@
prop = new MockAbstractJcrProperty(node, executionContext, name);
}
+ @Test
+ public void shouldAllowVisitation() throws Exception {
+ ItemVisitor visitor = Mockito.mock(ItemVisitor.class);
+ prop.accept(visitor);
+ Mockito.verify(visitor).visit(prop);
+ }
+
@Test( expected = AssertionError.class )
public void shouldNotAllowNoSession() throws Exception {
new MockAbstractJcrProperty(null, executionContext, name);
@@ -71,7 +82,26 @@
new MockAbstractJcrProperty(node, executionContext, null);
}
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeAncestorDepth() throws Exception {
+ stub(node.getAncestor(-2)).toThrow(new IllegalArgumentException());
+ prop.getAncestor(-1);
+ }
+
@Test
+ public void shouldProvideAncestor() throws Exception {
+ assertThat(prop.getAncestor(0), is((Item)prop));
+ stub(node.getAncestor(0)).toReturn(node);
+ assertThat(prop.getAncestor(1), is((Item)node));
+ }
+
+ @Test( expected = ItemNotFoundException.class )
+ public void shouldNotAllowAncestorDepthGreaterThanNodeDepth() throws Exception {
+ stub(node.getAncestor(1)).toThrow(new ItemNotFoundException());
+ prop.getAncestor(2);
+ }
+
+ @Test
public void shouldProvideSession() throws Exception {
Session session = Mockito.mock(Session.class);
stub(node.getSession()).toReturn(session);
@@ -94,6 +124,56 @@
assertThat(prop.getName(), is("name"));
}
+ @Test
+ public void shouldProvideParent() throws Exception {
+ assertThat(prop.getParent(), is(node));
+ }
+
+ @Test
+ public void shouldProvidePath() throws Exception {
+ stub(node.getPath()).toReturn("/nodeName");
+ stub(name.getString()).toReturn("propertyName");
+ assertThat(prop.getPath(), is("/nodeName/propertyName"));
+ }
+
+ @Test
+ public void shouldNotBeANode() {
+ assertThat(prop.isNode(), is(false));
+ }
+
+ @Test
+ public void shouldIndicateSameAsNodeWithSameParentAndName() throws Exception {
+ stub(name.getString()).toReturn("propertyName");
+ Node otherNode = Mockito.mock(Node.class);
+ Name otherName = Mockito.mock(Name.class);
+ stub(otherName.getString()).toReturn("propertyName");
+ stub(node.isSame(otherNode)).toReturn(true);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
+ assertThat(prop.isSame(otherProp), is(true));
+ }
+
+ @Test
+ public void shouldIndicateDifferentThanNodeWithDifferentParent() throws Exception {
+ stub(name.getString()).toReturn("propertyName");
+ Node otherNode = Mockito.mock(Node.class);
+ Name otherName = Mockito.mock(Name.class);
+ stub(otherName.getString()).toReturn("propertyName");
+ stub(node.isSame(otherNode)).toReturn(false);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
+ assertThat(prop.isSame(otherProp), is(false));
+ }
+
+ @Test
+ public void shouldIndicateDifferentThanNodeWithDifferentName() throws Exception {
+ stub(name.getString()).toReturn("propertyName");
+ Node otherNode = Mockito.mock(Node.class);
+ Name otherName = Mockito.mock(Name.class);
+ stub(otherName.getString()).toReturn("propertyName2");
+ stub(node.isSame(otherNode)).toReturn(true);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
+ assertThat(prop.isSame(otherProp), is(false));
+ }
+
private class MockAbstractJcrProperty extends AbstractJcrProperty {
MockAbstractJcrProperty( Node node,
@@ -123,6 +203,15 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() {
@@ -191,5 +280,14 @@
public Value getValue() {
return null;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValues()
+ */
+ public Value[] getValues() {
+ return null;
+ }
}
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -24,11 +24,15 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.stub;
+import java.util.ArrayList;
import java.util.HashSet;
-import java.util.Set;
+import java.util.UUID;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
-import javax.jcr.Value;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path.Segment;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -41,26 +45,40 @@
public class JcrNodeTest {
private JcrNode node;
+ private Node root;
@Mock
private Session session;
- private Set<Property> properties;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- properties = new HashSet<Property>();
- node = new JcrNode(session);
- node.setProperties(properties);
+ root = new JcrRootNode(session);
+ Name name = Mockito.mock(Name.class);
+ stub(name.getString()).toReturn("name");
+ UUID uuid = UUID.randomUUID();
+ node = new JcrNode(session, uuid, name);
+ stub(session.getNodeByUUID(uuid.toString())).toReturn(root);
+ node.setProperties(new HashSet<Property>());
+ node.setChildren(new ArrayList<Segment>());
}
+ @Test( expected = ItemNotFoundException.class )
+ public void shouldNotAllowAncestorDepthGreaterThanNodeDepth() throws Exception {
+ node.getAncestor(2);
+ }
+
@Test
+ public void shouldHaveZeroDepth() throws Exception {
+ assertThat(node.getDepth(), is(1));
+ }
+
+ @Test
public void shouldProvideName() throws Exception {
- Property property = Mockito.mock(Property.class);
- stub(property.getName()).toReturn("jcr:name");
- Value value = Mockito.mock(Value.class);
- stub(value.getString()).toReturn("name");
- stub(property.getValue()).toReturn(value);
- properties.add(property);
assertThat(node.getName(), is("name"));
}
+
+ @Test
+ public void shouldProvidePath() throws Exception {
+ assertThat(node.getPath(), is("/name"));
+ }
}
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.util.HashSet;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrPropertyIteratorTest {
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoProperties() throws Exception {
+ new JcrPropertyIterator(null);
+ }
+
+ @Test
+ public void shouldIndicateWhenPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ assertThat(iter.hasNext(), is(false));
+ props.add(Mockito.mock(Property.class));
+ iter = new JcrPropertyIterator(props);
+ assertThat(iter.hasNext(), is(true));
+ }
+
+ @Test
+ public void shouldAllowNextWhenPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ Property prop1 = Mockito.mock(Property.class);
+ props.add(prop1);
+ Property prop2 = Mockito.mock(Property.class);
+ props.add(prop2);
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ Property iterProp1 = (Property)iter.next();
+ assertThat(iterProp1, notNullValue());
+ Property iterProp2 = (Property)iter.next();
+ assertThat(iterProp2, notNullValue());
+ assertThat(iterProp1, is(not(iterProp2)));
+ }
+
+ @Test( expected = NoSuchElementException.class )
+ public void shouldNotAllowNextWhenNoPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.next();
+ }
+
+ @Test
+ public void shouldAllowNextPropertyWhenPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ Property prop1 = Mockito.mock(Property.class);
+ props.add(prop1);
+ Property prop2 = Mockito.mock(Property.class);
+ props.add(prop2);
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ Property iterProp1 = iter.nextProperty();
+ assertThat(iterProp1, notNullValue());
+ Property iterProp2 = iter.nextProperty();
+ assertThat(iterProp2, notNullValue());
+ assertThat(iterProp1, is(not(iterProp2)));
+ }
+
+ @Test( expected = NoSuchElementException.class )
+ public void shouldNotAllowNextPropertyWhenNoPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.nextProperty();
+ }
+
+ @Test
+ public void shouldAllowRemoveAfterNext() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.next();
+ iter.remove();
+ assertThat(props.isEmpty(), is(true));
+ }
+
+ @Test( expected = IllegalStateException.class )
+ public void shouldNotAllowRemoveBeforeNext() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.remove();
+ }
+
+ @Test( expected = IllegalStateException.class )
+ public void shouldNotAllowRemoveTwice() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.next();
+ iter.remove();
+ iter.remove();
+ }
+
+ @Test
+ public void shouldProvideSize() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ assertThat(iter.getSize(), is(0L));
+ props.add(Mockito.mock(Property.class));
+ iter = new JcrPropertyIterator(props);
+ assertThat(iter.getSize(), is(1L));
+ iter.next();
+ iter.remove();
+ assertThat(iter.getSize(), is(0L));
+ }
+
+ @Test
+ public void shouldProvidePosition() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ assertThat(iter.getPosition(), is(0L));
+ props.add(Mockito.mock(Property.class));
+ iter = new JcrPropertyIterator(props);
+ assertThat(iter.getPosition(), is(0L));
+ iter.next();
+ assertThat(iter.getPosition(), is(1L));
+ iter.remove();
+ assertThat(iter.getPosition(), is(1L));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeSkip() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.skip(-1);
+ }
+
+ @Test
+ public void shouldAllowSkip() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.skip(0);
+ assertThat(iter.hasNext(), is(true));
+ iter.skip(1);
+ assertThat(iter.hasNext(), is(false));
+ }
+
+ @Test( expected = NoSuchElementException.class )
+ public void shouldNotAllowSkipPastRemainingProperties() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.skip(1);
+ }
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -24,7 +24,9 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.io.InputStream;
+import java.io.Reader;
import java.util.Calendar;
import java.util.UUID;
import javax.jcr.Node;
@@ -35,8 +37,10 @@
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.connector.BasicExecutionContext;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -65,6 +69,7 @@
public void shouldProvideBoolean() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, true);
assertThat(prop.getBoolean(), is(true));
+ assertThat(prop.getType(), is(PropertyType.BOOLEAN));
}
@Test
@@ -72,36 +77,30 @@
Calendar cal = Calendar.getInstance();
Property prop = new JcrProperty(node, executionContext, name, cal);
assertThat(prop.getDate(), is(cal));
+ assertThat(prop.getType(), is(PropertyType.DATE));
prop = new JcrProperty(node, executionContext, name, cal.getTime());
assertThat(prop.getDate(), is(cal));
+ assertThat(prop.getType(), is(PropertyType.DATE));
}
@Test
public void shouldProvideDouble() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, 1.0);
assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
prop = new JcrProperty(node, executionContext, name, 1.0F);
assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
}
@Test
- public void shouldProvideLength() throws Exception {
- assertThat(new JcrProperty(node, executionContext, name, "value").getLength(), is(5L));
- Object obj = new Object();
- assertThat(new JcrProperty(node, executionContext, name, obj).getLength(), is((long)obj.toString().length()));
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideLengths() throws Exception {
- new JcrProperty(node, executionContext, name, "value").getLengths();
- }
-
- @Test
public void shouldProvideLong() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, 1);
assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getType(), is(PropertyType.LONG));
prop = new JcrProperty(node, executionContext, name, 1L);
assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getType(), is(PropertyType.LONG));
}
@Test
@@ -116,26 +115,68 @@
public void shouldProvideString() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, "value");
assertThat(prop.getString(), is("value"));
+ assertThat(prop.getType(), is(PropertyType.STRING));
}
@Test
- public void shouldProvideUuid() throws Exception {
+ public void shouldAllowReferenceValue() throws Exception {
UUID uuid = UUID.randomUUID();
Property prop = new JcrProperty(node, executionContext, name, uuid);
assertThat(prop.getString(), is(uuid.toString()));
+ assertThat(prop.getType(), is(PropertyType.REFERENCE));
}
@Test
- public void shouldProvideType() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, UUID.randomUUID());
- assertThat(prop.getType(), is(PropertyType.STRING));
+ public void shouldAllowBinaryValue() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, Mockito.mock(Reader.class));
+ assertThat(prop.getType(), is(PropertyType.BINARY));
+ prop = new JcrProperty(node, executionContext, name, Mockito.mock(InputStream.class));
+ assertThat(prop.getType(), is(PropertyType.BINARY));
+ prop = new JcrProperty(node, executionContext, name, new Object());
+ assertThat(prop.getType(), is(PropertyType.BINARY));
}
@Test
+ public void shouldAllowNameValue() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, name);
+ assertThat(prop.getType(), is(PropertyType.NAME));
+ }
+
+ @Test
+ public void shouldAllowPathValue() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, Mockito.mock(Path.class));
+ assertThat(prop.getType(), is(PropertyType.PATH));
+ }
+
+ @Test
public void shouldProvideValue() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, true);
Value val = prop.getValue();
assertThat(val, notNullValue());
assertThat(val.getBoolean(), is(true));
}
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideValues() throws Exception {
+ new JcrProperty(node, executionContext, name, true).getValues();
+ }
+
+ @Test
+ public void shouldProvideLength() throws Exception {
+ assertThat(new JcrProperty(node, executionContext, name, "value").getLength(), is(5L));
+ Object obj = new Object();
+ assertThat(new JcrProperty(node, executionContext, name, obj).getLength(), is((long)obj.toString().length()));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLengths() throws Exception {
+ new JcrProperty(node, executionContext, name, "value").getLengths();
+ }
+
+ @Test
+ public void shouldProvideDepth() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, true);
+ stub(node.getDepth()).toReturn(0);
+ assertThat(prop.getDepth(), is(1));
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -52,7 +52,17 @@
root.setProperties(properties);
}
+ @Test( expected = ItemNotFoundException.class )
+ public void shouldNotAllowAncestorDepthGreaterThanNodeDepth() throws Exception {
+ root.getAncestor(1);
+ }
+
@Test
+ public void shouldHaveZeroDepth() {
+ assertThat(root.getDepth(), is(0));
+ }
+
+ @Test
public void shouldHaveEmptyName() {
String name = root.getName();
assertThat(name, notNullValue());
@@ -63,4 +73,9 @@
public void shouldHaveNoParent() throws Exception {
root.getParent();
}
+
+ @Test
+ public void shouldProvidePath() {
+ assertThat(root.getPath(), is("/"));
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-08-26 21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-08-26 21:12:04 UTC (rev 474)
@@ -32,6 +32,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.UUID;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.Property;
@@ -84,7 +85,7 @@
private Session session;
@Mock
- private Map<String, WeakReference<Node>> uuid2NodeMap;
+ private Map<UUID, WeakReference<Node>> nodesByUuid;
@Before
public void before() throws Exception {
@@ -101,22 +102,22 @@
@Test( expected = AssertionError.class )
public void shouldNotAllowNoRepository() throws Exception {
- new JcrSession(null, executionContext, WORKSPACE_NAME, connection, uuid2NodeMap);
+ new JcrSession(null, executionContext, WORKSPACE_NAME, connection, nodesByUuid);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoExecutionContext() throws Exception {
- new JcrSession(repository, null, WORKSPACE_NAME, connection, uuid2NodeMap);
+ new JcrSession(repository, null, WORKSPACE_NAME, connection, nodesByUuid);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoWorkspaceName() throws Exception {
- new JcrSession(repository, executionContext, null, connection, uuid2NodeMap);
+ new JcrSession(repository, executionContext, null, connection, nodesByUuid);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoConnection() throws Exception {
- new JcrSession(repository, executionContext, WORKSPACE_NAME, null, uuid2NodeMap);
+ new JcrSession(repository, executionContext, WORKSPACE_NAME, null, nodesByUuid);
}
@Test( expected = AssertionError.class )
@@ -172,7 +173,7 @@
stub(executionContext.getSubject()).toReturn(subject);
stub(executionContext.getLoginContext()).toReturn(Mockito.mock(LoginContext.class));
Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME, Mockito.mock(RepositoryConnection.class),
- uuid2NodeMap);
+ nodesByUuid);
try {
assertThat(session.getUserID(), is("name"));
} finally {
@@ -182,15 +183,15 @@
@Test
public void shouldProvideRootNode() throws Exception {
- Map<String, WeakReference<Node>> uuid2NodeMap = new HashMap<String, WeakReference<Node>>();
+ Map<UUID, WeakReference<Node>> nodesByUuid = new HashMap<UUID, WeakReference<Node>>();
Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME,
- connectionFactory.createConnection(WORKSPACE_NAME), uuid2NodeMap);
- assertThat(uuid2NodeMap.isEmpty(), is(true));
+ connectionFactory.createConnection(WORKSPACE_NAME), nodesByUuid);
+ assertThat(nodesByUuid.isEmpty(), is(true));
Node root = session.getRootNode();
assertThat(root, notNullValue());
- String uuid = root.getUUID();
+ UUID uuid = ((JcrRootNode)root).getInternalUuid();
assertThat(uuid, notNullValue());
- WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+ WeakReference<Node> ref = nodesByUuid.get(uuid);
assertThat(ref, notNullValue());
assertThat(ref.get(), is(root));
}
15 years, 9 months
DNA SVN: r473 - trunk/dna-integration-tests/src/test/java/org/jboss/dna/tests/integration/jackrabbit.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-26 17:10:10 -0400 (Tue, 26 Aug 2008)
New Revision: 473
Modified:
trunk/dna-integration-tests/src/test/java/org/jboss/dna/tests/integration/jackrabbit/JackrabbitInMemoryTest.java
Log:
Added some tests to verify the inner workings of JackRabbit, which gives us the necessary information to maximize our JCR implementation's compatibility with JackRabbit.
Modified: trunk/dna-integration-tests/src/test/java/org/jboss/dna/tests/integration/jackrabbit/JackrabbitInMemoryTest.java
===================================================================
--- trunk/dna-integration-tests/src/test/java/org/jboss/dna/tests/integration/jackrabbit/JackrabbitInMemoryTest.java 2008-08-26 20:03:36 UTC (rev 472)
+++ trunk/dna-integration-tests/src/test/java/org/jboss/dna/tests/integration/jackrabbit/JackrabbitInMemoryTest.java 2008-08-26 21:10:10 UTC (rev 473)
@@ -21,7 +21,10 @@
*/
package org.jboss.dna.tests.integration.jackrabbit;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
@@ -157,4 +160,25 @@
this.session.exportDocumentView("/jcr:system", System.out, true, false);
}
+ @Test
+ public void shouldNotHaveNamePropertyForNodes() throws Exception {
+ Node node = session.getRootNode().addNode("test");
+ assertThat(node, notNullValue());
+ assertThat(node.hasProperty("jcr:name"), is(false));
+ }
+
+ @Test
+ public void shouldNotHaveUuidPropertyForNonReferenceableNodes() throws Exception {
+ Node node = session.getRootNode().addNode("test");
+ assertThat(node, notNullValue());
+ assertThat(node.hasProperty("jcr:uuid"), is(false));
+ }
+
+ @Test
+ public void shouldHaveUuidPropertyForReferenceableNodes() throws Exception {
+ Node node = session.getRootNode().addNode("test");
+ node.addMixin("mix:referenceable");
+ assertThat(node, notNullValue());
+ assertThat(node.hasProperty("jcr:uuid"), is(true));
+ }
}
15 years, 9 months
DNA SVN: r472 - in trunk/extensions/dna-connector-federation/src: main/java/org/jboss/dna/connector/federation/merge and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-26 16:03:36 -0400 (Tue, 26 Aug 2008)
New Revision: 472
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java
Log:
DNA-115 Create federation service
Chagned a bean property on the FederatedRepository so that it's a little easier to understand and configure.
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-26 19:53:53 UTC (rev 471)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-26 20:03:36 UTC (rev 472)
@@ -47,7 +47,6 @@
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.connector.federation.executor.FederatingCommandExecutor;
import org.jboss.dna.connector.federation.executor.SingleProjectionCommandExecutor;
import org.jboss.dna.spi.ExecutionContext;
@@ -90,29 +89,32 @@
*/
public static final int DEFAULT_RETRY_LIMIT = 0;
- public static final String[] DEFAULT_CONFIGURATION_SOURCE_PROJECTION_RULES = {"/dna:system => /"};
+ public static final String DEFAULT_CONFIGURATION_SOURCE_PATH = "/";
protected static final String REPOSITORY_NAME = "repositoryName";
protected static final String SOURCE_NAME = "sourceName";
protected static final String USERNAME = "username";
protected static final String PASSWORD = "password";
protected static final String CONFIGURATION_SOURCE_NAME = "configurationSourceName";
- protected static final String CONFIGURATION_SOURCE_PROJECTION_RULES = "configurationSourceProjectionRules";
+ protected static final String CONFIGURATION_SOURCE_PATH = "configurationSourcePath";
protected static final String REPOSITORY_CONNECTION_FACTORY_JNDI_NAME = "repositoryConnectionFactoryJndiName";
protected static final String EXECUTION_CONTEXT_FACTORY_JNDI_NAME = "executionContextFacotryJndiName";
protected static final String REPOSITORY_JNDI_NAME = "repositoryJndiName";
protected static final String SECURITY_DOMAIN = "securityDomain";
protected static final String RETRY_LIMIT = "retryLimit";
- protected static final String PROJECTION_RULES_CONFIG_PROPERTY_NAME = "dna:projectionRules";
- protected static final String CACHE_POLICY_TIME_TO_LIVE_CONFIG_PROPERTY_NAME = "dna:timeToLive";
+ public static final String PATH_TO_CONFIGURATION_INFORMATION = "/dna:system/dna:federation";
+ public static final String DNA_CACHE_SEGMENT = "dna:cache";
+ public static final String DNA_PROJECTIONS_SEGMENT = "dna:projections";
+ public static final String PROJECTION_RULES_CONFIG_PROPERTY_NAME = "dna:projectionRules";
+ public static final String CACHE_POLICY_TIME_TO_LIVE_CONFIG_PROPERTY_NAME = "dna:timeToLive";
private String repositoryName;
private String sourceName;
private String username;
private String password;
private String configurationSourceName;
- private String[] configurationSourceProjectionRules = DEFAULT_CONFIGURATION_SOURCE_PROJECTION_RULES;
+ private String configurationSourcePath = DEFAULT_CONFIGURATION_SOURCE_PATH;
private String repositoryConnectionFactoryJndiName;
private String executionContextFactoryJndiName;
private String securityDomain;
@@ -157,7 +159,7 @@
* @param sourceName the name of this repository source
* @see #setConfigurationSourceName(String)
* @see #setRepositoryConnectionFactoryJndiName(String)
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
@@ -254,7 +256,7 @@
* the federated repository instance is to be found in JNDI
* @see #getConfigurationSourceName()
* @see #setRepositoryConnectionFactoryJndiName(String)
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
@@ -270,31 +272,32 @@
/**
* Get the projection rule definitions used for the {@link #getConfigurationSourceName() configuration source}. The
- * {@link #DEFAULT_CONFIGURATION_SOURCE_PROJECTION_RULES default projection rules} map the root of the configuration source
- * into the <code>/dna:system</code> branch of the repository.
+ * {@link #DEFAULT_CONFIGURATION_SOURCE_PATH default path} is mapped into the <code>/dna:system</code> branch of the
+ * repository.
* <p>
* This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
* </p>
*
* @return the string array of projection rules, or null if the projection rules haven't yet been set or if the federated
* repository instance is to be found in JNDI
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
*/
- public String[] getConfigurationSourceProjectionRules() {
- return configurationSourceProjectionRules;
+ public String getConfigurationSourcePath() {
+ return configurationSourcePath;
}
/**
* Get the projection rule definitions used for the {@link #getConfigurationSourceName() configuration source}. The
- * {@link #DEFAULT_CONFIGURATION_SOURCE_PROJECTION_RULES default projection rules} map the root of the configuration source
- * into the <code>/dna:system</code> branch of the repository.
+ * {@link #DEFAULT_CONFIGURATION_SOURCE_PATH default path} is mapped into the <code>/dna:system</code> branch of the
+ * repository.
* <p>
* This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
* </p>
*
- * @param projectionRules the string array of projection rules, or null if the projection rules haven't yet been set or if the
- * federated repository instance is to be found in JNDI
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @param pathInSourceToConfigurationRoot the path within the configuration source to the node that should be the root of the
+ * configuration information, or null if the path hasn't yet been set or if the federated repository instance is to be
+ * found in JNDI
+ * @see #setConfigurationSourcePath(String)
* @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setConfigurationSourceName(String)
* @see #setPassword(String)
@@ -303,15 +306,10 @@
* @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
- public void setConfigurationSourceProjectionRules( String[] projectionRules ) {
- if (projectionRules != null) {
- List<String> rules = new LinkedList<String>();
- for (String rule : projectionRules) {
- if (rule != null && rule.trim().length() != 0) rules.add(rule);
- }
- projectionRules = rules.toArray(new String[rules.size()]);
- }
- this.configurationSourceProjectionRules = projectionRules != null ? projectionRules : DEFAULT_CONFIGURATION_SOURCE_PROJECTION_RULES;
+ public void setConfigurationSourcePath( String pathInSourceToConfigurationRoot ) {
+ if (this.configurationSourcePath == pathInSourceToConfigurationRoot || this.configurationSourcePath != null
+ && this.configurationSourcePath.equals(pathInSourceToConfigurationRoot)) return;
+ this.configurationSourcePath = pathInSourceToConfigurationRoot != null ? pathInSourceToConfigurationRoot : DEFAULT_CONFIGURATION_SOURCE_PATH;
}
/**
@@ -340,7 +338,7 @@
* repository instance is to be found in JNDI
* @see #getExecutionContextFactoryJndiName()
* @see #setConfigurationSourceName(String)
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
* @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setPassword(String)
* @see #setUsername(String)
@@ -381,7 +379,7 @@
* repository instance is to be found in JNDI
* @see #getRepositoryConnectionFactoryJndiName()
* @see #setConfigurationSourceName(String)
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
@@ -440,7 +438,7 @@
* @throws IllegalArgumentException if the repository name is null, empty or blank
* @see #getRepositoryName()
* @see #setConfigurationSourceName(String)
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryConnectionFactoryJndiName(String)
@@ -477,7 +475,7 @@
* @see #getUsername()
* @see #setPassword(String)
* @see #setConfigurationSourceName(String)
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setRepositoryName(String)
* @see #setRepositoryConnectionFactoryJndiName(String)
@@ -512,7 +510,7 @@
* @param password the password, or null if no password have been set or are not to be used
* @see #getPassword()
* @see #setConfigurationSourceName(String)
- * @see #setConfigurationSourceProjectionRules(String[])
+ * @see #setConfigurationSourcePath(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
* @see #setRepositoryConnectionFactoryJndiName(String)
@@ -735,7 +733,8 @@
// Create the configuration projection ...
ProjectionParser projectionParser = ProjectionParser.getInstance();
- Projection.Rule[] rules = projectionParser.rulesFromStrings(context, this.getConfigurationSourceProjectionRules());
+ String ruleStr = "/dna:system => " + this.getConfigurationSourcePath();
+ Projection.Rule[] rules = projectionParser.rulesFromStrings(context, ruleStr);
Projection configurationProjection = new Projection(this.getConfigurationSourceName(), rules);
// Create a federating command executor to execute the commands and merge the results into a single set of
@@ -760,7 +759,7 @@
// The configuration projection (via "executor") will convert this path into a path that exists in the configuration
// repository
- Path configNode = pathFactory.create("/dna:system/dna:federation");
+ Path configNode = pathFactory.create(PATH_TO_CONFIGURATION_INFORMATION);
try {
// Get the repository node ...
@@ -770,8 +769,18 @@
throw new FederationException(FederationI18n.federatedRepositoryCannotBeFound.text(repositoryName));
}
+ // Get the first child node of the "dna:cache" node, since this represents the source used as the cache ...
+ Path cacheNode = pathFactory.create(configNode, nameFactory.create(DNA_CACHE_SEGMENT));
+ BasicGetChildrenCommand getCacheSource = new BasicGetChildrenCommand(cacheNode);
+
+ executor.execute(getCacheSource);
+ if (getCacheSource.hasError() || getCacheSource.getChildren().size() < 1) {
+ I18n msg = FederationI18n.requiredNodeDoesNotExistRelativeToNode;
+ throw new FederationException(msg.text(DNA_CACHE_SEGMENT, configNode));
+ }
+
// Add a command to get the projection defining the cache ...
- Path pathToCacheRegion = pathFactory.create(configNode, nameFactory.create("dna:cache"));
+ Path pathToCacheRegion = pathFactory.create(cacheNode, getCacheSource.getChildren().get(0));
BasicGetNodeCommand getCacheRegion = new BasicGetNodeCommand(pathToCacheRegion);
executor.execute(getCacheRegion);
Projection cacheProjection = createProjection(context,
@@ -782,17 +791,17 @@
if (getCacheRegion.hasError()) {
I18n msg = FederationI18n.requiredNodeDoesNotExistRelativeToNode;
- throw new FederationException(msg.text("dna:cache", configNode));
+ throw new FederationException(msg.text(DNA_CACHE_SEGMENT, configNode));
}
// Get the source projections for the repository ...
- Path projectionsNode = pathFactory.create(configNode, nameFactory.create("dna:projections"));
+ Path projectionsNode = pathFactory.create(configNode, nameFactory.create(DNA_PROJECTIONS_SEGMENT));
BasicGetChildrenCommand getProjections = new BasicGetChildrenCommand(projectionsNode);
executor.execute(getProjections);
if (getProjections.hasError()) {
I18n msg = FederationI18n.requiredNodeDoesNotExistRelativeToNode;
- throw new FederationException(msg.text("dna:projections", configNode));
+ throw new FederationException(msg.text(DNA_PROJECTIONS_SEGMENT, configNode));
}
// Build the commands to get each of the projections (children of the "dna:projections" node) ...
@@ -897,17 +906,8 @@
if (getConfigurationSourceName() != null) {
ref.add(new StringRefAddr(CONFIGURATION_SOURCE_NAME, getConfigurationSourceName()));
}
- if (getConfigurationSourceProjectionRules() != null) {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (String rule : getConfigurationSourceProjectionRules()) {
- if (!first) {
- sb.append("\n");
- first = false;
- }
- sb.append(rule);
- }
- ref.add(new StringRefAddr(CONFIGURATION_SOURCE_PROJECTION_RULES, sb.toString()));
+ if (getConfigurationSourcePath() != null) {
+ ref.add(new StringRefAddr(CONFIGURATION_SOURCE_PATH, getConfigurationSourcePath()));
}
if (getRepositoryConnectionFactoryJndiName() != null) {
ref.add(new StringRefAddr(REPOSITORY_CONNECTION_FACTORY_JNDI_NAME, getRepositoryConnectionFactoryJndiName()));
@@ -949,7 +949,7 @@
String username = values.get(FederatedRepositorySource.USERNAME);
String password = values.get(FederatedRepositorySource.PASSWORD);
String configurationSourceName = values.get(FederatedRepositorySource.CONFIGURATION_SOURCE_NAME);
- String projectionRules = values.get(FederatedRepositorySource.CONFIGURATION_SOURCE_PROJECTION_RULES);
+ String configurationSourcePath = values.get(FederatedRepositorySource.CONFIGURATION_SOURCE_PATH);
String connectionFactoriesJndiName = values.get(FederatedRepositorySource.REPOSITORY_CONNECTION_FACTORY_JNDI_NAME);
String environmentJndiName = values.get(FederatedRepositorySource.EXECUTION_CONTEXT_FACTORY_JNDI_NAME);
String repositoryJndiName = values.get(FederatedRepositorySource.REPOSITORY_JNDI_NAME);
@@ -963,10 +963,7 @@
if (username != null) source.setUsername(username);
if (password != null) source.setPassword(password);
if (configurationSourceName != null) source.setConfigurationSourceName(configurationSourceName);
- if (projectionRules != null) {
- List<String> rules = StringUtil.splitLines(projectionRules);
- source.setConfigurationSourceProjectionRules(rules.toArray(new String[rules.size()]));
- }
+ if (configurationSourcePath != null) source.setConfigurationSourcePath(configurationSourcePath);
if (connectionFactoriesJndiName != null) source.setRepositoryConnectionFactoryJndiName(connectionFactoriesJndiName);
if (environmentJndiName != null) source.setExecutionContextFactoryJndiName(environmentJndiName);
if (repositoryJndiName != null) source.setRepositoryJndiName(repositoryJndiName);
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-08-26 19:53:53 UTC (rev 471)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-08-26 20:03:36 UTC (rev 472)
@@ -28,10 +28,10 @@
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.UuidFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
import org.jboss.dna.spi.graph.Path.Segment;
/**
@@ -100,7 +100,7 @@
if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
try {
uuid = uuidFactory.create(property.getValues().next());
- } catch (IoException e) {
+ } catch (ValueFormatException e) {
// Ignore conversion exceptions
}
}
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-26 19:53:53 UTC (rev 471)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-26 20:03:36 UTC (rev 472)
@@ -104,21 +104,24 @@
source.setUsername(username);
source.setPassword(credentials);
source.setConfigurationSourceName(configurationSourceName);
- source.setConfigurationSourceProjectionRules(new String[] {"/dna:system/dna:federation/ => /dna:repositories/Test Repository"});
+ source.setConfigurationSourcePath("/dna:repositories/Test Repository");
source.setRepositoryConnectionFactoryJndiName(repositoryConnectionFactoryJndiName);
source.setExecutionContextFactoryJndiName(executionContextFactoryJndiName);
source.setContext(jndiContext);
source.setSecurityDomain(securityDomain);
configRepository = SimpleRepository.get("Configuration Repository");
- configRepository.setProperty(context, "/dna:repositories/Test Repository", "dna:timeToExpire", "100000");
- configRepository.setProperty(context, "/dna:repositories/Test Repository", "dna:timeToCache", "100000");
- configRepository.setProperty(context, "/dna:repositories/Test Repository/dna:cache", "dna:projectionRules", "/ => /");
+ configRepository.setProperty(context, "/dna:repositories/Test Repository/dna:federation/", "dna:timeToExpire", "100000");
+ configRepository.setProperty(context, "/dna:repositories/Test Repository/dna:federation/", "dna:timeToCache", "100000");
configRepository.setProperty(context,
- "/dna:repositories/Test Repository/dna:projections/source 1/",
+ "/dna:repositories/Test Repository/dna:federation/dna:cache/cache source",
"dna:projectionRules",
+ "/ => /");
+ configRepository.setProperty(context,
+ "/dna:repositories/Test Repository/dna:federation/dna:projections/source 1/",
+ "dna:projectionRules",
"/ => /s1");
configRepository.setProperty(context,
- "/dna:repositories/Test Repository/dna:projections/source 2/",
+ "/dna:repositories/Test Repository/dna:federation/dna:projections/source 2/",
"dna:projectionRules",
"/ => /s1");
configRepositorySource = new SimpleRepositorySource();
@@ -268,7 +271,7 @@
source.setRetryLimit(retryLimit);
source.setName("Some source");
source.setConfigurationSourceName("config source");
- source.setConfigurationSourceProjectionRules(new String[] {"/dna:system => /a/b/c"});
+ source.setConfigurationSourcePath("/a/b/c");
source.setRepositoryConnectionFactoryJndiName("repository connection factory jndi name");
source.setRepositoryJndiName("repository jndi name");
source.setExecutionContextFactoryJndiName("env jndi name");
@@ -291,8 +294,7 @@
assertThat((String)refAttributes.remove(FederatedRepositorySource.RETRY_LIMIT), is(Integer.toString(retryLimit)));
assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_SOURCE_NAME),
is(source.getConfigurationSourceName()));
- assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_SOURCE_PROJECTION_RULES),
- is("/dna:system => /a/b/c"));
+ assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_SOURCE_PATH), is("/a/b/c"));
assertThat((String)refAttributes.remove(FederatedRepositorySource.REPOSITORY_CONNECTION_FACTORY_JNDI_NAME),
is(source.getRepositoryConnectionFactoryJndiName()));
assertThat((String)refAttributes.remove(FederatedRepositorySource.EXECUTION_CONTEXT_FACTORY_JNDI_NAME),
@@ -316,7 +318,7 @@
assertThat(recoveredSource.getRepositoryName(), is(source.getRepositoryName()));
assertThat(recoveredSource.getRetryLimit(), is(source.getRetryLimit()));
assertThat(recoveredSource.getConfigurationSourceName(), is(source.getConfigurationSourceName()));
- assertThat(recoveredSource.getConfigurationSourceProjectionRules(), is(source.getConfigurationSourceProjectionRules()));
+ assertThat(recoveredSource.getConfigurationSourcePath(), is(source.getConfigurationSourcePath()));
assertThat(recoveredSource.getRepositoryConnectionFactoryJndiName(), is(source.getRepositoryConnectionFactoryJndiName()));
assertThat(recoveredSource.getExecutionContextFactoryJndiName(), is(source.getExecutionContextFactoryJndiName()));
assertThat(recoveredSource.getRepositoryJndiName(), is(source.getRepositoryJndiName()));
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java 2008-08-26 19:53:53 UTC (rev 471)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java 2008-08-26 20:03:36 UTC (rev 472)
@@ -39,7 +39,6 @@
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -190,7 +189,6 @@
assertThat(node.getUuid(), is(originalUuid));
}
- @Ignore
@Test
public void shouldNotSetTheUuidOnTheNodeIfThereIsASingleValuedPropertyNamedUuidWithValueThatDoesNotConvertToUuidInstance() {
final UUID originalUuid = node.getUuid();
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java 2008-08-26 19:53:53 UTC (rev 471)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java 2008-08-26 20:03:36 UTC (rev 472)
@@ -44,7 +44,6 @@
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -190,12 +189,6 @@
assertThat(contributions.get(0).getChildren(), hasSegmentIterator("childA", "childB[1]", "childB[2]"));
}
- @Ignore
- @Test
- public void shouldCreateMergePlanInTheFederatedNode() {
- strategy.merge(node, contributions, context);
- }
-
protected Matcher<List<Path.Segment>> hasSegments( String... segment ) {
List<Path.Segment> segments = new ArrayList<Path.Segment>();
for (String seg : segment) {
15 years, 9 months
DNA SVN: r471 - trunk/docs/examples/gettingstarted/dna-example-java-sequencer.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-26 15:53:53 -0400 (Tue, 26 Aug 2008)
New Revision: 471
Modified:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/
Log:
Added svn:ignore to the project
Property changes on: trunk/docs/examples/gettingstarted/dna-example-java-sequencer
___________________________________________________________________
Name: svn:ignore
+ target
15 years, 9 months
DNA SVN: r470 - in trunk/extensions/dna-connector-federation/src: main/java/org/jboss/dna/connector/federation/merge and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-26 13:21:32 -0400 (Tue, 26 Aug 2008)
New Revision: 470
Added:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java
Removed:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Renamed the StandardMergeStrategy to SimpleMergeStrategy, and fully implemented and tested it to merge multiple contributions. This merge strategy may not be sufficient for many uses, but it works now and does merge properties. Note that while it does not merge any children, it does ensure that any same-name siblings (from all contributions) have the proper indexes.
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-26 09:33:40 UTC (rev 469)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-26 17:21:32 UTC (rev 470)
@@ -41,7 +41,7 @@
import org.jboss.dna.connector.federation.merge.MergePlan;
import org.jboss.dna.connector.federation.merge.MergeStrategy;
import org.jboss.dna.connector.federation.merge.OneContributionMergeStrategy;
-import org.jboss.dna.connector.federation.merge.StandardMergeStrategy;
+import org.jboss.dna.connector.federation.merge.SimpleMergeStrategy;
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
@@ -155,7 +155,7 @@
if (this.sourceProjections.size() == 1 && this.sourceProjections.get(0).isSimple()) {
this.mergingStrategy = new OneContributionMergeStrategy();
} else {
- this.mergingStrategy = new StandardMergeStrategy();
+ this.mergingStrategy = new SimpleMergeStrategy();
}
}
assert this.mergingStrategy != null;
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-08-26 09:33:40 UTC (rev 469)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-08-26 17:21:32 UTC (rev 470)
@@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.IoException;
@@ -34,11 +35,32 @@
import org.jboss.dna.spi.graph.Path.Segment;
/**
+ * A merge strategy that is optimized for merging when there is a single contribution.
+ *
* @author Randall Hauch
*/
+@ThreadSafe
public class OneContributionMergeStrategy implements MergeStrategy {
+ public static final boolean DEFAULT_REUSE_UUID_FROM_CONTRIBUTION = true;
+
+ private boolean useUuidFromContribution = DEFAULT_REUSE_UUID_FROM_CONTRIBUTION;
+
/**
+ * @return reuseUuidFromContribution
+ */
+ public boolean isContributionUuidUsedForFederatedNode() {
+ return useUuidFromContribution;
+ }
+
+ /**
+ * @param useUuidFromContribution Sets useUuidFromContribution to the specified value.
+ */
+ public void setContributionUuidUsedForFederatedNode( boolean useUuidFromContribution ) {
+ this.useUuidFromContribution = useUuidFromContribution;
+ }
+
+ /**
* {@inheritDoc}
* <p>
* This method only uses the one and only one non-null {@link Contribution} in the <code>contributions</code>.
@@ -51,10 +73,12 @@
List<Contribution> contributions,
ExecutionContext context ) {
assert federatedNode != null;
+ assert context != null;
assert contributions != null;
assert contributions.size() > 0;
Contribution contribution = contributions.get(0);
assert contribution != null;
+ final boolean findUuid = isContributionUuidUsedForFederatedNode();
// Copy the children ...
List<Segment> children = federatedNode.getChildren();
children.clear();
@@ -72,7 +96,7 @@
while (propertyIterator.hasNext()) {
Property property = propertyIterator.next();
properties.put(property.getName(), property);
- if (uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
+ if (findUuid && uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
try {
uuid = uuidFactory.create(property.getValues().next());
Copied: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java (from rev 460, trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java)
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java 2008-08-26 17:21:32 UTC (rev 470)
@@ -0,0 +1,275 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.federation.merge;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.IoException;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.PropertyFactory;
+import org.jboss.dna.spi.graph.UuidFactory;
+import org.jboss.dna.spi.graph.ValueComparators;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * This merge strategy simply merges all of the contributions' properties and combines the children according to the order of the
+ * contributions. No children are merged, and all properties are used (except if they are deemed to be duplicates of the property
+ * in other contributions).
+ *
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class SimpleMergeStrategy implements MergeStrategy {
+
+ private boolean removeDuplicateProperties = true;
+
+ /**
+ * @return removeDuplicateProperties
+ */
+ public boolean isRemoveDuplicateProperties() {
+ return removeDuplicateProperties;
+ }
+
+ /**
+ * @param removeDuplicateProperties Sets removeDuplicateProperties to the specified value.
+ */
+ public void setRemoveDuplicateProperties( boolean removeDuplicateProperties ) {
+ this.removeDuplicateProperties = removeDuplicateProperties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.federation.merge.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
+ * java.util.List, org.jboss.dna.spi.ExecutionContext)
+ */
+ public void merge( FederatedNode federatedNode,
+ List<Contribution> contributions,
+ ExecutionContext context ) {
+ assert federatedNode != null;
+ assert context != null;
+ assert contributions != null;
+ assert contributions.size() > 0;
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ // Prepare the federated node ...
+ List<Segment> children = federatedNode.getChildren();
+ children.clear();
+ Map<Name, Integer> childNames = new HashMap<Name, Integer>();
+ Map<Name, Property> properties = federatedNode.getPropertiesByName();
+ properties.clear();
+ UUID uuid = null;
+ UuidFactory uuidFactory = null;
+ final boolean removeDuplicateProperties = isRemoveDuplicateProperties();
+ // Iterate over the set of contributions (in order) ...
+ for (Contribution contribution : contributions) {
+ // Copy the children ...
+ int childListIndex = 0;
+ Iterator<Segment> childIterator = contribution.getChildren();
+ while (childIterator.hasNext()) {
+ Segment child = childIterator.next();
+ int index = Path.NO_INDEX;
+ Integer previous = childNames.put(child.getName(), 1);
+ if (previous != null) {
+ int previousValue = previous.intValue();
+ if (previousValue == 1) {
+ // If the previous value was 1, then go back and look for the child that has no index but that should ...
+ // Walk backwards, just in case the previous same-name-sibling is closer to the end
+ for (int i = children.size() - 1; i >= 0; --i) {
+ Path.Segment childSegment = children.get(i);
+ if (childSegment.getName().equals(child.getName())) {
+ children.set(i, pathFactory.createSegment(child.getName(), 1));
+ break;
+ }
+ }
+ }
+ // Add the previous value back in ...
+ childNames.put(child.getName(), ++previousValue);
+ index = previousValue;
+ }
+ children.add(pathFactory.createSegment(child.getName(), index));
+ ++childListIndex;
+ }
+
+ // Copy the properties ...
+ Iterator<Property> propertyIterator = contribution.getProperties();
+ while (propertyIterator.hasNext()) {
+ Property property = propertyIterator.next();
+ Property existing = properties.put(property.getName(), property);
+ if (existing != null) {
+ // There's already an existing property, so we need to merge them ...
+ Property merged = merge(existing, property, context.getPropertyFactory(), removeDuplicateProperties);
+ properties.put(property.getName(), merged);
+ }
+
+ if (uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
+ if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
+ try {
+ uuid = uuidFactory.create(property.getValues().next());
+ } catch (IoException e) {
+ // Ignore conversion exceptions
+ assert uuid == null;
+ }
+ }
+ }
+ }
+ // If we found a single "uuid" property whose value is a valid UUID ..
+ if (uuid != null) {
+ // then set the UUID on the federated node ...
+ federatedNode.setUuid(uuid);
+ }
+ // Assign the merge plan ...
+ MergePlan mergePlan = MergePlan.create(contributions);
+ federatedNode.setMergePlan(mergePlan);
+ }
+
+ /**
+ * Merge the values from the two properties with the same name, returning a new property with the newly merged values.
+ * <p>
+ * The current algorithm merges the values by concatenating the values from <code>property1</code> and <code>property2</code>,
+ * and if <code>removeDuplicates</code> is true any values in <code>property2</code> that are identical to values found in
+ * <code>property1</code> are skipped.
+ * </p>
+ *
+ * @param property1 the first property; may not be null, and must have the same {@link Property#getName() name} as
+ * <code>property2</code>
+ * @param property2 the second property; may not be null, and must have the same {@link Property#getName() name} as
+ * <code>property1</code>
+ * @param factory the property factory, used to create the result
+ * @param removeDuplicates true if this method removes any values in the second property that duplicate values found in the
+ * first property.
+ * @return the property that contains the same {@link Property#getName() name} as the input properties, but with values that
+ * are merged from both of the input properties
+ */
+ protected Property merge( Property property1,
+ Property property2,
+ PropertyFactory factory,
+ boolean removeDuplicates ) {
+ assert property1 != null;
+ assert property2 != null;
+ assert property1.getName().equals(property2.getName());
+ if (property1.isEmpty()) return property2;
+ if (property2.isEmpty()) return property1;
+
+ // If they are both single-valued, then we can use a more efficient algorithm ...
+ if (property1.isSingle() && property2.isSingle()) {
+ Object value1 = property1.getValues().next();
+ Object value2 = property2.getValues().next();
+ if (removeDuplicates && ValueComparators.OBJECT_COMPARATOR.compare(value1, value2) == 0) return property1;
+ return factory.create(property1.getName(), new Object[] {value1, value2});
+ }
+
+ // One or both properties are multi-valued, so use an algorithm that works with in all cases ...
+ if (!removeDuplicates) {
+ Iterator<?> valueIterator = new DualIterator(property1.getValues(), property2.getValues());
+ return factory.create(property1.getName(), valueIterator);
+ }
+
+ // First copy all the values from property 1 ...
+ Object[] values = new Object[property1.size() + property2.size()];
+ int index = 0;
+ for (Object property1Value : property1) {
+ values[index++] = property1Value;
+ }
+ assert index == property1.size();
+ // Now add any values of property2 that don't match a value in property1 ...
+ for (Object property2Value : property2) {
+ // Brute force, go through the values of property1 and compare ...
+ boolean matched = false;
+ for (Object property1Value : property1) {
+ if (ValueComparators.OBJECT_COMPARATOR.compare(property1Value, property2Value) == 0) {
+ // The values are the same ...
+ matched = true;
+ break;
+ }
+ }
+ if (!matched) values[index++] = property2Value;
+ }
+ if (index != values.length) {
+ Object[] newValues = new Object[index];
+ System.arraycopy(values, 0, newValues, 0, index);
+ values = newValues;
+ }
+ return factory.create(property1.getName(), values);
+ }
+
+ protected static class DualIterator implements Iterator<Object> {
+
+ private final Iterator<?>[] iterators;
+ private Iterator<?> current;
+ private int index = 0;
+
+ protected DualIterator( Iterator<?>... iterators ) {
+ assert iterators != null;
+ assert iterators.length > 0;
+ this.iterators = iterators;
+ this.current = this.iterators[0];
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.current != null) return this.current.hasNext();
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ while (this.current != null) {
+ if (this.current.hasNext()) return this.current.next();
+ // Get the next iterator ...
+ if (++this.index < iterators.length) {
+ this.current = this.iterators[this.index];
+ } else {
+ this.current = null;
+ }
+ }
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-26 09:33:40 UTC (rev 469)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-26 17:21:32 UTC (rev 470)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.connector.federation.merge;
-
-import java.util.List;
-import org.jboss.dna.connector.federation.contribution.Contribution;
-import org.jboss.dna.spi.ExecutionContext;
-
-/**
- * @author Randall Hauch
- */
-public class StandardMergeStrategy implements MergeStrategy {
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.connector.federation.merge.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
- * java.util.List, org.jboss.dna.spi.ExecutionContext)
- */
- public void merge( FederatedNode federatedNode,
- List<Contribution> contributions,
- ExecutionContext context ) {
-
- // Children whose identity properties are the same will be considered to be the same node ...
-
- // Assemble the children ...
-
- // Assemble the properties (and look for UUID property) ...
-
- // Create a merge plan with the contributions ...
- MergePlan plan = MergePlan.create(contributions);
- federatedNode.setMergePlan(plan);
- }
-}
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java 2008-08-26 09:33:40 UTC (rev 469)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java 2008-08-26 17:21:32 UTC (rev 470)
@@ -82,7 +82,7 @@
}
@Test
- public void shouldMegeTheChildrenFromTheFirstContribution() {
+ public void shouldMergeTheChildrenFromTheFirstContribution() {
stub(contribution.getChildren()).toReturn(children.iterator());
stub(contribution.getProperties()).toReturn(properties.values().iterator());
strategy.merge(node, contributions, context);
@@ -90,7 +90,7 @@
}
@Test
- public void shouldMegeThePropertiesFromTheFirstContribution() {
+ public void shouldMergeThePropertiesFromTheFirstContribution() {
stub(contribution.getChildren()).toReturn(children.iterator());
stub(contribution.getProperties()).toReturn(properties.values().iterator());
stub(contribution.getProperties()).toReturn(properties.values().iterator());
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java 2008-08-26 17:21:32 UTC (rev 470)
@@ -0,0 +1,304 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.federation.merge;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.hamcrest.Matcher;
+import org.jboss.dna.common.collection.IsIteratorContaining;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * @author Randall Hauch
+ */
+public class SimpleMergeStrategyTest {
+
+ private SimpleMergeStrategy strategy;
+ private List<Contribution> contributions;
+ private ExecutionContext context;
+ private FederatedNode node;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ Path path = mock(Path.class);
+ node = new FederatedNode(path, UUID.randomUUID());
+ strategy = new SimpleMergeStrategy();
+ contributions = new LinkedList<Contribution>();
+ context = new BasicExecutionContext();
+ context.getNamespaceRegistry().register("dna", "http://www.jboss.org/dna/something");
+ context.getNamespaceRegistry().register("jcr", "http://www.jcr.org");
+ }
+
+ @Test
+ public void shouldAddChildrenFromOneContribution() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), hasSegments("childA", "childB[1]", "childB[2]"));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromOneContribution() {
+ addContribution("source1").setProperty("p1", "p1 value");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(1));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ }
+
+ @Test
+ public void shouldAddChildrenFromMultipleContributionsInOrderAndShouldNotChangeSameNameSiblingIndexesWhenChildrenDoNotShareNamesWithChildrenFromDifferentContributions() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
+ addContribution("source2").addChildren("childX", "childY[1]", "childY[2]");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), hasSegments("childA", "childB[1]", "childB[2]", "childX", "childY[1]", "childY[2]"));
+ }
+
+ @Test
+ public void shouldAddChildrenFromMultipleContributionsInOrderAndShouldChangeSameNameSiblingIndexesWhenChildrenDoShareNamesWithChildrenFromDifferentContributions() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
+ addContribution("source2").addChildren("childX", "childB", "childY");
+ addContribution("source3").addChildren("childX", "childB");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), hasSegments("childA",
+ "childB[1]",
+ "childB[2]",
+ "childX[1]",
+ "childB[3]",
+ "childY",
+ "childX[2]",
+ "childB[4]"));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsAndRemoveNoValuesWhenNoContributionsContainSameProperty() {
+ addContribution("source1").setProperty("p1", "p1 value");
+ addContribution("source2").setProperty("p2", "p2 value");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(2));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsAndRemoveDuplicateValuesWhenContributionsContainSameProperty() {
+ addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
+ addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", "3", "4");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(3));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
+ assertThat(node.getPropertiesByName().get(name("p12")), is(property("p12", "1", "2", "3", "4")));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsAndMaintainAllValuesForEveryProperty() {
+ addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
+ addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", "3", "4");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(3));
+ for (Contribution contribution : contributions) {
+ Iterator<Property> iter = contribution.getProperties();
+ while (iter.hasNext()) {
+ Property contributionProperty = iter.next();
+ Property mergedProperty = node.getPropertiesByName().get(contributionProperty.getName());
+ assertThat(mergedProperty, is(notNullValue()));
+ // Make sure that the merged property has each value ...
+ for (Object contributedValue : contributionProperty.getValuesAsArray()) {
+ boolean foundValue = false;
+ for (Object mergedValue : mergedProperty.getValuesAsArray()) {
+ if (mergedValue.equals(contributedValue)) {
+ foundValue = true;
+ break;
+ }
+ }
+ assertThat(foundValue, is(true));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsWhenPropertyValuesAreOfDifferentPropertyTypes() {
+ addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
+ addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", 3, 4);
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(3));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
+ assertThat(node.getPropertiesByName().get(name("p12")), is(property("p12", "1", "2", "3", 4)));
+ }
+
+ @Test
+ public void shouldCreateMergePlanWhenMergingContributions() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]").setProperty("p1", "p1 value");
+ addContribution("source2").addChildren("childX", "childB", "childY").setProperty("p2", "p2 value");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getMergePlan(), is(notNullValue()));
+ assertThat(node.getMergePlan().getContributionCount(), is(2));
+ assertThat(node.getMergePlan().getContributionFrom("source1"), is(sameInstance(contributions.get(0))));
+ assertThat(node.getMergePlan().getContributionFrom("source2"), is(sameInstance(contributions.get(1))));
+ }
+
+ @Test
+ public void shouldCorrectlyBuildMockUsingContributionBuilder() {
+ assertThat(contributions.size(), is(0));
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]").setProperty("p1", "p1 value");
+ assertThat(contributions.size(), is(1));
+ assertThat(contributions.get(0).getChildren(), hasSegmentIterator("childA", "childB[1]", "childB[2]"));
+ }
+
+ @Ignore
+ @Test
+ public void shouldCreateMergePlanInTheFederatedNode() {
+ strategy.merge(node, contributions, context);
+ }
+
+ protected Matcher<List<Path.Segment>> hasSegments( String... segment ) {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ for (String seg : segment) {
+ segments.add(context.getValueFactories().getPathFactory().createSegment(seg));
+ }
+ return equalTo(segments);
+ }
+
+ protected Matcher<Iterator<Path.Segment>> hasSegmentIterator( String... segment ) {
+ Path.Segment[] segments = new Path.Segment[segment.length];
+ int index = 0;
+ for (String seg : segment) {
+ segments[index++] = context.getValueFactories().getPathFactory().createSegment(seg);
+ }
+ return IsIteratorContaining.hasItems(segments);
+ }
+
+ protected Name name( String name ) {
+ return context.getValueFactories().getNameFactory().create(name);
+ }
+
+ protected Property property( String name,
+ Object... values ) {
+ return context.getPropertyFactory().create(name(name), values);
+ }
+
+ protected ContributionBuilder addContribution( String sourceName ) {
+ ContributionBuilder builder = new ContributionBuilder(context, sourceName, contributions);
+ contributions.add(builder.getMock());
+ return builder;
+ }
+
+ protected class ContributionBuilder {
+ protected final Contribution mockContribution;
+ protected final ExecutionContext context;
+ protected final Map<Name, Property> properties = new HashMap<Name, Property>();
+ protected final List<Path.Segment> children = new ArrayList<Path.Segment>();
+
+ protected ContributionBuilder( ExecutionContext context,
+ String name,
+ List<Contribution> contributions ) {
+ this.context = context;
+ this.mockContribution = Mockito.mock(Contribution.class);
+ stub(mockContribution.getSourceName()).toReturn(name);
+ stub(mockContribution.getChildren()).toAnswer(new Answer<Iterator<Path.Segment>>() {
+ public Iterator<Path.Segment> answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.children.iterator();
+ }
+ });
+ stub(mockContribution.getChildrenCount()).toAnswer(new Answer<Integer>() {
+ public Integer answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.children.size();
+ }
+ });
+ stub(mockContribution.getProperties()).toAnswer(new Answer<Iterator<Property>>() {
+ public Iterator<Property> answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.properties.values().iterator();
+ }
+ });
+ stub(mockContribution.getPropertyCount()).toAnswer(new Answer<Integer>() {
+ public Integer answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.properties.size();
+ }
+ });
+ }
+
+ public Contribution getMock() {
+ return this.mockContribution;
+ }
+
+ public ContributionBuilder addChildren( String... segmentNamesForChildren ) {
+ for (String childSegmentName : segmentNamesForChildren) {
+ children.add(context.getValueFactories().getPathFactory().createSegment(childSegmentName));
+ }
+ return this;
+ }
+
+ public ContributionBuilder addChildren( Name... segmentNamesForChildren ) {
+ for (Name childSegmentName : segmentNamesForChildren) {
+ children.add(context.getValueFactories().getPathFactory().createSegment(childSegmentName));
+ }
+ return this;
+ }
+
+ public ContributionBuilder addChildren( Path.Segment... segmentNamesForChildren ) {
+ for (Path.Segment childSegmentName : segmentNamesForChildren) {
+ children.add(childSegmentName);
+ }
+ return this;
+ }
+
+ public ContributionBuilder setProperty( String name,
+ Object... values ) {
+ Name propertyName = context.getValueFactories().getNameFactory().create(name);
+ Property property = context.getPropertyFactory().create(propertyName, values);
+ stub(mockContribution.getProperty(propertyName)).toReturn(property);
+ if (values != null && values.length > 0) {
+ properties.put(propertyName, property);
+ } else {
+ properties.remove(propertyName);
+ }
+ return this;
+ }
+ }
+
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 9 months
DNA SVN: r469 - trunk/docs/examples/gettingstarted/dna-example-java-sequencer.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-26 05:33:40 -0400 (Tue, 26 Aug 2008)
New Revision: 469
Modified:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml
Log:
make a small pom change
Modified: trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml 2008-08-26 07:32:23 UTC (rev 468)
+++ trunk/docs/examples/gettingstarted/dna-example-java-sequencer/pom.xml 2008-08-26 09:33:40 UTC (rev 469)
@@ -14,7 +14,7 @@
<artifactId>dna-example-java-sequencer</artifactId>
<version>0.2-SNAPSHOT</version>
<packaging>jar</packaging>
- <name>Java Sequencer Example</name>
+ <name>JBoss DNA Java Sequencer Example</name>
<description>
Examples that show case how to use Java Sequencer with a JCR
repository.
15 years, 9 months