diff --git a/source/java/org/alfresco/repo/version/Node2ServiceImpl.java b/source/java/org/alfresco/repo/version/Node2ServiceImpl.java index f12b6277b5..b5c9c4ecb9 100644 --- a/source/java/org/alfresco/repo/version/Node2ServiceImpl.java +++ b/source/java/org/alfresco/repo/version/Node2ServiceImpl.java @@ -51,12 +51,7 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve * Type translation for version store */ public QName getType(NodeRef nodeRef) throws InvalidNodeRefException - { - if (nodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getType(nodeRef); - } - + { // frozen node type -> replaced by actual node type of the version node return (QName)this.dbNodeService.getType(VersionUtil.convertNodeRef(nodeRef)); } @@ -66,11 +61,6 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve */ public Set getAspects(NodeRef nodeRef) throws InvalidNodeRefException { - if (nodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getAspects(nodeRef); - } - Set aspects = this.dbNodeService.getAspects(VersionUtil.convertNodeRef(nodeRef)); aspects.remove(Version2Model.ASPECT_VERSION); return aspects; @@ -81,11 +71,6 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve */ public Map getProperties(NodeRef nodeRef) throws InvalidNodeRefException { - if (nodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getProperties(nodeRef); - } - Map props = dbNodeService.getProperties(VersionUtil.convertNodeRef(nodeRef)); VersionUtil.convertFrozenToOriginalProps(props); @@ -97,11 +82,6 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve */ public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException { - if (nodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getProperty(nodeRef, qname); - } - // TODO optimise - get property directly and convert if needed Map properties = getProperties(VersionUtil.convertNodeRef(nodeRef)); return properties.get(qname); @@ -114,11 +94,6 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve */ public List getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) { - if (nodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getParentAssocs(nodeRef, typeQNamePattern, qnamePattern); - } - List result = new ArrayList(); if (qnamePattern.isMatch(rootAssocName) == true) { @@ -136,11 +111,6 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve */ public List getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) throws InvalidNodeRefException { - if (nodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getChildAssocs(nodeRef, typeQNamePattern, qnamePattern); - } - // Get the child assoc references from the version store List childAssocRefs = this.dbNodeService.getChildAssocs( VersionUtil.convertNodeRef(nodeRef), @@ -183,11 +153,6 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve */ public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) throws InvalidNodeRefException { - if (nodeRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getPrimaryParent(nodeRef); - } - return new ChildAssociationRef( ContentModel.ASSOC_CHILDREN, dbNodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, Version2Model.STORE_ID)), @@ -203,11 +168,6 @@ public class Node2ServiceImpl extends NodeServiceImpl implements NodeService, Ve @Override public List getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern) { - if (sourceRef.getStoreRef().getIdentifier().equals(VersionModel.STORE_ID)) - { - return super.getTargetAssocs(sourceRef, qnamePattern); - } - // Get the assoc references from the version store List childAssocRefs = this.dbNodeService.getChildAssocs( VersionUtil.convertNodeRef(sourceRef), diff --git a/source/test-java/org/alfresco/AllUnitTestsSuite.java b/source/test-java/org/alfresco/AllUnitTestsSuite.java index a17ff82c0d..f7628d091d 100644 --- a/source/test-java/org/alfresco/AllUnitTestsSuite.java +++ b/source/test-java/org/alfresco/AllUnitTestsSuite.java @@ -45,6 +45,7 @@ public class AllUnitTestsSuite extends TestSuite suite.addTestSuite(org.alfresco.repo.module.ModuleVersionNumberTest.class); suite.addTestSuite(org.alfresco.repo.module.tool.ModuleManagementToolTest.class); suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.module.tool.WarHelperImplTest.class)); + suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.module.tool.ModuleServiceImplTest.class)); suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.nodelocator.NodeLocatorServiceImplTest.class)); suite.addTestSuite(org.alfresco.repo.policy.MTPolicyComponentTest.class); suite.addTestSuite(org.alfresco.repo.policy.PolicyComponentTest.class); @@ -103,7 +104,7 @@ public class AllUnitTestsSuite extends TestSuite suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.search.impl.solr.SolrStoreMappingWrapperTest.class)); suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.security.authentication.CompositePasswordEncoderTest.class)); suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.security.authentication.PasswordHashingTest.class)); - - suite.addTest(org.alfresco.traitextender.TraitExtenderUnitTestSuite.suite()); - suite.addTest(org.alfresco.repo.virtual.VirtualizationUnitTestSuite.suite()); } + suite.addTest(org.alfresco.traitextender.TraitExtenderUnitTestSuite.suite()); + suite.addTest(org.alfresco.repo.virtual.VirtualizationUnitTestSuite.suite()); + } } diff --git a/source/test-java/org/alfresco/repo/attributes/AttributeServiceTest.java b/source/test-java/org/alfresco/repo/attributes/AttributeServiceTest.java index 5ef11305be..446cc8e01f 100644 --- a/source/test-java/org/alfresco/repo/attributes/AttributeServiceTest.java +++ b/source/test-java/org/alfresco/repo/attributes/AttributeServiceTest.java @@ -37,6 +37,7 @@ import org.alfresco.service.cmr.attributes.AttributeService.AttributeQueryCallba import org.alfresco.service.cmr.attributes.DuplicateAttributeException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.GUID; import org.alfresco.util.Pair; import org.apache.commons.lang.mutable.MutableInt; import org.springframework.context.ApplicationContext; @@ -94,7 +95,17 @@ public class AttributeServiceTest extends TestCase assertEquals(VALUE_AAA_STRING, attributeService.getAttribute(KEY_AAA)); assertEquals(VALUE_AAB_STRING, attributeService.getAttribute(KEY_AAB)); assertEquals(VALUE_AAC_STRING, attributeService.getAttribute(KEY_AAC)); -// + + //Too many keys + try + { + attributeService.exists(new Serializable[]{"a", "a", "a", "a", "a"}); + fail("You can't have more than 3 keys"); + } + catch (IllegalArgumentException expected) + { + } + // attributeService.removeAttribute(KEY_AAA); // attributeService.removeAttribute(KEY_AAB); // attributeService.removeAttribute(KEY_AAC); @@ -298,4 +309,33 @@ public class AttributeServiceTest extends TestCase propertyValueDAO.cleanupUnusedValues(); } } + + public void testUpdateOrCreateAttribute() + { + final String KEY_RND_STR_1 = "string1"+ GUID.generate(); + final String KEY_RND_STR_2 = "string2"+ GUID.generate(); + + try + { + attributeService.updateOrCreateAttribute(KEY_RND_STR_2, null, null, KEY_RND_STR_1, null, null); + try + { + attributeService.updateOrCreateAttribute(KEY_RND_STR_2, null, null, KEY_RND_STR_1, null, null); + fail("Duplicate attribute creation should not be allowed"); + } + catch (DuplicateAttributeException expected) + { + } + + //First call creates it, the second updates it. No errors. + attributeService.updateOrCreateAttribute(KEY_RND_STR_1, null, null, KEY_RND_STR_2, null, null); + attributeService.updateOrCreateAttribute(KEY_RND_STR_2, null, null, KEY_RND_STR_2, null, null); + } + finally + { + attributeService.removeAttribute(KEY_RND_STR_1, null, null); + attributeService.removeAttribute(KEY_RND_STR_2, null, null); + } + + } } diff --git a/source/test-java/org/alfresco/repo/lock/JobLockServiceTest.java b/source/test-java/org/alfresco/repo/lock/JobLockServiceTest.java index 8dc7418ba6..7d018b1e2d 100644 --- a/source/test-java/org/alfresco/repo/lock/JobLockServiceTest.java +++ b/source/test-java/org/alfresco/repo/lock/JobLockServiceTest.java @@ -115,8 +115,21 @@ public class JobLockServiceTest extends TestCase lockToken = jobLockService.getLock(lockAAA, 20L, 5L, 0); // No retries jobLockService.refreshLock(lockToken, lockAAA, 20L); jobLockService.releaseLock(lockToken, lockAAA); + + try + { + jobLockService.getLock(lockAAA, 20L, 5L, -1); + fail("getLock should have failed "); + } + catch (IllegalArgumentException expected) + { + expected.getMessage().contains("Job lock retry count cannot be negative"); + } + } - + + + public void testEnforceTxn() { try diff --git a/source/test-java/org/alfresco/repo/module/tool/ModuleServiceImplTest.java b/source/test-java/org/alfresco/repo/module/tool/ModuleServiceImplTest.java new file mode 100644 index 0000000000..383add30e5 --- /dev/null +++ b/source/test-java/org/alfresco/repo/module/tool/ModuleServiceImplTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2005-2015 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 . + */ +package org.alfresco.repo.module.tool; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.alfresco.repo.admin.registry.RegistryKey; +import org.alfresco.repo.admin.registry.RegistryService; +import org.alfresco.repo.module.ModuleServiceImpl; +import org.alfresco.repo.module.ModuleVersionNumber; +import org.alfresco.service.cmr.module.ModuleDetails; +import org.junit.Before; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.springframework.context.ApplicationContext; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.List; + +/** + * Tests some of ModuleServiceImpl that is not covered by other tests + * @author Gethin James + */ +public class ModuleServiceImplTest +{ + ModuleServiceImpl moduleService; + + @Before + public void setUp() throws Exception + { + moduleService = new ModuleServiceImpl(); + Resource simpleMod = new PathMatchingResourcePatternResolver().getResource("classpath:alfresco/module/simplemodule.properties"); + assertNotNull(simpleMod); + RegistryService reg = mock(RegistryService.class); + ApplicationContext applicationContext = mock(ApplicationContext.class); + + when(reg.getProperty((RegistryKey) anyObject())).thenAnswer(new Answer() + { + public Serializable answer(InvocationOnMock invocation) throws Throwable + { + RegistryKey key = (RegistryKey) invocation.getArguments()[0]; + return new ModuleVersionNumber("1.1"); + } + }); + doReturn(Arrays.asList("fee", "alfresco-simple-module", "fo")).when(reg).getChildElements((RegistryKey) anyObject()); + doReturn(new Resource[] {simpleMod}).when(applicationContext).getResources(anyString()); + moduleService.setRegistryService(reg); + moduleService.setApplicationContext(applicationContext); + } + + @Test(expected = UnsupportedOperationException.class) + public void testSetApplyToTenants() throws Exception + { + moduleService.setApplyToTenants(false); + } + + @Test + public void testGetMissingModules() throws Exception + { + List miss = moduleService.getMissingModules(); + assertNotNull(miss); + //There are 3 modules. 2 of which are missing. "alfresco-simple-module" should be found. + assertEquals(2, miss.size()); + } +} \ No newline at end of file diff --git a/source/test-java/org/alfresco/repo/nodelocator/NodeLocatorServiceImplTest.java b/source/test-java/org/alfresco/repo/nodelocator/NodeLocatorServiceImplTest.java index 245c7a0a37..2b740c5f9b 100644 --- a/source/test-java/org/alfresco/repo/nodelocator/NodeLocatorServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/nodelocator/NodeLocatorServiceImplTest.java @@ -92,7 +92,13 @@ public class NodeLocatorServiceImplTest NodeRef result = nodeLocatorService.getNode(SitesHomeNodeLocator.NAME, null, null); assertEquals(sitesHome, result); } - + + @Test(expected = IllegalArgumentException.class) + public void testRegister() + { + nodeLocatorService.register(SitesHomeNodeLocator.NAME, new SelfNodeLocator()); + } + @Before public void setUpClass() { diff --git a/source/test-java/org/alfresco/repo/rendition/RenditionServiceImplTest.java b/source/test-java/org/alfresco/repo/rendition/RenditionServiceImplTest.java index 6327395e9c..fe6baa18d9 100644 --- a/source/test-java/org/alfresco/repo/rendition/RenditionServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/rendition/RenditionServiceImplTest.java @@ -96,6 +96,7 @@ public class RenditionServiceImplTest extends TestCase engineDefs = renditionService.getRenderingEngineDefinitions(); assertEquals(1, engineDefs.size()); assertSame(renderingDefinition, engineDefs.get(0)); + assertNotNull(renditionService.loadRenditionDefinitions(ENGINE_NAME)); // Check that when the action service returns a non-rendering action // definition then the rendering service does not include it. diff --git a/source/test-java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java b/source/test-java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java index 17aaa989e6..00c2455bf6 100644 --- a/source/test-java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java @@ -460,6 +460,28 @@ public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest } } } + + transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + renditionService.render(nodeWithDocContent, renditionName1, new RenderCallback() + { + @Override + public void handleSuccessfulRendition(ChildAssociationRef primaryParentOfNewRendition) + { + assertNotNull("The rendition association was null", primaryParentOfNewRendition); + } + + @Override + public void handleFailedRendition(Throwable t) + { + fail("No error should be thrown: "+t.getMessage()); + } + }); + return null; + } + }); } private void assertRenditionContainsTitle(final String titleValue, String output) diff --git a/source/test-java/org/alfresco/repo/security/authentication/AuthenticationTest.java b/source/test-java/org/alfresco/repo/security/authentication/AuthenticationTest.java index 0bffef929b..f031e5ae4c 100644 --- a/source/test-java/org/alfresco/repo/security/authentication/AuthenticationTest.java +++ b/source/test-java/org/alfresco/repo/security/authentication/AuthenticationTest.java @@ -30,6 +30,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.transaction.Status; import javax.transaction.UserTransaction; @@ -67,6 +68,7 @@ import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PersonService; @@ -392,6 +394,9 @@ public class AuthenticationTest extends TestCase public void testGuest() { authenticationService.authenticate(AuthenticationUtil.getGuestUserName(), "".toCharArray()); + Set guestUsers = authenticationService.getDefaultGuestUserNames(); + assertNotNull(guestUsers); + assertTrue(guestUsers.contains(AuthenticationUtil.getGuestUserName())); } public void testCreateUsers() @@ -466,9 +471,12 @@ public class AuthenticationTest extends TestCase public void testAuthenticateMultiTenant() { // Create a tenant domain - TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork() { - public Object doWork() throws Exception { - if (!tenantAdminService.existsTenant(TEST_TENANT_DOMAIN)) { + TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork() + { + public Object doWork() throws Exception + { + if (!tenantAdminService.existsTenant(TEST_TENANT_DOMAIN)) + { tenantAdminService.createTenant(TEST_TENANT_DOMAIN, TENANT_ADMIN_PW.toCharArray(), null); } return null; @@ -1767,6 +1775,61 @@ public class AuthenticationTest extends TestCase // authenticationService.deleteAuthentication("andy"); } + public void testAuthenticationServiceImpl() + { + Set domains = authenticationService.getDomains(); + assertNotNull(domains); + domains = authenticationService.getDomainsThatAllowUserCreation(); + assertNotNull(domains); + domains = authenticationService.getDomiansThatAllowUserPasswordChanges(); + assertNotNull(domains); + domains = authenticationService.getDomainsThatAllowUserDeletion(); + assertNotNull(domains); + + List services = ((AbstractChainingAuthenticationService) authenticationService).getUsableAuthenticationServices(); + for (AuthenticationService service : services) + { + if (service instanceof AuthenticationServiceImpl) + { + AuthenticationServiceImpl impl = (AuthenticationServiceImpl) service; + + assertFalse("Not just anyone", impl.authenticationExists("anyone")); + assertFalse("Hardcoded to true", impl.getAuthenticationEnabled("anyone")); + authenticationService.invalidateUserSession("anyone"); + + impl.setDomain("mydomain"); + String domain = impl.getDomain(); + assertEquals("mydomain", domain); + Set ticketComponents = impl.getTicketComponents(); + assertNotNull(ticketComponents); + + boolean allows = impl.getAllowsUserPasswordChange(); + impl.setAllowsUserPasswordChange(allows); + assertEquals(allows, impl.getAllowsUserPasswordChange()); + + allows = impl.getAllowsUserDeletion(); + impl.setAllowsUserDeletion(allows); + assertEquals(allows, impl.getAllowsUserDeletion()); + + allows = impl.getAllowsUserCreation(); + impl.setAllowsUserCreation(allows); + assertEquals(allows, impl.getAllowsUserCreation()); + + assertFalse(impl.isCurrentUserTheSystemUser()); + + Set users = impl.getUsersWithTickets(true); + assertNotNull(users); + int tickets = impl.countTickets(true); + assertFalse(tickets < users.size()); + + tickets = impl.invalidateTickets(true); + + assertTrue(impl.guestUserAuthenticationAllowed()); + + break; + } + } + } public void testLoginNotExistingTenant() { diff --git a/source/test-java/org/alfresco/repo/security/authority/ExtendedPermissionServiceTest.java b/source/test-java/org/alfresco/repo/security/authority/ExtendedPermissionServiceTest.java index 1564821cc3..105fd08eea 100644 --- a/source/test-java/org/alfresco/repo/security/authority/ExtendedPermissionServiceTest.java +++ b/source/test-java/org/alfresco/repo/security/authority/ExtendedPermissionServiceTest.java @@ -20,6 +20,7 @@ package org.alfresco.repo.security.authority; import org.alfresco.repo.security.permissions.impl.AbstractPermissionTest; import org.alfresco.repo.security.permissions.impl.SimplePermissionEntry; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; @@ -48,7 +49,7 @@ public class ExtendedPermissionServiceTest extends AbstractPermissionTest permissionService.clearPermission(rootNodeRef, "andy"); } - public void testDeletePermissionByRecipient() + public void testDeletePermissions() { authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); personService.getPerson("andy"); @@ -64,5 +65,14 @@ public class ExtendedPermissionServiceTest extends AbstractPermissionTest assertTrue(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED); permissionService.deletePermissions("GROUP_test"); assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED); + + //At the store level + permissionService.clearPermission(testStoreRef, "GROUP_test"); + permissionService.deletePermission(testStoreRef, "GROUP_test", PermissionService.READ); + } + + public void testExplainPermission() + { + assertNull("This method has not been implemented", permissionService.explainPermission(null,null)); } } diff --git a/source/test-java/org/alfresco/repo/security/permissions/impl/AbstractPermissionTest.java b/source/test-java/org/alfresco/repo/security/permissions/impl/AbstractPermissionTest.java index 71b460e919..0516a3fd5b 100644 --- a/source/test-java/org/alfresco/repo/security/permissions/impl/AbstractPermissionTest.java +++ b/source/test-java/org/alfresco/repo/security/permissions/impl/AbstractPermissionTest.java @@ -74,6 +74,8 @@ public class AbstractPermissionTest extends TestCase protected LocalSessionFactoryBean sessionFactory; + protected StoreRef testStoreRef; + protected NodeRef rootNodeRef; protected NamespacePrefixResolver namespacePrefixResolver; @@ -149,10 +151,10 @@ public class AbstractPermissionTest extends TestCase testTX = transactionService.getUserTransaction(); testTX.begin(); - - - StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime()); - rootNodeRef = nodeService.getRootNode(storeRef); + + + testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime()); + rootNodeRef = nodeService.getRootNode(testStoreRef); QName children = ContentModel.ASSOC_CHILDREN; QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system"); diff --git a/source/test-java/org/alfresco/repo/security/permissions/impl/PermissionServiceTest.java b/source/test-java/org/alfresco/repo/security/permissions/impl/PermissionServiceTest.java index a6925a5ab6..54b60d5551 100644 --- a/source/test-java/org/alfresco/repo/security/permissions/impl/PermissionServiceTest.java +++ b/source/test-java/org/alfresco/repo/security/permissions/impl/PermissionServiceTest.java @@ -18,9 +18,11 @@ */ package org.alfresco.repo.security.permissions.impl; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import net.sf.acegisecurity.Authentication; @@ -33,13 +35,16 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.ACLType; import org.alfresco.repo.security.permissions.AccessControlEntry; import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.repo.security.permissions.NodePermissionEntry; import org.alfresco.repo.security.permissions.PermissionEntry; +import org.alfresco.repo.security.permissions.PermissionReference; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AuthorityType; +import org.alfresco.service.cmr.security.PermissionContext; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.alfresco.test_category.OwnJVMTestsCategory; @@ -1718,6 +1723,23 @@ public class PermissionServiceTest extends AbstractPermissionTest assertEquals(36, answer.size()); } + + public void testSimplePermissionOnStore() + { + runAs("andy"); + + NodePermissionEntry entry = permissionService.getSetPermissions(testStoreRef); + assertNotNull(entry); + assertEquals(0, entry.getPermissionEntries().size()); + assertEquals(0, permissionService.getAllSetPermissions(testStoreRef).size()); + + //Test Nulls + assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(null, getPermission(PermissionService.READ))); + assertEquals(AccessStatus.DENIED, permissionService.hasPermission(rootNodeRef, (PermissionReference)null)); + assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(new NodeRef(testStoreRef, "I don't exist"), getPermission(PermissionService.READ))); + } + + public void testSimplePermissionOnRoot() { runAs("andy"); @@ -2732,7 +2754,18 @@ public class PermissionServiceTest extends AbstractPermissionTest NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef(); NodeRef n2 = nodeService.createNode(n1, ContentModel.ASSOC_CONTAINS, QName.createQName("{namespace}two"), ContentModel.TYPE_FOLDER).getChildRef(); + Long aclID = nodeService.getNodeAclId(n1); + PermissionContext context = new PermissionContext(QName.createQName("{namespace}one")); + assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(aclID, context, PermissionService.ALL_PERMISSIONS)); + runAs("andy"); + + //Pass null aclid + assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(null, context, PermissionService.ALL_PERMISSIONS)); + context.setStoreAcl(3455l); + //Gets further but should now fail + assertEquals(AccessStatus.DENIED, permissionService.hasPermission(null, context, PermissionService.ALL_PERMISSIONS)); + assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED); assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ_PROPERTIES)) == AccessStatus.ALLOWED); assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ_CHILDREN)) == AccessStatus.ALLOWED); diff --git a/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java b/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java index c6bcc589a2..f10f9b2e29 100644 --- a/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java @@ -30,6 +30,8 @@ import java.util.Map; import junit.framework.TestCase; import org.alfresco.model.ContentModel; +import org.alfresco.query.PagingRequest; +import org.alfresco.query.PagingResults; import org.alfresco.repo.action.ActionModel; import org.alfresco.repo.action.AsynchronousActionExecutionQueuePolicies; import org.alfresco.repo.action.AsynchronousActionExecutionQueuePolicies.OnAsyncActionExecute; @@ -361,6 +363,14 @@ public class TaggingServiceImplTest extends TestCase assertEquals(1, tagPage.size()); assertTrue(tagPage.get(0).contains("one")); + tagPage = taggingService.getTags(TaggingServiceImplTest.storeRef, "one"); + assertNotNull(pagedTags); + tagPage = pagedTags.getFirst(); + allFilteredTagsCount = pagedTags.getSecond(); + assertEquals(1, allFilteredTagsCount); + assertEquals(1, tagPage.size()); + assertTrue(tagPage.get(0).contains("one")); + // Check isTag method assertFalse(taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_2)); assertTrue(taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_1)); @@ -2162,6 +2172,90 @@ public class TaggingServiceImplTest extends TestCase assertEquals(tags.get(1).getCount(), 20); assertEquals(tags.get(2).getCount(), 1); } + + public void testPagedTags() throws UnsupportedEncodingException + { + authenticationComponent.setSystemUserAsCurrentUser(); + Pair, Integer> tags = taggingService.getPagedTags(storeRef, 1, 10); + assertNotNull(tags); + PagingResults> res = taggingService.getTags(storeRef, new PagingRequest(10)); + assertNotNull(res); + + + String guid = GUID.generate(); + // Create a node + Map docProps = new HashMap(1); + String docName = "testDocument" + guid + ".txt"; + docProps.put(ContentModel.PROP_NAME, docName); + NodeRef myDoc = nodeService.createNode( + folder, + ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, docName), + ContentModel.TYPE_CONTENT, + docProps).getChildRef(); + taggingService.addTag(myDoc,"dog"); + + res = taggingService.getTags(myDoc, new PagingRequest(10)); + assertNotNull(res); + assertTrue(res.getTotalResultCount().getFirst() == 1); + } + + public void testChangeTags() throws UnsupportedEncodingException + { + try + { + taggingService.changeTag(storeRef, null, null); + fail("Should throw exception"); + } + catch (TaggingException tae) + { + tae.getMessage().contains("Existing tag cannot be null"); + } + + try + { + taggingService.changeTag(storeRef, "bob", null); + fail("Should throw exception"); + } + catch (TaggingException tae) + { + tae.getMessage().contains("New tag cannot be null"); + } + + try + { + taggingService.changeTag(storeRef, "bob", "bob"); + fail("Should throw exception"); + } + catch (TaggingException tae) + { + tae.getMessage().contains("New and existing tags are the same"); + } + + try + { + taggingService.changeTag(storeRef, "bob", "hope"); + fail("Should throw exception"); + } + catch (NonExistentTagException net) + { + net.getMessage().contains("not found"); + } + + try + { + List storeTags = taggingService.getTags(storeRef); + assertNotNull(storeTags); + assertTrue(storeTags.size()>1); + taggingService.changeTag(storeRef, storeTags.get(0), storeTags.get(1)); + fail("Should throw exception"); + } + catch (TagExistsException tee) + { + tee.getMessage().contains("already exists"); + } + } + /* Test adding tags containing \n and | chars. Test all ways to create tag (e.g. createTag, addTag, setTags) */ public void testBadTags() diff --git a/source/test-java/org/alfresco/repo/template/TemplateServiceImplTest.java b/source/test-java/org/alfresco/repo/template/TemplateServiceImplTest.java index dd676aea1a..24d9f83957 100644 --- a/source/test-java/org/alfresco/repo/template/TemplateServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/template/TemplateServiceImplTest.java @@ -19,6 +19,7 @@ package org.alfresco.repo.template; import java.io.InputStream; +import java.io.StringWriter; import java.util.HashMap; import java.util.Map; @@ -34,12 +35,14 @@ import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.repository.TemplateException; import org.alfresco.service.cmr.repository.TemplateService; import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.junit.experimental.categories.Category; import org.springframework.context.ApplicationContext; +import org.springframework.extensions.surf.util.I18NUtil; /** * @author Kevin Roast @@ -49,7 +52,8 @@ public class TemplateServiceImplTest extends TestCase { private static final String TEMPLATE_1 = "org/alfresco/repo/template/test_template1.ftl"; private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); - + private NodeRef root_node; + private TemplateService templateService; private NodeService nodeService; private TransactionService transactionService; @@ -89,6 +93,19 @@ public class TemplateServiceImplTest extends TestCase DictionaryComponent dictionary = new DictionaryComponent(); dictionary.setDictionaryDAO(dictionaryDao); BaseNodeServiceTest.loadModel(ctx); + + transactionService.getRetryingTransactionHelper().doInTransaction( + new RetryingTransactionCallback() + { + @SuppressWarnings("unchecked") + public Object execute() throws Exception + { + StoreRef store = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "template_" + System.currentTimeMillis()); + root_node = nodeService.getRootNode(store); + BaseNodeServiceTest.buildNodeGraph(nodeService, root_node); + return null; + } + }); } @Override @@ -106,29 +123,68 @@ public class TemplateServiceImplTest extends TestCase @SuppressWarnings("unchecked") public Object execute() throws Exception { - StoreRef store = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "template_" + System.currentTimeMillis()); - NodeRef root = nodeService.getRootNode(store); - BaseNodeServiceTest.buildNodeGraph(nodeService, root); - + // check the default template engine exists assertNotNull(templateService.getTemplateProcessor("freemarker")); - - // create test model - Map model = new HashMap(7, 1.0f); - - model.put("root", new TemplateNode(root, serviceRegistry, null)); - + Map model = createTemplateModel(root_node); + // execute on test template String output = templateService.processTemplate("freemarker", TEMPLATE_1, model); // check template contains the expected output - assertTrue( (output.indexOf(root.getId()) != -1) ); - - System.out.print(output); - + assertTrue( (output.indexOf(root_node.getId()) != -1) ); + return null; } }); } + + private Map createTemplateModel(NodeRef root) + { + // create test model + Map model = new HashMap(7, 1.0f); + model.put("root", new TemplateNode(root, serviceRegistry, null)); + return model; + } + + public void testGetTemplateProcessor() + { + assertNotNull(templateService.getTemplateProcessor(null)); + } + + public void testProcessTemplate() + { + Map model = createTemplateModel(root_node); + StringWriter writer = new StringWriter(); + templateService.processTemplate(TEMPLATE_1, model, writer); + assertTrue( (writer.toString().indexOf(root_node.getId()) != -1) ); + + try + { + templateService.processTemplate("NOT_REAL", TEMPLATE_1, model, new StringWriter()); + fail("The engine name is nonsense"); + } catch (TemplateException expected) + { + // + } + + try + { + templateService.processTemplate("NOT_REAL", TEMPLATE_1, model, I18NUtil.getLocale()); + fail("The engine name is nonsense"); + } catch (TemplateException expected) + { + // + } + + try + { + templateService.processTemplateString("NOT_REAL", TEMPLATE_1, model, new StringWriter()); + fail("The engine name is nonsense"); + } catch (TemplateException expected) + { + // + } + } } diff --git a/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java b/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java index 7804577e00..41f8bc662c 100644 --- a/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java @@ -24,6 +24,7 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -221,6 +222,7 @@ public class MultiTServiceImplTest } }; transactionService.getRetryingTransactionHelper().doInTransaction(work); + assertEquals("fred", multiTServiceImpl.getMultiTenantDomainName("@fred@bloggs")); } @Test @@ -351,7 +353,48 @@ public class MultiTServiceImplTest }; transactionService.getRetryingTransactionHelper().doInTransaction(work); } - + + @Test + public void testGetNull() + { + assertNull(tenantService.getName((NodeRef)null)); + assertNull(tenantService.getName((String)null)); + assertNull(tenantService.getName((StoreRef) null)); + assertNull(tenantService.getName("", (StoreRef) null)); + assertNull(tenantService.getName((ChildAssociationRef) null)); + assertNull(tenantService.getName((AssociationRef) null)); + assertNull(tenantService.getName((NodeRef)null,(NodeRef)null)); + assertNull(tenantService.getBaseName((StoreRef) null)); + assertNull(tenantService.getBaseName((AssociationRef) null)); + assertNull(tenantService.getBaseName((ChildAssociationRef) null, false)); + assertNull(tenantService.getBaseName((String)null, false)); + tenantService.checkDomain((String)null); + } + + @Test + public void testInvalidDomainUser() + { + try + { + tenantService.getDomainUser(TenantService.SEPARATOR, "MYDOMAIN"); + fail("Should throw exception"); + } + catch (AlfrescoRuntimeException are) + { + are.getMessage().contains("Invalid base username"); + } + try + { + tenantService.getDomainUser("", TenantService.SEPARATOR); + fail("Should throw exception"); + } + catch (AlfrescoRuntimeException are) + { + are.getMessage().contains("Invalid tenant domain"); + } + + } + @Test public void testGetBaseName() { diff --git a/source/test-java/org/alfresco/repo/version/ContentServiceImplTest.java b/source/test-java/org/alfresco/repo/version/ContentServiceImplTest.java index d72df79cdb..6e0d3acb64 100644 --- a/source/test-java/org/alfresco/repo/version/ContentServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/version/ContentServiceImplTest.java @@ -18,17 +18,25 @@ */ package org.alfresco.repo.version; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; +import org.alfresco.repo.content.EmptyContentReader; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.content.MimetypeMapTest; import org.alfresco.repo.content.transform.ContentTransformer; +import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NoTransformerException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.TransformationOptions; import org.alfresco.service.cmr.version.Version; import org.alfresco.test_category.OwnJVMTestsCategory; import org.junit.experimental.categories.Category; +import java.util.HashMap; + /** * Tests for retrieving frozen content from a verioned node * @@ -87,7 +95,83 @@ public class ContentServiceImplTest extends BaseVersionStoreTest assertNotNull(contentReader2); assertEquals(UPDATED_CONTENT, contentReader2.getContentString()); } - + + public void testTransformAndNulls() + { + NodeRef versionableNode = createNewVersionableNode(); + ContentReader contentReader = this.contentService.getReader(versionableNode, ContentModel.PROP_CONTENT); + ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, false); + + //Call deprecated methods + assertTrue(this.contentService.isTransformable(contentReader, contentWriter)); + this.contentService.transform(contentReader, contentWriter, new HashMap()); + assertNotNull(this.contentService.getActiveTransformers(contentReader.getMimetype(), contentWriter.getMimetype(), new TransformationOptions())); + assertNull(this.contentService.getTransformer(MimetypeMap.MIMETYPE_TEXT_PLAIN, MimetypeMap.MIMETYPE_IMAGE_PNG, new TransformationOptions())); + + // this.nodeService.setProperty(versionableNode, ContentModel.PROP_NAME, "for debugTransformers.txt"); + try + { + this.contentService.transform(new MimetypeMapTest.DummyContentReader(MimetypeMap.MIMETYPE_TEXT_PLAIN), + new MimetypeMapTest.DummyContentWriter(MimetypeMap.MIMETYPE_IMAGE_PNG), + new TransformationOptions(versionableNode,ContentModel.PROP_NAME, null, null)); + } catch (NoTransformerException nte) + { + nte.getMessage().contains("No transformation exists"); + } + + try + { + this.contentService.transform(null, null); + fail("Should throw exception"); + } + catch (AlfrescoRuntimeException are) + { + are.getMessage().contains("The content reader must be set"); + } + + ContentReader empty = new EmptyContentReader("empty.txt"); + try + { + this.contentService.transform(empty, null); + fail("Should throw exception"); + } + catch (AlfrescoRuntimeException are) + { + are.getMessage().contains("The content reader mimetype must be set"); + } + + try + { + this.contentService.isTransformable(empty, null, new TransformationOptions()); + fail("Should throw exception"); + } + catch (AlfrescoRuntimeException are) + { + are.getMessage().contains("The content reader mimetype must be set"); + } + + try + { + contentWriter.setMimetype(null); + this.contentService.transform(contentReader, contentWriter); + fail("Should throw exception"); + } + catch (AlfrescoRuntimeException are) + { + are.getMessage().contains("The content writer mimetype must be set"); + } + + try + { + contentWriter.setMimetype(null); + this.contentService.isTransformable(contentReader, contentWriter, new TransformationOptions()); + fail("Should throw exception"); + } + catch (AlfrescoRuntimeException are) + { + are.getMessage().contains("The content writer mimetype must be set"); + } + } /** * Test getWriter */ diff --git a/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java b/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java index 5ea8231eb7..9ae598b2b1 100644 --- a/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java @@ -87,6 +87,7 @@ public abstract class AbstractWorkflowServiceIntegrationTest extends BaseSpringT protected TestGroupManager groupManager; protected NodeService nodeService; protected NodeRef companyHome; + protected ServiceRegistry serviceRegistry; protected WorkflowTestHelper wfTestHelper; protected TransactionServiceImpl transactionService; @@ -1236,7 +1237,7 @@ public abstract class AbstractWorkflowServiceIntegrationTest extends BaseSpringT protected abstract QName getAdhocProcessName(); - private InputStream getInputStream(String resource) + protected InputStream getInputStream(String resource) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); return classLoader.getResourceAsStream(resource); @@ -1329,25 +1330,25 @@ public abstract class AbstractWorkflowServiceIntegrationTest extends BaseSpringT protected void onSetUpInTransaction() throws Exception { super.onSetUpInTransaction(); - ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); - this.workflowService = registry.getWorkflowService(); + serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); + this.workflowService = serviceRegistry.getWorkflowService(); this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); - this.nodeService = registry.getNodeService(); + this.nodeService = serviceRegistry.getNodeService(); Repository repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper"); this.companyHome = repositoryHelper.getCompanyHome(); try { - this.transactionService = (TransactionServiceImpl) registry.getTransactionService(); + this.transactionService = (TransactionServiceImpl) serviceRegistry.getTransactionService(); } catch (ClassCastException e) { throw new AlfrescoRuntimeException("The AbstractWorkflowServiceIntegrationTest needs direct access to the TransactionServiceImpl"); } - MutableAuthenticationService authenticationService = registry.getAuthenticationService(); - AuthorityService authorityService = registry.getAuthorityService(); - PersonService personService = registry.getPersonService(); - SearchService searchService = registry.getSearchService(); + MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService(); + AuthorityService authorityService = serviceRegistry.getAuthorityService(); + PersonService personService = serviceRegistry.getPersonService(); + SearchService searchService = serviceRegistry.getSearchService(); authenticationComponent.setSystemUserAsCurrentUser(); diff --git a/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java b/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java index 373f5174ff..1291906929 100644 --- a/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java @@ -19,6 +19,7 @@ package org.alfresco.repo.workflow.activiti; +import java.io.InputStream; import java.io.Serializable; import java.util.Arrays; import java.util.Collections; @@ -28,15 +29,23 @@ import java.util.List; import java.util.Map; import org.alfresco.model.ContentModel; +import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.workflow.AbstractWorkflowServiceIntegrationTest; import org.alfresco.repo.workflow.WorkflowModel; import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.dictionary.TypeDefinition; +import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.workflow.WorkflowDefinition; +import org.alfresco.service.cmr.workflow.WorkflowDeployment; +import org.alfresco.service.cmr.workflow.WorkflowException; +import org.alfresco.service.cmr.workflow.WorkflowInstance; +import org.alfresco.service.cmr.workflow.WorkflowInstanceQuery; import org.alfresco.service.cmr.workflow.WorkflowPath; import org.alfresco.service.cmr.workflow.WorkflowTask; import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition; @@ -53,7 +62,12 @@ import org.alfresco.util.GUID; public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServiceIntegrationTest { private final static String USER_RECREATED = "WFUserRecreated" + GUID.generate(); - + public static final String ACTIVITI_TEST_TRANSACTION_BPMN20_XML = "activiti/testTransaction.bpmn20.xml"; + public static final String ALFRESCO_WORKFLOW_ADHOC_BPMN20_XML = "alfresco/workflow/adhoc.bpmn20.xml"; + public static final String ALFRESCO_WORKFLOW_REVIEW_POOLED_BPMN20_XML = "alfresco/workflow/review-pooled.bpmn20.xml"; + public static final String ALFRESCO_WORKFLOW_PARALLEL_REVIEW_BPMN20_XML = "alfresco/workflow/parallel-review.bpmn20.xml"; + public static final String ACTIVITI_TEST_TIMER_BPMN20_XML = "activiti/testTimer.bpmn20.xml"; + public void testOutcome() throws Exception { WorkflowDefinition definition = deployDefinition("alfresco/workflow/review.bpmn20.xml"); @@ -86,7 +100,7 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ Map props = new HashMap(); props.put(outcomePropName, "Approve"); workflowService.updateTask(reviewTask.getId(), props, null, null); - + // End task and check outcome property WorkflowTask result = workflowService.endTask(reviewTask.getId(), null); Serializable outcome = result.getProperties().get(WorkflowModel.PROP_OUTCOME); @@ -165,14 +179,17 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ assertNotNull(group); params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, group); - nodeService.addChild(workflowPackage, addedNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, - QName.createValidLocalName((String)nodeService.getProperty(addedNodeRef, ContentModel.PROP_NAME)))); + nodeService.addChild(workflowPackage, addedNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, + QName.createValidLocalName((String) nodeService.getProperty(addedNodeRef, ContentModel.PROP_NAME)))); WorkflowPath workflowPath = workflowService.startWorkflow(definition.getId(), params); assertNotNull(workflowPath); assertTrue(workflowPath.isActive()); final String workflowInstanceId = workflowPath.getInstance().getId(); - + + List pooledTasks = workflowService.getPooledTasks(GROUP); + assertNotNull(pooledTasks); + // End start task to progress workflow WorkflowTask startTask = workflowService.getStartTask(workflowInstanceId); String startTaskId = startTask.getId(); @@ -205,24 +222,28 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ // Create workflow parameters Map params = new HashMap(); - Serializable wfPackage = workflowService.createPackage(null); + NodeRef wfPackage = workflowService.createPackage(null); params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage); NodeRef assignee = personManager.get(USER2); params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee); // task instance field WorkflowPath path = workflowService.startWorkflow(definition.getId(), params); String instanceId = path.getInstance().getId(); - + WorkflowTask startTask = workflowService.getStartTask(instanceId); workflowService.endTask(startTask.getId(), null); - + + List taskPackage = workflowService.getPackageContents(startTask.getId()); + assertTrue(taskPackage.isEmpty()); + List packageContents = workflowService.getPackageContents(wfPackage); + assertTrue(packageContents.isEmpty()); + List tasks = workflowService.getTasksForWorkflowPath(path.getId()); assertEquals(1, tasks.size()); - - + // Assign task to user3 - workflowService.updateTask(tasks.get(0).getId(), Collections.singletonMap(WorkflowModel.ASSOC_ASSIGNEE, - (Serializable) personManager.get(USER3)), null, null); + workflowService.updateTask(tasks.get(0).getId(), Collections.singletonMap(WorkflowModel.ASSOC_ASSIGNEE, + (Serializable) personManager.get(USER3)), null, null); // Authenticate as user3 personManager.setUser(USER3); @@ -495,7 +516,122 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ nodeService.deleteNode(childAssoc.getChildRef()); } } - + + public void testWorkflowWithNodes() throws Exception + { + authenticationComponent.setSystemUserAsCurrentUser(); + + FileInfo incorrectNode = serviceRegistry.getFileFolderService().create(companyHome, "NO_WORKFLOW" + GUID.generate() + ".xml", ContentModel.TYPE_CONTENT); + FileInfo fileInfo = serviceRegistry.getFileFolderService().create(companyHome, "workflow" + GUID.generate() + ".xml", WorkflowModel.TYPE_WORKFLOW_DEF); + NodeRef workflowNode = fileInfo.getNodeRef(); + nodeService.setProperty(workflowNode, WorkflowModel.PROP_WORKFLOW_DEF_ENGINE_ID, getEngine()); + InputStream input = getInputStream("activiti/testDiagram.bpmn20.xml"); + ContentWriter contentWriter = serviceRegistry.getContentService().getWriter(fileInfo.getNodeRef(), ContentModel.TYPE_CONTENT, true); + contentWriter.setEncoding("UTF-8"); + contentWriter.putContent(input); + + try + { + workflowService.isDefinitionDeployed(incorrectNode.getNodeRef()); + fail("The content type is incorrect, it should not get here"); + } + catch (WorkflowException we) + { + assertTrue(we.getMessage().contains(" is not of type 'bpm:workflowDefinition'")); + } + + boolean isDeployed = workflowService.isDefinitionDeployed(workflowNode); + + try + { + workflowService.deployDefinition(incorrectNode.getNodeRef()); + fail("The content type is incorrect, it should not get here"); + } + catch (WorkflowException we) + { + assertTrue(we.getMessage().contains(" is not of type 'bpm:workflowDefinition'")); + } + + assertFalse(workflowService.isDefinitionDeployed(workflowNode)); + WorkflowDeployment workflowDeployment = workflowService.deployDefinition(workflowNode); + assertNotNull(workflowDeployment); + assertTrue(workflowService.isDefinitionDeployed(workflowNode)); + + List defs = workflowService.getAllDefinitionsByName(workflowDeployment.getDefinition().getName()); + assertNotNull(defs); + assertEquals(1, defs.size()); + + workflowService.undeployDefinition(workflowDeployment.getDefinition().getId()); + assertFalse(workflowService.isDefinitionDeployed(workflowNode)); + + try + { + workflowService.startWorkflowFromTemplate(incorrectNode.getNodeRef()); + fail("This method hasn't be implemented"); + } + catch (UnsupportedOperationException we) + { + } + + boolean multi = workflowService.isMultiTenantWorkflowDeploymentEnabled(); + assertTrue(multi); + } + + public void testWorkflowVarious() throws Exception + { + WorkflowDefinition definition = deployDefinition(getTestDefinitionPath()); + + // Start the Workflow + WorkflowPath path = workflowService.startWorkflow(definition.getId(), null); + String instanceId = path.getInstance().getId(); + + List workflowTasks = workflowService.getStartTasks(Arrays.asList(instanceId), true); + assertNotNull(workflowTasks); + assertEquals(1, workflowTasks.size()); + + assertFalse(workflowService.hasWorkflowImage(instanceId)); + assertNull(workflowService.getWorkflowImage(instanceId)); + + List instances = workflowService.cancelWorkflows(null); + assertTrue(instances.isEmpty()); + + WorkflowInstance wfi = workflowService.deleteWorkflow(instanceId); + assertEquals(instanceId, wfi.getId()); + + try + { + byte[] image = workflowService.getDefinitionImage(definition.getId()); + } + catch (WorkflowException we ) + { + assertTrue(we.getMessage().contains("Failed to retrieve workflow definition")); + } + + } + + public void testWorkflowQueries() throws Exception + { + WorkflowDefinition definition = deployDefinition(getTestDefinitionPath()); + + WorkflowInstanceQuery workflowInstanceQuery = new WorkflowInstanceQuery(true); + long active = workflowService.countWorkflows(workflowInstanceQuery); + assertNotNull(active); + + workflowInstanceQuery.setWorkflowDefinitionId(definition.getId()); + workflowInstanceQuery.setEngineId(getEngine()); + active = workflowService.countWorkflows(workflowInstanceQuery); + assertNotNull(active); + + WorkflowTaskQuery workflowTaskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED); + long completed = workflowService.countTasks(workflowTaskQuery); + assertNotNull(completed); + + workflowTaskQuery.setEngineId(getEngine()); + completed = workflowService.countTasks(workflowTaskQuery); + assertNotNull(completed); + } + + @Override protected String getEngine() { @@ -505,31 +641,31 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ @Override protected String getTestDefinitionPath() { - return "activiti/testTransaction.bpmn20.xml"; + return ACTIVITI_TEST_TRANSACTION_BPMN20_XML; } @Override protected String getAdhocDefinitionPath() { - return "alfresco/workflow/adhoc.bpmn20.xml"; + return ALFRESCO_WORKFLOW_ADHOC_BPMN20_XML; } @Override protected String getPooledReviewDefinitionPath() { - return "alfresco/workflow/review-pooled.bpmn20.xml"; + return ALFRESCO_WORKFLOW_REVIEW_POOLED_BPMN20_XML; } @Override protected String getParallelReviewDefinitionPath() { - return "alfresco/workflow/parallel-review.bpmn20.xml"; + return ALFRESCO_WORKFLOW_PARALLEL_REVIEW_BPMN20_XML; } @Override protected String getTestTimerDefinitionPath() { - return "activiti/testTimer.bpmn20.xml"; + return ACTIVITI_TEST_TIMER_BPMN20_XML; } protected String getAssignmentListenerDefinitionPath() diff --git a/source/test-resources/alfresco/module/simplemodule.properties b/source/test-resources/alfresco/module/simplemodule.properties new file mode 100644 index 0000000000..9eb834b8ae --- /dev/null +++ b/source/test-resources/alfresco/module/simplemodule.properties @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +# ==== Beginning of Alfresco required/optional properties ====== # +# NB: These properties are filtered at build time by Maven, single +# sourcing from POM properties +module.id=alfresco-simple-module +#module.aliases=myModule-123, my-module +module.title=Alfresco JAR Module Project +module.description=UNSUPPORTED experiment +module.version=1.0.0-SNAPSHOT + +# The following optional properties can be used to prevent the module from being added +# to inappropriate versions of the WAR file. +module.repo.version.min=2.0 \ No newline at end of file