mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)
74034: Merged EOL to HEAD-BUG-FIX (5.0/Cloud) 73956: ACE-2013 EOL JCR, JCR-RMI, etc in 5.0 - There are still quite a few JCR references, but some of these are for open CMIS and 2 jcrmodel xml files 74023: ACE-2013 EOL JCR, JCR-RMI, etc in 5.0 - Repo did not start git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74869 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -71,16 +71,6 @@ public class Repository01TestSuite extends TestSuite
|
||||
suite.addTestSuite(org.alfresco.filesys.repo.LockKeeperImplTest.class);
|
||||
}
|
||||
|
||||
static void tests5(TestSuite suite) // tests="19" time="12.852"
|
||||
{
|
||||
suite.addTestSuite(org.alfresco.jcr.importer.ImportTest.class);
|
||||
suite.addTestSuite(org.alfresco.jcr.item.Alf1791Test.class);
|
||||
suite.addTestSuite(org.alfresco.jcr.item.ItemTest.class);
|
||||
suite.addTestSuite(org.alfresco.jcr.query.QueryManagerImplTest.class);
|
||||
suite.addTestSuite(org.alfresco.jcr.repository.RepositoryImplTest.class);
|
||||
suite.addTestSuite(org.alfresco.jcr.session.SessionImplTest.class);
|
||||
}
|
||||
|
||||
static void tests6(TestSuite suite)
|
||||
{
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.opencmis.CMISTest.class));
|
||||
|
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* See {@link RepositoryMisc01TestSuite}
|
||||
*
|
||||
* @Author Alan Davis
|
||||
*/
|
||||
public class Repository05TestSuite extends TestSuite
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite();
|
||||
Repository01TestSuite.tests5(suite);
|
||||
return suite;
|
||||
}
|
||||
}
|
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.importer;
|
||||
|
||||
import javax.jcr.ImportUUIDBehavior;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
|
||||
import org.alfresco.jcr.test.BaseJCRTest;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class ImportTest extends BaseJCRTest
|
||||
{
|
||||
protected Session superuserSession;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray());
|
||||
superuserSession = repository.login(superuser, getWorkspace());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
superuserSession.logout();
|
||||
}
|
||||
|
||||
public void testSysImport()
|
||||
throws Exception
|
||||
{
|
||||
ClassPathResource sysview = new ClassPathResource("org/alfresco/jcr/test/sysview.xml");
|
||||
superuserSession.importXML("/testroot", sysview.getInputStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
|
||||
}
|
||||
|
||||
public void testDocImport()
|
||||
throws Exception
|
||||
{
|
||||
ClassPathResource sysview = new ClassPathResource("org/alfresco/jcr/test/docview.xml");
|
||||
superuserSession.importXML("/testroot", sysview.getInputStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
|
||||
}
|
||||
|
||||
public void testThrowCollision()
|
||||
throws Exception
|
||||
{
|
||||
ClassPathResource sysview = new ClassPathResource("org/alfresco/jcr/test/docview.xml");
|
||||
superuserSession.importXML("/testroot", sysview.getInputStream(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING);
|
||||
|
||||
try
|
||||
{
|
||||
superuserSession.importXML("/testroot", sysview.getInputStream(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
|
||||
fail("Failed to catch UUID collision");
|
||||
}
|
||||
catch(RepositoryException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
package org.alfresco.jcr.item;
|
||||
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
|
||||
import org.alfresco.jcr.test.BaseJCRTest;
|
||||
import org.alfresco.test_category.LegacyCategory;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class Alf1791Test extends BaseJCRTest
|
||||
{
|
||||
|
||||
protected Session superuserSession;
|
||||
protected Node node;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray());
|
||||
superuserSession = repository.login(superuser, getWorkspace());
|
||||
Node rootNode = superuserSession.getRootNode();
|
||||
node = rootNode.addNode("alf1791", "cm:content");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
node.remove();
|
||||
superuserSession.logout();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
public void testAlf1791()
|
||||
throws Exception
|
||||
{
|
||||
final String mixPrefix = node.getSession().getNamespacePrefix("http://www.jcp.org/jcr/mix/1.0");
|
||||
final String mixReferenceable = mixPrefix + ":referenceable";
|
||||
final String sysPrefix = node.getSession().getNamespacePrefix("http://www.alfresco.org/model/system/1.0");
|
||||
final String sysReferenceable = sysPrefix + ":referenceable";
|
||||
|
||||
node.addMixin(mixReferenceable);
|
||||
if (!hasMixin(node, mixReferenceable))
|
||||
{
|
||||
throw new RepositoryException("Node just made 'mix:referenceable' isn't! ('sys:referenceable'=" + hasMixin(node, sysReferenceable) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final boolean hasMixin(final Node node, final String mixinName)
|
||||
throws RepositoryException
|
||||
{
|
||||
final NodeType[] mixinNodeTypes = node.getMixinNodeTypes();
|
||||
if (mixinNodeTypes == null)
|
||||
return false;
|
||||
for (NodeType mixinNodeType : mixinNodeTypes)
|
||||
{
|
||||
if (mixinNodeType == null)
|
||||
continue;
|
||||
if (mixinName.equals(mixinNodeType.getName()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,339 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.item;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
import javax.jcr.version.Version;
|
||||
import javax.jcr.version.VersionHistory;
|
||||
import javax.jcr.version.VersionIterator;
|
||||
|
||||
import org.alfresco.jcr.api.JCRNodeRef;
|
||||
import org.alfresco.jcr.test.BaseJCRTest;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
import org.alfresco.test_category.LegacyCategory;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
|
||||
/**
|
||||
* One-off item tests - sanity checks for bug fixes
|
||||
*
|
||||
* @author janv
|
||||
*/
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class ItemTest extends BaseJCRTest
|
||||
{
|
||||
protected Session session;
|
||||
|
||||
private static final String QUICK_TXT = "The quick brown fox jumps over the lazy dog";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void test_ALFCOM_1655() throws RepositoryException
|
||||
{
|
||||
SimpleCredentials user = new SimpleCredentials(getAdminUserName(), "admin".toCharArray());
|
||||
|
||||
session = repository.login(user, getWorkspace());
|
||||
|
||||
try
|
||||
{
|
||||
Node rootNode = session.getRootNode();
|
||||
assertNotNull(rootNode);
|
||||
|
||||
Node aNode = rootNode.addNode("A1","my:a");
|
||||
assertNotNull(aNode);
|
||||
|
||||
Node bNode = aNode.addNode("B1","my:b");
|
||||
assertNotNull(bNode);
|
||||
|
||||
aNode = rootNode.addNode("A2","cm:folder");
|
||||
assertNotNull(aNode);
|
||||
|
||||
bNode = aNode.addNode("B2","cm:folder");
|
||||
assertNotNull(bNode);
|
||||
|
||||
Node cNode = rootNode.addNode("C1","my:c");
|
||||
assertNotNull(cNode);
|
||||
|
||||
aNode = cNode.addNode("A3","my:a");
|
||||
assertNotNull(aNode);
|
||||
|
||||
bNode = cNode.addNode("B3","my:b");
|
||||
assertNotNull(bNode);
|
||||
|
||||
session.save();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (session != null) { session.logout(); }
|
||||
}
|
||||
|
||||
session = repository.login(user, getWorkspace());
|
||||
|
||||
try
|
||||
{
|
||||
Node rootNode = session.getRootNode();
|
||||
assertNotNull(rootNode);
|
||||
|
||||
Node aNode = rootNode.getNode("A1");
|
||||
assertNotNull(aNode);
|
||||
|
||||
Node bNode = aNode.getNode("B1");
|
||||
assertNotNull(bNode);
|
||||
|
||||
aNode = rootNode.getNode("A2");
|
||||
assertNotNull(aNode);
|
||||
|
||||
bNode = aNode.getNode("B2");
|
||||
assertNotNull(bNode);
|
||||
|
||||
Node cNode = rootNode.getNode("C1");
|
||||
assertNotNull(cNode);
|
||||
|
||||
aNode = cNode.getNode("A3");
|
||||
assertNotNull(aNode);
|
||||
|
||||
bNode = cNode.getNode("B3");
|
||||
assertNotNull(bNode);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (session != null) { session.logout(); }
|
||||
}
|
||||
}
|
||||
|
||||
public void test_ALFCOM_1507() throws RepositoryException
|
||||
{
|
||||
SimpleCredentials user = new SimpleCredentials(getAdminUserName(), "admin".toCharArray());
|
||||
|
||||
session = repository.login(user, "SpacesStore");
|
||||
|
||||
try
|
||||
{
|
||||
Node rootNode = session.getRootNode();
|
||||
Node companyHome = rootNode.getNode("app:company_home");
|
||||
|
||||
// create the content node
|
||||
String name = "JCR sample (" + System.currentTimeMillis() + ")";
|
||||
Node content = companyHome.addNode("cm:" + name, "cm:content");
|
||||
content.setProperty("cm:name", name);
|
||||
|
||||
// add titled aspect (for Web Client display)
|
||||
content.addMixin("cm:titled");
|
||||
content.setProperty("cm:title", name);
|
||||
content.setProperty("cm:description", name);
|
||||
|
||||
//
|
||||
// write some content to new node
|
||||
//
|
||||
content.setProperty("cm:content", QUICK_TXT);
|
||||
|
||||
// use Alfresco native API to set mimetype
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
setMimetype(registry, content, "cm:content", MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
|
||||
// enable versioning capability
|
||||
content.addMixin("mix:versionable");
|
||||
|
||||
NodeRef nodeRef = JCRNodeRef.getNodeRef(content);
|
||||
|
||||
VersionService versionService = registry.getVersionService();
|
||||
NodeService nodeService = registry.getNodeService();
|
||||
|
||||
for (int i = 0; i <= 19; i++)
|
||||
{
|
||||
content.checkout();
|
||||
|
||||
content.setProperty("cm:title", "v"+i);
|
||||
|
||||
content.checkin();
|
||||
|
||||
VersionHistory vh = content.getVersionHistory();
|
||||
VersionIterator vi = vh.getAllVersions();
|
||||
assertEquals(i+1, vi.getSize());
|
||||
|
||||
Version v = content.getBaseVersion();
|
||||
assertEquals("", "0."+ (i + 1), v.getName());
|
||||
|
||||
org.alfresco.service.cmr.version.VersionHistory versionHistory = versionService.getVersionHistory(nodeRef);
|
||||
|
||||
// Before
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
org.alfresco.service.cmr.version.Version version = versionService.getCurrentVersion(nodeRef);
|
||||
|
||||
long beforeDuration = System.currentTimeMillis() - startTime;
|
||||
|
||||
assertEquals("0."+(i + 1), version.getVersionLabel());
|
||||
|
||||
// After
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
|
||||
if (versionHistory != null)
|
||||
{
|
||||
String versionLabel = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
|
||||
version = versionHistory.getVersion(versionLabel);
|
||||
}
|
||||
|
||||
long afterDuration = System.currentTimeMillis() - startTime;
|
||||
|
||||
assertEquals("0."+(i + 1), version.getVersionLabel());
|
||||
|
||||
System.out.println("getBaseVersion - get current version (BEFORE: " + beforeDuration + "ms, AFTER: " + afterDuration + "ms) ");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (session != null) { session.logout(); }
|
||||
}
|
||||
}
|
||||
|
||||
public void test_JAWS_191() throws Throwable
|
||||
{
|
||||
SimpleCredentials user = new SimpleCredentials(getAdminUserName(), "admin".toCharArray());
|
||||
|
||||
session = repository.login(user, "SpacesStore");
|
||||
|
||||
String runid = ""+System.currentTimeMillis();
|
||||
String pathname = "cm:JCR-"+runid+".jpg";
|
||||
|
||||
String name = "JCR Sample ("+runid+")";
|
||||
|
||||
try
|
||||
{
|
||||
Node rootNode = session.getRootNode();
|
||||
Node companyHome = rootNode.getNode("app:company_home");
|
||||
|
||||
// create the content node
|
||||
Node content = companyHome.addNode(pathname, "cm:content");
|
||||
content.setProperty("cm:name", name);
|
||||
|
||||
// add titled aspect (for Web Client display)
|
||||
content.addMixin("cm:titled");
|
||||
content.setProperty("cm:title", name);
|
||||
content.setProperty("cm:description", name);
|
||||
|
||||
InputStream is = getClass().getClassLoader().getResourceAsStream("org/alfresco/jcr/test/testQuick.jpg");
|
||||
assertNotNull(is);
|
||||
|
||||
//
|
||||
// write some content to new node
|
||||
//
|
||||
content.setProperty("cm:content", is);
|
||||
|
||||
content = companyHome.getNode(pathname);
|
||||
|
||||
// use Alfresco native API to get content data (for mimetype / encoding)
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
ContentData contentData = getContentData(registry, content);
|
||||
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, contentData.getMimetype());
|
||||
assertEquals("UTF-8", contentData.getEncoding());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (session != null) { session.logout(); }
|
||||
}
|
||||
|
||||
session = repository.login(user, "SpacesStore");
|
||||
|
||||
runid = ""+System.currentTimeMillis();
|
||||
pathname = "cm:JCR-"+runid+".txt";
|
||||
|
||||
name = "JCR Sample ("+runid+")";
|
||||
|
||||
try
|
||||
{
|
||||
Node rootNode = session.getRootNode();
|
||||
Node companyHome = rootNode.getNode("app:company_home");
|
||||
|
||||
// create the content node
|
||||
Node content = companyHome.addNode(pathname, "cm:content");
|
||||
content.setProperty("cm:name", name);
|
||||
|
||||
// add titled aspect (for Web Client display)
|
||||
content.addMixin("cm:titled");
|
||||
content.setProperty("cm:title", name);
|
||||
content.setProperty("cm:description", name);
|
||||
|
||||
// Write some content to new node, forcing it to be UTF-8
|
||||
// The source files are UTF-8, so these characters should be easily detected
|
||||
content.setProperty("cm:content", "äöå");
|
||||
|
||||
content = companyHome.getNode(pathname);
|
||||
|
||||
// use Alfresco native API to get content data (for mimetype / encoding)
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
ContentData contentData = getContentData(registry, content);
|
||||
|
||||
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentData.getMimetype());
|
||||
assertEquals("UTF-8", contentData.getEncoding());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (session != null) { session.logout(); }
|
||||
}
|
||||
}
|
||||
|
||||
private static void setMimetype(ServiceRegistry registry, Node node, String propertyName, String mimeType) throws RepositoryException
|
||||
{
|
||||
// convert the JCR Node to an Alfresco Node Reference
|
||||
NodeRef nodeRef = JCRNodeRef.getNodeRef(node);
|
||||
|
||||
// retrieve the Content Property (represented as a ContentData object in Alfresco)
|
||||
NodeService nodeService = registry.getNodeService();
|
||||
ContentData content = (ContentData)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
// update the Mimetype
|
||||
content = ContentData.setMimetype(content, mimeType);
|
||||
nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, content);
|
||||
}
|
||||
|
||||
private static ContentData getContentData(ServiceRegistry registry, Node node) throws RepositoryException
|
||||
{
|
||||
// convert the JCR Node to an Alfresco Node Reference
|
||||
NodeRef nodeRef = JCRNodeRef.getNodeRef(node);
|
||||
|
||||
// retrieve the Content Property (represented as a ContentData object in Alfresco)
|
||||
NodeService nodeService = registry.getNodeService();
|
||||
return (ContentData)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
|
||||
}
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.NodeIterator;
|
||||
import javax.jcr.Property;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
import javax.jcr.Value;
|
||||
import javax.jcr.query.Query;
|
||||
import javax.jcr.query.QueryManager;
|
||||
import javax.jcr.query.QueryResult;
|
||||
import javax.jcr.query.Row;
|
||||
import javax.jcr.query.RowIterator;
|
||||
|
||||
import org.alfresco.jcr.test.BaseJCRTest;
|
||||
|
||||
public class QueryManagerImplTest extends BaseJCRTest
|
||||
{
|
||||
|
||||
protected Session superuserSession;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray());
|
||||
superuserSession = repository.login(superuser, getWorkspace());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
superuserSession.logout();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
public void testQuery()
|
||||
throws Exception
|
||||
{
|
||||
QueryManager queryMgr = superuserSession.getWorkspace().getQueryManager();
|
||||
String[] languages = queryMgr.getSupportedQueryLanguages();
|
||||
assertEquals(1, languages.length);
|
||||
assertEquals(Query.XPATH, languages[0]);
|
||||
|
||||
Query query = queryMgr.createQuery("//*", Query.XPATH);
|
||||
QueryResult result = query.execute();
|
||||
String[] columnNames = result.getColumnNames();
|
||||
|
||||
// iterate via row iterator
|
||||
int rowCnt = 0;
|
||||
RowIterator rowIterator = result.getRows();
|
||||
while(rowIterator.hasNext())
|
||||
{
|
||||
Row row = rowIterator.nextRow();
|
||||
for (String columnName : columnNames)
|
||||
{
|
||||
Value value = row.getValue(columnName);
|
||||
if (value != null)
|
||||
{
|
||||
String strValue = value.getString();
|
||||
assertNotNull(strValue);
|
||||
}
|
||||
}
|
||||
rowCnt++;
|
||||
}
|
||||
|
||||
// iterate via node iterator
|
||||
int nodeCnt = 0;
|
||||
NodeIterator nodeIterator = result.getNodes();
|
||||
while(nodeIterator.hasNext())
|
||||
{
|
||||
Node node = nodeIterator.nextNode();
|
||||
Property property = node.getProperty("sys:node-uuid");
|
||||
Value value = property.getValue();
|
||||
String uuid = value.getString();
|
||||
assertNotNull(uuid);
|
||||
nodeCnt++;
|
||||
}
|
||||
|
||||
// check same number of items returned from each iterator
|
||||
assertEquals(rowCnt, nodeCnt);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.repository;
|
||||
|
||||
import javax.jcr.LoginException;
|
||||
import javax.jcr.NoSuchWorkspaceException;
|
||||
import javax.jcr.Repository;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
|
||||
import org.alfresco.jcr.test.BaseJCRTest;
|
||||
|
||||
|
||||
/**
|
||||
* Test JCR Repository Implementation
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class RepositoryImplTest extends BaseJCRTest
|
||||
{
|
||||
|
||||
public void testDescriptors()
|
||||
{
|
||||
String[] keys = repository.getDescriptorKeys();
|
||||
assertEquals(11, keys.length);
|
||||
for (String key : keys)
|
||||
{
|
||||
String value = repository.getDescriptor(key);
|
||||
assertNotNull(value);
|
||||
}
|
||||
|
||||
assertNotNull(repository.getDescriptor(Repository.REP_NAME_DESC));
|
||||
System.out.println(repository.getDescriptor(Repository.REP_NAME_DESC));
|
||||
assertNotNull(repository.getDescriptor(Repository.REP_VENDOR_DESC));
|
||||
assertNotNull(repository.getDescriptor(Repository.REP_VENDOR_URL_DESC));
|
||||
assertNotNull(repository.getDescriptor(Repository.REP_VERSION_DESC));
|
||||
System.out.println(repository.getDescriptor(Repository.REP_VERSION_DESC));
|
||||
assertNotNull(repository.getDescriptor(Repository.SPEC_NAME_DESC));
|
||||
assertNotNull(repository.getDescriptor(Repository.SPEC_VERSION_DESC));
|
||||
assertEquals("true", repository.getDescriptor(Repository.LEVEL_1_SUPPORTED));
|
||||
assertEquals("true", repository.getDescriptor(Repository.LEVEL_2_SUPPORTED));
|
||||
assertEquals("true", repository.getDescriptor(Repository.OPTION_TRANSACTIONS_SUPPORTED));
|
||||
assertEquals("true", repository.getDescriptor(Repository.QUERY_XPATH_DOC_ORDER));
|
||||
assertEquals("true", repository.getDescriptor(Repository.QUERY_XPATH_POS_INDEX));
|
||||
}
|
||||
|
||||
public void testBadUsernameLogin() throws Exception
|
||||
{
|
||||
SimpleCredentials badUser = new SimpleCredentials("baduser", "".toCharArray());
|
||||
try
|
||||
{
|
||||
repository.login(badUser);
|
||||
fail("Failed to catch bad username - username should not exist.");
|
||||
}
|
||||
catch (LoginException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testBadPwdLogin() throws Exception
|
||||
{
|
||||
SimpleCredentials badPwd = new SimpleCredentials("superuser", "badpwd".toCharArray());
|
||||
try
|
||||
{
|
||||
repository.login(badPwd);
|
||||
fail("Failed to catch bad password - password is invalid.");
|
||||
}
|
||||
catch (LoginException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testNoCredentialsLogin() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
repository.login();
|
||||
fail("Failed to catch no credentials.");
|
||||
}
|
||||
catch (LoginException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testLogin()
|
||||
throws RepositoryException
|
||||
{
|
||||
SimpleCredentials good = new SimpleCredentials("superuser", "".toCharArray());
|
||||
try
|
||||
{
|
||||
Session session = repository.login(good, getWorkspace());
|
||||
assertNotNull(session);
|
||||
session.logout();
|
||||
}
|
||||
catch (LoginException e)
|
||||
{
|
||||
fail("Failed to login.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Session session = repository.login(good, null);
|
||||
session.logout();
|
||||
}
|
||||
catch (NoSuchWorkspaceException e)
|
||||
{
|
||||
fail("Failed to detect default workspace");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.session;
|
||||
|
||||
import javax.jcr.Repository;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
|
||||
import org.alfresco.jcr.test.BaseJCRTest;
|
||||
|
||||
|
||||
/**
|
||||
* Test JCR Session
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class SessionImplTest extends BaseJCRTest
|
||||
{
|
||||
protected Session superuserSession;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray());
|
||||
superuser.setAttribute("attr1", "superuserValue");
|
||||
superuser.setAttribute("attr2", new Integer(1));
|
||||
superuserSession = repository.login(superuser, getWorkspace());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
superuserSession.logout();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testRepository()
|
||||
throws RepositoryException
|
||||
{
|
||||
Repository sessionRepository = superuserSession.getRepository();
|
||||
assertNotNull(sessionRepository);
|
||||
assertEquals(repository, sessionRepository);
|
||||
}
|
||||
|
||||
public void testUserId()
|
||||
{
|
||||
{
|
||||
String userId = superuserSession.getUserID();
|
||||
assertNotNull(userId);
|
||||
assertEquals("superuser", userId);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAttributes()
|
||||
{
|
||||
{
|
||||
String[] names = superuserSession.getAttributeNames();
|
||||
assertNotNull(names);
|
||||
assertEquals(2, names.length);
|
||||
String value1 = (String)superuserSession.getAttribute("attr1");
|
||||
assertNotNull(value1);
|
||||
assertEquals("superuserValue", value1);
|
||||
Integer value2 = (Integer)superuserSession.getAttribute("attr2");
|
||||
assertNotNull(value2);
|
||||
assertEquals(new Integer(1), value2);
|
||||
String value3 = (String)superuserSession.getAttribute("unknown");
|
||||
assertNull(value3);
|
||||
}
|
||||
}
|
||||
|
||||
public void testLogout()
|
||||
{
|
||||
boolean isLive = superuserSession.isLive();
|
||||
assertTrue(isLive);
|
||||
superuserSession.logout();
|
||||
isLive = superuserSession.isLive();
|
||||
assertFalse(isLive);
|
||||
}
|
||||
|
||||
|
||||
public void testSessionThread()
|
||||
{
|
||||
SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray());
|
||||
try
|
||||
{
|
||||
Session anotherSession = repository.login(superuser, getWorkspace());
|
||||
fail("Exception not thrown when establishing two sessions on same thread");
|
||||
}
|
||||
catch(RepositoryException e)
|
||||
{
|
||||
// successful - multiple sessions on one thread caught
|
||||
}
|
||||
superuserSession.logout();
|
||||
try
|
||||
{
|
||||
Session anotherSession = repository.login(superuser, getWorkspace());
|
||||
anotherSession.logout();
|
||||
}
|
||||
catch(RepositoryException e)
|
||||
{
|
||||
fail("Exception thrown when it shouldn't of been.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.tck;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.jcr.Repository;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
import org.alfresco.jcr.repository.RepositoryFactory;
|
||||
import org.alfresco.jcr.repository.RepositoryImpl;
|
||||
import org.alfresco.jcr.test.TestData;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Setup Repository for access via JNDI by TCK Web Application
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class RepositoryStartupServlet extends HttpServlet
|
||||
{
|
||||
private static final long serialVersionUID = -4763518135895358778L;
|
||||
|
||||
private static InitialContext jndiContext;
|
||||
|
||||
private final static String repositoryName = "Alfresco.Repository";
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the servlet
|
||||
*
|
||||
* @throws ServletException
|
||||
*/
|
||||
public void init()
|
||||
throws ServletException
|
||||
{
|
||||
super.init();
|
||||
|
||||
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
|
||||
RepositoryImpl repository = (RepositoryImpl)context.getBean(RepositoryFactory.REPOSITORY_BEAN);
|
||||
repository.setDefaultWorkspace(TestData.TEST_WORKSPACE);
|
||||
|
||||
try
|
||||
{
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
env.put(Context.PROVIDER_URL, "http://www.alfresco.org");
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.day.crx.jndi.provider.MemoryInitialContextFactory");
|
||||
jndiContext = new InitialContext(env);
|
||||
jndiContext.bind(repositoryName, (Repository)repository);
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the servlet
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
super.destroy();
|
||||
|
||||
if (jndiContext != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
jndiContext.unbind(repositoryName);
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
// Note: Itentionally ignore...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.test;
|
||||
|
||||
import javax.jcr.Repository;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.jcr.repository.RepositoryFactory;
|
||||
import org.alfresco.jcr.repository.RepositoryImpl;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Base JCR Test
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class BaseJCRTest extends TestCase
|
||||
{
|
||||
private RepositoryImpl repositoryImpl;
|
||||
protected Repository repository;
|
||||
protected StoreRef storeRef;
|
||||
protected String adminUserName;
|
||||
|
||||
protected static ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:org/alfresco/jcr/test/test-context.xml");
|
||||
|
||||
protected String getWorkspace()
|
||||
{
|
||||
return storeRef.getIdentifier();
|
||||
}
|
||||
|
||||
protected String getAdminUserName()
|
||||
{
|
||||
return adminUserName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
|
||||
TestData.generateTestData(applicationContext, storeRef.getIdentifier());
|
||||
repositoryImpl = (RepositoryImpl)applicationContext.getBean(RepositoryFactory.REPOSITORY_BEAN);
|
||||
repositoryImpl.setDefaultWorkspace(storeRef.getIdentifier());
|
||||
repository = repositoryImpl;
|
||||
adminUserName = AuthenticationUtil.getAdminUserName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.jcr.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationContext;
|
||||
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.view.ImporterService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
|
||||
|
||||
public class TestData
|
||||
{
|
||||
public static final String TEST_WORKSPACE = "test";
|
||||
|
||||
/**
|
||||
* Generate Test Workspace within Repository
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("org/alfresco/jcr/test/test-context.xml");
|
||||
generateTestData(context, TEST_WORKSPACE);
|
||||
System.out.println("Generated TCK test data to workspace: " + TEST_WORKSPACE);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap Repository with JCR Test Data
|
||||
*
|
||||
* @param applicationContext
|
||||
* @param workspaceName
|
||||
*/
|
||||
public static void generateTestData(final ApplicationContext applicationContext, String workspaceName)
|
||||
{
|
||||
final ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
TransactionService transactionService = serviceRegistry.getTransactionService();
|
||||
RetryingTransactionCallback<Object> createUserWork = new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
public Object execute() throws Exception
|
||||
{
|
||||
// Bootstrap Users
|
||||
MutableAuthenticationDao authDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
|
||||
if (authDAO.userExists("superuser") == false)
|
||||
{
|
||||
authDAO.createUser("superuser", "".toCharArray());
|
||||
}
|
||||
if (authDAO.userExists("user") == false)
|
||||
{
|
||||
authDAO.createUser("user", "".toCharArray());
|
||||
}
|
||||
if (authDAO.userExists("anonymous") == false)
|
||||
{
|
||||
authDAO.createUser("anonymous", "".toCharArray());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(createUserWork);
|
||||
|
||||
try
|
||||
{
|
||||
AuthenticationContext authenticationContext = (AuthenticationContext)applicationContext.getBean("authenticationContext");
|
||||
authenticationContext.setSystemUserAsCurrentUser();
|
||||
|
||||
try
|
||||
{
|
||||
// Bootstrap Workspace Test Data
|
||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, workspaceName);
|
||||
|
||||
ImporterBootstrap bootstrap = new ImporterBootstrap();
|
||||
bootstrap.setAuthenticationContext((AuthenticationContext) applicationContext.getBean("authenticationContext"));
|
||||
bootstrap.setImporterService((ImporterService) applicationContext.getBean(ServiceRegistry.IMPORTER_SERVICE.getLocalName()));
|
||||
bootstrap.setNodeService((NodeService) applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName()));
|
||||
bootstrap.setNamespaceService((NamespaceService) applicationContext.getBean(ServiceRegistry.NAMESPACE_SERVICE.getLocalName()));
|
||||
bootstrap.setTransactionService((TransactionService) applicationContext.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName()));
|
||||
bootstrap.setRetryingTransactionHelper((RetryingTransactionHelper) applicationContext.getBean("storeImporterTransactionHelper"));
|
||||
bootstrap.setStoreUrl(storeRef.toString());
|
||||
|
||||
List<Properties> views = new ArrayList<Properties>();
|
||||
Properties testView = new Properties();
|
||||
testView.setProperty("path", "/");
|
||||
testView.setProperty("location", "org/alfresco/jcr/test/testData.xml");
|
||||
views.add(testView);
|
||||
bootstrap.setBootstrapViews(views);
|
||||
bootstrap.bootstrap();
|
||||
|
||||
// Bootstrap clears security context
|
||||
authenticationContext.setSystemUserAsCurrentUser();
|
||||
|
||||
PermissionService permissionService = (PermissionService)applicationContext.getBean(ServiceRegistry.PERMISSIONS_SERVICE.getLocalName());
|
||||
NodeService nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
|
||||
// permissionService.setPermission(nodeService.getRootNode(storeRef), PermissionService.ALL_AUTHORITIES, PermissionService.ALL_PERMISSIONS, true);
|
||||
permissionService.setPermission(nodeService.getRootNode(storeRef), "superuser", PermissionService.ALL_PERMISSIONS, true);
|
||||
permissionService.setPermission(nodeService.getRootNode(storeRef), "anonymous", PermissionService.READ, true);
|
||||
permissionService.setPermission(nodeService.getRootNode(storeRef), "user", PermissionService.READ, true);
|
||||
permissionService.setPermission(nodeService.getRootNode(storeRef), "user", PermissionService.WRITE, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
authenticationContext.clearCurrentSecurityContext();
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
System.out.println("Exception: " + e);
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user