mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Retyped a counter so had to muck with many beans. Forced creation of layered directories
to work. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2930 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -17,7 +17,10 @@
|
||||
|
||||
package org.alfresco.repo.avm;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||
import org.alfresco.repo.avm.impl.AVMServiceImpl;
|
||||
@@ -76,10 +79,8 @@ public class AVMServiceTest extends TestCase
|
||||
try
|
||||
{
|
||||
fService.createDirectory("main:/", "testdir");
|
||||
ArrayList<String> toSnapshot = new ArrayList<String>();
|
||||
toSnapshot.add("main");
|
||||
fService.createSnapshot(toSnapshot);
|
||||
AVMNode node = fService.lookup(-1, "main:/");
|
||||
fService.createSnapshot("main");
|
||||
AVMNode node = fService.lookup(-1, "main:/").getCurrentNode();
|
||||
assertTrue(node instanceof PlainDirectoryNode);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -99,9 +100,20 @@ public class AVMServiceTest extends TestCase
|
||||
testCreateDirectory();
|
||||
fService.createFile("main:testdir", "testfile");
|
||||
fService.createFile("main:/", "testfile2");
|
||||
ArrayList<String> toSnapshot = new ArrayList<String>();
|
||||
toSnapshot.add("main");
|
||||
fService.createSnapshot(toSnapshot);
|
||||
fService.createSnapshot("main");
|
||||
PrintStream out = new PrintStream(fService.getFileOutputStream("main:testdir/testfile"));
|
||||
out.println("This is testdir/testfile");
|
||||
out.close();
|
||||
out = new PrintStream(fService.getFileOutputStream("main:testfile2"));
|
||||
out.println("This is testfile2");
|
||||
out.close();
|
||||
fService.createSnapshot("main");
|
||||
Set<Integer> versions = fService.getRepositoryVersions("main");
|
||||
for (Integer version : versions)
|
||||
{
|
||||
System.out.println("V:" + version);
|
||||
System.out.println(recursiveList("main", version));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -109,4 +121,118 @@ public class AVMServiceTest extends TestCase
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating a branch.
|
||||
*/
|
||||
public void testCreateBranch()
|
||||
{
|
||||
try
|
||||
{
|
||||
setupBasicTree();
|
||||
fService.createBranch(-1, "main:a", "main:d/e", "abranch");
|
||||
fService.createSnapshot("main");
|
||||
Set<Integer> versions = fService.getRepositoryVersions("main");
|
||||
for (Integer version : versions)
|
||||
{
|
||||
System.out.println("V:" + version);
|
||||
System.out.println(recursiveList("main", version));
|
||||
}
|
||||
List<FolderEntry> original = fService.getDirectoryListing(-1, "main:a");
|
||||
List<FolderEntry> branch = fService.getDirectoryListing(-1, "main:d/e/abranch");
|
||||
assertEquals(original, branch);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating a layer.
|
||||
*/
|
||||
public void testCreateLayer()
|
||||
{
|
||||
try
|
||||
{
|
||||
setupBasicTree();
|
||||
fService.createLayeredDirectory("main:a", "main:d/e", "alayer");
|
||||
fService.createSnapshot("main");
|
||||
System.out.println(recursiveList("main", -1));
|
||||
List<FolderEntry> original = fService.getDirectoryListing(-1, "main:a");
|
||||
List<FolderEntry> layer = fService.getDirectoryListing(-1, "main:d/e/alayer");
|
||||
assertEquals(original, layer);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to write a recursive listing of a repository at a given version.
|
||||
* @param repoName The name of the repository.
|
||||
* @param version The version to look under.
|
||||
*/
|
||||
private String recursiveList(String repoName, int version)
|
||||
{
|
||||
return recursiveList(repoName + ":/", version, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive list the given path.
|
||||
* @param path The path.
|
||||
* @param version The version.
|
||||
* @param indent The current indent level.
|
||||
*/
|
||||
private String recursiveList(String path, int version, int indent)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < indent; i++)
|
||||
{
|
||||
builder.append(' ');
|
||||
}
|
||||
builder.append(path);
|
||||
builder.append(' ');
|
||||
Lookup lookup = fService.lookup(version, path);
|
||||
AVMNode node = lookup.getCurrentNode();
|
||||
builder.append(node.toString(lookup));
|
||||
builder.append('\n');
|
||||
if (node instanceof DirectoryNode)
|
||||
{
|
||||
String basename = path.endsWith("/") ? path.substring(0, path.length() - 1) : path + "/";
|
||||
List<FolderEntry> listing = fService.getDirectoryListing(version, path);
|
||||
for (FolderEntry entry : listing)
|
||||
{
|
||||
builder.append(recursiveList(basename + entry.getName(), version, indent + 2));
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a basic tree.
|
||||
*/
|
||||
private void setupBasicTree()
|
||||
{
|
||||
fService.createDirectory("main:/", "a");
|
||||
fService.createDirectory("main:a", "b");
|
||||
fService.createDirectory("main:a/b", "c");
|
||||
fService.createDirectory("main:/", "d");
|
||||
fService.createDirectory("main:d", "e");
|
||||
fService.createDirectory("main:d/e", "f");
|
||||
fService.createFile("main:a/b/c", "foo");
|
||||
PrintStream out = new PrintStream(fService.getFileOutputStream("main:a/b/c/foo"));
|
||||
out.println("I am main:a/b/c/foo");
|
||||
out.close();
|
||||
fService.createFile("main:a/b/c", "bar");
|
||||
out = new PrintStream(fService.getFileOutputStream("main:a/b/c/bar"));
|
||||
out.println("I am main:a/b/c/bar");
|
||||
out.close();
|
||||
ArrayList<String> toSnapshot = new ArrayList<String>();
|
||||
toSnapshot.add("main");
|
||||
fService.createSnapshot(toSnapshot);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user