Author: rhauch
Date: 2009-01-09 18:06:15 -0500 (Fri, 09 Jan 2009)
New Revision: 702
Added:
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadingTest.java
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/DNA icon.png
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/commercial/
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/commercial/Boeing_777.jpg
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/commercial/Boeing_787.jpg
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/cars/
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/readme.txt
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/trains/
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractValueFactory.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java
trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties
Log:
DNA-34 Federate content stored on file system (read-only access)
Completed the file system connector and read support. Added unit test that uses the
standard connector read tests. Also fixed a bug in the AbstractValueFactory that
neglected to look for a Binary object in "create(Object)".
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractValueFactory.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractValueFactory.java 2009-01-09
21:47:14 UTC (rev 701)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/AbstractValueFactory.java 2009-01-09
23:06:15 UTC (rev 702)
@@ -116,6 +116,7 @@
if (value instanceof Path) return create((Path)value);
if (value instanceof Reference) return create((Reference)value);
if (value instanceof URI) return create((URI)value);
+ if (value instanceof Binary) return create((Binary)value);
if (value instanceof byte[]) return create((byte[])value);
if (value instanceof InputStream) return create((InputStream)value, 0);
if (value instanceof Reader) return create((Reader)value, 0);
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java 2009-01-09
21:47:14 UTC (rev 701)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java 2009-01-09
23:06:15 UTC (rev 702)
@@ -45,6 +45,7 @@
import org.jboss.dna.graph.connectors.RepositoryContext;
import org.jboss.dna.graph.connectors.RepositorySource;
import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.jboss.dna.graph.properties.DateTime;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.Property;
@@ -188,8 +189,9 @@
* Set up a {@link RepositorySource} that should be used for each of the unit tests.
*
* @return the repository source
+ * @throws Exception if there is a problem setting up the source
*/
- protected abstract RepositorySource setUpSource();
+ protected abstract RepositorySource setUpSource() throws Exception;
/**
* Initialize the content of the {@link RepositorySource} set up for each of the unit
tests. This method is called shortly
@@ -197,8 +199,9 @@
* {@link RepositorySource#initialize(RepositoryContext) initialized}.
*
* @param graph the graph for the {@link RepositorySource} returned from {@link
#setUpSource()}; never null
+ * @throws Exception if there is a problem initializing the source
*/
- protected abstract void initializeContent( Graph graph );
+ protected abstract void initializeContent( Graph graph ) throws Exception;
//
----------------------------------------------------------------------------------------------------------------
// Helper methods commonly needed in unit tests
@@ -291,6 +294,26 @@
return rootLocation.getUuid();
}
+ protected String string( Object value ) {
+ if (value instanceof Property) value = ((Property)value).getFirstValue();
+ return context.getValueFactories().getStringFactory().create(value);
+ }
+
+ protected DateTime date( Object value ) {
+ if (value instanceof Property) value = ((Property)value).getFirstValue();
+ return context.getValueFactories().getDateFactory().create(value);
+ }
+
+ protected long longValue( Object value ) {
+ if (value instanceof Property) value = ((Property)value).getFirstValue();
+ return context.getValueFactories().getLongFactory().create(value);
+ }
+
+ protected Name name( Object value ) {
+ if (value instanceof Property) value = ((Property)value).getFirstValue();
+ return context.getValueFactories().getNameFactory().create(value);
+ }
+
//
----------------------------------------------------------------------------------------------------------------
// Utility method that may be used to execute requests against a repository ...
//
----------------------------------------------------------------------------------------------------------------
Modified:
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
===================================================================
---
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java 2009-01-09
21:47:14 UTC (rev 701)
+++
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java 2009-01-09
23:06:15 UTC (rev 702)
@@ -134,6 +134,7 @@
}
}
request.setActualLocationOfNode(location);
+ setCacheableInfo(request);
}
/**
@@ -148,6 +149,7 @@
if (path.isRoot()) {
// There are no properties on the root ...
request.setActualLocationOfNode(location);
+ setCacheableInfo(request);
return;
}
@@ -204,6 +206,7 @@
}
request.setActualLocationOfNode(location);
+ setCacheableInfo(request);
}
/**
Modified:
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java
===================================================================
---
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java 2009-01-09
21:47:14 UTC (rev 701)
+++
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java 2009-01-09
23:06:15 UTC (rev 702)
@@ -74,10 +74,9 @@
*/
protected static final boolean SUPPORTS_SAME_NAME_SIBLINGS = true;
/**
- * This source supports udpates by default, but each instance may be configured to
{@link #setSupportsUpdates(boolean) be
- * read-only or updateable}.
+ * This source does not support udpates by default, but each instance may be
configured to be read-only or updateable}.
*/
- public static final boolean DEFAULT_SUPPORTS_UPDATES = true;
+ public static final boolean DEFAULT_SUPPORTS_UPDATES = false;
public static final int DEFAULT_RETRY_LIMIT = 0;
public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5 minutes
@@ -138,7 +137,7 @@
}
/**
- * Set the file system paths to each directory or file that should be exposed
immediately the root node nodes in this
+ * Set the file system paths to each directory or file that should be exposed
immediately under the root node in this
* connector. If not specified, all of the file system's root will be used.
*
* @param fileSystemPaths the paths in the file system path to the top-level files
and/or directories, or null if not yet set
@@ -157,15 +156,15 @@
return capabilities.supportsUpdates();
}
- /**
- * Set whether this source supports updates.
- *
- * @param supportsUpdates true if this source supports updating content, or false if
this source only supports reading
- * content.
- */
- public synchronized void setSupportsUpdates( boolean supportsUpdates ) {
- capabilities.setSupportsUpdates(supportsUpdates);
- }
+ // /**
+ // * Set whether this source supports updates.
+ // *
+ // * @param supportsUpdates true if this source supports updating content, or false
if this source only supports reading
+ // * content.
+ // */
+ // public synchronized void setSupportsUpdates( boolean supportsUpdates ) {
+ // capabilities.setSupportsUpdates(supportsUpdates);
+ // }
/**
* {@inheritDoc}
@@ -304,8 +303,10 @@
}
if (!pathsThatDontExist.isEmpty()) {
int count = pathsThatDontExist.size();
- I18n msg = count == 1 ? FileSystemI18n.fileSystemPathDoesNotExist :
FileSystemI18n.fileSystemPathsDoNotExist;
- throw new RepositorySourceException(getName(), msg.text(getName(),
pathsThatDontExist, count));
+ String msg = null;
+ if (count == 1) msg =
FileSystemI18n.fileSystemPathDoesNotExist.text(getName(), pathsThatDontExist);
+ else msg = FileSystemI18n.fileSystemPathsDoNotExist.text(getName(),
pathsThatDontExist, count);
+ throw new RepositorySourceException(getName(), msg);
}
} else {
// No file system paths specified, so get all of the file system's roots
...
Modified:
trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties
===================================================================
---
trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties 2009-01-09
21:47:14 UTC (rev 701)
+++
trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties 2009-01-09
23:06:15 UTC (rev 702)
@@ -19,10 +19,9 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
#
-
connectorName = JPA Graph Store Connector
-fileSystemPathsDoNotExist = {2} of the file system paths specified on the {0} source do
not exist or are invalid: {1}
fileSystemPathDoesNotExist = One of the file system paths specified on the {0} source
does not exist or is invalid: {1}
+fileSystemPathsDoNotExist = {2} of the file system paths specified on the {0} source do
not exist or are invalid: {1}
propertyIsRequired = The {0} property is required but has no value
locationInRequestMustHavePath = {0} requires a path in the request: {1}
sameNameSiblingsAreNotAllowed = {0} does not allow same name siblings on nodes: {1}
Added:
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadingTest.java
===================================================================
---
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadingTest.java
(rev 0)
+++
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadingTest.java 2009-01-09
23:06:15 UTC (rev 702)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.filesystem;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.Node;
+import org.jboss.dna.graph.connectors.RepositorySource;
+import org.jboss.dna.graph.connectors.test.ReadableConnectorTest;
+import org.jboss.dna.graph.properties.PathNotFoundException;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class FileSystemConnectorReadingTest extends ReadableConnectorTest {
+
+ private String[] pathsInFileSystemToTopLevelNodes;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws IOException {
+ // Find the current location of the project ...
+ File project = new File(".");
+ String absolutePathToProject = project.getCanonicalPath();
+
+ // Set the connection properties to be use the folders in the
"./src/test/resources/repositories" as a repository ...
+ FileSystemSource source = new FileSystemSource();
+ source.setName("Test Repository");
+
+ pathsInFileSystemToTopLevelNodes = new String[] {absolutePathToProject +
"/src/test/resources/repositories/airplanes",
+ absolutePathToProject + "/src/test/resources/repositories/cars",
+ absolutePathToProject +
"/src/test/resources/repositories/readme.txt"};
+ source.setFileSystemPaths(pathsInFileSystemToTopLevelNodes);
+
+ return source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connectors.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) {
+ // No need to initialize any content ...
+ }
+
+ public void assertThatNodeIsFile( Node node,
+ String mimeType,
+ String contents ) {
+ assertThat(node, is(notNullValue()));
+ assertThat(node.getProperty(JcrLexicon.PRIMARY_TYPE).getFirstValue(),
is((Object)JcrNtLexicon.FILE));
+
+ // Check that there is one child, and that the child is "jcr:content"
...
+ List<Location> children = node.getChildren();
+ assertThat(children.size(), is(1));
+ Location jcrContentLocation = children.get(0);
+ assertThat(jcrContentLocation.getPath().getLastSegment().getName(),
is(JcrLexicon.CONTENT));
+
+ // Check that the "jcr:content" node is correct ...
+ Node jcrContent = graph.getNodeAt(jcrContentLocation);
+ assertThat(string(jcrContent.getProperty(JcrLexicon.MIMETYPE).getFirstValue()),
is(mimeType));
+ if (contents != null) {
+ assertThat(string(jcrContent.getProperty(JcrLexicon.DATA).getFirstValue()),
is(contents));
+ }
+
+ }
+
+ public void assertThatNodeIsFolder( Node node ) {
+ assertThat(node, is(notNullValue()));
+ assertThat(node.getProperty(JcrLexicon.PRIMARY_TYPE).getFirstValue(),
is((Object)JcrNtLexicon.FOLDER));
+ }
+
+ @Test
+ public void shouldFindFolderSpecifiedInPathsAsNodesBelowRoot() {
+ Node readme = graph.getNodeAt("/readme.txt");
+ assertThatNodeIsFile(readme, "text/plain", "This directory
contains files and folders that are used in test cases.");
+
+ Node airplanes = graph.getNodeAt("/airplanes");
+ assertThatNodeIsFolder(airplanes);
+
+ Node commercial = graph.getNodeAt("/airplanes/commercial");
+ assertThatNodeIsFolder(commercial);
+ }
+
+ @Test( expected = PathNotFoundException.class )
+ public void
shouldNotFindOtherFileThatIsSiblingOfFileOrFoldersSpecifiedToBeTopLevelNodes() {
+ // Should not find these, since they're not included in the paths to
top-level nodes ...
+ assertThat(graph.getNodeAt("/trains"), is(nullValue()));
+ }
+
+ @Test( expected = PathNotFoundException.class )
+ public void
shouldNotFindOtherFolderThatIsSiblingOfFileOrFoldersSpecifiedToBeTopLevelNodes() {
+ // Should not find these, since they're not included in the paths to
top-level nodes ...
+ assertThat(graph.getNodeAt("/DNA icon"), is(nullValue()));
+ }
+}
Property changes on:
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadingTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/DNA
icon.png
===================================================================
(Binary files differ)
Property changes on:
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/DNA icon.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/commercial/Boeing_777.jpg
===================================================================
(Binary files differ)
Property changes on:
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/commercial/Boeing_777.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/commercial/Boeing_787.jpg
===================================================================
(Binary files differ)
Property changes on:
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/airplanes/commercial/Boeing_787.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/readme.txt
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/readme.txt
(rev 0)
+++
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/readme.txt 2009-01-09
23:06:15 UTC (rev 702)
@@ -0,0 +1 @@
+This directory contains files and folders that are used in test cases.
\ No newline at end of file
Property changes on:
trunk/extensions/dna-connector-filesystem/src/test/resources/repositories/readme.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain