Author: spagop
Date: 2009-01-08 07:56:19 -0500 (Thu, 08 Jan 2009)
New Revision: 697
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmAction.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionExecutor.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
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
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
Log:
an enhancement of the connector api and small code for the process createNode request
and also updated the copyright statements for all code and source files, from
"Copyright 2008" to "Copyright 2008-2009". No other changes were
made.
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmAction.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmAction.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmAction.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -0,0 +1,30 @@
+/*
+ * 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.scm;
+
+/**
+ * @author Serge Pagop
+ *
+ */
+public interface ScmAction {
+ public void applyAction(Object context) throws Exception;
+}
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionExecutor.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionExecutor.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionExecutor.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -0,0 +1,31 @@
+/*
+ * 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.scm;
+
+/**
+ * @author Serge Pagop
+ *
+ */
+public interface ScmActionExecutor {
+ public void execute( ScmAction action,
+ String message ) throws Exception;
+}
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/scm/ScmActionFactory.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -0,0 +1,46 @@
+/*
+ * 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.scm;
+
+/**
+ * @author Serge Pagop
+ */
+public interface ScmActionFactory {
+
+
+ public ScmAction addFile( String path,
+ String file,
+ byte[] content );
+
+ public ScmAction addDirectory( String root,
+ String path );
+
+ public ScmAction copyDirectory( String path,
+ String newPath,
+ long revision );
+
+ public ScmAction deleteFile( String path,
+ String file );
+
+ public ScmAction deleteDirectory( String path );
+
+}
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -0,0 +1,71 @@
+/*
+ * 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.svn;
+
+import org.jboss.dna.connector.scm.ScmAction;
+import org.jboss.dna.connector.scm.ScmActionExecutor;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+import org.tmatesoft.svn.core.io.SVNRepository;
+
+/**
+ * @author Serge Pagop
+ */
+public class SVNActionExecutor implements ScmActionExecutor {
+
+ private SVNRepository repository;
+
+ /**
+ * @param repository
+ */
+ public SVNActionExecutor( SVNRepository repository ) {
+ this.repository = repository;
+ }
+
+ /**
+ * @return repository
+ */
+ public SVNRepository getRepository() {
+ return repository;
+ }
+
+ /**
+ * @param action
+ * @param message
+ * @throws Exception
+ */
+ public void execute( ScmAction action,
+ String message ) throws Exception {
+ try {
+ ISVNEditor editor = this.repository.getCommitEditor( message,
+ null );
+ editor.openRoot( -1 );
+ action.applyAction( editor );
+ editor.closeDir();
+ editor.closeEdit();
+ } catch ( SVNException e ) {
+ e.printStackTrace();
+ //logger.error( "svn error: " );
+ throw e;
+ }
+ }
+}
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2009-01-07
22:26:34 UTC (rev 696)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -181,5 +181,4 @@
protected RepositorySourceListener getListener() {
return this.listener;
}
-
}
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 2009-01-07
22:26:34 UTC (rev 696)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -27,6 +27,8 @@
import java.util.Date;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.connector.scm.ScmAction;
+import org.jboss.dna.connector.scm.ScmActionFactory;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.JcrNtLexicon;
@@ -58,6 +60,7 @@
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.SVNProperty;
+import org.tmatesoft.svn.core.io.ISVNEditor;
import org.tmatesoft.svn.core.io.SVNRepository;
/**
@@ -66,7 +69,7 @@
*
* @author Serge Emmanuel Pagop
*/
-public class SVNRepositoryRequestProcessor extends RequestProcessor {
+public class SVNRepositoryRequestProcessor extends RequestProcessor implements
ScmActionFactory {
protected static final String BACK_SLASH = "/";
@@ -100,7 +103,9 @@
*/
@Override
public void process( CopyBranchRequest request ) {
+ logger.trace(request.toString());
verifyUpdatesAllowed();
+
}
/**
@@ -110,16 +115,64 @@
*/
@Override
public void process( CreateNodeRequest request ) {
+ logger.trace(request.toString());
verifyUpdatesAllowed();
+ Location myLocation = request.under();
+ Path parent = getPathFor(myLocation, request);
+ try {
+ String root =
parent.getString(getExecutionContext().getNamespaceRegistry());
+ SVNNodeKind rootKind = repository.checkPath(root, -1);
+ if (rootKind == SVNNodeKind.UNKNOWN) {
+ // TODO throw an checked exception
+ } else if (rootKind == SVNNodeKind.NONE) {
+ // TODO throw an checked exception
+ } else if (rootKind == SVNNodeKind.FILE) {
+ // TODO throw an checked exception
+ } else if (rootKind == SVNNodeKind.DIR) {
+ String childName =
request.named().getString(getExecutionContext().getNamespaceRegistry());
+ if (root.length() == 1 && root.charAt(0) == '/') {
+ // test if so a directory does not exist.
+ mkdir("",childName, request.toString());
+ } else {
+ if(root.length() > 1 && root.charAt(0) == '/') {
+ // test if so a directory does not exist.
+ mkdir(root.substring(1),childName, request.toString());
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ }
+ //
}
/**
+ * Create a directory .
+ * @param root - the root directory where the created directory will reside
+ * @param childName - the name of the created directory.
+ * @param message - comment for the creation.
+ * @throws Exception - if during the creation, there is an error.
+ */
+ private void mkdir( String root,
+ String childName, String message) throws Exception {
+ SVNNodeKind childKind = repository.checkPath(childName, -1);
+ if (childKind == SVNNodeKind.NONE) {
+ ScmAction addNodeAction = addDirectory(root, childName);
+ SVNActionExecutor executor = new SVNActionExecutor(repository);
+ executor.execute(addNodeAction, message);
+ } else {
+ // TODO throwns an exception
+ }
+ }
+
+ /**
* {@inheritDoc}
*
* @see
org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.DeleteBranchRequest)
*/
@Override
public void process( DeleteBranchRequest request ) {
+ logger.trace(request.toString());
verifyUpdatesAllowed();
}
@@ -130,6 +183,7 @@
*/
@Override
public void process( MoveBranchRequest request ) {
+ logger.trace(request.toString());
verifyUpdatesAllowed();
}
@@ -279,6 +333,7 @@
*/
@Override
public void process( RemovePropertiesRequest request ) {
+ logger.trace(request.toString());
verifyUpdatesAllowed();
super.process(request);
}
@@ -290,6 +345,7 @@
*/
@Override
public void process( RenameNodeRequest request ) {
+ logger.trace(request.toString());
verifyUpdatesAllowed();
super.process(request);
}
@@ -301,8 +357,15 @@
*/
@Override
public void process( UpdatePropertiesRequest request ) {
+ logger.trace(request.toString());
+ verifyUpdatesAllowed();
}
+ /**
+ * Verify if change is allowed on a specific source.
+ *
+ * @throws RepositorySourceException if change on that repository source is not
allowed.
+ */
protected void verifyUpdatesAllowed() {
if (!updatesAllowed) {
throw new RepositorySourceException(getSourceName(),
@@ -319,22 +382,50 @@
return getExecutionContext().getValueFactories().getNameFactory();
}
+ /**
+ * Factory for path creation.
+ *
+ * @return a path factory.
+ */
protected PathFactory pathFactory() {
return getExecutionContext().getValueFactories().getPathFactory();
}
+ /**
+ * Factory for property creation.
+ *
+ * @return the property factory.
+ */
protected PropertyFactory propertyFactory() {
return getExecutionContext().getPropertyFactory();
}
+ /**
+ * Factory for date creation.
+ *
+ * @return the date factory.
+ */
protected DateTimeFactory dateFactory() {
return getExecutionContext().getValueFactories().getDateFactory();
}
+ /**
+ * Factory for binary creation.
+ *
+ * @return the binary factory..
+ */
protected ValueFactory<Binary> binaryFactory() {
return getExecutionContext().getValueFactories().getBinaryFactory();
}
+ /**
+ * Get the path for a locarion and check if the path is null or not.
+ *
+ * @param location - the location.
+ * @param request - the requested path.
+ * @return the path.
+ * @throws RepositorySourceException if the path of a location is null.
+ */
protected Path getPathFor( Location location,
Request request ) {
Path path = location.getPath();
@@ -361,6 +452,8 @@
}
/**
+ * Get the repository driver.
+ *
* @return repository
*/
public SVNRepository getRepository() {
@@ -416,4 +509,197 @@
}
return entry;
}
+
+ /**
+ * Open the directories where change has to be made.
+ *
+ * @param editor - abstract editor.
+ * @param rootPath - the pa to open.
+ * @throws SVNException
+ */
+ protected static void openDirectories( ISVNEditor editor,
+ String rootPath ) throws SVNException {
+ assert rootPath != null;
+ int pos = rootPath.indexOf('/', 0);
+ while (pos != -1) {
+ String dir = rootPath.substring(0, pos);
+ editor.openDir(dir, -1);
+ pos = rootPath.indexOf('/', pos + 1);
+ }
+ String dir = rootPath.substring(0, rootPath.length());
+ editor.openDir(dir, -1);
+ }
+
+ /**
+ * Close the directories where change was made.
+ *
+ * @param editor - the abstract editor.
+ * @param path - the directories to open.
+ * @throws SVNException
+ */
+ protected static void closeDirectories( ISVNEditor editor,
+ String path ) throws SVNException {
+ int length = path.length() - 1;
+ int pos = path.lastIndexOf('/', length);
+ editor.closeDir();
+ while (pos != -1) {
+ editor.closeDir();
+ pos = path.lastIndexOf('/', pos - 1);
+ }
+ }
+
+ /**
+ * Get the last revision.
+ *
+ * @return the last revision number.
+ * @throws Exception
+ */
+ public long getLatestRevision() throws Exception {
+ try {
+ return repository.getLatestRevision();
+ } catch (SVNException e) {
+ e.printStackTrace();
+ // logger.error( "svn error: " );
+ throw e;
+ }
+ }
+
+ /**
+ * @param repository
+ * @param root - the root path has to exist.
+ * @param child - new path to be added.
+ * @param message - information about the change action.
+ * @throws SVNException
+ */
+ protected void addDirEntry( SVNRepository repository,
+ String root,
+ String child,
+ String message ) throws SVNException {
+ assert root.trim().length() != 0;
+ SVNNodeKind rootKind = repository.checkPath(root, -1);
+ if (rootKind == SVNNodeKind.UNKNOWN) {
+ // TODO throw an checked exception
+ } else if (rootKind == SVNNodeKind.NONE) {
+ // TODO throw an checked exception
+ } else if (rootKind == SVNNodeKind.FILE) {
+ // TODO throw an checked exception
+ } else if (rootKind == SVNNodeKind.DIR) {
+ ISVNEditor editor = repository.getCommitEditor(message, null, true, null);
+ if (root.length() == 1 && root.charAt(0) == '/') {
+ addProcess(editor, root, "", child);
+ } else {
+ String rootPath = root.substring(1);
+ addProcess(editor, rootPath, null, child);
+ }
+ }
+ }
+
+ private void addProcess( ISVNEditor editor,
+ String rootPath,
+ String editedRoot,
+ String childSegmentName ) throws SVNException {
+ openDirectories(editor, editedRoot);
+ // test if so a directory does not exist.
+ SVNNodeKind childKind = repository.checkPath(childSegmentName, -1);
+ if (childKind == SVNNodeKind.NONE) {
+ editor.addDir(childSegmentName, null, -1);
+ closeDirectories(editor, childSegmentName);
+ if (editedRoot != null) {
+ closeDirectories(editor, editedRoot);
+ } else {
+ closeDirectories(editor, rootPath);
+ }
+
+ } else {
+ // TODO throws an exception
+ closeDirectories(editor, childSegmentName);
+ if (editedRoot != null) {
+ closeDirectories(editor, editedRoot);
+ } else {
+ closeDirectories(editor, rootPath);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.scm.ScmActionFactory#addDirectory(java.lang.String,
java.lang.String)
+ */
+ public ScmAction addDirectory( String root,
+ String path ) {
+ return new AddDirectory(root, path);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.scm.ScmActionFactory#addFile(java.lang.String,
java.lang.String, byte[])
+ */
+ public ScmAction addFile( String path,
+ String file,
+ byte[] content ) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.scm.ScmActionFactory#copyDirectory(java.lang.String,
java.lang.String, long)
+ */
+ public ScmAction copyDirectory( String path,
+ String newPath,
+ long revision ) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.connector.scm.ScmActionFactory#deleteDirectory(java.lang.String)
+ */
+ public ScmAction deleteDirectory( String path ) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.scm.ScmActionFactory#deleteFile(java.lang.String,
java.lang.String)
+ */
+ public ScmAction deleteFile( String path,
+ String file ) {
+ return null;
+ }
+
+ /**
+ * root should be the last, previously created, parent folder. Each directory in the
path will be created.
+ */
+ public static class AddDirectory implements ScmAction {
+ private String root;
+ private String path;
+
+ public AddDirectory( String root,
+ String path ) {
+ this.root = root;
+ this.path = path;
+ }
+
+ public void applyAction( Object context ) throws SVNException {
+
+ ISVNEditor editor = (ISVNEditor)context;
+
+ openDirectories(editor, this.root);
+ String[] paths = this.path.split("/");
+ String newPath = this.root;
+ for (int i = 0, length = paths.length; i < length; i++) {
+ newPath = (newPath.length() != 0) ? newPath + "/" + paths[i] :
paths[i];
+
+ editor.addDir(newPath, null, -1);
+ }
+
+ closeDirectories(editor, path);
+ closeDirectories(editor, this.root);
+ }
+ }
}
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 2009-01-07
22:26:34 UTC (rev 696)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -24,11 +24,14 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsSame.sameInstance;
+import static org.jboss.dna.graph.IsNodeWithChildren.hasChild;
+import static org.jboss.dna.graph.IsNodeWithProperty.hasProperty;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import org.jboss.dna.common.text.UrlEncoder;
import org.jboss.dna.common.util.FileUtil;
@@ -39,20 +42,29 @@
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.cache.CachePolicy;
import org.jboss.dna.graph.connectors.RepositorySourceListener;
+import org.jboss.dna.graph.properties.Binary;
+import org.jboss.dna.graph.properties.DateTimeFactory;
+import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.NameFactory;
+import org.jboss.dna.graph.properties.Path;
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.properties.ValueFactory;
import org.jboss.dna.graph.requests.ReadAllChildrenRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.io.SVNRepository;
+import com.sun.org.apache.bcel.internal.generic.NEW;
/**
* @author Serge Pagop
@@ -106,7 +118,7 @@
// Set up the appropriate factory for a particular protocol
repository = SVNConnectorTestUtil.createRepository(svnUrl, username, password);
sourceName = "the source name";
- connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE,
repository);
+ connection = new SVNRepositoryConnection(sourceName, policy, Boolean.TRUE,
repository);
// And create the graph ...
graph = Graph.create(connection, context);
}
@@ -244,10 +256,41 @@
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.
+ // then for any causes that I do not know now mimeType of this content is null.
assertThat(itemA2ContentProperties.size(), is(3));
}
+ @Test
+ public void shouldAlwaysReadRootNodeByPath() {
+ Node root = graph.getNodeAt("/");
+ assertThat(root, is(notNullValue()));
+ assertThat(root.getLocation().getPath(), is(path("/")));
+ }
+
+ @Test
+ public void shouldAddAndDeleteChildUnderRootNode() throws Exception {
+ graph.batch().create("/nodeC")
+ .with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER))
+ .and(propertyFactory().create(JcrLexicon.CREATED,dateFactory().create(new
Date()))).execute();
+ // Now look up the root node ...
+ Node root = graph.getNodeAt("/");
+ assertThat(root, is(notNullValue()));
+ assertThat(root.getChildren(), hasChild(child("nodeC")));
+ SVNNodeKind nodeCKind = repository.checkPath("nodeC", -1);
+ assertThat(nodeCKind, is(SVNNodeKind.DIR));
+ graph.batch().create("/nodeC/nodeC_1")
+ .with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER))
+
.and(propertyFactory().create(JcrLexicon.CREATED,dateFactory().create(new
Date()))).execute();
+ // Now look up the root node ...
+ Node nodeC = graph.getNodeAt("/nodeC");
+ assertThat(nodeC, is(notNullValue()));
+ assertThat(nodeC.getChildren(), hasChild(child("nodeC_1")));
+ SVNNodeKind nodeC1Kind = repository.checkPath("nodeC/nodeC_1", -1);
+ assertThat(nodeC1Kind, is(SVNNodeKind.DIR));
+
+ }
+
+
protected Collection<String> containsPaths( Collection<Location>
locations ) {
List<String> paths = new ArrayList<String>();
for (Location location : locations) {
@@ -256,4 +299,67 @@
return paths;
}
+ protected Path path( String path ) {
+ return context.getValueFactories().getPathFactory().create(path);
+ }
+
+ /**
+ * Factory for sample name.
+ *
+ * @return the name factory
+ */
+ protected NameFactory nameFactory() {
+ return context.getValueFactories().getNameFactory();
+ }
+
+ /**
+ * Factory for path creation.
+ *
+ * @return a path factory.
+ */
+ protected PathFactory pathFactory() {
+ return context.getValueFactories().getPathFactory();
+ }
+
+ /**
+ * Factory for property creation.
+ *
+ * @return the property factory.
+ */
+ protected PropertyFactory propertyFactory() {
+ return context.getPropertyFactory();
+ }
+
+ /**
+ * Factory for date creation.
+ *
+ * @return the date factory.
+ */
+ protected DateTimeFactory dateFactory() {
+ return context.getValueFactories().getDateFactory();
+ }
+
+ /**
+ * Factory for binary creation.
+ *
+ * @return the binary factory..
+ */
+ protected ValueFactory<Binary> binaryFactory() {
+ return context.getValueFactories().getBinaryFactory();
+ }
+
+ protected Name name( String name ) {
+ return context.getValueFactories().getNameFactory().create(name);
+ }
+
+ protected Property property( String name,
+ Object... values ) {
+ Name propName = name(name);
+ return context.getPropertyFactory().create(propName, values);
+ }
+
+ protected Path.Segment child( String name ) {
+ return context.getValueFactories().getPathFactory().createSegment(name);
+ }
+
}
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2009-01-07
22:26:34 UTC (rev 696)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2009-01-08
12:56:19 UTC (rev 697)
@@ -54,10 +54,9 @@
private RepositoryConnection connection;
private String validName;
private String validUuidPropertyName;
- // private String validFileURL;
- private String validHttpURL;
- private String validHttpURLUsername;
- private String validHttpURLPassword;
+ private String url;
+ private String username;
+ private String password;
private UUID validRootNodeUuid;
@Before
@@ -67,12 +66,12 @@
validUuidPropertyName = "dna:uuid";
// For file protocol access
- // validFileURL = "file:///Users/sp/SVNRepos/test";
+ url = "file:///Users/sp/SVNRepos/test";
// For http protocol access
- validHttpURL =
"http://anonsvn.jboss.org/repos/dna/trunk/extensions/dna-connector-svn/src/test/resources";
- validHttpURLUsername = "anonymous";
- validHttpURLPassword = "anonymous";
+ // url =
"http://anonsvn.jboss.org/repos/dna/trunk/extensions/dna-connector-svn/src/test/resources";
+ username = "anonymous";
+ password = "anonymous";
// For https protocol access
// For svn protocol access
@@ -173,9 +172,9 @@
cachePolicy.setTimeToLive(1000L, TimeUnit.MILLISECONDS);
convertToAndFromJndiReference(validName,
validRootNodeUuid,
- validHttpURL,
- validHttpURLUsername,
- validHttpURLPassword,
+ url,
+ username,
+ password,
validUuidPropertyName,
cachePolicy,
100);
@@ -243,23 +242,23 @@
}
// Only with local file protocol
- /*
+
@Test
public void shouldCreateFSRepositoryIfProtocolIsOfTypeFile() throws Exception {
this.source.setName(validName);
- this.source.setSVNURL(validFileURL);
+ this.source.setSVNURL(url);
this.connection = source.getConnection();
assertThat(this.connection, is(notNullValue()));
- }*/
-
- @Test
- public void shouldCreateDAVRepositoryIfProtocolIsOfTypeHttp() throws Exception {
- this.source.setName(validName);
- this.source.setSVNURL(validHttpURL);
- this.source.setSVNUsername(validHttpURLUsername);
- this.source.setSVNPassword(validHttpURLPassword);
- this.connection = source.getConnection();
- assertThat(this.connection, is(notNullValue()));
}
+ // @Test
+ // public void shouldCreateDAVRepositoryIfProtocolIsOfTypeHttp() throws Exception {
+ // this.source.setName(validName);
+ // this.source.setSVNURL(url);
+ // this.source.setSVNUsername(username);
+ // this.source.setSVNPassword(password);
+ // this.connection = source.getConnection();
+ // assertThat(this.connection, is(notNullValue()));
+ // }
+
}