[dna-commits] DNA SVN: r683 - in trunk/extensions/dna-connector-svn/src: test/java/org/jboss/dna/connector/svn and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Dec 11 17:02:26 EST 2008


Author: spagop
Date: 2008-12-11 17:02:26 -0500 (Thu, 11 Dec 2008)
New Revision: 683

Modified:
   trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
   trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
Log:
more testing about node properties

Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java	2008-12-11 20:55:11 UTC (rev 682)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java	2008-12-11 22:02:26 UTC (rev 683)
@@ -28,6 +28,7 @@
 import java.util.Date;
 import java.util.List;
 import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.Logger;
 import org.jboss.dna.graph.ExecutionContext;
 import org.jboss.dna.graph.JcrLexicon;
 import org.jboss.dna.graph.JcrNtLexicon;
@@ -76,6 +77,7 @@
     private final String defaultNamespaceUri;
     private final boolean updatesAllowed;
     private SVNRepository repository;
+    protected final Logger logger;
 
     /**
      * @param sourceName
@@ -92,6 +94,7 @@
         this.defaultNamespaceUri = getExecutionContext().getNamespaceRegistry().getDefaultNamespaceUri();
         this.updatesAllowed = updatesAllowed;
         this.repository = repository;
+        this.logger = getExecutionContext().getLogger(getClass());
     }
 
     /**
@@ -142,6 +145,7 @@
     @SuppressWarnings( "unchecked" )
     @Override
     public void process( ReadAllChildrenRequest request ) {
+        logger.trace(request.toString());
         Location myLocation = request.of();
         Path nodePath = getPathFor(myLocation, request);
         try {
@@ -201,6 +205,7 @@
      */
     @Override
     public void process( ReadAllPropertiesRequest request ) {
+        logger.trace(request.toString());
         Location myLocation = request.at();
         Path nodePath = getPathFor(myLocation, request);
         if (nodePath.isRoot()) {
@@ -218,29 +223,26 @@
                 Path parent = nodePath.getParent();
                 ByteArrayOutputStream os = new ByteArrayOutputStream();
                 SVNProperties fileProperties = new SVNProperties();
-                List<Property> properties = new ArrayList<Property>();
                 getData(parent.getString(getExecutionContext().getNamespaceRegistry()), fileProperties, os);
                 Property ntResourceproperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE);
-                properties.add(ntResourceproperty);
+                request.addProperty(ntResourceproperty);
                 String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
                 if (mimeType != null) {
                     Property jcrMimeTypeProperty = propertyFactory().create(JcrLexicon.MIMETYPE, mimeType);
-                    properties.add(jcrMimeTypeProperty);
+                    request.addProperty(jcrMimeTypeProperty);
                 }
                 SVNDirEntry entry = getEntryInfo(parent.getString(getExecutionContext().getNamespaceRegistry()));
                 Date lastModified = entry.getDate();
                 if (lastModified != null) {
                     Property jcrLastModifiedProperty = propertyFactory().create(JcrLexicon.LAST_MODIFIED,
                                                                                 dateFactory().create(lastModified));
-                    properties.add(jcrLastModifiedProperty);
+                    request.addProperty(jcrLastModifiedProperty);
                 }
                 if (os.toByteArray().length > 0) {
                     Property jcrDataProperty = propertyFactory().create(JcrLexicon.DATA,
-                                                                        binaryFactory().create(new InMemoryBinary(
-                                                                                                                  os.toByteArray())));
-                    properties.add(jcrDataProperty);
+                                                                        binaryFactory().create(os.toByteArray()));
+                    request.addProperty(jcrDataProperty);
                 }
-                request.addProperties(properties.toArray(new BasicMultiValueProperty[0]));
             } else {
                 SVNNodeKind kind = validateNodeKind(nodePath);
                 if (kind == SVNNodeKind.FILE) {
@@ -259,10 +261,12 @@
                 } else if (kind == SVNNodeKind.DIR) {
                     // A directory maps to a single node with a name that represents the name of the directory and a
                     // "jcr:primaryType" property whose value is "nt:folder"
-                    Property property = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER);
-                    request.addProperty(property);
+                    Property jcrPrimaryTypeProp = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER);
+                    request.addProperty(jcrPrimaryTypeProp);
                     SVNDirEntry dirEntry = getEntryInfo(nodePath.getString(getExecutionContext().getNamespaceRegistry()));
-                    request.addProperty(propertyFactory().create(JcrLexicon.CREATED, dateFactory().create(dirEntry.getDate())));
+                    Property jcrCreatedProp = propertyFactory().create(JcrLexicon.CREATED,
+                                                                       dateFactory().create(dirEntry.getDate()));
+                    request.addProperty(jcrCreatedProp);
                 }
             }
             request.setActualLocationOfNode(myLocation);

Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java	2008-12-11 20:55:11 UTC (rev 682)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java	2008-12-11 22:02:26 UTC (rev 683)
@@ -26,10 +26,13 @@
 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 static org.mockito.Mockito.verify;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 import org.jboss.dna.common.text.UrlEncoder;
 import org.jboss.dna.common.util.FileUtil;
 import org.jboss.dna.graph.BasicExecutionContext;
@@ -44,6 +47,7 @@
 import org.jboss.dna.graph.properties.NameFactory;
 import org.jboss.dna.graph.properties.PathFactory;
 import org.jboss.dna.graph.properties.PathNotFoundException;
+import org.jboss.dna.graph.properties.Property;
 import org.jboss.dna.graph.properties.PropertyFactory;
 import org.jboss.dna.graph.requests.ReadAllChildrenRequest;
 import org.junit.After;
@@ -74,6 +78,7 @@
     @Mock
     private ReadAllChildrenRequest request;
 
+    @SuppressWarnings( "deprecation" )
     @Before
     public void beforeEach() throws Exception {
         MockitoAnnotations.initMocks(this);
@@ -96,7 +101,7 @@
 
         // Now set the two path roots
         String svnUrl = dst.getCanonicalFile().toURL().toString();
-        svnUrl = svnUrl.replaceFirst("file:/", "file:///"); // add the 'localhost'
+        svnUrl = svnUrl.replaceFirst("file:/", "file://localhost/");
         String username = "sp";
         String password = "";
         // Create a Repository instance from the http-protocol, that use a anonymous credential.
@@ -151,7 +156,7 @@
     // CachePolicy policy = mock(CachePolicy.class);
     // repository = mock(SVNRepository.class);
     // connection = new SVNRepositoryConnection("the source name", policy, false, repository);
-    // stub(repository.getRepositoryRoot(true)).toReturn(null);
+    // // stub(repository.getRepositoryRoot(true)).toReturn(null);
     // assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
     // verify(repository).getRepositoryRoot(true);
     // }
@@ -190,7 +195,7 @@
     }
 
     @Test
-    public void shouldListLocationForChildrenOfAParentPath() {
+    public void shouldListChildrenLocationPathsOfASpecificPath() {
 
         // read children from the root node.
         List<Location> l = graph.getChildren().of(pathFactory.create("/"));
@@ -208,6 +213,45 @@
         assertThat(containsPaths(locations03).contains("/nodeB/nodeB1"), is(true));
     }
 
+    @Test
+    public void shouldNotHaveProperties() {
+        // Root location does not need properties.
+        Location root = new Location(pathFactory.create("/"));
+        Collection<Property> nilProperties = graph.getProperties().on(root);
+        assertThat(nilProperties, is(notNullValue()));
+        assertThat(nilProperties.isEmpty(), is(true));
+    }
+
+    @Test
+    public void shouldJustCatchThePropertiesOnLocation() {
+        // directory nodeA has "jcr:primaryType" with value "nt:folder" and also "jcr:created" with value folder created date
+        Location nodeA = new Location(pathFactory.create("/nodeA"));
+        Collection<Property> nodeAProperties = graph.getProperties().on(nodeA);
+        assertThat(nodeAProperties, is(notNullValue()));
+        assertThat(nodeAProperties.isEmpty(), is(false));
+        assertThat(nodeAProperties.size(), is(2));
+
+        // file itemA.txt has "jcr:primaryType" property whose value is "nt:file" and also "jcr:created" with value folder created
+        // date
+        Location itemA1 = new Location(pathFactory.create("/nodeA/itemA1.txt"));
+        Collection<Property> itemA1Properties = graph.getProperties().on(itemA1);
+        assertThat(itemA1Properties, is(notNullValue()));
+        assertThat(itemA1Properties.isEmpty(), is(false));
+        assertThat(itemA1Properties.size(), is(2));
+
+        // content itemA1.txt/jcr:content
+        // //"jcr:primaryType" property value of "nt:resource",
+        // "jcr:data" property whose value are the contents of the file
+        // and a few other properties, like "jcr:encoding", "jcr:mimeType" and "jcr:lastModified" and
+        // also "jcr:created" property
+        Location content = new Location(pathFactory.create("/nodeA/itemA2.txt/jcr:content"));
+        Collection<Property> itemA2ContentProperties = graph.getProperties().on(content);
+        assertThat(itemA2ContentProperties, is(notNullValue()));
+        assertThat(itemA2ContentProperties.isEmpty(), is(false));
+        // then for any causes, that I do not know now mimeType of this content is null.
+        assertThat(itemA2ContentProperties.size(), is(3));
+    }
+
     protected Collection<String> containsPaths( Collection<Location> locations ) {
         List<String> paths = new ArrayList<String>();
         for (Location location : locations) {




More information about the dna-commits mailing list