Author: spagop
Date: 2009-12-31 08:47:17 -0500 (Thu, 31 Dec 2009)
New Revision: 1502
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorWriteableTest.java
Log:
OPEN - issue DNA-607: Delete node/folder or rather item/file from the svn repository
through dna svn connector
https://jira.jboss.org/jira/browse/DNA-607
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorWriteableTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorWriteableTest.java 2009-12-31
13:46:43 UTC (rev 1501)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRespositoryConnectorWriteableTest.java 2009-12-31
13:47:17 UTC (rev 1502)
@@ -24,6 +24,7 @@
package org.jboss.dna.connector.svn;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
import java.io.ByteArrayOutputStream;
@@ -52,6 +53,7 @@
protected SVNNodeKind kind = null;
protected SVNProperties fileProperties = null;
protected ByteArrayOutputStream baos = null;
+
/**
* {@inheritDoc}
*
@@ -75,7 +77,7 @@
return source;
}
-
+
/**
* {@inheritDoc}
*
@@ -95,12 +97,12 @@
remoteRepos = null;
super.afterEach();
}
-
+
@Test( expected = RepositorySourceException.class )
public void shouldNotBeAbleToCreateInvalidTypeForRepository() {
graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.UNSTRUCTURED).orReplace().and();
}
-
+
@Test( expected = RepositorySourceException.class )
public void shouldNotBeAbleToSetArbitraryProperties() {
graph.create("/testFile").with(JcrLexicon.MIXIN_TYPES,
JcrMixLexicon.LOCKABLE).orReplace().and();
@@ -109,7 +111,6 @@
@Test
public void shouldBeAbleToCreateNodeFileWithContentLevel1() throws Exception {
-
// LEVEL 0
graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
@@ -141,11 +142,11 @@
baos = new ByteArrayOutputStream();
remoteRepos.getFile("root/testFile", -1, fileProperties, baos);
assertContents(baos, TEST_CONTENT);
-
+
// LEVEL 2
graph.create("/root/a/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
graph.create("/root/a/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
-
TEST_CONTENT.getBytes()).orReplace().and();
+
TEST_CONTENT.getBytes()).orReplace().and();
kind = remoteRepos.checkPath("root/a/testFile", -1);
assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
fileProperties = new SVNProperties();
@@ -153,22 +154,15 @@
remoteRepos.getFile("root/a/testFile", -1, fileProperties, baos);
assertContents(baos, TEST_CONTENT);
}
-
-
+
@Test
public void shouldRespectConflictBehaviorOnCreate() throws Exception {
graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
- graph.create("/testFile/jcr:content")
- .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
- .and(JcrLexicon.DATA, TEST_CONTENT.getBytes())
- .orReplace()
- .and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
- graph.create("/testFile/jcr:content")
- .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
- .and(JcrLexicon.DATA, "Should not overwrite".getBytes())
- .ifAbsent()
- .and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
"Should not overwrite".getBytes()).ifAbsent().and();
kind = remoteRepos.checkPath("testFile", -1);
assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
@@ -177,7 +171,7 @@
remoteRepos.getFile("testFile", -1, fileProperties, baos);
assertContents(baos, TEST_CONTENT);
}
-
+
@Test
public void shouldBeAbleToCreateFileWithNoContent() throws Exception {
graph.create("/testEmptyFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
@@ -189,25 +183,25 @@
remoteRepos.getFile("testEmptyFile", -1, fileProperties, baos);
assertContents(baos, EMPTY_CONTENT);
}
-
+
@Test
public void shouldBeAbleToCreateFolder() throws Exception {
graph.create("/testFolder").orReplace().and();
kind = remoteRepos.checkPath("testFolder", -1);
assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
-
+
graph.create("/root/testFolder").orReplace().and();
kind = remoteRepos.checkPath("root/testFolder", -1);
assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
-
+
graph.create("/root/a/testFolder").orReplace().and();
kind = remoteRepos.checkPath("root/a/testFolder", -1);
assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
}
-
+
@Test
public void shouldBeAbleToAddChildrenToFolder() throws Exception {
graph.create("/testFolder").orReplace().and();
@@ -216,11 +210,8 @@
assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
- graph.create("/testFolder/testFile/jcr:content")
- .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
- .and(JcrLexicon.DATA, TEST_CONTENT.getBytes())
- .orReplace()
- .and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
kind = remoteRepos.checkPath("testFolder/testFile", -1);
assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
@@ -228,18 +219,15 @@
baos = new ByteArrayOutputStream();
remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
assertContents(baos, TEST_CONTENT);
-
+
graph.create("/root/testFolder").orReplace().and();
kind = remoteRepos.checkPath("root/testFolder", -1);
assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
graph.create("/root/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
- graph.create("/root/testFolder/testFile/jcr:content")
- .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
- .and(JcrLexicon.DATA, TEST_CONTENT.getBytes())
- .orReplace()
- .and();
+
graph.create("/root/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
kind = remoteRepos.checkPath("root/testFolder/testFile", -1);
assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
@@ -249,61 +237,210 @@
assertContents(baos, TEST_CONTENT);
}
-// @Test
-// public void shouldBeAbleToCopyFile() throws Exception {
-// graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
-// graph.create("/testFile/jcr:content")
-// .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
-// .and(JcrLexicon.DATA, TEST_CONTENT.getBytes())
-// .orReplace()
-// .and();
-//
-// kind = remoteRepos.checkPath("testFile", -1);
-// assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
-// fileProperties = new SVNProperties();
-// baos = new ByteArrayOutputStream();
-// remoteRepos.getFile("testFile", -1, fileProperties, baos);
-// assertContents(baos, TEST_CONTENT);
-//
-// graph.copy("/testFile").to("/copiedFile");
-// kind = remoteRepos.checkPath("copiedFile", -1);
-// assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
-// fileProperties = new SVNProperties();
-// baos = new ByteArrayOutputStream();
-// remoteRepos.getFile("copiedFile", -1, fileProperties, baos);
-// assertContents(baos, TEST_CONTENT);
-// }
-//
-// @Test
-// public void shouldBeAbleToCopyFolder() throws Exception {
-// graph.create("/testFolder").orReplace().and();
-// graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
-// graph.create("/testFolder/testFile/jcr:content")
-// .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
-// .and(JcrLexicon.DATA, TEST_CONTENT.getBytes())
-// .orReplace()
-// .and();
-//
-// kind = remoteRepos.checkPath("testFolder/testFile", -1);
-// assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
-// fileProperties = new SVNProperties();
-// baos = new ByteArrayOutputStream();
-// remoteRepos.getFile("testFolder/testFile", -1, fileProperties,
baos);
-// assertContents(baos, TEST_CONTENT);
-//
-//
-// graph.copy("/testFolder").to("/copiedFolder");
-// kind = remoteRepos.checkPath("copiedFolder", -1);
-// assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
-// fileProperties = new SVNProperties();
-// baos = new ByteArrayOutputStream();
-// remoteRepos.getFile("copiedFolder/testFile", -1, fileProperties,
baos);
-// assertContents(baos, TEST_CONTENT);
-// }
+ // @Test
+ // public void shouldBeAbleToCopyFile() throws Exception {
+ // graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ // graph.create("/testFile/jcr:content")
+ // .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
+ // .and(JcrLexicon.DATA, TEST_CONTENT.getBytes())
+ // .orReplace()
+ // .and();
+ //
+ // kind = remoteRepos.checkPath("testFile", -1);
+ // assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ // fileProperties = new SVNProperties();
+ // baos = new ByteArrayOutputStream();
+ // remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ // assertContents(baos, TEST_CONTENT);
+ //
+ // graph.copy("/testFile").to("/copiedFile");
+ // kind = remoteRepos.checkPath("copiedFile", -1);
+ // assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ // fileProperties = new SVNProperties();
+ // baos = new ByteArrayOutputStream();
+ // remoteRepos.getFile("copiedFile", -1, fileProperties, baos);
+ // assertContents(baos, TEST_CONTENT);
+ // }
+ //
+ // @Test
+ // public void shouldBeAbleToCopyFolder() throws Exception {
+ // graph.create("/testFolder").orReplace().and();
+ // graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ // graph.create("/testFolder/testFile/jcr:content")
+ // .with(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE)
+ // .and(JcrLexicon.DATA, TEST_CONTENT.getBytes())
+ // .orReplace()
+ // .and();
+ //
+ // kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ // assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ // fileProperties = new SVNProperties();
+ // baos = new ByteArrayOutputStream();
+ // remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ // assertContents(baos, TEST_CONTENT);
+ //
+ //
+ // graph.copy("/testFolder").to("/copiedFolder");
+ // kind = remoteRepos.checkPath("copiedFolder", -1);
+ // assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+ // fileProperties = new SVNProperties();
+ // baos = new ByteArrayOutputStream();
+ // remoteRepos.getFile("copiedFolder/testFile", -1, fileProperties, baos);
+ // assertContents(baos, TEST_CONTENT);
+ // }
+
+ @Test
+ public void shouldBeAbleToDeleteFolderWithContents() throws Exception {
+ graph.create("/testFolder").orReplace().and();
+ graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+
+ kind = remoteRepos.checkPath("testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.delete("/testFolder");
+
+ kind = remoteRepos.checkPath("testFolder", -1);
+ assertThat(kind == SVNNodeKind.NONE, is(Boolean.TRUE));
+
+
+ }
+
+ @Test
+ public void shouldBeAbleToDeleteFile() throws Exception {
+ graph.create("/testFolder").orReplace().and();
+ graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+
+ kind = remoteRepos.checkPath("testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.delete("/testFolder/testFile");
+
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.NONE, is(Boolean.TRUE));
+
+
+ graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.delete("/testFile");
+
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind == SVNNodeKind.NONE, is(Boolean.TRUE));
+ }
+ @Test
+ public void shouldBeAbleToDeleteOnlyTheFileContent() throws Exception {
+ graph.create("/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+ graph.create("/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.delete("/testFile/jcr:content");
+
+ kind = remoteRepos.checkPath("testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFile", -1, fileProperties, baos);
+
+ assertEmptyContents(baos, TEST_CONTENT);
+
+ graph.create("/testFolder").orReplace().and();
+ graph.create("/testFolder/testFile").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testFolder/testFile/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testFolder", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.delete("/testFolder/testFile/jcr:content");
+
+ kind = remoteRepos.checkPath("testFolder/testFile", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testFolder/testFile", -1, fileProperties, baos);
+
+ assertEmptyContents(baos, TEST_CONTENT);
+
+
+ graph.create("/testNode1").orReplace().and();
+ graph.create("/testNode1/testNode10").orReplace().and();
+
graph.create("/testNode1/testNode10/testItem0").with(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FILE).orReplace().and();
+
graph.create("/testNode1/testNode10/testItem0/jcr:content").with(JcrLexicon.PRIMARY_TYPE,
DnaLexicon.RESOURCE).and(JcrLexicon.DATA,
+
TEST_CONTENT.getBytes()).orReplace().and();
+ kind = remoteRepos.checkPath("testNode1", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ kind = remoteRepos.checkPath("testNode1/testNode10", -1);
+ assertThat(kind == SVNNodeKind.DIR, is(Boolean.TRUE));
+
+ kind = remoteRepos.checkPath("testNode1/testNode10/testItem0", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testNode1/testNode10/testItem0", -1,
fileProperties, baos);
+ assertContents(baos, TEST_CONTENT);
+
+ graph.delete("/testNode1/testNode10/testItem0/jcr:content");
+
+ kind = remoteRepos.checkPath("testNode1/testNode10/testItem0", -1);
+ assertThat(kind == SVNNodeKind.FILE, is(Boolean.TRUE));
+
+ fileProperties = new SVNProperties();
+ baos = new ByteArrayOutputStream();
+ remoteRepos.getFile("testNode1/testNode10/testItem0", -1,
fileProperties, baos);
+
+ assertEmptyContents(baos, TEST_CONTENT);
+ }
+
protected void assertContents( ByteArrayOutputStream baos,
String contents ) {
assertThat(baos, notNullValue());
assertThat(baos.toString(), is(contents));
}
+
+ protected void assertEmptyContents( ByteArrayOutputStream baos,
+ String contents ) {
+ assertThat(baos, notNullValue());
+ assertThat(baos.toString(), not(contents));
+ }
}