mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Tests for the new CapabilityService methods and CustomEMailMappingService methods
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@44389 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -109,7 +109,7 @@ public interface CapabilityService
|
||||
* @param groupId The id of a group for which the list of capabilities should be retrieved
|
||||
* @return {@link List}<{@link Capability}> List of capabilities for the given group
|
||||
*/
|
||||
List<Capability> getCapabilitiesByGroup(String groupId);
|
||||
List<Capability> getCapabilitiesByGroupId(String groupId);
|
||||
|
||||
/**
|
||||
* Get a list of capabilities for the given group
|
||||
|
@@ -199,10 +199,10 @@ public class CapabilityServiceImpl implements CapabilityService
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesByGroup(java.lang.String)
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesByGroupId(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public List<Capability> getCapabilitiesByGroup(String groupId)
|
||||
public List<Capability> getCapabilitiesByGroupId(String groupId)
|
||||
{
|
||||
ParameterCheck.mandatoryString("groupId", groupId);
|
||||
|
||||
@@ -241,7 +241,7 @@ public class CapabilityServiceImpl implements CapabilityService
|
||||
{
|
||||
ParameterCheck.mandatory("group", group);
|
||||
|
||||
return getCapabilitiesByGroup(group.getId());
|
||||
return getCapabilitiesByGroupId(group.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -19,7 +19,6 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.script.capability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -109,7 +108,7 @@ public class CapabilitiesGet extends DeclarativeWebScript
|
||||
{
|
||||
String capabilityGroupId = group.getId();
|
||||
|
||||
List<Capability> capabilities = capabilityService.getCapabilitiesByGroup(capabilityGroupId);
|
||||
List<Capability> capabilities = capabilityService.getCapabilitiesByGroupId(capabilityGroupId);
|
||||
for (Capability capability : capabilities)
|
||||
{
|
||||
String capabilityName = capability.getName();
|
||||
|
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 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.module.org_alfresco_module_rm.test.capabilities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Group;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.GroupImpl;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
|
||||
/**
|
||||
* Test class for testing the methods in {@link CapabilityService}
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.1
|
||||
*/
|
||||
public class CapabilityServiceTest extends BaseRMTestCase
|
||||
{
|
||||
public void testGetAddRemoveGroups() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
Group auditGroup = capabilityService.getGroup("audit");
|
||||
assertNotNull(auditGroup);
|
||||
assertTrue(auditGroup.getIndex() == 1);
|
||||
assertTrue(auditGroup.getTitle().equalsIgnoreCase("Audit"));
|
||||
assertTrue(auditGroup.getId().equalsIgnoreCase("audit"));
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
GroupImpl testGroup = new GroupImpl();
|
||||
testGroup.setId("testGroup");
|
||||
testGroup.setIndex(14);
|
||||
testGroup.setTitle("Test group");
|
||||
capabilityService.addGroup(testGroup);
|
||||
|
||||
assertTrue(capabilityService.getGroups().size() == 14);
|
||||
|
||||
Group group = capabilityService.getGroup("testGroup");
|
||||
assertNotNull(group);
|
||||
assertTrue(group.getId().equalsIgnoreCase("testGroup"));
|
||||
assertTrue(group.getTitle().equalsIgnoreCase("Test group"));
|
||||
assertTrue(group.getIndex() == 14);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
Group testGroup = capabilityService.getGroup("testGroup");
|
||||
assertNotNull(testGroup);
|
||||
|
||||
capabilityService.removeGroup(testGroup);
|
||||
assertTrue(capabilityService.getGroups().size() == 13);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
List<Group> groups = capabilityService.getGroups();
|
||||
assertNotNull(groups);
|
||||
|
||||
int size = groups.size();
|
||||
assertTrue(size == 13);
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
assertNotNull(groups.get(i));
|
||||
assertTrue(groups.get(i).getIndex() == (i + 1));
|
||||
}
|
||||
|
||||
Group auditGroup = groups.get(0);
|
||||
assertNotNull(auditGroup);
|
||||
assertTrue(auditGroup.getIndex() == 1);
|
||||
assertTrue(auditGroup.getId().equalsIgnoreCase("audit"));
|
||||
assertTrue(auditGroup.getTitle().equalsIgnoreCase("Audit"));
|
||||
|
||||
Group vitalRecords = groups.get(size - 1);
|
||||
assertNotNull(vitalRecords);
|
||||
assertTrue(vitalRecords.getIndex() == 13);
|
||||
assertTrue(vitalRecords.getId().equalsIgnoreCase("vitalRecords"));
|
||||
assertTrue(vitalRecords.getTitle().equalsIgnoreCase("Vital Records"));
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testGetCapabilitiesByGroup() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
List<Group> groups = capabilityService.getGroups();
|
||||
assertNotNull(groups);
|
||||
|
||||
Group auditGroup = groups.get(0);
|
||||
assertNotNull(auditGroup);
|
||||
|
||||
List<Capability> auditCapabilities = capabilityService.getCapabilitiesByGroup(auditGroup);
|
||||
assertNotNull(auditCapabilities);
|
||||
|
||||
int vitalRecordCapabilitiesSize = auditCapabilities.size();
|
||||
assertTrue(vitalRecordCapabilitiesSize == 6);
|
||||
|
||||
for (int i = 0; i < vitalRecordCapabilitiesSize; i++)
|
||||
{
|
||||
Capability capability = auditCapabilities.get(i);
|
||||
assertNotNull(capability);
|
||||
assertTrue(capability.getIndex() == (i + 1));
|
||||
}
|
||||
|
||||
Group vitalRecordsGroup = groups.get(groups.size() - 1);
|
||||
assertNotNull(vitalRecordsGroup);
|
||||
|
||||
List<Capability> vitalRecordCapabilities = capabilityService.getCapabilitiesByGroupId(vitalRecordsGroup.getId());
|
||||
assertNotNull(vitalRecordCapabilities);
|
||||
|
||||
vitalRecordCapabilitiesSize = vitalRecordCapabilities.size();
|
||||
assertTrue(vitalRecordCapabilitiesSize == 3);
|
||||
|
||||
for (int i = 0; i < vitalRecordCapabilitiesSize; i++)
|
||||
{
|
||||
Capability capability = vitalRecordCapabilities.get(i);
|
||||
assertNotNull(capability);
|
||||
assertTrue(capability.getIndex() == (i + 1));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -18,8 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.email.CustomMapping;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
@@ -48,62 +46,74 @@ public class CustomEMailMappingServiceImplTest extends BaseRMTestCase
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
eMailMappingService.registerEMailMappingKey("EmailMappingKeyTest1");
|
||||
eMailMappingService.registerEMailMappingKey("EmailMappingKeyTest2");
|
||||
}
|
||||
|
||||
public void testCRUD() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
public Void run()
|
||||
{
|
||||
checkCustomMappingSize(20);
|
||||
// Check the initial custom mapping size
|
||||
assertTrue(checkCustomMappingsSize(20));
|
||||
|
||||
// Add a custom mapping
|
||||
eMailMappingService.addCustomMapping("monkey", "cm:monkeyFace");
|
||||
|
||||
CustomMapping monkeyMapping = getCustomMapping("monkey", "cm:monkeyFace", checkCustomMappingSize(21), true);
|
||||
// Check the new size
|
||||
assertTrue(checkCustomMappingsSize(21));
|
||||
|
||||
// Check the new added custom mapping
|
||||
CustomMapping monkeyMapping = getCustomMapping("monkey", "cm:monkeyFace");
|
||||
assertNotNull(monkeyMapping);
|
||||
assertEquals("monkey", monkeyMapping.getFrom());
|
||||
assertEquals("cm:monkeyFace", monkeyMapping.getTo());
|
||||
|
||||
// Delete the new added custom mapping
|
||||
eMailMappingService.deleteCustomMapping("monkey", "cm:monkeyFace");
|
||||
getCustomMapping("monkey", "cm:monkeyFace", checkCustomMappingSize(20), false);
|
||||
|
||||
// Check the size after deletion
|
||||
assertTrue(checkCustomMappingsSize(20));
|
||||
|
||||
// Check the custom mapping after deletion if it exists
|
||||
assertNull(getCustomMapping("monkey", "cm:monkeyFace"));
|
||||
|
||||
// Check the email mapping keys size
|
||||
// There are 6 "standard" EmailMappingKeys + 2 CustomEmailMappingKeys are added on setUp
|
||||
assertTrue(checkEmailMappingKeysSize(8));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, rmAdminName);
|
||||
}
|
||||
|
||||
private CustomMapping getCustomMapping(String from, String to, Set<CustomMapping> maps, boolean contains)
|
||||
private CustomMapping getCustomMapping(String from, String to)
|
||||
{
|
||||
CustomMapping result = null;
|
||||
CustomMapping key = new CustomMapping(from, to);
|
||||
assertEquals(contains, maps.contains(key));
|
||||
|
||||
if (contains == true)
|
||||
for (CustomMapping customMapping : eMailMappingService.getCustomMappings())
|
||||
{
|
||||
for (CustomMapping map : maps)
|
||||
if (customMapping.getFrom().equalsIgnoreCase(from) && customMapping.getTo().equalsIgnoreCase(to))
|
||||
{
|
||||
if (map.equals(key) == true)
|
||||
{
|
||||
result = key;
|
||||
break;
|
||||
}
|
||||
result = customMapping;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Set<CustomMapping> checkCustomMappingSize(int expected)
|
||||
private boolean checkCustomMappingsSize(int expected)
|
||||
{
|
||||
Set<CustomMapping> maps = eMailMappingService.getCustomMappings();
|
||||
assertEquals(expected, maps.size());
|
||||
return maps;
|
||||
return expected == eMailMappingService.getCustomMappings().size() ? true : false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void print(Set<CustomMapping> maps)
|
||||
private boolean checkEmailMappingKeysSize(int expected)
|
||||
{
|
||||
for (CustomMapping map : maps)
|
||||
{
|
||||
System.out.println(map.getFrom() + " -> " + map.getTo());
|
||||
}
|
||||
return expected == eMailMappingService.getEmailMappingKeys().size() ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user