DNA SVN: r448 - trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-19 15:34:20 -0400 (Tue, 19 Aug 2008)
New Revision: 448
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
Log:
Corrected the order in which factories are selected given the PropertyType, and overrode some methods in the ObjectValueFactory to simply return the values rather than convert the values to strings (which is what the AbstractValueFactory methods did).
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java 2008-08-19 19:29:48 UTC (rev 447)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java 2008-08-19 19:34:20 UTC (rev 448)
@@ -68,8 +68,6 @@
return getLongFactory();
case NAME:
return getNameFactory();
- case OBJECT:
- return getObjectFactory();
case PATH:
return getPathFactory();
case REFERENCE:
@@ -80,6 +78,8 @@
return getUriFactory();
case UUID:
return getUuidFactory();
+ case OBJECT:
+ return getObjectFactory();
}
return getObjectFactory();
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-19 19:29:48 UTC (rev 447)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-19 19:34:20 UTC (rev 448)
@@ -176,7 +176,27 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.impl.AbstractValueFactory#create(java.lang.Object)
*/
+ @Override
+ public Object create( Object value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.impl.AbstractValueFactory#create(java.lang.Object[])
+ */
+ @Override
+ public Object[] create( Object[] values ) {
+ return values;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Object create( byte[] value ) {
return getBinaryValueFactory().create(value);
}
15 years, 10 months
DNA SVN: r447 - trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-19 15:29:48 -0400 (Tue, 19 Aug 2008)
New Revision: 447
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
Log:
Added a toString implementation.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java 2008-08-19 15:04:03 UTC (rev 446)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java 2008-08-19 19:29:48 UTC (rev 447)
@@ -23,6 +23,7 @@
import java.util.Iterator;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Property;
@@ -111,4 +112,22 @@
}
return false;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getName());
+ sb.append(" = ");
+ if (isSingle()) {
+ sb.append(StringUtil.readableString(getValues().next()));
+ } else {
+ sb.append(StringUtil.readableString(getValuesAsArray()));
+ }
+ return sb.toString();
+ }
}
15 years, 10 months
DNA SVN: r446 - in trunk/extensions/dna-connector-federation/src: test/java/org/jboss/dna/connector/federation/merge and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-19 11:04:03 -0400 (Tue, 19 Aug 2008)
New Revision: 446
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Added more unit tests for the FederatedNode class.
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java 2008-08-19 14:46:40 UTC (rev 445)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java 2008-08-19 15:04:03 UTC (rev 446)
@@ -34,11 +34,13 @@
*/
public class FederatedNode extends BasicGetNodeCommand implements CreateNodeCommand {
+ protected static final NodeConflictBehavior DEFAULT_CONFLICT_BEHAVIOR = NodeConflictBehavior.UPDATE;
+
private static final long serialVersionUID = 1L;
private final UUID uuid;
private MergePlan mergePlan;
- private NodeConflictBehavior nodeConflictBehavior = NodeConflictBehavior.UPDATE;
+ private NodeConflictBehavior nodeConflictBehavior = DEFAULT_CONFLICT_BEHAVIOR;
/**
* Create a federated node given the path and UUID.
@@ -136,10 +138,12 @@
}
/**
- * @param nodeConflictBehavior Sets nodeConflictBehavior to the specified value.
+ * Set the behavior when node conflicts arise.
+ *
+ * @param nodeConflictBehavior the conflict behavior, or null if the default should be used
*/
- public void setNodeConflictBehavior( NodeConflictBehavior nodeConflictBehavior ) {
- this.nodeConflictBehavior = nodeConflictBehavior;
+ public void setConflictBehavior( NodeConflictBehavior nodeConflictBehavior ) {
+ this.nodeConflictBehavior = nodeConflictBehavior != null ? nodeConflictBehavior : DEFAULT_CONFLICT_BEHAVIOR;
}
}
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java 2008-08-19 14:46:40 UTC (rev 445)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java 2008-08-19 15:04:03 UTC (rev 446)
@@ -21,21 +21,101 @@
*/
package org.jboss.dna.connector.federation.merge;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+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.UUID;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author Randall Hauch
*/
public class FederatedNodeTest {
+ private FederatedNode node;
+ private UUID uuid;
+ @Mock
+ private Path path;
+
@Before
public void beforeEach() {
+ MockitoAnnotations.initMocks(this);
+ uuid = UUID.randomUUID();
+ node = new FederatedNode(path, uuid);
}
@Test
- public void shouldDoSomething() {
+ public void shouldHaveSameUuidSuppliedToConstructor() {
+ assertThat(node.getUuid(), is(sameInstance(uuid)));
+ }
+ @Test
+ public void shouldHaveSamePathSuppliedToConstructor() {
+ assertThat(node.getPath(), is(sameInstance(path)));
}
+ @Test
+ public void shouldNotHaveMergePlanUponConstruction() {
+ assertThat(node.getMergePlan(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldAllowSettingMergePlan() {
+ MergePlan mergePlan = mock(MergePlan.class);
+ node.setMergePlan(mergePlan);
+ assertThat(node.getMergePlan(), is(sameInstance(mergePlan)));
+ }
+
+ @Test
+ public void shouldHaveDefaultConflictBehaviorUponConstruction() {
+ assertThat(node.getConflictBehavior(), is(FederatedNode.DEFAULT_CONFLICT_BEHAVIOR));
+ }
+
+ @Test
+ public void shouldAllowSettingConflictBehavior() {
+ NodeConflictBehavior behavior = NodeConflictBehavior.REPLACE;
+ assertThat(node.getConflictBehavior(), is(not(behavior)));
+ node.setConflictBehavior(behavior);
+ assertThat(node.getConflictBehavior(), is(behavior));
+ }
+
+ @Test
+ public void shouldAllowSettingConflictBehaviorToNull() {
+ node.setConflictBehavior(null);
+ assertThat(node.getConflictBehavior(), is(FederatedNode.DEFAULT_CONFLICT_BEHAVIOR));
+
+ // Set to something that is not the default, then set to null
+ NodeConflictBehavior behavior = NodeConflictBehavior.REPLACE;
+ assertThat(node.getConflictBehavior(), is(not(behavior)));
+ node.setConflictBehavior(behavior);
+ assertThat(node.getConflictBehavior(), is(behavior));
+ node.setConflictBehavior(null);
+ assertThat(node.getConflictBehavior(), is(FederatedNode.DEFAULT_CONFLICT_BEHAVIOR));
+ }
+
+ @Test
+ public void shouldCompareFederatedNodesBasedUponPaths() {
+ Path path2 = mock(Path.class);
+ stub(path2.compareTo(path)).toReturn(1);
+ stub(path.compareTo(path2)).toReturn(-1);
+ FederatedNode node2 = new FederatedNode(path2, UUID.randomUUID());
+ assertThat(node.compareTo(node2), is(-1));
+ assertThat(node2.compareTo(node), is(1));
+ }
+
+ @Test
+ public void shouldHaveHashCodeThatIsTheHashCodeOfTheUuid() {
+ node = new FederatedNode(path, uuid);
+ assertThat(node.hashCode(), is(uuid.hashCode()));
+ }
+
}
15 years, 10 months
DNA SVN: r445 - trunk.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-19 10:46:40 -0400 (Tue, 19 Aug 2008)
New Revision: 445
Modified:
trunk/eclipse-preferences.epf
Log:
Added Mockito.spy(...) to the favorites of the content assist preferences
Modified: trunk/eclipse-preferences.epf
===================================================================
--- trunk/eclipse-preferences.epf 2008-08-19 12:06:15 UTC (rev 444)
+++ trunk/eclipse-preferences.epf 2008-08-19 14:46:40 UTC (rev 445)
@@ -72,7 +72,7 @@
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.source=1.5
-/instance/org.eclipse.jdt.ui/content_assist_favorite_static_members=org.junit.Assert.*;org.hamcrest.core.IsEqual.*;org.junit.matchers.JUnitMatchers.*;org.hamcrest.core.AllOf.*;org.hamcrest.core.AnyOf.*;org.hamcrest.core.IsInstanceOf.*;org.hamcrest.core.IsNot.*;org.hamcrest.core.IsNull.*;org.hamcrest.core.IsSame.*;org.hamcrest.core.DescribedAs.*;org.junit.matchers.IsCollectionContaining.*;org.junit.matchers.StringContains.*;org.hamcrest.core.Is.is;org.hamcrest.core.IsNot.not;org.hamcrest.core.IsNull.nullValue;org.hamcrest.core.IsNull.notNullValue;org.hamcrest.core.IsSame.sameInstance;org.hamcrest.core.IsInstanceOf.instanceOf;org.hamcrest.core.IsEqual.equalTo;org.hamcrest.core.IsAnything.anything;org.hamcrest.core.IsAnything.any;org.hamcrest.core.DescribedAs.describedAs;org.hamcrest.core.AnyOf.anyOf;org.hamcrest.core.AllOf.allOf;org.junit.matchers.IsCollectionContaining.hasItem;org.junit.matchers.IsCollectionContaining.hasItems;org.junit.matchers.Each.each;org.junit.matchers.!
JUnitMatchers.hasItem;org.junit.matchers.JUnitMatchers.hasItems;org.junit.matchers.JUnitMatchers.containsString;org.junit.matchers.JUnitMatchers.each;org.junit.matchers.JUnitMatchers.both;org.junit.matchers.JUnitMatchers.either;org.junit.matchers.StringContains.containsString;org.junit.matchers.TypeSafeMatcher.matches;org.hamcrest.collection.IsArray.*;org.hamcrest.collection.IsArrayContaining.*;org.hamcrest.number.IsCloseTo.*;org.mockito.Mockito.mock;org.mockito.Mockito.stub;org.mockito.Mockito.verify;org.mockito.Mockito.atLeastOnce;org.mockito.Mockito.inOrder;org.mockito.Mockito.never;org.mockito.Mockito.stubVoid;org.mockito.Mockito.times;org.mockito.Matchers;org.mockito.Matchers.anyBoolean;org.mockito.Matchers.anyByte;org.mockito.Matchers.anyChar;org.mockito.Matchers.anyDouble;org.mockito.Matchers.anyFloat;org.mockito.Matchers.anyInt;org.mockito.Matchers.anyLong;org.mockito.Matchers.anyObject;org.mockito.Matchers.anyShort;org.mockito.Matchers.anyString;org.mockito.Matcher!
s.argThat;org.mockito.Matchers.booleanThat;org.mockito.Matchers.byteTh
at;org.mockito.Matchers.charThat;org.mockito.Matchers.contains;org.mockito.Matchers.doubleThat;org.mockito.Matchers.endsWith;org.mockito.Matchers.eq;org.mockito.Matchers.floatThat;org.mockito.Matchers.intThat;org.mockito.Matchers.isA;org.mockito.Matchers.isNull;org.mockito.Matchers.longThat;org.mockito.Matchers.matches;org.mockito.Matchers.notNull;org.mockito.Matchers.refEq;org.mockito.Matchers.same;org.mockito.Matchers.shortThat;org.mockito.Matchers.startsWith;org.jboss.dna.common.text.StringMatcher.startsWith;org.jboss.dna.spi.graph.connection.RepositorySourceLoadHarness.runLoadTest;org.mockito.Mockito.verifyNoMoreInteractions;org.mockito.Mockito.verifyZeroInteractions;org.jboss.dna.common.collection.IsIteratorContaining.hasItems;org.jboss.dna.common.collection.IsIteratorContaining.hasItem.*;org.mockito.Mockito.doReturn;org.mockito.Mockito.doThrow;org.mockito.Mockito.doAnswer;org.mockito.Mockito.doNothing;org.mockito.Mockito.anyList;org.mockito.Mockito.anyMap;org.mockito.M!
ockito.anyCollection
+/instance/org.eclipse.jdt.ui/content_assist_favorite_static_members=org.junit.Assert.*;org.hamcrest.core.IsEqual.*;org.junit.matchers.JUnitMatchers.*;org.hamcrest.core.AllOf.*;org.hamcrest.core.AnyOf.*;org.hamcrest.core.IsInstanceOf.*;org.hamcrest.core.IsNot.*;org.hamcrest.core.IsNull.*;org.hamcrest.core.IsSame.*;org.hamcrest.core.DescribedAs.*;org.junit.matchers.IsCollectionContaining.*;org.junit.matchers.StringContains.*;org.hamcrest.core.Is.is;org.hamcrest.core.IsNot.not;org.hamcrest.core.IsNull.nullValue;org.hamcrest.core.IsNull.notNullValue;org.hamcrest.core.IsSame.sameInstance;org.hamcrest.core.IsInstanceOf.instanceOf;org.hamcrest.core.IsEqual.equalTo;org.hamcrest.core.IsAnything.anything;org.hamcrest.core.IsAnything.any;org.hamcrest.core.DescribedAs.describedAs;org.hamcrest.core.AnyOf.anyOf;org.hamcrest.core.AllOf.allOf;org.junit.matchers.IsCollectionContaining.hasItem;org.junit.matchers.IsCollectionContaining.hasItems;org.junit.matchers.Each.each;org.junit.matchers.!
JUnitMatchers.hasItem;org.junit.matchers.JUnitMatchers.hasItems;org.junit.matchers.JUnitMatchers.containsString;org.junit.matchers.JUnitMatchers.each;org.junit.matchers.JUnitMatchers.both;org.junit.matchers.JUnitMatchers.either;org.junit.matchers.StringContains.containsString;org.junit.matchers.TypeSafeMatcher.matches;org.hamcrest.collection.IsArray.*;org.hamcrest.collection.IsArrayContaining.*;org.hamcrest.number.IsCloseTo.*;org.mockito.Mockito.mock;org.mockito.Mockito.stub;org.mockito.Mockito.verify;org.mockito.Mockito.atLeastOnce;org.mockito.Mockito.inOrder;org.mockito.Mockito.never;org.mockito.Mockito.stubVoid;org.mockito.Mockito.times;org.mockito.Matchers;org.mockito.Matchers.anyBoolean;org.mockito.Matchers.anyByte;org.mockito.Matchers.anyChar;org.mockito.Matchers.anyDouble;org.mockito.Matchers.anyFloat;org.mockito.Matchers.anyInt;org.mockito.Matchers.anyLong;org.mockito.Matchers.anyObject;org.mockito.Matchers.anyShort;org.mockito.Matchers.anyString;org.mockito.Matcher!
s.argThat;org.mockito.Matchers.booleanThat;org.mockito.Matchers.byteTh
at;org.mockito.Matchers.charThat;org.mockito.Matchers.contains;org.mockito.Matchers.doubleThat;org.mockito.Matchers.endsWith;org.mockito.Matchers.eq;org.mockito.Matchers.floatThat;org.mockito.Matchers.intThat;org.mockito.Matchers.isA;org.mockito.Matchers.isNull;org.mockito.Matchers.longThat;org.mockito.Matchers.matches;org.mockito.Matchers.notNull;org.mockito.Matchers.refEq;org.mockito.Matchers.same;org.mockito.Matchers.shortThat;org.mockito.Matchers.startsWith;org.jboss.dna.common.text.StringMatcher.startsWith;org.jboss.dna.spi.graph.connection.RepositorySourceLoadHarness.runLoadTest;org.mockito.Mockito.verifyNoMoreInteractions;org.mockito.Mockito.verifyZeroInteractions;org.jboss.dna.common.collection.IsIteratorContaining.hasItems;org.jboss.dna.common.collection.IsIteratorContaining.hasItem.*;org.mockito.Mockito.doReturn;org.mockito.Mockito.doThrow;org.mockito.Mockito.doAnswer;org.mockito.Mockito.doNothing;org.mockito.Mockito.anyList;org.mockito.Mockito.anyMap;org.mockito.M!
ockito.anyCollection;org.mockito.Mockito.spy
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.gettersetter.use.is=true
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.ignorelowercasenames=true
/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.importorder=\#;java;javax;org;com;
15 years, 10 months
DNA SVN: r444 - trunk/extensions/dna-sequencer-java/src/test/resources.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-19 08:06:15 -0400 (Tue, 19 Aug 2008)
New Revision: 444
Modified:
trunk/extensions/dna-sequencer-java/src/test/resources/java-source-artifact.cnd
Log:
- support sequencing package declaration( FQL name of the package). Not supported is to get information for package annotation
- support for sequencing class definition (modifiers, class name)
- support for sequencing imports (single import and import on demand)
- support for primitive type sequencing (modifiers, types, variables).Not supported is the javadoc
- support for methods sequencing (modifiers, return type, method name, parameters).Not supported are javadoc
- dna-sequencer-java.patch (randall)
Modified: trunk/extensions/dna-sequencer-java/src/test/resources/java-source-artifact.cnd
===================================================================
--- trunk/extensions/dna-sequencer-java/src/test/resources/java-source-artifact.cnd 2008-08-19 12:05:59 UTC (rev 443)
+++ trunk/extensions/dna-sequencer-java/src/test/resources/java-source-artifact.cnd 2008-08-19 12:06:15 UTC (rev 444)
@@ -49,7 +49,13 @@
* Element-value
*/
[java:elementValue] > nt:unstructured
- + java:kindOfvalues (java:conditionalExpression, java:annotationType, java:elementValueArrayInitializer) mandatory
+ + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
+
+/**
+ * Modifiers
+ */
+[java:modifierDeclaration] > nt:unstructured
+ - java:name (string) mandatory
/**
* Expression element-value type
@@ -79,8 +85,8 @@
/**
* Annotation type
*/
-[java:annotationType] > nt:unstructured
- + java:annotation (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
+[java:annotationDeclaration] > nt:unstructured
+ + java:annotationType (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
/**
* Normal annotation e.g. @Entity(name="Customer")
@@ -93,7 +99,7 @@
* Marker annotation e.g. @GET
*/
[java:markerAnnotation] > nt:unstructured
- - typeName (string)
+ - java:typeName (string) mandatory
/**
* Single element annotation e.g. @Path("/book")
@@ -105,54 +111,36 @@
* Formal parameter
*/
[java:formalParameter] > nt:unstructured
- - java:name (string)
+ java:type (java:primitiveType, java:referenceType) mandatory multiple
-/**
- * No Return type
- */
-[java:noReturnType] > nt:unstructured
- - java:noReturn (string)
- < 'void'
-
-/**
- * Integral type
- */
-[java:integralType] > nt:unstructured
- - java:predefinedIntegralType (string) mandatory
- < 'byte', 'short', 'int', 'long', 'char'
-
-/**
- * Floating point type
- */
-[java:floatingPointType] > nt:unstructured
- - java:predefinedFloatingType (string) mandatory
- < 'float', 'double'
-
/**
- * Primitive type
+ * Primitive type:
+ * - Integral type ('byte', 'short', 'int', 'long', 'char')
+ * - Floating point type ('float', 'double')
+ * - Boolean type ('boolean')
+ * - No return type (''void')
*/
[java:primitiveType] > nt:unstructured
- - java:booleanType (string)
- < 'boolean'
- + java:numericType (java:integralType, java:floatingPointType)
+ - java:description (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:typeName (string)
+ + java:variable (java:variable) = java:variable
-
+ [java:variable] > nt:unstructured
+ - java:variableName (string)
+
/**
* Reference type (TODO to enhance)
- */
+ */
[java:referenceType] > nt:unstructured
-
+ - java:description (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:name (string) mandatory
+
/**
* Field type
*/
[java:fieldType] > nt:unstructured
- - java:description (string)
- - java:modifier (string)
- < 'public', 'protected', 'private'
- - java:declaredAs (string) multiple
- < 'static','final', 'transient', 'volatile'
- - java:name (string) mandatory
+ java:type (java:primitiveType, java:referenceType) mandatory multiple
/**
@@ -160,12 +148,9 @@
*/
[java:methodDeclaration] > nt:unstructured
- java:description (string)
- - java:modifier (string)
- < 'public', 'protected', 'private'
- + java:resultType (java:noReturnType, java:primitiveType, java:referenceType) mandatory
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ + java:resultType (java:primitiveType, java:referenceType) mandatory
- java:name (string) mandatory
- - java:declaredAs (string) multiple
- < 'static','final', 'native', 'strictfp', 'synchronized'
+ java:parameter (java:formalParameter) multiple
/**
@@ -173,8 +158,7 @@
*/
[java:constructorDeclaration] > nt:unstructured
- java:description (string)
- - java:modifier (string)
- < 'public', 'protected', 'private'
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- java:name (string) mandatory
+ java:parameter (java:formalParameter)
@@ -183,7 +167,7 @@
* Package declarations
*/
[java:packageDeclaration] > nt:unstructured
- + java:annotation (java:annotationType) = java:annotationType
+ + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
- java:keyword (string)
< 'package'
- java:packageName (string) mandatory
@@ -192,33 +176,19 @@
* Import declarations
*/
[java:singleTypeImportDeclaration] > nt:unstructured
- - keyword (string) mandatory
+ - java:keyword (string) mandatory
< 'import'
- - typeName (string) mandatory
+ - java:typeName (string) mandatory
-// TODO: needs to be enhance
[java:typeImportOnDemandDeclaration] > nt:unstructured
- - keyword (string) mandatory
+ - java:keyword (string) mandatory
< 'import'
- - packageOrTypeName (string) mandatory
+ - java:typeName (string) mandatory
-// TODO: needs to be enhance
-[java:singleStaticImportDeclaration] > nt:unstructured
- - single_static (string) mandatory
- < 'import static'
- - typeName (string) mandatory
-
-// TODO: needs to be enhance
-[java:staticImportOnDemandDeclaration] > nt:unstructured
- - static_import (string) mandatory
- < 'import static'
- - typeName (string) mandatory
+ [java:importDeclaration] > nt:unstructured
+ + java:singleImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
+ + java:importOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
-[java:importDeclaration] > nt:unstructured
- + java:singleTypeImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
- + java:typeImportOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
- + java:singleStaticImport (java:singleStaticImportDeclaration) = java:singleStaticImportDeclaration
- + java:staticImportOnDemand (java:staticImportOnDemandDeclaration) = java:staticImportOnDemandDeclaration
/**
* Class declaration
@@ -228,9 +198,7 @@
*/
[java:normalClassDeclaration] > nt:unstructured
- java:description (string)
- - java:modifier = 'public'
- - java:declaredAs (string)
- < 'abstract', 'final'
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- java:name (string) mandatory
+ java:field (java:fieldType) = java:fieldType multiple
+ java:method (java:methodDeclaration) = java:methodDeclaration multiple
@@ -243,11 +211,12 @@
+ java:enum (java:enumDeclaration) = java:enumDeclaration
/**
- * Interface declaration
+ * Interface declaration
*
* The body of class declares members (fields and methods and nested classes and interfaces),
* instance and static initializers, and constructors
- */
+ */
+ //TODO
[java:interfaceDeclaration] > nt:unstructured
@@ -257,4 +226,4 @@
[java:compilationUnit] > nt:unstructured
+ java:package (java:packageDeclaration) = java:packageDeclaration
+ java:import (java:importDeclaration) = java:importDeclaration
- + java:typeDeclaration (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
+ + java:unitType (java:classDeclaration, java:interfaceDeclaration)
\ No newline at end of file
15 years, 10 months
DNA SVN: r443 - trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-19 08:05:59 -0400 (Tue, 19 Aug 2008)
New Revision: 443
Modified:
trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd
Log:
- support sequencing package declaration( FQL name of the package). Not supported is to get information for package annotation
- support for sequencing class definition (modifiers, class name)
- support for sequencing imports (single import and import on demand)
- support for primitive type sequencing (modifiers, types, variables).Not supported is the javadoc
- support for methods sequencing (modifiers, return type, method name, parameters).Not supported are javadoc
- dna-sequencer-java.patch (randall)
Modified: trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd 2008-08-19 12:05:45 UTC (rev 442)
+++ trunk/extensions/dna-sequencer-java/src/main/resources/org/jboss/dna/sequencer/java/java-source-artifact.cnd 2008-08-19 12:05:59 UTC (rev 443)
@@ -49,7 +49,7 @@
* Element-value
*/
[java:elementValue] > nt:unstructured
- + java:kindOfvalues (java:conditionalExpression, java:annotationType, java:elementValueArrayInitializer) mandatory
+ + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
/**
* Modifiers
@@ -124,7 +124,6 @@
- java:description (string)
+ java:modifier (java:modifierDeclaration) = java:modifierDeclaration
- java:typeName (string)
- < 'byte','short','char','int,'long','float','double','boolean','void'
+ java:variable (java:variable) = java:variable
[java:variable] > nt:unstructured
15 years, 10 months
DNA SVN: r442 - in trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna: sequencer/java and 1 other directory.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-19 08:05:45 -0400 (Tue, 19 Aug 2008)
New Revision: 442
Modified:
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java
trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
Log:
- support sequencing package declaration( FQL name of the package). Not supported is to get information for package annotation
- support for sequencing class definition (modifiers, class name)
- support for sequencing imports (single import and import on demand)
- support for primitive type sequencing (modifiers, types, variables).Not supported is the javadoc
- support for methods sequencing (modifiers, return type, method name, parameters).Not supported are javadoc
- dna-sequencer-java.patch (randall)
Modified: trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java 2008-08-19 12:05:11 UTC (rev 441)
+++ trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/jackrabbitcdnsupport/jackrabbitCNDSupportsTest.java 2008-08-19 12:05:45 UTC (rev 442)
@@ -91,7 +91,7 @@
FileInputStream cndFile = new FileInputStream(TESTATA_PATH + "java-source-artifact.cnd");
assertNotNull(cndFile);
NodeType[] nodeTypes = ntm.registerNodeTypes(cndFile, JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
- assertEquals(29, nodeTypes.length);
+ assertEquals(26, nodeTypes.length);
for (NodeType nodeType : nodeTypes) {
System.out.println("node type name: " + nodeType.getName());
}
Modified: trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-08-19 12:05:11 UTC (rev 441)
+++ trunk/extensions/dna-sequencer-java/src/test/java/org/jboss/dna/sequencer/java/JavaMetadataSequencerTest.java 2008-08-19 12:05:45 UTC (rev 442)
@@ -105,7 +105,7 @@
"java:typeName"),
is(new Object[] {"java.util"}));
- // support for sequencing class definition (moodifiers, class name)
+ // support for sequencing class definition (modifiers, class name)
assertThat(output.getPropertyValues("java:compilationUnit/java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:modifier/java:modifierDeclaration[1]",
"java:modifierName"),
is(new Object[] {"public"}));
15 years, 10 months
DNA SVN: r441 - in trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java: metadata and 1 other directory.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-08-19 08:05:11 -0400 (Tue, 19 Aug 2008)
New Revision: 441
Modified:
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataUtil.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/AnnotationMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ClassMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/FieldMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ImportOnDemandMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MarkerAnnotationMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodTypeMemberMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ModifierMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/NormalAnnotationMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ParameterizedFieldMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleImportMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleMemberAnnotationMetadata.java
trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/TypeMetadata.java
Log:
- support sequencing package declaration( FQL name of the package). Not supported is to get information for package annotation
- support for sequencing class definition (modifiers, class name)
- support for sequencing imports (single import and import on demand)
- support for primitive type sequencing (modifiers, types, variables).Not supported is the javadoc
- support for methods sequencing (modifiers, return type, method name, parameters).Not supported are javadoc
- dna-sequencer-java.patch (randall)
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/AbstractJavaMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -66,7 +66,7 @@
import org.jboss.dna.sequencer.java.metadata.Variable;
/**
- * Abstract definition of a <tt>JavaMetadata<tt>. This class exposes some useful methods, that can
+ * Abstract definition of a <code>JavaMetadata<code>. This class exposes some useful methods, that can
* be used to create meta data of a compilation unit. Methods can also separately be used.
*
* @author Serge Pagop
@@ -205,12 +205,14 @@
}
/**
- * @param typeDeclaration
- * @param classMetadata
+ * Process modifiers of {@link TypeDeclaration}.
+ *
+ * @param typeDeclaration - the type declaration.
+ * @param classMetadata - class meta data.
*/
@SuppressWarnings( "unchecked" )
- private void processModifiersOfTypDeclaration( TypeDeclaration typeDeclaration,
- ClassMetadata classMetadata ) {
+ protected void processModifiersOfTypDeclaration( TypeDeclaration typeDeclaration,
+ ClassMetadata classMetadata ) {
List<IExtendedModifier> modifiers = typeDeclaration.modifiers();
for (IExtendedModifier extendedModifier : modifiers) {
@@ -237,7 +239,7 @@
* @param methodDeclaration - the MethodDeclaration.
* @return methodMetadata - the method meta data.
*/
- private MethodMetadata getMethodMetadataFrom( MethodDeclaration methodDeclaration ) {
+ protected MethodMetadata getMethodMetadataFrom( MethodDeclaration methodDeclaration ) {
if (methodDeclaration != null) {
if (methodDeclaration.isConstructor()) {
return getConstructorMetadataFrom(methodDeclaration);
@@ -255,7 +257,7 @@
* @return methodTypeMemberMetadata
*/
@SuppressWarnings( "unchecked" )
- private MethodMetadata getMethodTypeMemberMetadataFrom( MethodDeclaration methodDeclaration ) {
+ protected MethodMetadata getMethodTypeMemberMetadataFrom( MethodDeclaration methodDeclaration ) {
MethodTypeMemberMetadata methodTypeMemberMetadata = new MethodTypeMemberMetadata();
processReturnTypeOfMethodDeclaration(methodDeclaration, methodTypeMemberMetadata);
processModifiersOfMethodDeclaration(methodDeclaration, methodTypeMemberMetadata);
@@ -269,18 +271,20 @@
}
/**
- * @param methodDeclaration
- * @param methodMetadata
+ * Process return type of a {@link MethodDeclaration}.
+ *
+ * @param methodDeclaration - the method declaration.
+ * @param methodMetadata - the method meta data.
*/
- private void processReturnTypeOfMethodDeclaration( MethodDeclaration methodDeclaration,
- MethodMetadata methodMetadata ) {
+ protected void processReturnTypeOfMethodDeclaration( MethodDeclaration methodDeclaration,
+ MethodMetadata methodMetadata ) {
Type type = methodDeclaration.getReturnType2();
- if(type.isPrimitiveType()) {
+ if (type.isPrimitiveType()) {
PrimitiveFieldMetadata primitive = new PrimitiveFieldMetadata();
primitive.setType(((PrimitiveType)type).getPrimitiveTypeCode().toString());
methodMetadata.setReturnType(primitive);
}
- if(type.isSimpleType()) {
+ if (type.isSimpleType()) {
ReferenceFieldMetadata referenceFieldMetadata = new ReferenceFieldMetadata();
referenceFieldMetadata.setType(JavaMetadataUtil.getName(((SimpleType)type).getName()));
methodMetadata.setReturnType(referenceFieldMetadata);
@@ -288,12 +292,14 @@
}
/**
- * @param methodDeclaration
- * @param methodMetadata
+ * Process parameters of a {@link MethodDeclaration}.
+ *
+ * @param methodDeclaration - the method declaration.
+ * @param methodMetadata - the method meta data.
*/
@SuppressWarnings( "unchecked" )
- private void processParametersOfMethodDeclaration( MethodDeclaration methodDeclaration,
- MethodMetadata methodMetadata ) {
+ protected void processParametersOfMethodDeclaration( MethodDeclaration methodDeclaration,
+ MethodMetadata methodMetadata ) {
List<SingleVariableDeclaration> params = methodDeclaration.parameters();
for (SingleVariableDeclaration singleVariableDeclaration : params) {
Type type = singleVariableDeclaration.getType();
@@ -358,7 +364,7 @@
* @param methodDeclaration
* @return constructorMetadata
*/
- private MethodMetadata getConstructorMetadataFrom( MethodDeclaration methodDeclaration ) {
+ protected MethodMetadata getConstructorMetadataFrom( MethodDeclaration methodDeclaration ) {
ConstructorMetadata constructorMetadata = new ConstructorMetadata();
// modifiers
processModifiersOfMethodDeclaration(methodDeclaration, constructorMetadata);
@@ -374,8 +380,7 @@
* @param fieldDeclaration - the declaration.
* @return fieldMetadata - meta data.
*/
- @SuppressWarnings( "unchecked" )
- private FieldMetadata getFieldMetadataFrom( FieldDeclaration fieldDeclaration ) {
+ protected FieldMetadata getFieldMetadataFrom( FieldDeclaration fieldDeclaration ) {
if (fieldDeclaration != null && fieldDeclaration.getType() != null && (!fieldDeclaration.fragments().isEmpty())) {
// type
Type type = fieldDeclaration.getType();
@@ -412,12 +417,14 @@
}
/**
- * @param fieldDeclaration
- * @param type
- * @return SimpleFieldMetadata
+ * Process the simple type of a {@link FieldDeclaration}.
+ *
+ * @param fieldDeclaration - the field declaration.
+ * @param type - the type.
+ * @return SimpleFieldMetadata.
*/
- private SimpleFieldMetadata processSimpleType( FieldDeclaration fieldDeclaration,
- Type type ) {
+ protected SimpleFieldMetadata processSimpleType( FieldDeclaration fieldDeclaration,
+ Type type ) {
SimpleType simpleType = (SimpleType)type;
SimpleFieldMetadata simpleFieldMetadata = new SimpleFieldMetadata();
simpleFieldMetadata.setType(JavaMetadataUtil.getName(simpleType.getName()));
@@ -428,12 +435,14 @@
}
/**
- * @param fieldDeclaration
- * @param type
- * @return ParameterizedFieldMetadata
+ * Process the parameterized type of a {@link FieldDeclaration}.
+ *
+ * @param fieldDeclaration - the field declaration.
+ * @param type - the type.
+ * @return ParameterizedFieldMetadata.
*/
- private ParameterizedFieldMetadata processParameterizedType( FieldDeclaration fieldDeclaration,
- Type type ) {
+ protected ParameterizedFieldMetadata processParameterizedType( FieldDeclaration fieldDeclaration,
+ Type type ) {
ParameterizedType parameterizedType = (ParameterizedType)type;
Type typeOfParameterizedType = parameterizedType.getType(); // type may be a simple type or a qualified type.
ParameterizedFieldMetadata referenceFieldMetadata = (ParameterizedFieldMetadata)createParameterizedFieldMetadataFrom(typeOfParameterizedType);
@@ -445,12 +454,14 @@
}
/**
- * @param fieldDeclaration
- * @param type
- * @return PrimitiveFieldMetadata
+ * Process the primitive type of a {@link FieldDeclaration}.
+ *
+ * @param fieldDeclaration - the field declaration.
+ * @param type - the type.
+ * @return PrimitiveFieldMetadata.
*/
- private PrimitiveFieldMetadata processPrimitiveType( FieldDeclaration fieldDeclaration,
- Type type ) {
+ protected PrimitiveFieldMetadata processPrimitiveType( FieldDeclaration fieldDeclaration,
+ Type type ) {
PrimitiveType primitiveType = (PrimitiveType)type;
PrimitiveFieldMetadata primitiveFieldMetadata = new PrimitiveFieldMetadata();
primitiveFieldMetadata.setType(primitiveType.getPrimitiveTypeCode().toString());
@@ -491,8 +502,8 @@
* @param methodMetadata
*/
@SuppressWarnings( "unchecked" )
- private void processModifiersOfMethodDeclaration( MethodDeclaration methodDeclaration,
- MethodMetadata methodMetadata ) {
+ protected void processModifiersOfMethodDeclaration( MethodDeclaration methodDeclaration,
+ MethodMetadata methodMetadata ) {
List<IExtendedModifier> extendedModifiers = methodDeclaration.modifiers();
for (IExtendedModifier extendedModifier : extendedModifiers) {
ModifierMetadata modifierMetadata = new ModifierMetadata();
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/CompilationUnitParser.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -29,7 +29,6 @@
* The Parser, tha process the a compilation unit.
*
* @author Serge Pagop
- *
*/
public class CompilationUnitParser {
@@ -54,5 +53,5 @@
ASTNode result = parser.createAST(null);
return result;
}
-
+
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataSequencer.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -26,6 +26,7 @@
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.sequencer.java.metadata.AnnotationMetadata;
import org.jboss.dna.sequencer.java.metadata.ClassMetadata;
import org.jboss.dna.sequencer.java.metadata.ConstructorMetadata;
@@ -231,11 +232,10 @@
javaMetadata.getPackageMetadata().getName());
}
- List<AnnotationMetadata> annotations = packageMetadata.getAnnotationMetada();
int markerAnnotationIndex = 1;
int singleAnnatationIndex = 1;
int normalAnnotationIndex = 1;
- for (AnnotationMetadata annotationMetadata : annotations) {
+ for (AnnotationMetadata annotationMetadata : packageMetadata.getAnnotationMetada()) {
if (annotationMetadata instanceof MarkerAnnotationMetadata) {
MarkerAnnotationMetadata markerAnnotationMetadata = (MarkerAnnotationMetadata)annotationMetadata;
Path markerAnnotationChildNode = pathFactory.create(JAVA_COMPILATION_UNIT_NODE + SLASH
@@ -287,10 +287,9 @@
}
// sequence import declarations of a unit
- List<ImportMetadata> imports = javaMetadata.getImports();
int importOnDemandIndex = 1;
int singleImportIndex = 1;
- for (ImportMetadata importMetadata : imports) {
+ for (ImportMetadata importMetadata : javaMetadata.getImports()) {
if (importMetadata instanceof ImportOnDemandMetadata) {
ImportOnDemandMetadata importOnDemandMetadata = (ImportOnDemandMetadata)importMetadata;
Path importOnDemandChildNode = pathFactory.create(JAVA_COMPILATION_UNIT_NODE + SLASH + JAVA_IMPORT_CHILD_NODE
@@ -318,8 +317,7 @@
}
// sequence type declaration (class declaration) information
- List<TypeMetadata> types = javaMetadata.getTypeMetadata();
- for (TypeMetadata typeMetadata : types) {
+ for (TypeMetadata typeMetadata : javaMetadata.getTypeMetadata()) {
// class declaration
if (typeMetadata instanceof ClassMetadata) {
ClassMetadata classMetadata = (ClassMetadata)typeMetadata;
@@ -349,21 +347,19 @@
}
// process fields of the class unit.
- List<FieldMetadata> fields = classMetadata.getFields();
int primitiveIndex = 1;
- for (FieldMetadata fieldMetadata : fields) {
+ for (FieldMetadata fieldMetadata : classMetadata.getFields()) {
if (fieldMetadata instanceof PrimitiveFieldMetadata) {
PrimitiveFieldMetadata primitiveFieldMetadata = (PrimitiveFieldMetadata)fieldMetadata;
- StringBuffer primitiveFieldRootPath = createPathWithIndex(JAVA_COMPILATION_UNIT_NODE + SLASH
- + JAVA_UNIT_TYPE_CHILD_NODE + SLASH
- + JAVA_CLASS_DECLARATION_CHILD_NODE + SLASH
- + JAVA_NORMAL_CLASS_CHILD_NODE + SLASH
- + JAVA_NORMAL_CLASS_DECLARATION_CHILD_NODE
- + SLASH + JAVA_FIELD_CHILD_NODE + SLASH
- + JAVA_FIELD_TYPE_CHILD_NODE + SLASH
- + JAVA_TYPE_CHILD_NODE + SLASH
- + JAVA_PRIMITIVE_TYPE_CHILD_NODE,
- primitiveIndex);
+ String primitiveFieldRootPath = createPathWithIndex(JAVA_COMPILATION_UNIT_NODE + SLASH
+ + JAVA_UNIT_TYPE_CHILD_NODE + SLASH
+ + JAVA_CLASS_DECLARATION_CHILD_NODE + SLASH
+ + JAVA_NORMAL_CLASS_CHILD_NODE + SLASH
+ + JAVA_NORMAL_CLASS_DECLARATION_CHILD_NODE
+ + SLASH + JAVA_FIELD_CHILD_NODE + SLASH
+ + JAVA_FIELD_TYPE_CHILD_NODE + SLASH
+ + JAVA_TYPE_CHILD_NODE + SLASH
+ + JAVA_PRIMITIVE_TYPE_CHILD_NODE, primitiveIndex);
// type
Path primitiveTypeChildNode = pathFactory.create(primitiveFieldRootPath);
output.setProperty(primitiveTypeChildNode,
@@ -373,10 +369,10 @@
List<ModifierMetadata> modifiers = primitiveFieldMetadata.getModifiers();
int primitiveModifierIndex = 1;
for (ModifierMetadata modifierMetadata2 : modifiers) {
- String modifierPath = createPathWithIndex(primitiveFieldRootPath.toString() + SLASH
+ String modifierPath = createPathWithIndex(primitiveFieldRootPath + SLASH
+ JAVA_MODIFIER_CHILD_NODE + SLASH
+ JAVA_MODIFIER_DECLARATION_CHILD_NODE,
- primitiveModifierIndex).toString();
+ primitiveModifierIndex);
Path modifierChildNode = pathFactory.create(modifierPath);
output.setProperty(modifierChildNode,
nameFactory.create(JAVA_MODIFIER_NAME),
@@ -410,15 +406,15 @@
if (methodMetadata.isContructor()) {
// process contructor
ConstructorMetadata constructorMetadata = (ConstructorMetadata)methodMetadata;
- StringBuffer constructorRootPath = createPathWithIndex(JAVA_COMPILATION_UNIT_NODE + SLASH
- + JAVA_UNIT_TYPE_CHILD_NODE + SLASH
- + JAVA_CLASS_DECLARATION_CHILD_NODE + SLASH
- + JAVA_NORMAL_CLASS_CHILD_NODE + SLASH
- + JAVA_NORMAL_CLASS_DECLARATION_CHILD_NODE
- + SLASH + JAVA_CONSTRUCTOR_CHILD_NODE + SLASH
- + JAVA_CONSTRUCTOR_DECLARATION_CHILD_NODE,
- constructorIndex);
- Path constructorChildNode = pathFactory.create(constructorRootPath.toString());
+ String constructorRootPath = createPathWithIndex(JAVA_COMPILATION_UNIT_NODE + SLASH
+ + JAVA_UNIT_TYPE_CHILD_NODE + SLASH
+ + JAVA_CLASS_DECLARATION_CHILD_NODE + SLASH
+ + JAVA_NORMAL_CLASS_CHILD_NODE + SLASH
+ + JAVA_NORMAL_CLASS_DECLARATION_CHILD_NODE + SLASH
+ + JAVA_CONSTRUCTOR_CHILD_NODE + SLASH
+ + JAVA_CONSTRUCTOR_DECLARATION_CHILD_NODE,
+ constructorIndex);
+ Path constructorChildNode = pathFactory.create(constructorRootPath);
output.setProperty(constructorChildNode,
nameFactory.create(JAVA_METHOD_NAME),
constructorMetadata.getName());
@@ -426,10 +422,10 @@
// modifiers
int constructorModifierIndex = 1;
for (ModifierMetadata modifierMetadata : modifiers) {
- String contructorModifierPath = createPathWithIndex(constructorRootPath.toString() + SLASH
+ String contructorModifierPath = createPathWithIndex(constructorRootPath + SLASH
+ JAVA_MODIFIER_CHILD_NODE + SLASH
+ JAVA_MODIFIER_DECLARATION_CHILD_NODE,
- constructorModifierIndex).toString();
+ constructorModifierIndex);
Path constructorModifierChildNode = pathFactory.create(contructorModifierPath);
output.setProperty(constructorModifierChildNode,
nameFactory.create(JAVA_MODIFIER_NAME),
@@ -441,10 +437,10 @@
int constructorParameterIndex = 1;
for (FieldMetadata fieldMetadata2 : constructorMetadata.getParameters()) {
- String constructorParameterRootPath = createPathWithIndex(constructorRootPath.toString() + SLASH
+ String constructorParameterRootPath = createPathWithIndex(constructorRootPath + SLASH
+ JAVA_PARAMETER + SLASH
+ JAVA_FORMAL_PARAMETER,
- constructorParameterIndex).toString();
+ constructorParameterIndex);
if (fieldMetadata2 instanceof PrimitiveFieldMetadata) {
@@ -452,9 +448,9 @@
String constructPrimitiveFormalParamRootPath = createPath(constructorParameterRootPath
+ SLASH + JAVA_TYPE_CHILD_NODE
+ SLASH
- + JAVA_PRIMITIVE_TYPE_CHILD_NODE).toString();
+ + JAVA_PRIMITIVE_TYPE_CHILD_NODE);
String constructorPrimitiveParamVariablePath = createPath(constructPrimitiveFormalParamRootPath
- + SLASH + JAVA_VARIABLE).toString();
+ + SLASH + JAVA_VARIABLE);
Path constructorParamChildNode = pathFactory.create(constructorPrimitiveParamVariablePath);
for (Variable variable : primitive.getVariables()) {
// name
@@ -480,14 +476,14 @@
// normal method
MethodTypeMemberMetadata methodTypeMemberMetadata = (MethodTypeMemberMetadata)methodMetadata;
- StringBuffer methodRootPath = createPathWithIndex(JAVA_COMPILATION_UNIT_NODE + SLASH
- + JAVA_UNIT_TYPE_CHILD_NODE + SLASH
- + JAVA_CLASS_DECLARATION_CHILD_NODE + SLASH
- + JAVA_NORMAL_CLASS_CHILD_NODE + SLASH
- + JAVA_NORMAL_CLASS_DECLARATION_CHILD_NODE + SLASH
- + JAVA_METHOD_CHILD_NODE + SLASH
- + JAVA_METHOD_DECLARATION_CHILD_NODE, methodIndex);
- Path methodChildNode = pathFactory.create(methodRootPath.toString());
+ String methodRootPath = createPathWithIndex(JAVA_COMPILATION_UNIT_NODE + SLASH
+ + JAVA_UNIT_TYPE_CHILD_NODE + SLASH
+ + JAVA_CLASS_DECLARATION_CHILD_NODE + SLASH
+ + JAVA_NORMAL_CLASS_CHILD_NODE + SLASH
+ + JAVA_NORMAL_CLASS_DECLARATION_CHILD_NODE + SLASH
+ + JAVA_METHOD_CHILD_NODE + SLASH
+ + JAVA_METHOD_DECLARATION_CHILD_NODE, methodIndex);
+ Path methodChildNode = pathFactory.create(methodRootPath);
output.setProperty(methodChildNode,
nameFactory.create(JAVA_METHOD_NAME),
methodTypeMemberMetadata.getName());
@@ -495,10 +491,9 @@
// method modifiers
int methodModierIndex = 1;
for (ModifierMetadata modifierMetadata : methodTypeMemberMetadata.getModifiers()) {
- String methodModifierPath = createPathWithIndex(methodRootPath.toString() + SLASH
- + JAVA_MODIFIER_CHILD_NODE + SLASH
- + JAVA_MODIFIER_DECLARATION_CHILD_NODE,
- methodModierIndex).toString();
+ String methodModifierPath = createPathWithIndex(methodRootPath + SLASH + JAVA_MODIFIER_CHILD_NODE
+ + SLASH + JAVA_MODIFIER_DECLARATION_CHILD_NODE,
+ methodModierIndex);
Path methodModifierChildNode = pathFactory.create(methodModifierPath);
output.setProperty(methodModifierChildNode,
nameFactory.create(JAVA_MODIFIER_NAME),
@@ -509,10 +504,9 @@
int methodParameterIndex = 1;
for (FieldMetadata fieldMetadata : methodMetadata.getParameters()) {
- String methodPrimitiveParamRootPath = createPathWithIndex(methodRootPath.toString() + SLASH
- + JAVA_PARAMETER + SLASH
- + JAVA_FORMAL_PARAMETER,
- methodParameterIndex).toString();
+ String methodPrimitiveParamRootPath = createPathWithIndex(methodRootPath + SLASH + JAVA_PARAMETER
+ + SLASH + JAVA_FORMAL_PARAMETER,
+ methodParameterIndex);
if (fieldMetadata instanceof PrimitiveFieldMetadata) {
@@ -520,10 +514,10 @@
String methodPrimitiveFormalParamRootPath = createPath(methodPrimitiveParamRootPath + SLASH
+ JAVA_TYPE_CHILD_NODE + SLASH
- + JAVA_PRIMITIVE_TYPE_CHILD_NODE).toString();
+ + JAVA_PRIMITIVE_TYPE_CHILD_NODE);
String methodPrimitiveParamVariablePath = createPath(methodPrimitiveFormalParamRootPath
- + SLASH + JAVA_VARIABLE).toString();
+ + SLASH + JAVA_VARIABLE);
Path methodParamChildNode = pathFactory.create(methodPrimitiveParamVariablePath);
for (Variable variable : primitive.getVariables()) {
@@ -547,12 +541,12 @@
// method return type
FieldMetadata methodReturnType = methodTypeMemberMetadata.getReturnType();
-
+
if (methodReturnType instanceof PrimitiveFieldMetadata) {
PrimitiveFieldMetadata methodReturnPrimitiveType = (PrimitiveFieldMetadata)methodReturnType;
String methodReturnPrimitiveTypePath = createPath(methodRootPath.toString() + SLASH
+ JAVA_RETURN_TYPE + SLASH
- + JAVA_PRIMITIVE_TYPE_CHILD_NODE).toString();
+ + JAVA_PRIMITIVE_TYPE_CHILD_NODE);
Path methodReturnPrimitiveTypeChildNode = pathFactory.create(methodReturnPrimitiveTypePath);
output.setProperty(methodReturnPrimitiveTypeChildNode,
nameFactory.create(JAVA_TYPE),
@@ -578,34 +572,27 @@
/**
* Create a path for the tree with index.
*
- * @param path - the path.
- * @param index - the index begin with 1.
- * @return {@link StringBuffer}
+ * @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
*/
- private StringBuffer createPathWithIndex( String path,
- int index ) {
- StringBuffer rootPath = new StringBuffer();
-
- if (StringUtils.isEmpty(path)) {
- throw new IllegalArgumentException("path has to be unique and not empty");
- }
- if (index < 1) {
- throw new IllegalArgumentException("index must begin with 1");
- }
- rootPath.append(path + "[" + index + "]");
- return rootPath;
+ private 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 a {@link StringBuffer}
+ * @return the string
+ * @throws IllegalArgumentException if the path is null, blank or empty
*/
- private StringBuffer createPath( String path ) {
- if (StringUtils.isEmpty(path)) {
- throw new IllegalArgumentException("path has to be unique and not empty");
- }
- return new StringBuffer().append(path);
+ private String createPath( String path ) {
+ ArgCheck.isNotEmpty(path, "path");
+ return path;
}
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataUtil.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataUtil.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/JavaMetadataUtil.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -25,13 +25,14 @@
import java.io.InputStream;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.internal.compiler.util.Util;
+import org.jboss.dna.common.util.ArgCheck;
/**
* @author Serge Pagop
*/
public class JavaMetadataUtil {
/**
- * Get the length of the inputstream.
+ * Get the length of the input stream.
*
* @param stream - the <code>InputStream</code>
* @return the length of the stream.
@@ -46,7 +47,7 @@
*
* @param inputStream - the <code>FileInputStream</code>.
* @param length - the length of the java file.
- * @param encoding - the encoding of the sourece, if there is one.
+ * @param encoding - the encoding of the source, if there is one.
* @return the array character of the java source.
* @throws IOException - exceptional error can be thrown during the reading of the file.
*/
@@ -64,10 +65,11 @@
* @return a FQN of the name.
*/
public static String getName( Name name ) {
- if (name != null) {
- return name.getFullyQualifiedName();
- }
- final String message = "name cannot be null";
- throw new IllegalArgumentException(message);
+ ArgCheck.isNotNull(name, "name");
+ return name.getFullyQualifiedName();
}
+
+ // prevent construction
+ private JavaMetadataUtil() {
+ }
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/AnnotationMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/AnnotationMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/AnnotationMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -25,11 +25,12 @@
* @author Serge Pagop
*/
public abstract class AnnotationMetadata {
-
+
private String name;
/**
* Get the name of the modifier.
+ *
* @return name of the modifier.
*/
public String getName() {
@@ -42,5 +43,5 @@
public void setName( String name ) {
this.name = name;
}
-
+
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ClassMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ClassMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ClassMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,12 +21,9 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
-
/**
* @author Serge Pagop
*/
public class ClassMetadata extends TypeMetadata {
-
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/FieldMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/FieldMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/FieldMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -28,13 +28,13 @@
* @author Serge Pagop
*/
public class FieldMetadata {
-
+
/** The type of the field */
private String type;
-
+
/** The variables */
private List<Variable> variables = new ArrayList<Variable>();
-
+
private List<ModifierMetadata> modifierMetadatas = new ArrayList<ModifierMetadata>();
/**
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ImportOnDemandMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ImportOnDemandMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ImportOnDemandMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
/**
* @author Serge Pagop
*/
@@ -29,7 +28,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.jboss.dna.sequencer.java.metadata.ImportMetadata#isOnDemand()
*/
@Override
@@ -39,12 +38,12 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.jboss.dna.sequencer.java.metadata.ImportMetadata#isSingle()
*/
@Override
protected boolean isSingle() {
return false;
}
-
+
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MarkerAnnotationMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MarkerAnnotationMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MarkerAnnotationMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
/**
*
*/
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -30,11 +30,11 @@
public abstract class MethodMetadata {
private String name;
-
+
private FieldMetadata returnType;
public abstract boolean isContructor();
-
+
private List<ModifierMetadata> modifiers = new ArrayList<ModifierMetadata>();
private List<FieldMetadata> parameters = new ArrayList<FieldMetadata>();
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodTypeMemberMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodTypeMemberMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/MethodTypeMemberMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -28,7 +28,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.jboss.dna.sequencer.java.metadata.MethodMetadata#isContructor()
*/
@Override
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ModifierMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ModifierMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ModifierMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -25,5 +25,5 @@
*
*/
public class ModifierMetadata extends AnnotationMetadata {
-
+
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/NormalAnnotationMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/NormalAnnotationMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/NormalAnnotationMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,12 +21,11 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
/**
*
*/
public class NormalAnnotationMetadata extends AnnotationMetadata {
- private boolean normal;
+ private boolean normal;
/**
* @return normal
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ParameterizedFieldMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ParameterizedFieldMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ParameterizedFieldMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,11 +21,9 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
/**
* Field meta data for parameterized type.
*/
public class ParameterizedFieldMetadata extends ReferenceFieldMetadata {
-
}
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/ReferenceFieldMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
/**
* Field meta data for parameterized type.
*/
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleImportMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleImportMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleImportMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
/**
* Serge Pagop
*/
@@ -29,7 +28,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.jboss.dna.sequencer.java.metadata.ImportMetadata#isOnDemand()
*/
@Override
@@ -39,7 +38,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.jboss.dna.sequencer.java.metadata.ImportMetadata#isSingle()
*/
@Override
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleMemberAnnotationMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleMemberAnnotationMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/SingleMemberAnnotationMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.sequencer.java.metadata;
-
/**
*
*/
Modified: trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/TypeMetadata.java
===================================================================
--- trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/TypeMetadata.java 2008-08-18 21:38:58 UTC (rev 440)
+++ trunk/extensions/dna-sequencer-java/src/main/java/org/jboss/dna/sequencer/java/metadata/TypeMetadata.java 2008-08-19 12:05:11 UTC (rev 441)
@@ -81,7 +81,6 @@
}
/**
- *
* @return modifiers
*/
public List<ModifierMetadata> getModifiers() {
15 years, 10 months
DNA SVN: r440 - in trunk: dna-spi/src/main/java/org/jboss/dna/spi/cache and 11 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-18 17:38:58 -0400 (Mon, 18 Aug 2008)
New Revision: 440
Added:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlanTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlanTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MergePlanTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlanTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlanTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlanTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlanTest.java
trunk/extensions/dna-connector-federation/src/test/resources/log4j.properties
Removed:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/BasicFederatedNodeTest.java
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
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/FederationI18n.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/contribution/Contribution.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/EmptyContribution.java
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/FiveContributionMergePlan.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlan.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlan.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlan.java
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/ThreeContributionMergePlan.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlan.java
trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties
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/ProjectionTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Changed the signature of the BasicCachePolicy, which affected several tests and test classes. Also added quite a few more unit tests to the federation connector code.
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -96,7 +96,7 @@
configSourceName = "configSource";
Projection.Rule configProjectionRule = new Projection.PathRule(pathInRepository, pathInSource);
configProjection = new Projection(configSourceName, configProjectionRule);
- configRepository = new SimpleRepository("Configuration Repository");
+ configRepository = SimpleRepository.get("Configuration Repository");
configRepositorySource = new SimpleRepositorySource();
configRepositorySource.setRepositoryName(configRepository.getRepositoryName());
configRepositorySource.setName(configSourceName);
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/BasicCachePolicy.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -21,19 +21,24 @@
*/
package org.jboss.dna.spi.cache;
+import java.util.concurrent.TimeUnit;
+import org.jboss.dna.common.util.ArgCheck;
+
/**
* @author Randall Hauch
*/
public class BasicCachePolicy implements CachePolicy {
private static final long serialVersionUID = 1L;
- private long timeToLive;
+ private long timeToLiveInMillis = 0L;
public BasicCachePolicy() {
}
- public BasicCachePolicy( long timeToCache ) {
- this.timeToLive = timeToCache;
+ public BasicCachePolicy( long timeToCache,
+ TimeUnit unit ) {
+ ArgCheck.isNotNull(unit, "unit");
+ this.timeToLiveInMillis = TimeUnit.MILLISECONDS.convert(timeToCache, unit);
}
/**
@@ -42,18 +47,22 @@
* @see org.jboss.dna.spi.cache.CachePolicy#getTimeToLive()
*/
public long getTimeToLive() {
- return this.timeToLive;
+ return this.timeToLiveInMillis;
}
/**
+ * Set the time for values and information to live in the cache.
+ *
* @param timeToLive Sets timeToLive to the specified value.
+ * @param unit the unit in which the time to live value is defined
*/
- public void setTimeToLive( long timeToLive ) {
- this.timeToLive = timeToLive;
+ public void setTimeToLive( long timeToLive,
+ TimeUnit unit ) {
+ this.timeToLiveInMillis = TimeUnit.NANOSECONDS.convert(timeToLive, unit);
}
public boolean isEmpty() {
- return this.timeToLive == 0;
+ return this.timeToLiveInMillis == 0;
}
public CachePolicy getUnmodifiable() {
@@ -83,7 +92,7 @@
*/
@Override
public String toString() {
- return "{ TTL=" + this.timeToLive + " }";
+ return "{ TTL=" + this.timeToLiveInMillis + " ms }";
}
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -37,6 +37,7 @@
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.impl.BasicPath;
/**
* A very simple repository that maintains properties for nodes identified by a path, and computes the children based upon the set
@@ -57,7 +58,9 @@
private static final ConcurrentMap<String, SimpleRepository> repositoriesByName = new ConcurrentHashMap<String, SimpleRepository>();
public static SimpleRepository get( String name ) {
- return repositoriesByName.get(name);
+ SimpleRepository newRepository = new SimpleRepository(name);
+ SimpleRepository repository = repositoriesByName.putIfAbsent(name, newRepository);
+ return repository != null ? repository : newRepository;
}
public static void shutdownAll() {
@@ -73,9 +76,11 @@
public SimpleRepository( String repositoryName ) {
this.repositoryName = repositoryName;
- if (repositoriesByName.putIfAbsent(repositoryName, this) != null) {
- throw new IllegalArgumentException("Repository \"" + repositoryName + "\" already exists and may not be recreated");
- }
+ // if (repositoriesByName.putIfAbsent(repositoryName, this) != null) {
+ // throw new IllegalArgumentException("Repository \"" + repositoryName + "\" already exists and may not be recreated");
+ // }
+ // Create a root node ...
+ data.putIfAbsent(BasicPath.ROOT, new HashMap<Name, Property>());
}
/**
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-18 18:45:57 UTC (rev 439)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -59,6 +59,7 @@
private String repositoryName;
private String name;
private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
+ private CachePolicy defaultCachePolicy;
public SimpleRepositorySource() {
super();
@@ -113,6 +114,20 @@
}
/**
+ * @return defaultCachePolicy
+ */
+ public CachePolicy getDefaultCachePolicy() {
+ return defaultCachePolicy;
+ }
+
+ /**
+ * @param defaultCachePolicy Sets defaultCachePolicy to the specified value.
+ */
+ public void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
+ this.defaultCachePolicy = defaultCachePolicy;
+ }
+
+ /**
* {@inheritDoc}
*
* @see javax.naming.Referenceable#getReference()
@@ -174,21 +189,25 @@
*/
public RepositoryConnection getConnection() throws RepositorySourceException {
String reposName = this.getRepositoryName();
+ if (reposName == null) throw new RepositorySourceException("Invalid repository source: missing repository name");
SimpleRepository repository = SimpleRepository.get(reposName);
if (repository == null) {
throw new RepositorySourceException(this.getName(), "Unable to find repository \"" + reposName + "\"");
}
- return new Connection(repository);
+ return new Connection(repository, this.getDefaultCachePolicy());
}
protected class Connection implements RepositoryConnection {
private RepositorySourceListener listener;
private final SimpleRepository repository;
+ private final CachePolicy defaultCachePolicy;
- protected Connection( SimpleRepository repository ) {
+ protected Connection( SimpleRepository repository,
+ CachePolicy defaultCachePolicy ) {
assert repository != null;
this.repository = repository;
+ this.defaultCachePolicy = defaultCachePolicy;
}
/**
@@ -225,7 +244,7 @@
* @see org.jboss.dna.spi.connector.RepositoryConnection#getDefaultCachePolicy()
*/
public CachePolicy getDefaultCachePolicy() {
- return null;
+ return defaultCachePolicy;
}
/**
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-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -28,6 +28,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -823,7 +824,7 @@
BasicCachePolicy cachePolicy = new BasicCachePolicy();
Property timeToLiveProperty = getRepository.getPropertiesByName().get(nameFactory.create(CACHE_POLICY_TIME_TO_LIVE_CONFIG_PROPERTY_NAME));
if (timeToLiveProperty != null && !timeToLiveProperty.isEmpty()) {
- cachePolicy.setTimeToLive(longFactory.create(timeToLiveProperty.getValues().next()));
+ cachePolicy.setTimeToLive(longFactory.create(timeToLiveProperty.getValues().next()), TimeUnit.MILLISECONDS);
}
CachePolicy defaultCachePolicy = cachePolicy.isEmpty() ? null : cachePolicy.getUnmodifiable();
return new FederatedRepositoryConfig(repositoryName, cacheProjection, sourceProjections, defaultCachePolicy);
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -32,6 +32,8 @@
public static I18n requiredNodeDoesNotExistRelativeToNode;
public static I18n propertyIsRequired;
+ public static I18n nodeDoesNotExistAtPath;
+ public static I18n errorRemovingNodeFromCache;
public static I18n interruptedWhileUsingFederationConfigurationRepository;
public static I18n unableToFindFederatedRepositoryInJndi;
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-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -172,7 +172,7 @@
* Pattern that identifies the form:
*
* <pre>
- * repository_path [=> source_path [$ exception ]*]?
+ * repository_path => source_path [$ exception ]*
* </pre>
*
* where the following groups are captured on the first call to {@link Matcher#find()}:
@@ -212,6 +212,10 @@
if (!matcher.find()) return null;
String reposPathStr = matcher.group(1);
String sourcePathStr = matcher.group(2);
+ if (reposPathStr == null || sourcePathStr == null) return null;
+ reposPathStr = reposPathStr.trim();
+ sourcePathStr = sourcePathStr.trim();
+ if (reposPathStr.length() == 0 || sourcePathStr.length() == 0) return null;
PathFactory pathFactory = context.getValueFactories().getPathFactory();
Path repositoryPath = pathFactory.create(reposPathStr);
Path sourcePath = pathFactory.create(sourcePathStr);
@@ -315,6 +319,21 @@
}
/**
+ * Get the paths in the repository that serve as top-level nodes exposed by this projection.
+ *
+ * @param factory the path factory that can be used to create new paths; may not be null
+ * @return the set of top-level paths; never null
+ */
+ public Set<Path> getTopLevelPathsInRepository( PathFactory factory ) {
+ ArgCheck.isNotNull(factory, "factory");
+ Set<Path> paths = new HashSet<Path>();
+ for (Rule rule : getRules()) {
+ paths.addAll(rule.getTopLevelPathsInRepository(factory));
+ }
+ return paths;
+ }
+
+ /**
* Determine whether this project is a simple projection that only involves for any one repository path no more than a single
* source path.
*
@@ -415,7 +434,7 @@
}
/**
- * A rule used within a project do define how content within a source is project into the federated repository. This mapping
+ * A rule used within a project do define how content within a source is projected into the federated repository. This mapping
* is bi-directional, meaning it's possible to determine
* <ul>
* <li>the path in repository given a path in source; and</li>
@@ -426,7 +445,16 @@
*/
@Immutable
public static abstract class Rule implements Comparable<Rule> {
+
/**
+ * Get the paths in the repository that serve as top-level nodes exposed by this rule.
+ *
+ * @param factory the path factory that can be used to create new paths; may not be null
+ * @return the set of top-level paths; never null
+ */
+ public abstract Set<Path> getTopLevelPathsInRepository( PathFactory factory );
+
+ /**
* Get the path in source that is projected from the supplied repository path, or null if the supplied repository path is
* not projected into the source.
*
@@ -585,6 +613,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.federation.Projection.Rule#getTopLevelPathsInRepository(org.jboss.dna.spi.graph.PathFactory)
+ */
+ @Override
+ public Set<Path> getTopLevelPathsInRepository( PathFactory factory ) {
+ return Collections.singleton(getPathInRepository());
+ }
+
+ /**
+ * {@inheritDoc}
* <p>
* This method considers a path that is at or below the rule's {@link #getPathInSource() source path} to be included,
* except if there are {@link #getExceptionsToRule() exceptions} that explicitly disallow the path.
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -26,11 +26,13 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.impl.JodaDateTime;
/**
* The contribution of a source to the information for a single federated node. Users of this interface should treat contributions
@@ -287,6 +289,15 @@
}
/**
+ * Return whether this contribution is an empty contribution.
+ *
+ * @return true if this contribution is empty, or false otherwise
+ */
+ public boolean isEmpty() {
+ return false;
+ }
+
+ /**
* {@inheritDoc}
* <p>
* This implementation returns the hash code of the {@link #getSourceName() source name}, and is compatible with the
@@ -300,6 +311,51 @@
/**
* {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Contribution from \"");
+ sb.append(getSourceName());
+ if (isExpired(new JodaDateTime().toUtcTimeZone())) {
+ sb.append("\": expired ");
+ } else {
+ sb.append("\": expires ");
+ }
+ sb.append(getExpirationTimeInUtc().getString());
+ if (getPropertyCount() != 0) {
+ sb.append(" { ");
+ boolean first = true;
+ Iterator<Property> propIter = getProperties();
+ while (propIter.hasNext()) {
+ if (!first) sb.append(", ");
+ else first = false;
+ Property property = propIter.next();
+ sb.append(property.getName());
+ sb.append('=');
+ sb.append(StringUtil.readableString(property.getValuesAsArray()));
+ }
+ sb.append(" }");
+ }
+ if (getChildrenCount() != 0) {
+ sb.append("< ");
+ boolean first = true;
+ Iterator<Segment> childIter = getChildren();
+ while (childIter.hasNext()) {
+ if (!first) sb.append(", ");
+ else first = false;
+ Segment child = childIter.next();
+ sb.append(child);
+ }
+ sb.append(" >");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * {@inheritDoc}
* <p>
* This implementation only compares the {@link #getSourceName() source name}.
* </p>
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/EmptyContribution.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/EmptyContribution.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/EmptyContribution.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -68,8 +68,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.federation.contribution.Contribution#isEmpty()
*/
@Override
+ public boolean isEmpty() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean equals( Object obj ) {
if (obj == this) return true;
if (obj instanceof EmptyContribution) {
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-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -30,8 +30,11 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.connector.federation.FederationI18n;
import org.jboss.dna.connector.federation.Projection;
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.connector.federation.merge.FederatedNode;
@@ -47,7 +50,6 @@
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceException;
import org.jboss.dna.spi.graph.DateTime;
-import org.jboss.dna.spi.graph.DateTimeFactory;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
@@ -61,7 +63,6 @@
import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
import org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor;
import org.jboss.dna.spi.graph.commands.impl.BasicCreateNodeCommand;
-import org.jboss.dna.spi.graph.commands.impl.BasicGetChildrenCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
import org.jboss.dna.spi.graph.impl.BasicSingleValueProperty;
@@ -78,11 +79,12 @@
private final List<Projection> sourceProjections;
private final Set<String> sourceNames;
private final RepositoryConnectionFactory connectionFactory;
- private final MergeStrategy mergingStrategy;
+ private MergeStrategy mergingStrategy;
/** The set of all connections, including the cache connection */
private final Map<String, RepositoryConnection> connectionsBySourceName;
/** A direct reference to the cache connection */
private RepositoryConnection cacheConnection;
+ private Logger logger;
/**
* Create a command executor that federates (merges) the information from multiple sources described by the source
@@ -139,14 +141,52 @@
for (Projection projection : this.sourceProjections) {
this.sourceNames.add(projection.getSourceName());
}
- if (this.sourceProjections.size() == 1 && this.sourceProjections.get(0).isSimple()) {
- this.mergingStrategy = new OneContributionMergeStrategy();
+ setLogger(null);
+ setMergingStrategy(null);
+ }
+
+ /**
+ * @param logger Sets logger to the specified value.
+ */
+ public void setLogger( Logger logger ) {
+ this.logger = logger != null ? logger : Logger.getLogger(getClass());
+ }
+
+ /**
+ * @param mergingStrategy Sets mergingStrategy to the specified value.
+ */
+ public void setMergingStrategy( MergeStrategy mergingStrategy ) {
+ if (mergingStrategy != null) {
+ this.mergingStrategy = mergingStrategy;
} else {
- this.mergingStrategy = new StandardMergeStrategy(DnaLexicon.UUID);
+ if (this.sourceProjections.size() == 1 && this.sourceProjections.get(0).isSimple()) {
+ this.mergingStrategy = new OneContributionMergeStrategy();
+ } else {
+ this.mergingStrategy = new StandardMergeStrategy(DnaLexicon.UUID);
+ }
}
+ assert this.mergingStrategy != null;
}
/**
+ * Get an unmodifiable list of the immutable source projections.
+ *
+ * @return the set of projections used as sources; never null
+ */
+ public List<Projection> getSourceProjections() {
+ return Collections.unmodifiableList(sourceProjections);
+ }
+
+ /**
+ * Get the projection defining the cache.
+ *
+ * @return the cache projection
+ */
+ public Projection getCacheProjection() {
+ return cacheProjection;
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#close()
@@ -187,6 +227,10 @@
return connection;
}
+ protected Set<String> getOpenConnections() {
+ return connectionsBySourceName.keySet();
+ }
+
/**
* {@inheritDoc}
* <p>
@@ -199,6 +243,7 @@
@Override
public void execute( GetNodeCommand command ) throws RepositorySourceException, InterruptedException {
BasicGetNodeCommand nodeInfo = getNode(command.getPath());
+ if (nodeInfo.hasError()) return;
for (Property property : nodeInfo.getProperties()) {
command.setProperty(property);
}
@@ -215,6 +260,7 @@
@Override
public void execute( GetPropertiesCommand command ) throws RepositorySourceException, InterruptedException {
BasicGetNodeCommand nodeInfo = getNode(command.getPath());
+ if (nodeInfo.hasError()) return;
for (Property property : nodeInfo.getProperties()) {
command.setProperty(property);
}
@@ -228,6 +274,7 @@
@Override
public void execute( GetChildrenCommand command ) throws RepositorySourceException, InterruptedException {
BasicGetNodeCommand nodeInfo = getNode(command.getPath());
+ if (nodeInfo.hasError()) return;
for (Segment child : nodeInfo.getChildren()) {
command.addChild(child, nodeInfo.getChildIdentityProperties(child));
}
@@ -247,106 +294,191 @@
RepositoryConnection cacheConnection = getConnectionToCache();
BasicGetNodeCommand fromCache = new BasicGetNodeCommand(path);
cacheConnection.execute(context, fromCache);
+
+ // Look at the cache results from the cache for problems, or if found a plan in the cache look
+ // at the contributions. We'll be putting together the set of source names for which we need to
+ // get the contributions.
+ Set<String> sourceNames = null;
+ List<Contribution> contributions = new LinkedList<Contribution>();
+
if (fromCache.hasError()) {
- if (fromCache.getError() instanceof PathNotFoundException) {
- // The path was not found in the cache, so since we don't know whether the ancestors are federated
- // from multiple source nodes, we need to populate the cache starting with the lowest ancestor
- // that already exists in the cache.
- PathNotFoundException notFound = (PathNotFoundException)fromCache.getError();
- Path lowestExistingAncestor = notFound.getLowestAncestorThatDoesExist();
- Path ancestor = path.getAncestor();
+ Throwable error = fromCache.getError();
+ if (!(error instanceof PathNotFoundException)) return fromCache;
- if (!ancestor.equals(lowestExistingAncestor)) {
- // Create the commands that load the children (not properties) of the existing ancestor,
- // then the children (not properties) of the child next on the desired path, etc.,
- // down to (but excluding) the desired path.
- LinkedList<BasicGetChildrenCommand> loadChildrenCommands = new LinkedList<BasicGetChildrenCommand>();
- Path pathToLoad = path.getAncestor();
- while (!pathToLoad.equals(lowestExistingAncestor)) {
- BasicGetChildrenCommand command = new BasicGetChildrenCommand(pathToLoad);
- loadChildrenCommands.addFirst(command);
- pathToLoad = pathToLoad.getAncestor();
+ // The path was not found in the cache, so since we don't know whether the ancestors are federated
+ // from multiple source nodes, we need to populate the cache starting with the lowest ancestor
+ // that already exists in the cache.
+ PathNotFoundException notFound = (PathNotFoundException)fromCache.getError();
+ Path lowestExistingAncestor = notFound.getLowestAncestorThatDoesExist();
+ Path ancestor = path.getAncestor();
+
+ if (!ancestor.equals(lowestExistingAncestor)) {
+ // Load the nodes along the path below the existing ancestor, down to (but excluding) the desired path
+ Path pathToLoad = path.getAncestor();
+ while (!pathToLoad.equals(lowestExistingAncestor)) {
+ loadContributionsFromSources(pathToLoad, null, contributions); // sourceNames may be null or empty
+ FederatedNode mergedNode = createFederatedNode(pathToLoad, contributions, true);
+ if (mergedNode == null) {
+ // No source had a contribution ...
+ I18n msg = FederationI18n.nodeDoesNotExistAtPath;
+ fromCache.setError(new PathNotFoundException(path, ancestor, msg.text(path, ancestor)));
+ return fromCache;
}
- // Now execute these commands (one-by-one is fine, since this is an executor) ...
- for (BasicGetChildrenCommand command : loadChildrenCommands) {
- execute(command);
+ contributions.clear();
+ // Move to the next child along the path ...
+ pathToLoad = pathToLoad.getAncestor();
+ }
+ }
+ // At this point, all ancestors exist ...
+ } else {
+ // There is no error, so look for the merge plan ...
+ MergePlan mergePlan = getMergePlan(fromCache);
+ if (mergePlan != null) {
+ // We found the merge plan, so check whether it's still valid ...
+ final DateTime now = getCurrentTimeInUtc();
+ if (mergePlan.isExpired(now)) {
+ // It is still valid, so check whether any contribution is from a non-existant projection ...
+ for (Contribution contribution : mergePlan) {
+ if (!this.sourceNames.contains(contribution.getSourceName())) {
+ // TODO: Record that the cached contribution is from a source that is no longer in this repository
+ }
}
+ return fromCache;
}
- // Load the node from the sources ...
- FederatedNode mergedNode = loadFromSources(path);
+ // At least one of the contributions is expired, so go through the contributions and place
+ // the valid contributions in the 'contributions' list; any expired contribution
+ // needs to be loaded by adding the name to the 'sourceNames'
+ if (mergePlan.getContributionCount() > 0) {
+ sourceNames = new HashSet<String>(sourceNames);
+ for (Contribution contribution : mergePlan) {
+ if (!contribution.isExpired(now)) {
+ sourceNames.remove(contribution.getSourceName());
+ contributions.add(contribution);
+ }
+ }
+ }
+ }
+ }
- // Place the results into the cache ...
- updateCache(mergedNode);
+ // Get the contributions from the sources given their names ...
+ loadContributionsFromSources(path, sourceNames, contributions); // sourceNames may be null or empty
+ FederatedNode mergedNode = createFederatedNode(path, contributions, true);
+ if (mergedNode == null) {
+ // No source had a contribution ...
+ Path ancestor = path.getAncestor();
+ I18n msg = FederationI18n.nodeDoesNotExistAtPath;
+ fromCache.setError(new PathNotFoundException(path, ancestor, msg.text(path, ancestor)));
+ return fromCache;
+ }
+ return mergedNode;
+ }
- // Return the results ...
- return mergedNode;
+ protected FederatedNode createFederatedNode( Path path,
+ List<Contribution> contributions,
+ boolean updateCache ) throws RepositorySourceException, InterruptedException {
+
+ // If there are no contributions from any source ...
+ boolean foundNonEmptyContribution = false;
+ for (Contribution contribution : contributions) {
+ if (!contribution.isEmpty()) {
+ foundNonEmptyContribution = true;
+ break;
}
- return fromCache; // with an error
}
+ if (foundNonEmptyContribution) return null;
+ if (logger.isTraceEnabled()) {
+ logger.trace("Loaded {0} from sources, resulting in these contributions:", path);
+ int i = 0;
+ for (Contribution contribution : contributions) {
+ logger.trace(" {0} {1}", ++i, contribution);
+ }
+ }
- // The cache had the node information, so look for the merge plan ...
- MergePlan mergePlan = getMergePlan(fromCache);
- assert mergePlan != null;
- if (!isCurrent(path, mergePlan)) {
- // Some of the merge plan is out of date, so we need to read the information from those regions that are expired ...
- // MergePlan newMergePlan = new BasicMergePlan();
- // for (Projection projection : sourceProjections) {
- // // Does this region apply to the path ...
- // if (projection.appliesTo(path)) {
- // // Get any existing contribution ...
- // Contribution contribution = mergePlan.getContributionFrom(region.getSourceName());
- // if (contribution == null || contribution.isExpired(getCurrentTimeInUtc())) {
- // contribution = getContribution(contribution.getSourceName(), path);
- // }
- // newMergePlan.addContribution(contribution);
- // }
- // }
- // for ( Contribution contribution : mergePlan.getContributions() ) {
- // // Is the contribution still represented by a region?
- //
- // if ( contribution.isExpired(getCurrentTimeInUtc())) {
- // contribution = getContribution(contribution.getSourceName(),path);
- // }
- // newMergePlan.addContribution(contribution);
- // }
-
- // What about other (new) regions?
+ // Merge the results into a single set of results ...
+ FederatedNode mergedNode = new FederatedNode(path, UUID.randomUUID());
+ ExecutionContext context = getExecutionContext();
+ mergingStrategy.merge(mergedNode, contributions, context);
+ if (mergedNode.getCachePolicy() == null) {
+ mergedNode.setCachePolicy(defaultCachePolicy);
}
-
- return fromCache;
+ if (updateCache) {
+ // Place the results into the cache ...
+ updateCache(mergedNode);
+ }
+ // And return the results ...
+ return mergedNode;
}
/**
+ * Load the node at the supplied path from the sources with the supplied name, returning the information. This method always
+ * obtains the information from the sources and does not use or update the cache.
+ *
* @param path the path of the node that is to be loaded
- * @return the federated node containing information loaded from the sources
+ * @param sourceNames the names of the sources from which contributions are to be loaded; may be empty or null if all
+ * contributions from all sources are to be loaded
+ * @param contributions the list into which the contributions are to be placed
* @throws InterruptedException
* @throws RepositorySourceException
*/
- protected FederatedNode loadFromSources( Path path ) throws RepositorySourceException, InterruptedException {
+ protected void loadContributionsFromSources( Path path,
+ Set<String> sourceNames,
+ List<Contribution> contributions )
+ throws RepositorySourceException, InterruptedException {
// At this point, there is no merge plan, so read information from the sources ...
ExecutionContext context = getExecutionContext();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
- DateTimeFactory timeFactory = context.getValueFactories().getDateFactory();
- List<Contribution> contributions = new LinkedList<Contribution>();
for (Projection projection : this.sourceProjections) {
final String source = projection.getSourceName();
+ if (sourceNames != null && !sourceNames.contains(source)) continue;
final RepositoryConnection sourceConnection = getConnection(projection);
+ if (sourceConnection == null) continue; // No source exists by this name
try {
// Get the cached information ...
CachePolicy cachePolicy = sourceConnection.getDefaultCachePolicy();
if (cachePolicy == null) cachePolicy = this.defaultCachePolicy;
DateTime expirationTime = null;
if (cachePolicy != null) {
- expirationTime = timeFactory.create(getCurrentTimeInUtc(), cachePolicy.getTimeToLive());
+ expirationTime = getCurrentTimeInUtc().plus(cachePolicy.getTimeToLive(), TimeUnit.MILLISECONDS);
}
// Get the paths-in-source where we should fetch node contributions ...
Set<Path> pathsInSource = projection.getPathsInSource(path, pathFactory);
if (pathsInSource.isEmpty()) {
- // The source has no contributions ...
- contributions.add(Contribution.create(source, expirationTime));
+ // The source has no contributions, but see whether the project exists BELOW this path.
+ // We do this by getting the top-level repository paths of the projection, and then
+ // use those to figure out the children of the nodes.
+ Contribution contribution = null;
+ Set<Path> topLevelPaths = projection.getTopLevelPathsInRepository(pathFactory);
+ switch (topLevelPaths.size()) {
+ case 0:
+ break;
+ case 1: {
+ Path topLevelPath = topLevelPaths.iterator().next();
+ if (path.isAncestorOf(topLevelPath)) {
+ assert topLevelPath.size() > path.size();
+ Path.Segment child = topLevelPath.getSegment(path.size());
+ contribution = Contribution.create(source, path, expirationTime, null, child);
+ }
+ break;
+ }
+ default: {
+ Set<Path.Segment> children = new HashSet<Path.Segment>();
+ for (Path topLevelPath : topLevelPaths) {
+ if (path.isAncestorOf(topLevelPath)) {
+ assert topLevelPath.size() > path.size();
+ Path.Segment child = topLevelPath.getSegment(path.size());
+ children.add(child);
+ }
+ }
+ if (children.size() > 0) {
+ contribution = Contribution.create(source, path, expirationTime, null, children);
+ }
+ }
+ }
+ if (contribution == null) contribution = Contribution.create(source, expirationTime);
+ contributions.add(contribution);
} else {
- // There is at least one contribution ...
+ // There is at least one (real) contribution ...
// Get the contributions ...
final int numPaths = pathsInSource.size();
@@ -357,8 +489,8 @@
if (!fromSource.hasError()) {
Collection<Property> properties = fromSource.getProperties();
Collection<Segment> children = fromSource.getChildren();
- DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
- fromSource.getCachePolicy().getTimeToLive());
+ DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
+ TimeUnit.MILLISECONDS);
Contribution contribution = Contribution.create(source, pathInSource, expTime, properties, children);
contributions.add(contribution);
}
@@ -373,8 +505,8 @@
if (fromSource.hasError()) continue;
Collection<Property> properties = fromSource.getProperties();
Collection<Segment> children = fromSource.getChildren();
- DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
- fromSource.getCachePolicy().getTimeToLive());
+ DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
+ TimeUnit.MILLISECONDS);
Contribution contribution = Contribution.create(source,
fromSource.getPath(),
expTime,
@@ -388,15 +520,140 @@
sourceConnection.close();
}
}
- // Merge the results into a single set of results ...
- FederatedNode mergedNode = new FederatedNode(path, UUID.randomUUID());
- mergingStrategy.merge(mergedNode, contributions, context);
- if (mergedNode.getCachePolicy() == null) {
- mergedNode.setCachePolicy(defaultCachePolicy);
- }
- return mergedNode;
}
+ // /**
+ // * Load the node at the supplied path, returning the information. This method always obtains the information from the
+ // sources
+ // * and does not use or update the cache.
+ // *
+ // * @param path the path of the node that is to be loaded
+ // * @return the federated node containing information loaded from the sources, or null if none of the sources had a
+ // * contribution
+ // * @throws InterruptedException
+ // * @throws RepositorySourceException
+ // */
+ // protected FederatedNode loadFromSources( Path path ) throws RepositorySourceException, InterruptedException {
+ // // At this point, there is no merge plan, so read information from the sources ...
+ // ExecutionContext context = getExecutionContext();
+ // PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ // DateTimeFactory timeFactory = context.getValueFactories().getDateFactory();
+ // List<Contribution> contributions = new LinkedList<Contribution>();
+ // boolean foundContribution = false;
+ // for (Projection projection : this.sourceProjections) {
+ // final String source = projection.getSourceName();
+ // final RepositoryConnection sourceConnection = getConnection(projection);
+ // if (sourceConnection == null) continue; // No source exists by this name
+ // try {
+ // // Get the cached information ...
+ // CachePolicy cachePolicy = sourceConnection.getDefaultCachePolicy();
+ // if (cachePolicy == null) cachePolicy = this.defaultCachePolicy;
+ // DateTime expirationTime = null;
+ // if (cachePolicy != null) {
+ // expirationTime = getCurrentTimeInUtc().plus(cachePolicy.getTimeToLive(), TimeUnit.MILLISECONDS);
+ // }
+ // // Get the paths-in-source where we should fetch node contributions ...
+ // Set<Path> pathsInSource = projection.getPathsInSource(path, pathFactory);
+ // if (pathsInSource.isEmpty()) {
+ // // The source has no contributions, but see whether the project exists BELOW this path.
+ // // We do this by getting the top-level repository paths of the projection, and then
+ // // use those to figure out the children of the nodes.
+ // Contribution contribution = null;
+ // Set<Path> topLevelPaths = projection.getTopLevelPathsInRepository(pathFactory);
+ // switch (topLevelPaths.size()) {
+ // case 0:
+ // break;
+ // case 1: {
+ // Path topLevelPath = topLevelPaths.iterator().next();
+ // if (path.isAncestorOf(topLevelPath)) {
+ // assert topLevelPath.size() > path.size();
+ // Path.Segment child = topLevelPath.getSegment(path.size());
+ // contribution = Contribution.create(source, path, expirationTime, null, child);
+ // foundContribution = true;
+ // }
+ // break;
+ // }
+ // default: {
+ // Set<Path.Segment> children = new HashSet<Path.Segment>();
+ // for (Path topLevelPath : topLevelPaths) {
+ // if (path.isAncestorOf(topLevelPath)) {
+ // assert topLevelPath.size() > path.size();
+ // Path.Segment child = topLevelPath.getSegment(path.size());
+ // children.add(child);
+ // }
+ // }
+ // if (children.size() > 0) {
+ // contribution = Contribution.create(source, path, expirationTime, null, children);
+ // foundContribution = true;
+ // }
+ // }
+ // }
+ // if (contribution == null) contribution = Contribution.create(source, expirationTime);
+ // contributions.add(contribution);
+ // } else {
+ // // There is at least one (real) contribution ...
+ //
+ // // Get the contributions ...
+ // final int numPaths = pathsInSource.size();
+ // if (numPaths == 1) {
+ // Path pathInSource = pathsInSource.iterator().next();
+ // BasicGetNodeCommand fromSource = new BasicGetNodeCommand(pathInSource);
+ // sourceConnection.execute(getExecutionContext(), fromSource);
+ // if (!fromSource.hasError()) {
+ // Collection<Property> properties = fromSource.getProperties();
+ // Collection<Segment> children = fromSource.getChildren();
+ // DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
+ // fromSource.getCachePolicy().getTimeToLive());
+ // Contribution contribution = Contribution.create(source, pathInSource, expTime, properties, children);
+ // if (!contribution.isEmpty()) foundContribution = true;
+ // contributions.add(contribution);
+ // }
+ // } else {
+ // BasicGetNodeCommand[] fromSourceCommands = new BasicGetNodeCommand[numPaths];
+ // int i = 0;
+ // for (Path pathInSource : pathsInSource) {
+ // fromSourceCommands[i++] = new BasicGetNodeCommand(pathInSource);
+ // }
+ // sourceConnection.execute(context, fromSourceCommands);
+ // for (BasicGetNodeCommand fromSource : fromSourceCommands) {
+ // if (fromSource.hasError()) continue;
+ // Collection<Property> properties = fromSource.getProperties();
+ // Collection<Segment> children = fromSource.getChildren();
+ // DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
+ // fromSource.getCachePolicy().getTimeToLive());
+ // Contribution contribution = Contribution.create(source,
+ // fromSource.getPath(),
+ // expTime,
+ // properties,
+ // children);
+ // if (!contribution.isEmpty()) foundContribution = true;
+ // contributions.add(contribution);
+ // }
+ // }
+ // }
+ // } finally {
+ // sourceConnection.close();
+ // }
+ // }
+ // // If there are no contributions from any source ...
+ // if (!foundContribution) return null;
+ // if (logger.isTraceEnabled()) {
+ // logger.trace("Loaded {0} from sources, resulting in these contributions:", path);
+ // int i = 0;
+ // for (Contribution contribution : contributions) {
+ // logger.trace(" {0} {1}", ++i, contribution);
+ // }
+ // }
+ //
+ // // Merge the results into a single set of results ...
+ // FederatedNode mergedNode = new FederatedNode(path, UUID.randomUUID());
+ // mergingStrategy.merge(mergedNode, contributions, context);
+ // if (mergedNode.getCachePolicy() == null) {
+ // mergedNode.setCachePolicy(defaultCachePolicy);
+ // }
+ // return mergedNode;
+ // }
+ //
protected MergePlan getMergePlan( BasicGetNodeCommand command ) {
Property mergePlanProperty = command.getPropertiesByName().get(mergePlanPropertyName);
if (mergePlanProperty == null || mergePlanProperty.isEmpty()) {
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlan.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlan.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.connector.federation.contribution.Contribution;
/**
@@ -46,11 +47,11 @@
* @param contribution4 the fourth contribution for this merge plan
* @param contribution5 the fifth contribution for this merge plan
*/
- public FiveContributionMergePlan( Contribution contribution1,
- Contribution contribution2,
- Contribution contribution3,
- Contribution contribution4,
- Contribution contribution5 ) {
+ /*package*/FiveContributionMergePlan( Contribution contribution1,
+ Contribution contribution2,
+ Contribution contribution3,
+ Contribution contribution4,
+ Contribution contribution5 ) {
assert contribution1 != null;
assert contribution2 != null;
assert contribution3 != null;
@@ -61,6 +62,7 @@
this.contribution3 = contribution3;
this.contribution4 = contribution4;
this.contribution5 = contribution5;
+ assert checkEachContributionIsFromDistinctSource();
}
/**
@@ -95,7 +97,7 @@
*/
public Iterator<Contribution> iterator() {
return new Iterator<Contribution>() {
- private int next = 4;
+ private int next = 5;
public boolean hasNext() {
return next > 0;
@@ -147,4 +149,14 @@
return false;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return HashCode.compute(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlan.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlan.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.connector.federation.contribution.Contribution;
/**
@@ -44,10 +45,10 @@
* @param contribution3 the third contribution for this merge plan
* @param contribution4 the fourth contribution for this merge plan
*/
- public FourContributionMergePlan( Contribution contribution1,
- Contribution contribution2,
- Contribution contribution3,
- Contribution contribution4 ) {
+ /*package*/FourContributionMergePlan( Contribution contribution1,
+ Contribution contribution2,
+ Contribution contribution3,
+ Contribution contribution4 ) {
assert contribution1 != null;
assert contribution2 != null;
assert contribution3 != null;
@@ -56,6 +57,7 @@
this.contribution2 = contribution2;
this.contribution3 = contribution3;
this.contribution4 = contribution4;
+ assert checkEachContributionIsFromDistinctSource();
}
/**
@@ -136,4 +138,14 @@
return false;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return HashCode.compute(contribution1, contribution2, contribution3, contribution4);
+ }
+
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -24,11 +24,19 @@
import java.io.InvalidClassException;
import java.io.Serializable;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.CommonI18n;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.connector.federation.contribution.EmptyContribution;
import org.jboss.dna.spi.graph.DateTime;
@@ -54,6 +62,8 @@
public static MergePlan create( Contribution... contributions ) {
ArgCheck.isNotNull(contributions, "contributions");
switch (contributions.length) {
+ case 0:
+ throw new IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text("contributions"));
case 1:
return new OneContributionMergePlan(contributions[0]);
case 2:
@@ -74,6 +84,8 @@
ArgCheck.isNotNull(contributions, "contributions");
Iterator<Contribution> iter = contributions.iterator();
switch (contributions.size()) {
+ case 0:
+ throw new IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text("contributions"));
case 1:
return new OneContributionMergePlan(iter.next());
case 2:
@@ -91,10 +103,11 @@
public static MergePlan addContribution( MergePlan plan,
Contribution contribution ) {
+ ArgCheck.isNotNull(plan, "plan");
+ ArgCheck.isNotNull(contribution, "contribution");
if (plan instanceof MultipleContributionMergePlan) {
- MultipleContributionMergePlan multiPlan = (MultipleContributionMergePlan)plan;
- multiPlan.addContribution(contribution);
- return multiPlan;
+ ((MultipleContributionMergePlan)plan).addContribution(contribution);
+ return plan;
}
MergePlan newPlan = null;
if (plan instanceof OneContributionMergePlan) {
@@ -160,8 +173,10 @@
*/
private static final long serialVersionUID = 1L;
+ private final ReadWriteLock annotationLock = new ReentrantReadWriteLock();
+ private DateTime expirationTimeInUtc;
+ @GuardedBy( "annotationLock" )
private Map<Name, Property> annotations = null;
- private DateTime expirationTimeInUtc;
/**
* Create an empty merge plan
@@ -180,7 +195,7 @@
public boolean isExpired( DateTime utcTime ) {
assert utcTime != null;
assert utcTime.toUtcTimeZone().equals(utcTime); // check that it is passed UTC time
- return !expirationTimeInUtc.isAfter(utcTime);
+ return utcTime.isAfter(getExpirationTimeInUtc());
}
/**
@@ -190,6 +205,17 @@
* @return the expiration time in UTC, or null if there is no known expiration time
*/
public DateTime getExpirationTimeInUtc() {
+ if (expirationTimeInUtc == null) {
+ // This is computed regardless of a lock, since it's not expensive and idempotent
+ DateTime earliest = null;
+ for (Contribution contribution : this) {
+ DateTime contributionTime = contribution.getExpirationTimeInUtc();
+ if (earliest == null || (contributionTime != null && contributionTime.isBefore(earliest))) {
+ earliest = contributionTime;
+ }
+ }
+ expirationTimeInUtc = earliest;
+ }
return expirationTimeInUtc;
}
@@ -224,8 +250,13 @@
*/
public Property getAnnotation( Name name ) {
if (name == null) return null;
- if (this.annotations == null) return null;
- return this.annotations.get(name);
+ try {
+ annotationLock.readLock().lock();
+ if (this.annotations == null) return null;
+ return this.annotations.get(name);
+ } finally {
+ annotationLock.readLock().unlock();
+ }
}
/**
@@ -239,21 +270,131 @@
*/
public Property setAnnotation( Property annotation ) {
if (annotation == null) return null;
- if (this.annotations == null) {
- this.annotations = new HashMap<Name, Property>();
+ try {
+ annotationLock.writeLock().lock();
+ if (this.annotations == null) {
+ this.annotations = new HashMap<Name, Property>();
+ }
+ return this.annotations.put(annotation.getName(), annotation);
+ } finally {
+ annotationLock.writeLock().unlock();
}
- return this.annotations.put(annotation.getName(), annotation);
}
+ /**
+ * Get the number of annotations.
+ *
+ * @return the number of annotations
+ */
+ public int getAnnotationCount() {
+ try {
+ annotationLock.readLock().lock();
+ if (this.annotations == null) return 0;
+ return this.annotations.size();
+ } finally {
+ annotationLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Get the set of annotation {@link Name names}.
+ *
+ * @return the unmodifiable set of names, or an empty set if there are no annotations
+ */
+ public Set<Name> getAnnotationNames() {
+ try {
+ annotationLock.readLock().lock();
+ if (this.annotations == null) return Collections.emptySet();
+ return Collections.unmodifiableSet(this.annotations.keySet());
+ } finally {
+ annotationLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Set the annotations. This
+ *
+ * @param annotations
+ */
protected void setAnnotations( Map<Name, Property> annotations ) {
- this.annotations = annotations;
+ try {
+ annotationLock.writeLock().lock();
+ this.annotations = annotations == null || annotations.isEmpty() ? null : annotations;
+ } finally {
+ annotationLock.writeLock().unlock();
+ }
}
/**
- * @return annotations
+ * Get a copy of the annotations.
+ *
+ * @return a copy of annotations; never null
*/
- protected Map<Name, Property> getAnnotations() {
- return annotations;
+ public Map<Name, Property> getAnnotations() {
+ Map<Name, Property> result = null;
+ try {
+ annotationLock.writeLock().lock();
+ if (this.annotations != null && !this.annotations.isEmpty()) {
+ result = new HashMap<Name, Property>(this.annotations);
+ } else {
+ result = Collections.emptyMap();
+ }
+ } finally {
+ annotationLock.writeLock().unlock();
+ }
+ return result;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (Contribution contribution : this) {
+ if (!first) {
+ first = false;
+ sb.append(", ");
+ }
+ sb.append(contribution);
+ }
+ sb.append(StringUtil.readableString(getAnnotations()));
+ return sb.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof MergePlan) {
+ MergePlan that = (MergePlan)obj;
+ if (this.getContributionCount() != that.getContributionCount()) return false;
+ Iterator<Contribution> thisContribution = this.iterator();
+ Iterator<Contribution> thatContribution = that.iterator();
+ while (thisContribution.hasNext() && thatContribution.hasNext()) {
+ if (!thisContribution.next().equals(thatContribution.next())) return false;
+ }
+ if (this.getAnnotationCount() != that.getAnnotationCount()) return false;
+ if (!this.getAnnotations().equals(that.getAnnotations())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean checkEachContributionIsFromDistinctSource() {
+ Set<String> sourceNames = new HashSet<String>();
+ for (Contribution contribution : this) {
+ boolean added = sourceNames.add(contribution.getSourceName());
+ if (!added) return false;
+ }
+ return true;
+ }
+
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlan.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlan.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -34,43 +34,43 @@
public class MultipleContributionMergePlan extends MergePlan {
private static final long serialVersionUID = 1L;
- private final List<Contribution> contributions;
+ private final List<Contribution> contributions = new CopyOnWriteArrayList<Contribution>();
/**
* @param contributions the contributions for this merge plan
*/
- public MultipleContributionMergePlan( Contribution... contributions ) {
+ /*package*/MultipleContributionMergePlan( Contribution... contributions ) {
assert contributions != null;
- this.contributions = new CopyOnWriteArrayList<Contribution>();
for (int i = 0; i != contributions.length; ++i) {
assert contributions[i] != null;
this.contributions.add(contributions[i]);
}
+ assert checkEachContributionIsFromDistinctSource();
}
/**
* @param contributions the contributions for this merge plan
*/
- public MultipleContributionMergePlan( Iterable<Contribution> contributions ) {
+ /*package*/MultipleContributionMergePlan( Iterable<Contribution> contributions ) {
assert contributions != null;
- this.contributions = new CopyOnWriteArrayList<Contribution>();
for (Contribution contribution : contributions) {
assert contribution != null;
this.contributions.add(contribution);
}
+ assert checkEachContributionIsFromDistinctSource();
}
/**
* @param contributions the contributions for this merge plan
*/
- public MultipleContributionMergePlan( Iterator<Contribution> contributions ) {
+ /*package*/MultipleContributionMergePlan( Iterator<Contribution> contributions ) {
assert contributions != null;
- this.contributions = new CopyOnWriteArrayList<Contribution>();
while (contributions.hasNext()) {
Contribution contribution = contributions.next();
assert contribution != null;
this.contributions.add(contribution);
}
+ assert checkEachContributionIsFromDistinctSource();
}
/**
@@ -138,4 +138,14 @@
this.contributions.add(contribution);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return contributions.hashCode();
+ }
+
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlan.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlan.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -38,7 +38,7 @@
/**
* @param contribution the contribution for this merge plan
*/
- public OneContributionMergePlan( Contribution contribution ) {
+ /*package*/OneContributionMergePlan( Contribution contribution ) {
assert contribution != null;
this.contribution = contribution;
}
@@ -101,4 +101,14 @@
return contribution.getSourceName().equals(sourceName);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return contribution.hashCode();
+ }
+
}
Modified: 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-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -50,5 +50,8 @@
// Children whose identity properties are the same will be considered to be the same node ...
assert identityPropertyName != null;
+ // Create a merge plan with the contributions ...
+ MergePlan plan = MergePlan.create(contributions);
+ federatedNode.setMergePlan(plan);
}
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlan.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlan.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.connector.federation.contribution.Contribution;
/**
@@ -42,15 +43,16 @@
* @param contribution2 the second contribution for this merge plan
* @param contribution3 the third contribution for this merge plan
*/
- public ThreeContributionMergePlan( Contribution contribution1,
- Contribution contribution2,
- Contribution contribution3 ) {
+ /*package*/ThreeContributionMergePlan( Contribution contribution1,
+ Contribution contribution2,
+ Contribution contribution3 ) {
assert contribution1 != null;
assert contribution2 != null;
assert contribution3 != null;
this.contribution1 = contribution1;
this.contribution2 = contribution2;
this.contribution3 = contribution3;
+ assert checkEachContributionIsFromDistinctSource();
}
/**
@@ -125,4 +127,14 @@
return false;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return HashCode.compute(contribution1, contribution2, contribution3);
+ }
+
}
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlan.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlan.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.connector.federation.contribution.Contribution;
/**
@@ -40,12 +41,13 @@
* @param contribution1 the first contribution for this merge plan
* @param contribution2 the second contribution for this merge plan
*/
- public TwoContributionMergePlan( Contribution contribution1,
- Contribution contribution2 ) {
+ /*package*/TwoContributionMergePlan( Contribution contribution1,
+ Contribution contribution2 ) {
assert contribution1 != null;
assert contribution2 != null;
this.contribution1 = contribution1;
this.contribution2 = contribution2;
+ assert checkEachContributionIsFromDistinctSource();
}
/**
@@ -112,4 +114,14 @@
return contribution1.getSourceName().equals(sourceName) || contribution2.getSourceName().equals(sourceName);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return HashCode.compute(contribution1, contribution2);
+ }
+
}
Modified: trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties 2008-08-18 21:38:58 UTC (rev 440)
@@ -21,6 +21,8 @@
#
requiredNodeDoesNotExistRelativeToNode = The required node {0} does not exist relative to {1}
propertyIsRequired = The {0} property is required but has no value
+nodeDoesNotExistAtPath = No node exists at {0} (or below {1})
+errorRemovingNodeFromCache = Error while removing {0} from cache
interruptedWhileUsingFederationConfigurationRepository = Interrupted while using federation configuration repository "{0}"
unableToFindFederatedRepositoryInJndi = Unable to find a FederatedRepository instance in JNDI under "{1}" when creating connection to federated source "{0}"
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-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -109,7 +109,7 @@
source.setExecutionContextFactoryJndiName(executionContextFactoryJndiName);
source.setContext(jndiContext);
source.setSecurityDomain(securityDomain);
- configRepository = new SimpleRepository("Configuration Repository");
+ 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", "/ => /");
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionTest.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -22,6 +22,8 @@
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.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;
import static org.mockito.Mockito.stub;
@@ -227,4 +229,50 @@
Set<Path> pathsInRepository = projection.getPathsInRepository(pathInSource, pathFactory);
assertThat(pathsInRepository, hasItems(pathInRepository1, pathInRepository23));
}
+
+ @Test
+ public void shouldParsePathRuleFromDefinitionWithNonRootRepositoryPathAndNonRootSourcePath() {
+ Projection.Rule rule = Projection.parsePathRule("/a => /b", context);
+ assertThat(rule, is(instanceOf(Projection.PathRule.class)));
+ Projection.PathRule pathRule = (Projection.PathRule)rule;
+ assertThat(pathRule.getPathInRepository(), is(pathFactory.create("/a")));
+ assertThat(pathRule.getPathInSource(), is(pathFactory.create("/b")));
+ }
+
+ @Test
+ public void shouldParsePathRuleFromDefinitionWithRootRepositoryPathAndNonRootSourcePath() {
+ Projection.Rule rule = Projection.parsePathRule("/ => /b", context);
+ assertThat(rule, is(instanceOf(Projection.PathRule.class)));
+ Projection.PathRule pathRule = (Projection.PathRule)rule;
+ assertThat(pathRule.getPathInRepository(), is(pathFactory.createRootPath()));
+ assertThat(pathRule.getPathInSource(), is(pathFactory.create("/b")));
+ }
+
+ @Test
+ public void shouldParsePathRuleFromDefinitionWithNonRootRepositoryPathAndRootSourcePath() {
+ Projection.Rule rule = Projection.parsePathRule("/a => /", context);
+ assertThat(rule, is(instanceOf(Projection.PathRule.class)));
+ Projection.PathRule pathRule = (Projection.PathRule)rule;
+ assertThat(pathRule.getPathInRepository(), is(pathFactory.create("/a")));
+ assertThat(pathRule.getPathInSource(), is(pathFactory.createRootPath()));
+ }
+
+ @Test
+ public void shouldParsePathRuleFromDefinitionWithRootRepositoryPathAndRootSourcePath() {
+ Projection.Rule rule = Projection.parsePathRule("/ => /", context);
+ assertThat(rule, is(instanceOf(Projection.PathRule.class)));
+ Projection.PathRule pathRule = (Projection.PathRule)rule;
+ assertThat(pathRule.getPathInRepository(), is(pathFactory.createRootPath()));
+ assertThat(pathRule.getPathInSource(), is(pathFactory.createRootPath()));
+ }
+
+ @Test
+ public void shouldNotParsePathRuleFromDefinitionWithRootRepositoryPathAndNoSourcePath() {
+ assertThat(Projection.parsePathRule("/", context), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotParsePathRuleFromDefinitionWithNonRootRepositoryPathAndNoSourcePath() {
+ assertThat(Projection.parsePathRule("a/", context), is(nullValue()));
+ }
}
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -21,16 +21,481 @@
*/
package org.jboss.dna.connector.federation.executor;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.jboss.dna.common.collection.IsIteratorContaining.hasItems;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import org.jboss.dna.connector.federation.Projection;
+import org.jboss.dna.connector.federation.ProjectionParser;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.cache.BasicCachePolicy;
+import org.jboss.dna.spi.cache.CachePolicy;
+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.SimpleRepository;
+import org.jboss.dna.spi.connector.SimpleRepositorySource;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
/**
* @author Randall Hauch
*/
public class FederatingCommandExecutorTest {
+ private FederatingCommandExecutor executor;
+ private ExecutionContext context;
+ private PathFactory pathFactory;
+ private String sourceName;
+ private Projection cacheProjection;
+ private CachePolicy cachePolicy;
+ private List<Projection> sourceProjections;
+ private Projection.Rule[] cacheProjectionRules = new Projection.Rule[] {};
+ private SimpleRepositorySource cacheSource;
+ private SimpleRepositorySource source1;
+ private SimpleRepositorySource source2;
+ private SimpleRepositorySource source3;
+ @Mock
+ private RepositoryConnectionFactory connectionFactory;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ context = new BasicExecutionContext();
+ pathFactory = context.getValueFactories().getPathFactory();
+ sourceName = "Federated Source";
+ cachePolicy = new BasicCachePolicy(10L, TimeUnit.SECONDS);
+ cacheSource = new SimpleRepositorySource();
+ cacheSource.setName("Cache");
+ cacheSource.setRepositoryName("Cache Repository");
+ ProjectionParser ruleParser = ProjectionParser.getInstance();
+ cacheProjectionRules = ruleParser.rulesFromStrings(context, "/ => /cache/repo/A");
+ cacheProjection = new Projection(cacheSource.getName(), cacheProjectionRules);
+ source1 = new SimpleRepositorySource();
+ source2 = new SimpleRepositorySource();
+ source3 = new SimpleRepositorySource();
+ source1.setName("Source 1");
+ source2.setName("Source 2");
+ source3.setName("Source 3");
+ source1.setRepositoryName("Repository 1");
+ source2.setRepositoryName("Repository 2");
+ source3.setRepositoryName("Repository 3");
+ // Set up the cache policies ...
+ source1.setDefaultCachePolicy(new BasicCachePolicy(100, TimeUnit.SECONDS));
+ source2.setDefaultCachePolicy(new BasicCachePolicy(200, TimeUnit.SECONDS));
+ source3.setDefaultCachePolicy(new BasicCachePolicy(300, TimeUnit.SECONDS));
+ sourceProjections = new ArrayList<Projection>();
+ // Source 1 projects from '/source/one/a' into repository '/a'
+ // and from '/source/one/b' into repository '/b'
+ sourceProjections.add(new Projection(source1.getName(), ruleParser.rulesFromStrings(context,
+ "/a => /source/one/a",
+ "/b => /source/one/b")));
+ // Source 2 projects from '/source/two/a' into repository '/a'
+ sourceProjections.add(new Projection(source2.getName(), ruleParser.rulesFromStrings(context, "/a => /source/two/a")));
+ // Source 3 projects everything into repository at root
+ sourceProjections.add(new Projection(source3.getName(), ruleParser.rulesFromStrings(context, "/ => /")));
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ // stub(connectionFactory.createConnection(source1.getName())).toReturn(source1.getConnection());
+ doReturn(source1.getConnection()).when(connectionFactory).createConnection(source1.getName());
+ doReturn(source2.getConnection()).when(connectionFactory).createConnection(source2.getName());
+ doReturn(source3.getConnection()).when(connectionFactory).createConnection(source3.getName());
+ doReturn(cacheSource.getConnection()).when(connectionFactory).createConnection(cacheSource.getName());
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ SimpleRepository.shutdownAll();
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenExecutionContextIsNull() {
+ context = null;
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenSourceNameIsNull() {
+ sourceName = null;
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenSourceNameIsEmpty() {
+ sourceName = "";
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenSourceNameIsBlank() {
+ sourceName = " ";
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenConnectionFactoryIsNull() {
+ connectionFactory = null;
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ }
+
@Test
- public void shouldDoSomething() {
+ public void shouldNotFailWhenCacheProjectionIsNullAndCachePolicyIsNull() {
+ cachePolicy = null;
+ cacheProjection = null;
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ }
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCacheProjectionIsNullAndCachePolicyIsNotNull() {
+ cachePolicy = null;
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
}
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCacheProjectionIsProvidedToConstructorButCachePolicyIsNot() {
+ assertThat(cacheProjection, is(nullValue()));
+ cachePolicy = null;
+ executor = new FederatingCommandExecutor(context, sourceName, cacheProjection, cachePolicy, sourceProjections,
+ connectionFactory);
+ }
+
+ @Test
+ public void shouldHaveCurrentTimeInUtc() {
+ DateTime currentTimeInUtc = executor.getCurrentTimeInUtc();
+ assertThat(currentTimeInUtc, is(notNullValue()));
+ assertThat(currentTimeInUtc.toUtcTimeZone(), is(currentTimeInUtc));
+ }
+
+ @Test
+ public void shouldReturnSameExecutionContextSuppliedToConstructor() {
+ assertThat(executor.getExecutionContext(), is(sameInstance(context)));
+ }
+
+ @Test
+ public void shouldObtainCacheConnectionFromConnectionFactoryThenHoldOntoReference() throws Exception {
+ RepositoryConnection connection = mock(RepositoryConnection.class);
+ stub(connectionFactory.createConnection(cacheSource.getName())).toReturn(connection);
+ assertThat(executor.getConnectionToCache(), is(sameInstance(connection)));
+ verify(connectionFactory, times(1)).createConnection(cacheSource.getName());
+ // Call it again, and should not ask the factory ...
+ assertThat(executor.getConnectionToCache(), is(sameInstance(connection)));
+ verifyNoMoreInteractions(connectionFactory);
+ }
+
+ @Test
+ public void shouldObtainRepositoryConnectionFromConnectionFactoryThenHoldOntoReference() throws Exception {
+ String sourceName = "Some source";
+ Projection projection = mock(Projection.class);
+ stub(projection.getSourceName()).toReturn(sourceName);
+ RepositoryConnection connection = mock(RepositoryConnection.class);
+ stub(connectionFactory.createConnection(sourceName)).toReturn(connection);
+
+ assertThat(executor.getConnection(projection), is(sameInstance(connection)));
+ verify(connectionFactory, times(1)).createConnection(sourceName);
+ // Call it again, and should not ask the factory ...
+ assertThat(executor.getConnection(projection), is(sameInstance(connection)));
+ verifyNoMoreInteractions(connectionFactory);
+ }
+
+ @Test
+ public void shouldCloseHavingNotOpenedConnections() throws Exception {
+ assertThat(executor.getOpenConnections().isEmpty(), is(true));
+ executor.close();
+ assertThat(executor.getOpenConnections().isEmpty(), is(true));
+ verifyNoMoreInteractions(connectionFactory);
+ }
+
+ @Test
+ public void shouldCloseAllOpenConnectionsWhenClosingExecutor() throws Exception {
+ // Load the connections
+ assertThat(executor.getConnectionToCache(), is(notNullValue()));
+ for (Projection projection : executor.getSourceProjections()) {
+ assertThat(executor.getConnection(projection), is(notNullValue()));
+ }
+ verify(connectionFactory).createConnection(cacheSource.getName());
+ verify(connectionFactory).createConnection(source1.getName());
+ verify(connectionFactory).createConnection(source2.getName());
+ verify(connectionFactory).createConnection(source3.getName());
+ assertThat(executor.getOpenConnections().isEmpty(), is(false));
+ // Close the executor and verify all connections have been closed
+ executor.close();
+ assertThat(executor.getOpenConnections().isEmpty(), is(true));
+ verifyNoMoreInteractions(connectionFactory);
+ }
+
+ @Test
+ public void shouldLoadContributionsForRootNodeFromSources() throws Exception {
+ Path path = pathFactory.createRootPath();
+ List<Contribution> contributions = new LinkedList<Contribution>();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ assertThat(contributions.size(), is(3)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source1.getName()));
+ assertThat(contributions.get(1).getSourceName(), is(source2.getName()));
+ assertThat(contributions.get(2).getSourceName(), is(source3.getName()));
+
+ Path.Segment aSeg = pathFactory.createSegment("a");
+ Path.Segment bSeg = pathFactory.createSegment("b");
+ assertThat(contributions.get(0).getChildren(), hasItems(aSeg, bSeg));
+ assertThat(contributions.get(1).getChildren(), hasItems(aSeg));
+ assertThat(contributions.get(2).getChildrenCount(), is(0));
+ }
+
+ @Test
+ public void shouldLoadContributionsForNonRootNodeWithOneContributionFromSources() throws Exception {
+ // Set up the content of source 3
+ SimpleRepository repository3 = SimpleRepository.get(source3.getRepositoryName());
+ repository3.setProperty(context, "/x/y", "desc", "y escription");
+ repository3.setProperty(context, "/x/y/zA", "desc", "zA description");
+ repository3.setProperty(context, "/x/y/zB", "desc", "zB description");
+ repository3.setProperty(context, "/x/y/zC", "desc", "zC description");
+
+ Path path = pathFactory.create("/x/y"); // from source 3
+ List<Contribution> contributions = new LinkedList<Contribution>();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ assertThat(contributions.size(), is(3)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source1.getName()));
+ assertThat(contributions.get(1).getSourceName(), is(source2.getName()));
+ assertThat(contributions.get(2).getSourceName(), is(source3.getName()));
+
+ Path.Segment child1 = pathFactory.createSegment("zA");
+ Path.Segment child2 = pathFactory.createSegment("zB");
+ Path.Segment child3 = pathFactory.createSegment("zC");
+ assertThat(contributions.get(0).isEmpty(), is(true));
+ assertThat(contributions.get(1).isEmpty(), is(true));
+ assertThat(contributions.get(2).getChildren(), hasItems(child1, child2, child3));
+
+ path = pathFactory.create("/x"); // from source 3
+ contributions.clear();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ assertThat(contributions.size(), is(3)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source1.getName()));
+ assertThat(contributions.get(1).getSourceName(), is(source2.getName()));
+ assertThat(contributions.get(2).getSourceName(), is(source3.getName()));
+
+ child1 = pathFactory.createSegment("y");
+ assertThat(contributions.get(0).isEmpty(), is(true));
+ assertThat(contributions.get(1).isEmpty(), is(true));
+ assertThat(contributions.get(2).getChildren(), hasItems(child1));
+ }
+
+ @Test
+ public void shouldLoadNonRootNodeWithTwoContributionFromSources() throws Exception {
+ // Set up the content of source 1
+ SimpleRepository repository1 = SimpleRepository.get(source1.getRepositoryName());
+ repository1.setProperty(context, "/source/one/a", "desc", "source 1 node a escription");
+ repository1.setProperty(context, "/source/one/a/nA", "desc", "source 1 node nA description");
+ repository1.setProperty(context, "/source/one/a/nB", "desc", "source 1 node nB description");
+ repository1.setProperty(context, "/source/one/a/nC", "desc", "source 1 node nC description");
+ repository1.setProperty(context, "/source/one/b", "desc", "source 1 node b description");
+ repository1.setProperty(context, "/source/one/b/pA", "desc", "source 1 node pA description");
+ repository1.setProperty(context, "/source/one/b/pB", "desc", "source 1 node pB description");
+ repository1.setProperty(context, "/source/one/b/pC", "desc", "source 1 node pC description");
+ // Set up the content of source 2
+ SimpleRepository repository2 = SimpleRepository.get(source2.getRepositoryName());
+ repository2.setProperty(context, "/source/two/a", "desc", "source 2 node a escription");
+ repository2.setProperty(context, "/source/two/a/qA", "desc", "source 2 node qA description");
+ repository2.setProperty(context, "/source/two/a/qB", "desc", "source 2 node qB description");
+ repository2.setProperty(context, "/source/two/a/qC", "desc", "source 2 node qC description");
+ // Set up the content of source 3
+ SimpleRepository repository3 = SimpleRepository.get(source3.getRepositoryName());
+ repository3.setProperty(context, "/x/y", "desc", "y escription");
+ repository3.setProperty(context, "/x/y/zA", "desc", "zA description");
+ repository3.setProperty(context, "/x/y/zB", "desc", "zB description");
+ repository3.setProperty(context, "/x/y/zC", "desc", "zC description");
+ repository3.setProperty(context, "/b/by", "desc", "by escription");
+ repository3.setProperty(context, "/b/by/bzA", "desc", "bzA description");
+ repository3.setProperty(context, "/b/by/bzB", "desc", "bzB description");
+
+ Path path = pathFactory.create("/b"); // from source 2 and source 3
+ List<Contribution> contributions = new LinkedList<Contribution>();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ assertThat(contributions.size(), is(3)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source1.getName()));
+ assertThat(contributions.get(1).getSourceName(), is(source2.getName()));
+ assertThat(contributions.get(2).getSourceName(), is(source3.getName()));
+
+ Path.Segment child1 = pathFactory.createSegment("pA");
+ Path.Segment child2 = pathFactory.createSegment("pB");
+ Path.Segment child3 = pathFactory.createSegment("pC");
+ Path.Segment child4 = pathFactory.createSegment("by");
+ assertThat(contributions.get(0).getChildren(), hasItems(child1, child2, child3));
+ assertThat(contributions.get(1).isEmpty(), is(true));
+ assertThat(contributions.get(2).getChildren(), hasItems(child4));
+
+ path = pathFactory.create("/b/by"); // from source 3
+ contributions.clear();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ assertThat(contributions.size(), is(2)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source2.getName()));
+ assertThat(contributions.get(1).getSourceName(), is(source3.getName()));
+
+ child1 = pathFactory.createSegment("bzA");
+ child2 = pathFactory.createSegment("bzB");
+ assertThat(contributions.get(0).isEmpty(), is(true));
+ assertThat(contributions.get(1).getChildren(), hasItems(child1));
+ }
+
+ @Test
+ public void shouldLoadNonRootNodeWithThreeContributionFromSources() throws Exception {
+ // Set up the content of source 1
+ SimpleRepository repository1 = SimpleRepository.get(source1.getRepositoryName());
+ repository1.setProperty(context, "/source/one/a", "desc", "source 1 node a escription");
+ repository1.setProperty(context, "/source/one/a/nA", "desc", "source 1 node nA description");
+ repository1.setProperty(context, "/source/one/a/nB", "desc", "source 1 node nB description");
+ repository1.setProperty(context, "/source/one/a/nC", "desc", "source 1 node nC description");
+ repository1.setProperty(context, "/source/one/b", "desc", "source 1 node b description");
+ repository1.setProperty(context, "/source/one/b/pA", "desc", "source 1 node pA description");
+ repository1.setProperty(context, "/source/one/b/pB", "desc", "source 1 node pB description");
+ repository1.setProperty(context, "/source/one/b/pC", "desc", "source 1 node pC description");
+ // Set up the content of source 2
+ SimpleRepository repository2 = SimpleRepository.get(source2.getRepositoryName());
+ repository2.setProperty(context, "/source/two/a", "desc", "source 2 node a escription");
+ repository2.setProperty(context, "/source/two/a/qA", "desc", "source 2 node qA description");
+ repository2.setProperty(context, "/source/two/a/qB", "desc", "source 2 node qB description");
+ repository2.setProperty(context, "/source/two/a/qC", "desc", "source 2 node qC description");
+ // Set up the content of source 3
+ SimpleRepository repository3 = SimpleRepository.get(source3.getRepositoryName());
+ repository3.setProperty(context, "/x/y", "desc", "y escription");
+ repository3.setProperty(context, "/x/y/zA", "desc", "zA description");
+ repository3.setProperty(context, "/x/y/zB", "desc", "zB description");
+ repository3.setProperty(context, "/x/y/zC", "desc", "zC description");
+ repository3.setProperty(context, "/b/by", "desc", "by escription");
+ repository3.setProperty(context, "/b/by/bzA", "desc", "bzA description");
+ repository3.setProperty(context, "/b/by/bzB", "desc", "bzB description");
+ repository3.setProperty(context, "/a/ay", "desc", "by escription");
+ repository3.setProperty(context, "/a/ay/azA", "desc", "bzA description");
+ repository3.setProperty(context, "/a/ay/azB", "desc", "bzB description");
+
+ Path path = pathFactory.create("/a"); // from sources 1, 2 and 3
+ List<Contribution> contributions = new LinkedList<Contribution>();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ assertThat(contributions.size(), is(3)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source1.getName()));
+ assertThat(contributions.get(1).getSourceName(), is(source2.getName()));
+ assertThat(contributions.get(2).getSourceName(), is(source3.getName()));
+
+ Path.Segment child1 = pathFactory.createSegment("nA");
+ Path.Segment child2 = pathFactory.createSegment("nB");
+ Path.Segment child3 = pathFactory.createSegment("nC");
+ Path.Segment child4 = pathFactory.createSegment("qA");
+ Path.Segment child5 = pathFactory.createSegment("qB");
+ Path.Segment child6 = pathFactory.createSegment("qC");
+ Path.Segment child7 = pathFactory.createSegment("ay");
+ assertThat(contributions.get(0).getChildren(), hasItems(child1, child2, child3));
+ assertThat(contributions.get(1).getChildren(), hasItems(child4, child5, child6));
+ assertThat(contributions.get(2).getChildren(), hasItems(child7));
+
+ path = pathFactory.create("/a/ay"); // from source 3
+ contributions.clear();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ assertThat(contributions.size(), is(1)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source3.getName()));
+ child1 = pathFactory.createSegment("azA");
+ child2 = pathFactory.createSegment("azB");
+ assertThat(contributions.get(0).getChildren(), hasItems(child1, child2));
+ }
+
+ @Test
+ public void shouldFailToLoadNodeFromSourcesWhenTheNodeDoesNotAppearInAnyOfTheSources() throws Exception {
+ Path nonExistant = pathFactory.create("/nonExistant/Node/In/AnySource");
+ List<Contribution> contributions = new LinkedList<Contribution>();
+ executor.loadContributionsFromSources(nonExistant, null, contributions);
+ // All of the contributions should be empty ...
+ for (Contribution contribution : contributions) {
+ assertThat(contribution.isEmpty(), is(true));
+ }
+ }
+
+ @Test
+ public void shouldComputeCachePolicyCorrectlyUsingCurrentTimeAndSourceDefaultCachePolicy() throws Exception {
+ // Set up the content of source 1
+ SimpleRepository repository1 = SimpleRepository.get(source1.getRepositoryName());
+ repository1.setProperty(context, "/source/one/a", "desc", "source 1 node a escription");
+ repository1.setProperty(context, "/source/one/a/nA", "desc", "source 1 node nA description");
+ repository1.setProperty(context, "/source/one/a/nB", "desc", "source 1 node nB description");
+ repository1.setProperty(context, "/source/one/a/nC", "desc", "source 1 node nC description");
+ repository1.setProperty(context, "/source/one/b", "desc", "source 1 node b description");
+ repository1.setProperty(context, "/source/one/b/pA", "desc", "source 1 node pA description");
+ repository1.setProperty(context, "/source/one/b/pB", "desc", "source 1 node pB description");
+ repository1.setProperty(context, "/source/one/b/pC", "desc", "source 1 node pC description");
+ // Set up the content of source 2
+ SimpleRepository repository2 = SimpleRepository.get(source2.getRepositoryName());
+ repository2.setProperty(context, "/source/two/a", "desc", "source 2 node a escription");
+ repository2.setProperty(context, "/source/two/a/qA", "desc", "source 2 node qA description");
+ repository2.setProperty(context, "/source/two/a/qB", "desc", "source 2 node qB description");
+ repository2.setProperty(context, "/source/two/a/qC", "desc", "source 2 node qC description");
+ // Set up the content of source 3
+ SimpleRepository repository3 = SimpleRepository.get(source3.getRepositoryName());
+ repository3.setProperty(context, "/x/y", "desc", "y escription");
+ repository3.setProperty(context, "/x/y/zA", "desc", "zA description");
+ repository3.setProperty(context, "/x/y/zB", "desc", "zB description");
+ repository3.setProperty(context, "/x/y/zC", "desc", "zC description");
+ repository3.setProperty(context, "/b/by", "desc", "by escription");
+ repository3.setProperty(context, "/b/by/bzA", "desc", "bzA description");
+ repository3.setProperty(context, "/b/by/bzB", "desc", "bzB description");
+ repository3.setProperty(context, "/a/ay", "desc", "by escription");
+ repository3.setProperty(context, "/a/ay/azA", "desc", "bzA description");
+ repository3.setProperty(context, "/a/ay/azB", "desc", "bzB description");
+
+ Path path = pathFactory.create("/a"); // from sources 1, 2 and 3
+ List<Contribution> contributions = new LinkedList<Contribution>();
+ executor.loadContributionsFromSources(path, null, contributions);
+
+ // Check when the contributions expire ...
+ DateTime nowInUtc = executor.getCurrentTimeInUtc();
+ DateTime nowPlus10InUtc = nowInUtc.plusSeconds(10);
+ DateTime nowPlus110InUtc = nowInUtc.plusSeconds(110);
+ DateTime nowPlus210InUtc = nowInUtc.plusSeconds(210);
+ DateTime nowPlus310InUtc = nowInUtc.plusSeconds(310);
+ assertThat(contributions.size(), is(3)); // order is based upon order of projections
+ assertThat(contributions.get(0).getSourceName(), is(source1.getName()));
+ assertThat(contributions.get(1).getSourceName(), is(source2.getName()));
+ assertThat(contributions.get(2).getSourceName(), is(source3.getName()));
+ assertThat(contributions.get(0).isExpired(nowPlus10InUtc), is(false));
+ assertThat(contributions.get(0).isExpired(nowPlus110InUtc), is(true));
+ assertThat(contributions.get(1).isExpired(nowPlus10InUtc), is(false));
+ assertThat(contributions.get(1).isExpired(nowPlus210InUtc), is(true));
+ assertThat(contributions.get(2).isExpired(nowPlus10InUtc), is(false));
+ assertThat(contributions.get(2).isExpired(nowPlus210InUtc), is(false));
+ assertThat(contributions.get(2).isExpired(nowPlus310InUtc), is(true));
+ }
+
+ @Test
+ public void shouldGetNodeUsingPath() {
+
+ }
+
}
Deleted: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/BasicFederatedNodeTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/BasicFederatedNodeTest.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/BasicFederatedNodeTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -1,41 +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 org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Randall Hauch
- */
-public class BasicFederatedNodeTest {
-
- @Before
- public void beforeEach() {
- }
-
- @Test
- public void shouldDoSomething() {
-
- }
-
-}
Copied: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java (from rev 420, trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/BasicFederatedNodeTest.java)
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FederatedNodeTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,41 @@
+/*
+ * 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 org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class FederatedNodeTest {
+
+ @Before
+ public void beforeEach() {
+ }
+
+ @Test
+ public void shouldDoSomething() {
+
+ }
+
+}
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlanTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlanTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlanTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,133 @@
+/*
+ * 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.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.stub;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class FiveContributionMergePlanTest {
+
+ private FiveContributionMergePlan plan;
+ @Mock
+ private Contribution contribution1;
+ @Mock
+ private Contribution contribution2;
+ @Mock
+ private Contribution contribution3;
+ @Mock
+ private Contribution contribution4;
+ @Mock
+ private Contribution contribution5;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ stub(contribution1.getSourceName()).toReturn("source1");
+ stub(contribution2.getSourceName()).toReturn("source2");
+ stub(contribution3.getSourceName()).toReturn("source3");
+ stub(contribution4.getSourceName()).toReturn("source4");
+ stub(contribution5.getSourceName()).toReturn("source5");
+ plan = new FiveContributionMergePlan(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFirstContribution() {
+ contribution1 = null;
+ plan = new FiveContributionMergePlan(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullSecondContribution() {
+ contribution2 = null;
+ plan = new FiveContributionMergePlan(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullThirdContribution() {
+ contribution3 = null;
+ plan = new FiveContributionMergePlan(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFourthContribution() {
+ contribution4 = null;
+ plan = new FiveContributionMergePlan(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFifthContribution() {
+ contribution5 = null;
+ plan = new FiveContributionMergePlan(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithMultipleContributionsFromTheSameSource() {
+ stub(contribution5.getSourceName()).toReturn("source1");
+ plan = new FiveContributionMergePlan(contribution1, contribution2, contribution3, contribution4, contribution5);
+ }
+
+ @Test
+ public void shouldReturnIteratorOverContributions() {
+ assertThat(plan, hasItems(contribution1, contribution2, contribution3, contribution4, contribution5));
+ }
+
+ @Test
+ public void shouldHaveContributionCountOfFive() {
+ assertThat(plan.getContributionCount(), is(5));
+ }
+
+ @Test
+ public void shouldReturnContributionWhenSuppliedNameMatchesContributionsSourceName() {
+ assertThat(plan.getContributionFrom(contribution1.getSourceName()), is(sameInstance(contribution1)));
+ assertThat(plan.getContributionFrom(contribution2.getSourceName()), is(sameInstance(contribution2)));
+ assertThat(plan.getContributionFrom(contribution3.getSourceName()), is(sameInstance(contribution3)));
+ assertThat(plan.getContributionFrom(contribution4.getSourceName()), is(sameInstance(contribution4)));
+ assertThat(plan.getContributionFrom(contribution5.getSourceName()), is(sameInstance(contribution5)));
+ }
+
+ @Test
+ public void shouldReturnNullContributionWhenSuppliedNameDoesNotMatchContributionsSourceName() {
+ assertThat(plan.getContributionFrom("other source"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldCompareSourceNameOfContributionsWhenCallingIsSource() {
+ assertThat(plan.isSource(contribution1.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution2.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution3.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution4.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution5.getSourceName()), is(true));
+ assertThat(plan.isSource("other source"), is(false));
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FiveContributionMergePlanTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlanTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlanTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlanTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,121 @@
+/*
+ * 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.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.stub;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class FourContributionMergePlanTest {
+
+ private FourContributionMergePlan plan;
+ @Mock
+ private Contribution contribution1;
+ @Mock
+ private Contribution contribution2;
+ @Mock
+ private Contribution contribution3;
+ @Mock
+ private Contribution contribution4;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ stub(contribution1.getSourceName()).toReturn("source1");
+ stub(contribution2.getSourceName()).toReturn("source2");
+ stub(contribution3.getSourceName()).toReturn("source3");
+ stub(contribution4.getSourceName()).toReturn("source4");
+ plan = new FourContributionMergePlan(contribution1, contribution2, contribution3, contribution4);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFirstContribution() {
+ contribution1 = null;
+ plan = new FourContributionMergePlan(contribution1, contribution2, contribution3, contribution4);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullSecondContribution() {
+ contribution2 = null;
+ plan = new FourContributionMergePlan(contribution1, contribution2, contribution3, contribution4);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullThirdContribution() {
+ contribution3 = null;
+ plan = new FourContributionMergePlan(contribution1, contribution2, contribution3, contribution4);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFourthContribution() {
+ contribution4 = null;
+ plan = new FourContributionMergePlan(contribution1, contribution2, contribution3, contribution4);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithMultipleContributionsFromTheSameSource() {
+ plan = new FourContributionMergePlan(contribution1, contribution1, contribution3, contribution4);
+ }
+
+ @Test
+ public void shouldReturnIteratorOverContributions() {
+ assertThat(plan, hasItems(contribution1, contribution2, contribution3, contribution4));
+ }
+
+ @Test
+ public void shouldHaveContributionCountOfFour() {
+ assertThat(plan.getContributionCount(), is(4));
+ }
+
+ @Test
+ public void shouldReturnContributionWhenSuppliedNameMatchesContributionsSourceName() {
+ assertThat(plan.getContributionFrom(contribution1.getSourceName()), is(sameInstance(contribution1)));
+ assertThat(plan.getContributionFrom(contribution2.getSourceName()), is(sameInstance(contribution2)));
+ assertThat(plan.getContributionFrom(contribution3.getSourceName()), is(sameInstance(contribution3)));
+ assertThat(plan.getContributionFrom(contribution4.getSourceName()), is(sameInstance(contribution4)));
+ }
+
+ @Test
+ public void shouldReturnNullContributionWhenSuppliedNameDoesNotMatchContributionsSourceName() {
+ assertThat(plan.getContributionFrom("other source"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldCompareSourceNameOfContributionsWhenCallingIsSource() {
+ assertThat(plan.isSource(contribution1.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution2.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution3.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution4.getSourceName()), is(true));
+ assertThat(plan.isSource("other source"), is(false));
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/FourContributionMergePlanTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MergePlanTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MergePlanTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MergePlanTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,330 @@
+/*
+ * 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.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.impl.BasicEmptyProperty;
+import org.jboss.dna.spi.graph.impl.BasicName;
+import org.jboss.dna.spi.graph.impl.JodaDateTime;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class MergePlanTest {
+
+ private MergePlan plan;
+ private List<Contribution> contributions;
+
+ @Before
+ public void beforeEach() throws Exception {
+ contributions = new ArrayList<Contribution>();
+ }
+
+ protected void addContributions( int number ) {
+ for (int i = 0; i != number; ++i) {
+ Contribution contribution = mock(Contribution.class);
+ stub(contribution.getSourceName()).toReturn("source " + i);
+ contributions.add(contribution);
+ }
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldFailToCreateMergePlanFromArrayWithNoContributions() {
+ MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromArrayWithOneContribution() {
+ addContributions(1);
+ plan = MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(OneContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(1));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromArrayWithTwoContributions() {
+ addContributions(2);
+ plan = MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(TwoContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(2));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromArrayWithThreeContributions() {
+ addContributions(3);
+ plan = MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(ThreeContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(3));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromArrayWithFourContributions() {
+ addContributions(4);
+ plan = MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(FourContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(4));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromArrayWithFiveContributions() {
+ addContributions(5);
+ plan = MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(FiveContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(5));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromArrayWithSixContributions() {
+ addContributions(6);
+ plan = MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(MultipleContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(6));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromArrayWithManyContributions() {
+ addContributions(100);
+ plan = MergePlan.create(contributions.toArray(new Contribution[contributions.size()]));
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(MultipleContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(100));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldFailToCreateMergePlanFromListWithNoContributions() {
+ MergePlan.create(contributions);
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromListWithOneContribution() {
+ addContributions(1);
+ plan = MergePlan.create(contributions);
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(OneContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(1));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromListWithTwoContributions() {
+ addContributions(2);
+ plan = MergePlan.create(contributions);
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(TwoContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(2));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromListWithThreeContributions() {
+ addContributions(3);
+ plan = MergePlan.create(contributions);
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(ThreeContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(3));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromListWithFourContributions() {
+ addContributions(4);
+ plan = MergePlan.create(contributions);
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(FourContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(4));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromListWithFiveContributions() {
+ addContributions(5);
+ plan = MergePlan.create(contributions);
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(FiveContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(5));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromListWithSixContributions() {
+ addContributions(6);
+ plan = MergePlan.create(contributions);
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(MultipleContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(6));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldCreateMergePlanFromListWithManyContributions() {
+ addContributions(100);
+ plan = MergePlan.create(contributions);
+ assertThat(plan, is(instanceOf(MergePlan.class)));
+ assertThat(plan, is(instanceOf(MultipleContributionMergePlan.class)));
+ assertThat(plan.getContributionCount(), is(100));
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldComputeOnlyOnceTheExpirationTimeFromTheContributions() {
+ DateTime nowInUtc = new JodaDateTime().toUtcTimeZone();
+ DateTime nowPlus100InUtc = nowInUtc.plusSeconds(100);
+ DateTime nowPlus200InUtc = nowInUtc.plusSeconds(200);
+
+ addContributions(2);
+ stub(contributions.get(0).getExpirationTimeInUtc()).toReturn(nowPlus100InUtc);
+ stub(contributions.get(1).getExpirationTimeInUtc()).toReturn(nowPlus200InUtc);
+
+ plan = MergePlan.create(contributions);
+ DateTime expires = plan.getExpirationTimeInUtc();
+ assertThat(expires, is(nowPlus100InUtc));
+ verify(contributions.get(0), times(1)).getSourceName();
+ verify(contributions.get(1), times(1)).getSourceName();
+ verify(contributions.get(0), times(1)).getExpirationTimeInUtc();
+ verify(contributions.get(1), times(1)).getExpirationTimeInUtc();
+
+ DateTime expires2 = plan.getExpirationTimeInUtc();
+ assertThat(expires2, is(nowPlus100InUtc));
+ verifyNoMoreInteractions(contributions.get(0));
+ verifyNoMoreInteractions(contributions.get(1));
+ }
+
+ @Test
+ public void shouldDetermineIfExpired() {
+ DateTime nowInUtc = new JodaDateTime().toUtcTimeZone();
+ DateTime nowPlus100InUtc = nowInUtc.plusSeconds(100);
+ DateTime nowPlus200InUtc = nowInUtc.plusSeconds(200);
+ DateTime nowPlus300InUtc = nowInUtc.plusSeconds(300);
+
+ addContributions(2);
+ stub(contributions.get(0).getExpirationTimeInUtc()).toReturn(nowPlus100InUtc);
+ stub(contributions.get(1).getExpirationTimeInUtc()).toReturn(nowPlus200InUtc);
+
+ plan = MergePlan.create(contributions);
+ DateTime expires = plan.getExpirationTimeInUtc();
+ assertThat(expires, is(nowPlus100InUtc));
+ verify(contributions.get(0), times(1)).getExpirationTimeInUtc();
+ verify(contributions.get(1), times(1)).getExpirationTimeInUtc();
+ assertThat(plan.isExpired(nowInUtc), is(false));
+ assertThat(plan.isExpired(nowPlus100InUtc), is(false));
+ assertThat(plan.isExpired(nowPlus200InUtc), is(true));
+ assertThat(plan.isExpired(nowPlus300InUtc), is(true));
+ }
+
+ @Test
+ public void shouldHaveNoAnnotationsUponConstruction() {
+ addContributions(2);
+ plan = MergePlan.create(contributions);
+ assertThat(plan.getAnnotationCount(), is(0));
+ }
+
+ @Test
+ public void shouldAllowSettingAnnotationAndShouldReturnNullWhenSettingNullAnnotation() {
+ addContributions(2);
+ plan = MergePlan.create(contributions);
+ assertThat(plan.setAnnotation(null), is(nullValue()));
+ }
+
+ @Test
+ public void shouldAllowSettingAnnotationAndShouldReturnPreviousPropertyWhenSettingAnnotation() {
+ Property property = new BasicEmptyProperty(new BasicName("uri", "name"));
+ Property property2 = new BasicEmptyProperty(property.getName());
+
+ addContributions(2);
+ plan = MergePlan.create(contributions);
+ assertThat(plan.setAnnotation(property), is(nullValue()));
+ assertThat(plan.setAnnotation(property2), is(property));
+ }
+
+ @SuppressWarnings( "unchecked" )
+ @Test
+ public void shouldSetAnnotationsMapToNullIfPassedNullOrEmptyMap() {
+ addContributions(2);
+ plan = MergePlan.create(contributions);
+ plan.setAnnotations(null);
+ assertThat(plan.getAnnotationCount(), is(0));
+
+ Map<Name, Property> newAnnotations = mock(Map.class);
+ plan.setAnnotations(newAnnotations);
+ assertThat(plan.getAnnotationCount(), is(0));
+ verify(newAnnotations).size();
+ }
+
+ @SuppressWarnings( "unchecked" )
+ @Test
+ public void shouldSetAnnotationsMapToSameInstancePassedIn() {
+ addContributions(2);
+ plan = MergePlan.create(contributions);
+ Map<Name, Property> newAnnotations = mock(Map.class);
+ stub(newAnnotations.size()).toReturn(3);
+ plan.setAnnotations(newAnnotations);
+ assertThat(plan.getAnnotationCount(), is(3));
+ verify(newAnnotations).size();
+ }
+
+ @Test
+ public void shouldReturnCopyOfAnnotationsMapFromGetAnnotations() {
+ Property property = new BasicEmptyProperty(new BasicName("uri", "name"));
+ Map<Name, Property> annotations = new HashMap<Name, Property>();
+ annotations.put(property.getName(), property);
+
+ addContributions(2);
+ plan = MergePlan.create(contributions);
+ plan.setAnnotations(annotations);
+ Map<Name, Property> annotationsCopy = plan.getAnnotations();
+ assertThat(annotationsCopy, is(not(sameInstance(annotations))));
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MergePlanTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlanTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlanTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlanTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,125 @@
+/*
+ * 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.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.LinkedList;
+import java.util.List;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class MultipleContributionMergePlanTest {
+
+ private MultipleContributionMergePlan plan;
+ private List<Contribution> contributions;
+
+ @Before
+ public void beforeEach() throws Exception {
+ contributions = new LinkedList<Contribution>();
+ addContributions(10);
+ plan = new MultipleContributionMergePlan(contributions);
+ }
+
+ protected void addContributions( int number ) {
+ for (int i = 0; i != number; ++i) {
+ Contribution contribution = mock(Contribution.class);
+ stub(contribution.getSourceName()).toReturn("source " + i);
+ contributions.add(contribution);
+ }
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFirstContribution() {
+ contributions.add(0, null);
+ plan = new MultipleContributionMergePlan(contributions);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullSecondContribution() {
+ contributions.add(1, null);
+ plan = new MultipleContributionMergePlan(contributions);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullThirdContribution() {
+ contributions.add(2, null);
+ plan = new MultipleContributionMergePlan(contributions);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFourthContribution() {
+ contributions.add(3, null);
+ plan = new MultipleContributionMergePlan(contributions);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFifthContribution() {
+ contributions.add(4, null);
+ plan = new MultipleContributionMergePlan(contributions);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithMultipleContributionsFromTheSameSource() {
+ contributions.add(contributions.get(0));
+ plan = new MultipleContributionMergePlan(contributions);
+ }
+
+ @Test
+ public void shouldReturnIteratorOverContributions() {
+ assertThat(plan, hasItems(contributions.toArray(new Contribution[contributions.size()])));
+ }
+
+ @Test
+ public void shouldHaveContributionCountOfFive() {
+ assertThat(plan.getContributionCount(), is(contributions.size()));
+ }
+
+ @Test
+ public void shouldReturnContributionWhenSuppliedNameMatchesContributionsSourceName() {
+ for (Contribution contribution : contributions) {
+ assertThat(plan.getContributionFrom(contribution.getSourceName()), is(sameInstance(contribution)));
+ }
+ }
+
+ @Test
+ public void shouldReturnNullContributionWhenSuppliedNameDoesNotMatchContributionsSourceName() {
+ assertThat(plan.getContributionFrom("other source"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldCompareSourceNameOfContributionsWhenCallingIsSource() {
+ for (Contribution contribution : contributions) {
+ assertThat(plan.isSource(contribution.getSourceName()), is(true));
+ }
+ assertThat(plan.isSource("other source"), is(false));
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/MultipleContributionMergePlanTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlanTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlanTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlanTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,88 @@
+/*
+ * 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.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+import static org.mockito.Mockito.stub;
+import java.util.Iterator;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class OneContributionMergePlanTest {
+
+ private OneContributionMergePlan plan;
+ @Mock
+ private Contribution contribution1;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ plan = new OneContributionMergePlan(contribution1);
+ stub(contribution1.getSourceName()).toReturn("source");
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFirstContribution() {
+ contribution1 = null;
+ plan = new OneContributionMergePlan(contribution1);
+ }
+
+ @Test
+ public void shouldReturnIteratorOverContributions() {
+ Iterator<Contribution> iter = plan.iterator();
+ assertThat(iter.hasNext(), is(true));
+ assertThat(iter.next(), is(sameInstance(contribution1)));
+ assertThat(iter.hasNext(), is(false));
+ assertThat(plan, hasItem(contribution1));
+ }
+
+ @Test
+ public void shouldHaveContributionCountOfOne() {
+ assertThat(plan.getContributionCount(), is(1));
+ }
+
+ @Test
+ public void shouldReturnContributionWhenSuppliedNameMatchesContributionsSourceName() {
+ assertThat(plan.getContributionFrom(contribution1.getSourceName()), is(sameInstance(contribution1)));
+ }
+
+ @Test
+ public void shouldReturnNullContributionWhenSuppliedNameDoesNotMatchContributionsSourceName() {
+ assertThat(plan.getContributionFrom("other source"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldCompareSourceNameOfContributionsWhenCallingIsSource() {
+ assertThat(plan.isSource(contribution1.getSourceName()), is(true));
+ assertThat(plan.isSource("other source"), is(false));
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergePlanTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlanTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlanTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlanTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,110 @@
+/*
+ * 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.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.stub;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class ThreeContributionMergePlanTest {
+
+ private ThreeContributionMergePlan plan;
+ @Mock
+ private Contribution contribution1;
+ @Mock
+ private Contribution contribution2;
+ @Mock
+ private Contribution contribution3;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ stub(contribution1.getSourceName()).toReturn("source1");
+ stub(contribution2.getSourceName()).toReturn("source2");
+ stub(contribution3.getSourceName()).toReturn("source3");
+ plan = new ThreeContributionMergePlan(contribution1, contribution2, contribution3);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFirstContribution() {
+ contribution1 = null;
+ plan = new ThreeContributionMergePlan(contribution1, contribution2, contribution3);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullSecondContribution() {
+ contribution2 = null;
+ plan = new ThreeContributionMergePlan(contribution1, contribution2, contribution3);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullThirdContribution() {
+ contribution3 = null;
+ plan = new ThreeContributionMergePlan(contribution1, contribution2, contribution3);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithMultipleContributionsFromTheSameSource() {
+ plan = new ThreeContributionMergePlan(contribution1, contribution2, contribution1);
+ }
+
+ @Test
+ public void shouldReturnIteratorOverContributions() {
+ assertThat(plan, hasItems(contribution1, contribution2, contribution3));
+ }
+
+ @Test
+ public void shouldHaveContributionCountOfThree() {
+ assertThat(plan.getContributionCount(), is(3));
+ }
+
+ @Test
+ public void shouldReturnContributionWhenSuppliedNameMatchesContributionsSourceName() {
+ assertThat(plan.getContributionFrom(contribution1.getSourceName()), is(sameInstance(contribution1)));
+ assertThat(plan.getContributionFrom(contribution2.getSourceName()), is(sameInstance(contribution2)));
+ assertThat(plan.getContributionFrom(contribution3.getSourceName()), is(sameInstance(contribution3)));
+ }
+
+ @Test
+ public void shouldReturnNullContributionWhenSuppliedNameDoesNotMatchContributionsSourceName() {
+ assertThat(plan.getContributionFrom("other source"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldCompareSourceNameOfContributionsWhenCallingIsSource() {
+ assertThat(plan.isSource(contribution1.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution2.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution3.getSourceName()), is(true));
+ assertThat(plan.isSource("other source"), is(false));
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/ThreeContributionMergePlanTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlanTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlanTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlanTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,99 @@
+/*
+ * 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.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.stub;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class TwoContributionMergePlanTest {
+
+ private TwoContributionMergePlan plan;
+ @Mock
+ private Contribution contribution1;
+ @Mock
+ private Contribution contribution2;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ stub(contribution1.getSourceName()).toReturn("source1");
+ stub(contribution2.getSourceName()).toReturn("source2");
+ plan = new TwoContributionMergePlan(contribution1, contribution2);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullFirstContribution() {
+ contribution1 = null;
+ plan = new TwoContributionMergePlan(contribution1, contribution2);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithNullSecondContribution() {
+ contribution2 = null;
+ plan = new TwoContributionMergePlan(contribution1, contribution2);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailWhenCreatingMergePlanWithMultipleContributionsFromTheSameSource() {
+ plan = new TwoContributionMergePlan(contribution1, contribution1);
+ }
+
+ @Test
+ public void shouldReturnIteratorOverContributions() {
+ assertThat(plan, hasItems(contribution1, contribution2));
+ }
+
+ @Test
+ public void shouldHaveContributionCountOfTwo() {
+ assertThat(plan.getContributionCount(), is(2));
+ }
+
+ @Test
+ public void shouldReturnContributionWhenSuppliedNameMatchesContributionsSourceName() {
+ assertThat(plan.getContributionFrom(contribution1.getSourceName()), is(sameInstance(contribution1)));
+ assertThat(plan.getContributionFrom(contribution2.getSourceName()), is(sameInstance(contribution2)));
+ }
+
+ @Test
+ public void shouldReturnNullContributionWhenSuppliedNameDoesNotMatchContributionsSourceName() {
+ assertThat(plan.getContributionFrom("other source"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldCompareSourceNameOfContributionsWhenCallingIsSource() {
+ assertThat(plan.isSource(contribution1.getSourceName()), is(true));
+ assertThat(plan.isSource(contribution2.getSourceName()), is(true));
+ assertThat(plan.isSource("other source"), is(false));
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/TwoContributionMergePlanTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-federation/src/test/resources/log4j.properties
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/resources/log4j.properties (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/resources/log4j.properties 2008-08-18 21:38:58 UTC (rev 440)
@@ -0,0 +1,17 @@
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n
+
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Set up the default logging to be INFO level, then override specific units
+log4j.logger.org.jboss.dna=INFO
+log4j.logger.org.jboss.dna.connector.federation.executor=TRACE
+
+# Jackrabbit logging
+log4j.logger.org.apache.jackrabbit=WARN, stdout
+log4j.logger.org.apache.derby=INFO, stdout
+
Property changes on: trunk/extensions/dna-connector-federation/src/test/resources/log4j.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
===================================================================
--- trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-18 18:45:57 UTC (rev 439)
+++ trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-18 21:38:58 UTC (rev 440)
@@ -32,6 +32,7 @@
import java.util.Hashtable;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
@@ -153,7 +154,7 @@
@Test
public void shouldCreateJndiReferenceAndRecreatedObjectFromReference() throws Exception {
BasicCachePolicy cachePolicy = new BasicCachePolicy();
- cachePolicy.setTimeToLive(1000L);
+ cachePolicy.setTimeToLive(1000L, TimeUnit.MILLISECONDS);
convertToAndFromJndiReference(validName,
validRootNodeUuid,
validCacheConfigurationName,
@@ -167,7 +168,7 @@
@Test
public void shouldCreateJndiReferenceAndRecreatedObjectFromReferenceWithNullProperties() throws Exception {
BasicCachePolicy cachePolicy = new BasicCachePolicy();
- cachePolicy.setTimeToLive(1000L);
+ cachePolicy.setTimeToLive(1000L, TimeUnit.MILLISECONDS);
convertToAndFromJndiReference("some source", null, null, null, null, null, null, 100);
convertToAndFromJndiReference(null, null, null, null, null, null, null, 100);
}
15 years, 10 months
DNA SVN: r439 - trunk/dna-common/src/test/java/org/jboss/dna/common.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-08-18 14:45:57 -0400 (Mon, 18 Aug 2008)
New Revision: 439
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java
Log:
DNA-207: Changed AbstractI18nTest to use the locale and problem methods from I18n.class rather than assuming each i18n class contains corresponding methods.
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java 2008-08-18 16:58:48 UTC (rev 438)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java 2008-08-18 18:45:57 UTC (rev 439)
@@ -25,7 +25,6 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Locale;
import java.util.Set;
@@ -44,7 +43,6 @@
}
@Test
- @SuppressWarnings( "unchecked" )
public void shouldNotHaveProblems() throws Exception {
for (Field fld : i18nClass.getDeclaredFields()) {
if (fld.getType() == I18n.class && (fld.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC
@@ -57,12 +55,10 @@
}
}
// Check for global problems after checking field problems since global problems are detected lazily upon field usage
- Method method = i18nClass.getDeclaredMethod("getLocalizationProblemLocales", (Class[])null);
- Set<Locale> locales = (Set<Locale>)method.invoke(null, (Object[])null);
+ Set<Locale> locales = I18n.getLocalizationProblemLocales(i18nClass);
if (!locales.isEmpty()) {
- method = i18nClass.getDeclaredMethod("getLocalizationProblems", Locale.class);
for (Locale locale : locales) {
- Set<String> problems = (Set<String>)method.invoke(null, locale);
+ Set<String> problems = I18n.getLocalizationProblems(i18nClass, locale);
try {
assertThat(problems.isEmpty(), is(true));
} catch (AssertionError error) {
15 years, 10 months