mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
First round trip. A unit test instantiates an AVMService and creates a new empty
repository. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2926 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
67
source/java/org/alfresco/repo/avm/AVMServiceTest.java
Normal file
67
source/java/org/alfresco/repo/avm/AVMServiceTest.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.avm;
|
||||
|
||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||
import org.alfresco.repo.avm.impl.AVMServiceImpl;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Big test of AVM behavior.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* The AVMService we are testing.
|
||||
*/
|
||||
private AVMService fService;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
Configuration cfg = HibernateHelper.GetConfiguration();
|
||||
SchemaExport se = new SchemaExport(cfg);
|
||||
se.drop(false, true);
|
||||
AVMServiceImpl service = new AVMServiceImpl();
|
||||
service.setStorage("storage");
|
||||
service.init(true);
|
||||
fService = service;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Nothing. Just make sure set up works.
|
||||
*/
|
||||
public void testNothing()
|
||||
{
|
||||
}
|
||||
}
|
@@ -19,8 +19,6 @@ package org.alfresco.repo.avm;
|
||||
|
||||
import org.alfresco.repo.avm.hibernate.BasicAttributesBean;
|
||||
import org.alfresco.repo.avm.hibernate.BasicAttributesBeanImpl;
|
||||
import org.alfresco.repo.avm.hibernate.ContentBean;
|
||||
import org.alfresco.repo.avm.hibernate.ContentBeanImpl;
|
||||
import org.alfresco.repo.avm.hibernate.PlainFileNodeBean;
|
||||
import org.alfresco.repo.avm.hibernate.PlainFileNodeBeanImpl;
|
||||
|
||||
|
@@ -17,6 +17,8 @@
|
||||
|
||||
package org.alfresco.repo.avm.hibernate;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* This is a helper class that knows how to issue identifiers.
|
||||
* @author britt
|
||||
@@ -51,10 +53,11 @@ public class Issuer
|
||||
* @param name The name of this issuer.
|
||||
* @param next The next number to issue.
|
||||
*/
|
||||
public Issuer(String name, long next)
|
||||
public Issuer(String name, long next, Session session)
|
||||
{
|
||||
fName = name;
|
||||
fNext = next;
|
||||
session.save(this);
|
||||
}
|
||||
|
||||
// Bean methods.
|
||||
|
@@ -76,9 +76,9 @@ public class TestPopulate extends TestCase
|
||||
public void perform(Session session)
|
||||
{
|
||||
// Set up issuers.
|
||||
Issuer nodeIssuer = new Issuer("node", 0);
|
||||
Issuer contentIssuer = new Issuer("content", 0);
|
||||
Issuer repositoryIssuer = new Issuer("repository", 0);
|
||||
Issuer nodeIssuer = new Issuer("node", 0, session);
|
||||
Issuer contentIssuer = new Issuer("content", 0, session);
|
||||
Issuer repositoryIssuer = new Issuer("repository", 0, session);
|
||||
// Make the initial root directory.
|
||||
long time = System.currentTimeMillis();
|
||||
BasicAttributesBean attrs = new BasicAttributesBeanImpl("britt",
|
||||
@@ -105,9 +105,6 @@ public class TestPopulate extends TestCase
|
||||
session.save(rep);
|
||||
rep.getRoots().put(rep.getNextVersionID(), root);
|
||||
rep.setNextVersionID(rep.getNextVersionID() + 1);
|
||||
session.save(nodeIssuer);
|
||||
session.save(contentIssuer);
|
||||
session.save(repositoryIssuer);
|
||||
root.setIsNew(false);
|
||||
}
|
||||
});
|
||||
|
@@ -30,8 +30,10 @@ import org.alfresco.repo.avm.SuperRepository;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateHelper;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateTxn;
|
||||
import org.alfresco.repo.avm.hibernate.HibernateTxnCallback;
|
||||
import org.alfresco.repo.avm.hibernate.Issuer;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
|
||||
/**
|
||||
* Implements the AVMService. Stub.
|
||||
@@ -61,13 +63,46 @@ public class AVMServiceImpl implements AVMService
|
||||
|
||||
/**
|
||||
* Basic constructor for the service.
|
||||
* @param createTables Flag for whether tables should be created.
|
||||
*/
|
||||
public AVMServiceImpl()
|
||||
{
|
||||
fSuperRepository = new ThreadLocal<SuperRepository>();
|
||||
fSessionFactory = HibernateHelper.GetSessionFactory();
|
||||
fTransaction = new HibernateTxn(fSessionFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Final initialization of the service. Must be called only on a
|
||||
* fully initialized instance.
|
||||
* @param createTables Whether we should create tables, and a default
|
||||
* repository.
|
||||
*/
|
||||
public void init(boolean createTables)
|
||||
{
|
||||
if (createTables)
|
||||
{
|
||||
SchemaExport se = new SchemaExport(HibernateHelper.GetConfiguration());
|
||||
se.drop(false, true);
|
||||
se.create(false, true);
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public InputStream in = null;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
new Issuer("node", 0L, session);
|
||||
new Issuer("content", 0L, session);
|
||||
new Issuer("branch", 0L, session);
|
||||
new Issuer("layer", 0L, session);
|
||||
}
|
||||
};
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit);
|
||||
createRepository("main");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the location of file storage.
|
||||
* @param storage
|
||||
|
@@ -98,7 +98,7 @@ public class RepositoryImpl implements Repository
|
||||
fSuper.getSession().save(rootBean);
|
||||
fData.setRoot(rootBean);
|
||||
fData.getRoots().put(fData.getNextVersionID(), rootBean);
|
||||
fData.setNextVersionID(fData.getNextVersionID() + 1);
|
||||
fData.setNextVersionID(fData.getNextVersionID());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -153,13 +153,16 @@ public class SuperRepositoryImpl implements SuperRepository
|
||||
String [] pathParts = SplitPath(srcPath);
|
||||
Repository srcRepo = getRepositoryByName(pathParts[0]);
|
||||
Lookup sPath = srcRepo.lookup(version, pathParts[1]);
|
||||
// Lookup the destination direcctory.
|
||||
// Lookup the destination directory.
|
||||
pathParts = SplitPath(dstPath);
|
||||
Repository dstRepo = getRepositoryByName(pathParts[0]);
|
||||
Lookup dPath = dstRepo.lookupDirectory(-1, pathParts[1]);
|
||||
DirectoryNode dirNode = (DirectoryNode)dPath.getCurrentNode();
|
||||
AVMNode srcNode = sPath.getCurrentNode();
|
||||
AVMNode dstNode = null;
|
||||
// We do different things depending on what kind of thing we're
|
||||
// branching from. I'd be considerably happier if we disallowed
|
||||
// certain scenarios, but Jon won't let me :P (bhp).
|
||||
if (srcNode instanceof PlainDirectoryNode)
|
||||
{
|
||||
dstNode = new PlainDirectoryNode((PlainDirectoryNode)srcNode, dstRepo);
|
||||
@@ -200,6 +203,7 @@ public class SuperRepositoryImpl implements SuperRepository
|
||||
public void rename(String srcPath, String srcName, String dstPath,
|
||||
String dstName)
|
||||
{
|
||||
// This is about as ugly as it gets.
|
||||
String [] pathParts = SplitPath(srcPath);
|
||||
Repository srcRepo = getRepositoryByName(pathParts[0]);
|
||||
Lookup sPath = srcRepo.lookupDirectory(-1, pathParts[1]);
|
||||
@@ -246,6 +250,8 @@ public class SuperRepositoryImpl implements SuperRepository
|
||||
}
|
||||
else if (srcNode instanceof LayeredDirectoryNode)
|
||||
{
|
||||
// TODO I think I need to subdivide this logic again.
|
||||
// based on whether the destination is a layer or not.
|
||||
if (!sPath.isLayered() || (sPath.isInThisLayer() &&
|
||||
srcDir instanceof LayeredDirectoryNode &&
|
||||
((LayeredDirectoryNode)srcDir).directlyContains(srcNode)))
|
||||
@@ -295,6 +301,9 @@ public class SuperRepositoryImpl implements SuperRepository
|
||||
srcDir.removeChild(srcName, sPath);
|
||||
}
|
||||
|
||||
// TODO Should we allow cross-repository sliding. Tentatively no, because
|
||||
// it serves no earthly purpose. God knows we need to trim the combinatorial
|
||||
// tree of possibilities.
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.SuperRepository#slide(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
@@ -502,7 +511,7 @@ public class SuperRepositoryImpl implements SuperRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to split a path, foo:/bar/baz into its repository and path parts.
|
||||
* Utility to split a path, foo:bar/baz into its repository and path parts.
|
||||
* @param path The fully qualified path.
|
||||
* @return The repository name and the repository path.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user