mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V3.1 to HEAD
13965: Line-endings only 13967: Enable upgrade of MT env from 3.0.x to 3.1.1+ (with out-of-date config warning on startup rather than errors later) 13976: Line-endings only 13977: MT - add unit test (for dynamic models) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13980 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.tenant;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
@@ -42,7 +43,10 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
@@ -86,35 +90,37 @@ public class MultiTDemoTest extends TestCase
|
||||
private TenantService tenantService;
|
||||
private AuthorityService authorityService;
|
||||
private CategoryService categoryService;
|
||||
private CheckOutCheckInService cociService;
|
||||
private CheckOutCheckInService cociService;
|
||||
private RepoAdminService repoAdminService;
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
public static int NUM_TENANTS = 11;
|
||||
public static int NUM_TENANTS = 2;
|
||||
|
||||
public static final String TEST_TENANT_DOMAIN = "my.test";
|
||||
public static final String TEST_TENANT_DOMAIN2 = TEST_TENANT_DOMAIN+"2";
|
||||
|
||||
public static List<String> tenants;
|
||||
|
||||
static
|
||||
{
|
||||
tenants = new ArrayList<String>(NUM_TENANTS);
|
||||
for (int i = 1; i <= NUM_TENANTS; i++)
|
||||
{
|
||||
tenants.add(TEST_TENANT_DOMAIN+i);
|
||||
}
|
||||
public static final String TEST_TENANT_DOMAIN = "my.test";
|
||||
public static final String TEST_TENANT_DOMAIN2 = TEST_TENANT_DOMAIN+"2";
|
||||
|
||||
public static List<String> tenants;
|
||||
|
||||
static
|
||||
{
|
||||
tenants = new ArrayList<String>(NUM_TENANTS);
|
||||
for (int i = 1; i <= NUM_TENANTS; i++)
|
||||
{
|
||||
tenants.add(TEST_TENANT_DOMAIN+i);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String ROOT_DIR = "./tenantstores";
|
||||
|
||||
public static final String DEFAULT_ADMIN_PW = "admin";
|
||||
public static final String DEFAULT_ADMIN_PW = "admin";
|
||||
|
||||
public static final String DEFAULT_GUEST_UN = "guest";
|
||||
public static final String DEFAULT_GUEST_PW = "thiscanbeanything";
|
||||
|
||||
public static final String DEFAULT_GUEST_UN = "guest";
|
||||
public static final String DEFAULT_GUEST_PW = "thiscanbeanything";
|
||||
|
||||
public static final String TEST_USER1 = "alice";
|
||||
public static final String TEST_USER2 = "bob";
|
||||
public static final String TEST_USER3 = "eve";
|
||||
public static final String TEST_USER4 = "fred";
|
||||
public static final String TEST_USER4 = "fred";
|
||||
|
||||
private static final int DEFAULT_STORE_COUNT = 7; // including siteStore
|
||||
|
||||
@@ -142,7 +148,9 @@ public class MultiTDemoTest extends TestCase
|
||||
ownableService = (OwnableService) ctx.getBean("OwnableService");
|
||||
authorityService = (AuthorityService) ctx.getBean("AuthorityService");
|
||||
categoryService = (CategoryService) ctx.getBean("CategoryService");
|
||||
cociService = (CheckOutCheckInService) ctx.getBean("CheckoutCheckinService");
|
||||
cociService = (CheckOutCheckInService) ctx.getBean("CheckoutCheckinService");
|
||||
repoAdminService = (RepoAdminService) ctx.getBean("RepoAdminService");
|
||||
dictionaryService = (DictionaryService) ctx.getBean("DictionaryService");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,8 +162,8 @@ public class MultiTDemoTest extends TestCase
|
||||
|
||||
public void testCreateTenants() throws Throwable
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin
|
||||
|
||||
logger.info("Create tenants");
|
||||
|
||||
Set<NodeRef> personRefs = personService.getAllPeople();
|
||||
@@ -180,8 +188,8 @@ public class MultiTDemoTest extends TestCase
|
||||
{
|
||||
if (! tenantAdminService.existsTenant(tenantDomain))
|
||||
{
|
||||
//tenantAdminService.createTenant(tenantDomain, DEFAULT_ADMIN_PW.toCharArray(), ROOT_DIR + "/" + tenantDomain);
|
||||
tenantAdminService.createTenant(tenantDomain, (DEFAULT_ADMIN_PW+" "+tenantDomain).toCharArray(), null); // use default root dir
|
||||
//tenantAdminService.createTenant(tenantDomain, DEFAULT_ADMIN_PW.toCharArray(), ROOT_DIR + "/" + tenantDomain);
|
||||
tenantAdminService.createTenant(tenantDomain, (DEFAULT_ADMIN_PW+" "+tenantDomain).toCharArray(), null); // use default root dir
|
||||
|
||||
logger.info("Created tenant " + tenantDomain);
|
||||
}
|
||||
@@ -219,18 +227,18 @@ public class MultiTDemoTest extends TestCase
|
||||
{
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
createUser(TEST_USER1, tenantDomain, TEST_USER1+" "+tenantDomain);
|
||||
createUser(TEST_USER2, tenantDomain, TEST_USER2+" "+tenantDomain);
|
||||
createUser(TEST_USER1, tenantDomain, TEST_USER1+" "+tenantDomain);
|
||||
createUser(TEST_USER2, tenantDomain, TEST_USER2+" "+tenantDomain);
|
||||
|
||||
if (tenantDomain.equals(TEST_TENANT_DOMAIN2))
|
||||
{
|
||||
createUser(TEST_USER3, tenantDomain, TEST_USER3+" "+tenantDomain);
|
||||
createUser(TEST_USER3, tenantDomain, TEST_USER3+" "+tenantDomain);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -240,7 +248,7 @@ public class MultiTDemoTest extends TestCase
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
@@ -248,17 +256,17 @@ public class MultiTDemoTest extends TestCase
|
||||
{
|
||||
Set<NodeRef> personRefs = personService.getAllPeople();
|
||||
|
||||
for (NodeRef personRef : personRefs)
|
||||
{
|
||||
String userName = (String)nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
|
||||
assertTrue(userName.endsWith(tenantDomain));
|
||||
|
||||
logger.info("Create users: get all people - found user: "+userName);
|
||||
|
||||
NodeRef homeSpaceRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);
|
||||
assertNotNull(homeSpaceRef);
|
||||
}
|
||||
|
||||
for (NodeRef personRef : personRefs)
|
||||
{
|
||||
String userName = (String)nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
|
||||
assertTrue(userName.endsWith(tenantDomain));
|
||||
|
||||
logger.info("Create users: get all people - found user: "+userName);
|
||||
|
||||
NodeRef homeSpaceRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);
|
||||
assertNotNull(homeSpaceRef);
|
||||
}
|
||||
|
||||
if (tenantDomain.equals(TEST_TENANT_DOMAIN2))
|
||||
{
|
||||
assertEquals(5, personRefs.size()); // admin@tenant, guest@tenant, alice@tenant, bob@tenant, eve@tenant
|
||||
@@ -269,7 +277,7 @@ public class MultiTDemoTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantAdminName);
|
||||
@@ -284,9 +292,9 @@ public class MultiTDemoTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testLoginTenantUsers() throws Throwable
|
||||
public void testLoginTenantUsers() throws Throwable
|
||||
{
|
||||
logger.info("Login tenant users");
|
||||
logger.info("Login tenant users");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -294,13 +302,13 @@ public class MultiTDemoTest extends TestCase
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
loginLogoutUser(tenantService.getDomainUser(TEST_USER1, tenantDomain), TEST_USER1+" "+tenantDomain);
|
||||
loginLogoutUser(tenantService.getDomainUser(TEST_USER1, tenantDomain), TEST_USER1+" "+tenantDomain);
|
||||
|
||||
loginLogoutUser(tenantService.getDomainUser(TEST_USER2, tenantDomain), TEST_USER2+" "+tenantDomain);
|
||||
loginLogoutUser(tenantService.getDomainUser(TEST_USER2, tenantDomain), TEST_USER2+" "+tenantDomain);
|
||||
|
||||
if (tenantDomain.equals(TEST_TENANT_DOMAIN2))
|
||||
{
|
||||
loginLogoutUser(tenantService.getDomainUser(TEST_USER3, tenantDomain), TEST_USER3+" "+tenantDomain);
|
||||
loginLogoutUser(tenantService.getDomainUser(TEST_USER3, tenantDomain), TEST_USER3+" "+tenantDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,57 +321,57 @@ public class MultiTDemoTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testLoginTenantGuests() throws Throwable
|
||||
{
|
||||
logger.info("Login tenant guests");
|
||||
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
loginLogoutUser(tenantService.getDomainUser(DEFAULT_GUEST_UN, tenantDomain), DEFAULT_GUEST_UN);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
StringWriter stackTrace = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(stackTrace));
|
||||
System.err.println(stackTrace.toString());
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
public void testLoginTenantAdmin() throws Throwable
|
||||
{
|
||||
logger.info("Login tenant admins");
|
||||
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
loginLogoutUser(tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain), DEFAULT_ADMIN_PW+" "+tenantDomain);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
StringWriter stackTrace = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(stackTrace));
|
||||
System.err.println(stackTrace.toString());
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
public void testLoginTenantGuests() throws Throwable
|
||||
{
|
||||
logger.info("Login tenant guests");
|
||||
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
loginLogoutUser(tenantService.getDomainUser(DEFAULT_GUEST_UN, tenantDomain), DEFAULT_GUEST_UN);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
StringWriter stackTrace = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(stackTrace));
|
||||
System.err.println(stackTrace.toString());
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
public void testLoginTenantAdmin() throws Throwable
|
||||
{
|
||||
logger.info("Login tenant admins");
|
||||
|
||||
try
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
loginLogoutUser(tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain), DEFAULT_ADMIN_PW+" "+tenantDomain);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
StringWriter stackTrace = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(stackTrace));
|
||||
System.err.println(stackTrace.toString());
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateGroups()
|
||||
{
|
||||
logger.info("Create demo groups");
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
@@ -394,7 +402,7 @@ public class MultiTDemoTest extends TestCase
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
@@ -524,11 +532,11 @@ public class MultiTDemoTest extends TestCase
|
||||
assertTrue("Super admin: ", (nodeService.getStores().size() >= DEFAULT_STORE_COUNT));
|
||||
return null;
|
||||
}
|
||||
}, AuthenticationUtil.getAdminUserName());
|
||||
}, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
@@ -542,118 +550,171 @@ public class MultiTDemoTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetProperty()
|
||||
{
|
||||
logger.info("Test get property");
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
NodeRef personNodeRef = createUser(TEST_USER4, tenantDomain, TEST_USER4+" "+tenantDomain);
|
||||
|
||||
// Test nodeRef property
|
||||
NodeRef homeFolderNodeRef = (NodeRef)nodeService.getProperty(personNodeRef, ContentModel.PROP_HOMEFOLDER);
|
||||
assertFalse(homeFolderNodeRef.toString().contains(tenantDomain));
|
||||
|
||||
Map<QName, Serializable> props = (Map<QName, Serializable>)nodeService.getProperties(personNodeRef);
|
||||
assertFalse(props.get(ContentModel.PROP_HOMEFOLDER).toString().contains(tenantDomain));
|
||||
|
||||
// Test "store-identifier" property
|
||||
String storeId = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_STORE_IDENTIFIER);
|
||||
assertFalse(storeId.contains(tenantDomain));
|
||||
|
||||
assertFalse(props.get(ContentModel.PROP_STORE_IDENTIFIER).toString().contains(tenantDomain));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantAdminName);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCOCIandSearch()
|
||||
{
|
||||
logger.info("Test checkout/checkin and search");
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
final String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// search for local copy of bootstrapped file 'invite_user_email.ftl' (see email_templates.acp)
|
||||
String origText = "You have been invited to";
|
||||
String query = "+PATH:\"/app:company_home/app:dictionary/app:email_templates/*\" +TEXT:\""+origText+"\"";
|
||||
ResultSet resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
|
||||
assertEquals(1, resultSet.length());
|
||||
|
||||
NodeRef nodeRef = resultSet.getNodeRef(0);
|
||||
|
||||
// checkout, update and checkin
|
||||
|
||||
NodeRef workingCopyNodeRef = cociService.checkout(nodeRef);
|
||||
|
||||
ContentWriter writer = contentService.getWriter(workingCopyNodeRef, ContentModel.PROP_CONTENT, true);
|
||||
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.setEncoding("UTF-8");
|
||||
|
||||
String updateText = "Updated by "+tenantAdminName;
|
||||
writer.putContent(updateText);
|
||||
|
||||
cociService.checkin(workingCopyNodeRef, null);
|
||||
|
||||
query = "+PATH:\"/app:company_home/app:dictionary/app:email_templates/*\" +TEXT:\""+origText+"\"";
|
||||
resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
|
||||
assertEquals(0, resultSet.length());
|
||||
|
||||
query = "+PATH:\"/app:company_home/app:dictionary/app:email_templates/*\" +TEXT:\""+updateText+"\"";
|
||||
resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
|
||||
assertEquals(1, resultSet.length());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantAdminName);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteArchiveAndRestoreContent()
|
||||
{
|
||||
logger.info("test delete/archive & restore content");
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
final String tenantUserName = tenantService.getDomainUser(TEST_USER1, tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
NodeRef homeSpaceRef = getHomeSpaceFolderNode(tenantUserName);
|
||||
NodeRef contentRef = addTextContent(homeSpaceRef, tenantUserName+" tqbfjotld.txt", "The quick brown fox jumps over the lazy dog (tenant " + tenantDomain + ")");
|
||||
|
||||
NodeRef storeArchiveNode = nodeService.getStoreArchiveNode(contentRef.getStoreRef());
|
||||
|
||||
nodeService.deleteNode(contentRef);
|
||||
|
||||
// deduce archived nodeRef
|
||||
StoreRef archiveStoreRef = storeArchiveNode.getStoreRef();
|
||||
NodeRef archivedContentRef = new NodeRef(archiveStoreRef, contentRef.getId());
|
||||
|
||||
nodeService.restoreNode(archivedContentRef, null, null, null);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantUserName);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetProperty()
|
||||
{
|
||||
logger.info("Test get property");
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
NodeRef personNodeRef = createUser(TEST_USER4, tenantDomain, TEST_USER4+" "+tenantDomain);
|
||||
|
||||
// Test nodeRef property
|
||||
NodeRef homeFolderNodeRef = (NodeRef)nodeService.getProperty(personNodeRef, ContentModel.PROP_HOMEFOLDER);
|
||||
assertFalse(homeFolderNodeRef.toString().contains(tenantDomain));
|
||||
|
||||
Map<QName, Serializable> props = (Map<QName, Serializable>)nodeService.getProperties(personNodeRef);
|
||||
assertFalse(props.get(ContentModel.PROP_HOMEFOLDER).toString().contains(tenantDomain));
|
||||
|
||||
// Test "store-identifier" property
|
||||
String storeId = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_STORE_IDENTIFIER);
|
||||
assertFalse(storeId.contains(tenantDomain));
|
||||
|
||||
assertFalse(props.get(ContentModel.PROP_STORE_IDENTIFIER).toString().contains(tenantDomain));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantAdminName);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCOCIandSearch()
|
||||
{
|
||||
logger.info("Test checkout/checkin and search");
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
final String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// search for local copy of bootstrapped file 'invite_user_email.ftl' (see email_templates.acp)
|
||||
String origText = "You have been invited to";
|
||||
String query = "+PATH:\"/app:company_home/app:dictionary/app:email_templates/*\" +TEXT:\""+origText+"\"";
|
||||
ResultSet resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
|
||||
assertEquals(1, resultSet.length());
|
||||
|
||||
NodeRef nodeRef = resultSet.getNodeRef(0);
|
||||
|
||||
// checkout, update and checkin
|
||||
|
||||
NodeRef workingCopyNodeRef = cociService.checkout(nodeRef);
|
||||
|
||||
ContentWriter writer = contentService.getWriter(workingCopyNodeRef, ContentModel.PROP_CONTENT, true);
|
||||
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.setEncoding("UTF-8");
|
||||
|
||||
String updateText = "Updated by "+tenantAdminName;
|
||||
writer.putContent(updateText);
|
||||
|
||||
cociService.checkin(workingCopyNodeRef, null);
|
||||
|
||||
query = "+PATH:\"/app:company_home/app:dictionary/app:email_templates/*\" +TEXT:\""+origText+"\"";
|
||||
resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
|
||||
assertEquals(0, resultSet.length());
|
||||
|
||||
query = "+PATH:\"/app:company_home/app:dictionary/app:email_templates/*\" +TEXT:\""+updateText+"\"";
|
||||
resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
|
||||
assertEquals(1, resultSet.length());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantAdminName);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteArchiveAndRestoreContent()
|
||||
{
|
||||
logger.info("test delete/archive & restore content");
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
final String tenantUserName = tenantService.getDomainUser(TEST_USER1, tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
NodeRef homeSpaceRef = getHomeSpaceFolderNode(tenantUserName);
|
||||
NodeRef contentRef = addTextContent(homeSpaceRef, tenantUserName+" tqbfjotld.txt", "The quick brown fox jumps over the lazy dog (tenant " + tenantDomain + ")");
|
||||
|
||||
NodeRef storeArchiveNode = nodeService.getStoreArchiveNode(contentRef.getStoreRef());
|
||||
|
||||
nodeService.deleteNode(contentRef);
|
||||
|
||||
// deduce archived nodeRef
|
||||
StoreRef archiveStoreRef = storeArchiveNode.getStoreRef();
|
||||
NodeRef archivedContentRef = new NodeRef(archiveStoreRef, contentRef.getId());
|
||||
|
||||
nodeService.restoreNode(archivedContentRef, null, null, null);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantUserName);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCustomDynamicModels()
|
||||
{
|
||||
logger.info("test custom/dynamic models");
|
||||
|
||||
final int defaultModelCnt = dictionaryService.getAllModels().size();
|
||||
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
final String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
|
||||
|
||||
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
// no custom models should be deployed yet (note: will fail if re-run)
|
||||
assertEquals(0, repoAdminService.getModels().size());
|
||||
assertEquals(defaultModelCnt, dictionaryService.getAllModels().size());
|
||||
assertNull(dictionaryService.getClass(QName.createQName("{my.new.model}sop")));
|
||||
|
||||
// deploy custom model
|
||||
InputStream modelStream = getClass().getClassLoader().getResourceAsStream("tenant/exampleModel.xml");
|
||||
repoAdminService.deployModel(modelStream, "exampleModel.xml");
|
||||
|
||||
assertEquals(1, repoAdminService.getModels().size());
|
||||
assertEquals(defaultModelCnt+1, dictionaryService.getAllModels().size());
|
||||
|
||||
ClassDefinition myType = dictionaryService.getClass(QName.createQName("{my.new.model}sop"));
|
||||
assertNotNull(myType);
|
||||
assertEquals(QName.createQName("{my.new.model}mynewmodel"),myType.getModel().getName());
|
||||
|
||||
// deactivate model
|
||||
repoAdminService.deactivateModel("exampleModel.xml");
|
||||
|
||||
assertEquals(1, repoAdminService.getModels().size()); // still deployed, although not active
|
||||
assertEquals(defaultModelCnt, dictionaryService.getAllModels().size());
|
||||
assertNull(dictionaryService.getClass(QName.createQName("{my.new.model}sop")));
|
||||
|
||||
// re-activate model
|
||||
repoAdminService.activateModel("exampleModel.xml");
|
||||
|
||||
assertEquals(1, repoAdminService.getModels().size());
|
||||
assertEquals(defaultModelCnt+1, dictionaryService.getAllModels().size());
|
||||
|
||||
myType = dictionaryService.getClass(QName.createQName("{my.new.model}sop"));
|
||||
assertNotNull(myType);
|
||||
assertEquals(QName.createQName("{my.new.model}mynewmodel"),myType.getModel().getName());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantAdminName);
|
||||
}
|
||||
}
|
||||
|
||||
private void createGroup(String shortName, String parentShortName)
|
||||
{
|
||||
// create new Group using authority Service
|
||||
@@ -681,12 +742,12 @@ public class MultiTDemoTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
private NodeRef createUser(String baseUserName, String tenantDomain, String password)
|
||||
private NodeRef createUser(String baseUserName, String tenantDomain, String password)
|
||||
{
|
||||
String userName = tenantService.getDomainUser(baseUserName, tenantDomain);
|
||||
|
||||
NodeRef personNodeRef = null;
|
||||
|
||||
NodeRef personNodeRef = null;
|
||||
|
||||
if (! this.authenticationService.authenticationExists(userName))
|
||||
{
|
||||
NodeRef baseHomeFolder = getUserHomesNodeRef(SPACES_STORE);
|
||||
@@ -708,24 +769,24 @@ public class MultiTDemoTest extends TestCase
|
||||
personProperties.put(ContentModel.PROP_LASTNAME, baseUserName+"-"+tenantDomain); // add domain suffix here for demo only
|
||||
personProperties.put(ContentModel.PROP_EMAIL, userName);
|
||||
|
||||
personNodeRef = this.personService.createPerson(personProperties);
|
||||
personNodeRef = this.personService.createPerson(personProperties);
|
||||
|
||||
// ensure the user can access their own Person object
|
||||
this.permissionService.setPermission(personNodeRef, userName, permissionService.getAllPermission(), true);
|
||||
this.permissionService.setPermission(personNodeRef, userName, permissionService.getAllPermission(), true);
|
||||
|
||||
NodeRef checkHomeSpaceRef = (NodeRef)nodeService.getProperty(personNodeRef, ContentModel.PROP_HOMEFOLDER);
|
||||
assertNotNull(checkHomeSpaceRef);
|
||||
|
||||
NodeRef checkHomeSpaceRef = (NodeRef)nodeService.getProperty(personNodeRef, ContentModel.PROP_HOMEFOLDER);
|
||||
assertNotNull(checkHomeSpaceRef);
|
||||
|
||||
logger.info("Created user " + userName);
|
||||
}
|
||||
else
|
||||
{
|
||||
personNodeRef = personService.getPerson(userName);
|
||||
|
||||
logger.info("Found existing user " + userName);
|
||||
}
|
||||
|
||||
return personNodeRef;
|
||||
else
|
||||
{
|
||||
personNodeRef = personService.getPerson(userName);
|
||||
|
||||
logger.info("Found existing user " + userName);
|
||||
}
|
||||
|
||||
return personNodeRef;
|
||||
}
|
||||
|
||||
private void loginLogoutUser(String username, String password)
|
||||
@@ -736,8 +797,8 @@ public class MultiTDemoTest extends TestCase
|
||||
// set the user name as stored by the back end
|
||||
username = authenticationService.getCurrentUserName();
|
||||
|
||||
NodeRef personRef = personService.getPerson(username);
|
||||
NodeRef homeSpaceRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);
|
||||
NodeRef personRef = personService.getPerson(username);
|
||||
NodeRef homeSpaceRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);
|
||||
|
||||
// check that the home space node exists - else user cannot login
|
||||
if (nodeService.exists(homeSpaceRef) == false)
|
||||
@@ -751,21 +812,24 @@ public class MultiTDemoTest extends TestCase
|
||||
|
||||
private NodeRef getUserHomesNodeRef(StoreRef storeRef)
|
||||
{
|
||||
// get the users' home location
|
||||
String path = "/app:company_home/app:user_homes";
|
||||
// get the "User Homes" location
|
||||
return findFolderNodeRef(storeRef, "/app:company_home/app:user_homes");
|
||||
}
|
||||
|
||||
private NodeRef findFolderNodeRef(StoreRef storeRef, String folderXPath)
|
||||
{
|
||||
ResultSet rs = this.searchService.query(storeRef, SearchService.LANGUAGE_XPATH, folderXPath);
|
||||
|
||||
ResultSet rs = this.searchService.query(storeRef, SearchService.LANGUAGE_XPATH, path);
|
||||
|
||||
NodeRef usersHomeNodeRef = null;
|
||||
if (rs.length() == 0)
|
||||
NodeRef folderNodeRef = null;
|
||||
if (rs.length() != 1)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Cannot find user homes location: " + path);
|
||||
throw new AlfrescoRuntimeException("Cannot find folder location: " + folderXPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
usersHomeNodeRef = rs.getNodeRef(0);
|
||||
folderNodeRef = rs.getNodeRef(0);
|
||||
}
|
||||
return usersHomeNodeRef;
|
||||
return folderNodeRef;
|
||||
}
|
||||
|
||||
private NodeRef createFolderNode(NodeRef parentFolderNodeRef, String nameValue)
|
||||
|
Reference in New Issue
Block a user