Added copy and delete of registry keys

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5557 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-04-26 08:27:23 +00:00
parent 27beca2047
commit 6d39078356
4 changed files with 355 additions and 39 deletions

View File

@@ -75,8 +75,11 @@ public class RegistryServiceImplTest extends TestCase
private static final Long VALUE_ONE = 1L;
private static final Long VALUE_TWO = 2L;
private static final Long VALUE_THREE = 3L;
private static final RegistryKey KEY_A = new RegistryKey(null, "a", null);
private static final RegistryKey KEY_A_B = new RegistryKey(null, "a", "b", null);
private static final RegistryKey KEY_A_B_0 = new RegistryKey(null, "a", "b", "0");
private static final RegistryKey KEY_A_B_1 = new RegistryKey(null, "a", "b", "1");
private static final RegistryKey KEY_A_B_C = new RegistryKey(null, "a", "b", "c", null);
private static final RegistryKey KEY_A_B_C_0 = new RegistryKey(null, "a", "b", "c", "0");
private static final RegistryKey KEY_A_B_C_1 = new RegistryKey(null, "a", "b", "c", "1");
private static final RegistryKey KEY_A_B_C_2 = new RegistryKey(null, "a", "b", "c", "2");
@@ -85,7 +88,12 @@ public class RegistryServiceImplTest extends TestCase
private static final RegistryKey KEY_A_B_C_D_1 = new RegistryKey(null, "a", "b", "c", "d", "1");
private static final RegistryKey KEY_A_B_C_D_2 = new RegistryKey(null, "a", "b", "c", "d", "2");
private static final RegistryKey KEY_A_B_C_D_3 = new RegistryKey(null, "a", "b", "c", "d", "3");
private static final RegistryKey KEY_X_Y_Z = new RegistryKey(null, "x", "y", "z", null);
private static final RegistryKey KEY_X_Y_Z_0 = new RegistryKey(null, "x", "y", "z", "0");
private static final RegistryKey KEY_X_Y_Z_1 = new RegistryKey(null, "x", "y", "z", "1");
private static final RegistryKey KEY_X_Y_Z_2 = new RegistryKey(null, "x", "y", "z", "2");
private static final RegistryKey KEY_X_Y_Z_D_1 = new RegistryKey(null, "x", "y", "z", "d", "1");
private static final RegistryKey KEY_X_Y_Z_D_2 = new RegistryKey(null, "x", "y", "z", "d", "2");
private static final RegistryKey KEY_SPECIAL = new RegistryKey(null, "me & you", "whatever");
private static final RegistryKey KEY_DOES_NOT_EXIST = new RegistryKey(null, "does", "not", "exist");
/**
@@ -93,29 +101,29 @@ public class RegistryServiceImplTest extends TestCase
*/
public void testProperUsage() throws Exception
{
registryService.addValue(KEY_A_B_C_1, VALUE_ONE);
registryService.addValue(KEY_A_B_C_2, VALUE_TWO);
registryService.addValue(KEY_A_B_C_3, VALUE_THREE);
registryService.addValue(KEY_A_B_C_D_1, VALUE_ONE);
registryService.addValue(KEY_A_B_C_D_2, VALUE_TWO);
registryService.addValue(KEY_A_B_C_D_3, VALUE_THREE);
registryService.addProperty(KEY_A_B_C_1, VALUE_ONE);
registryService.addProperty(KEY_A_B_C_2, VALUE_TWO);
registryService.addProperty(KEY_A_B_C_3, VALUE_THREE);
registryService.addProperty(KEY_A_B_C_D_1, VALUE_ONE);
registryService.addProperty(KEY_A_B_C_D_2, VALUE_TWO);
registryService.addProperty(KEY_A_B_C_D_3, VALUE_THREE);
assertEquals("Incorrect value from service registry", VALUE_ONE, registryService.getValue(KEY_A_B_C_1));
assertEquals("Incorrect value from service registry", VALUE_TWO, registryService.getValue(KEY_A_B_C_2));
assertEquals("Incorrect value from service registry", VALUE_THREE, registryService.getValue(KEY_A_B_C_3));
assertEquals("Incorrect value from service registry", VALUE_ONE, registryService.getValue(KEY_A_B_C_D_1));
assertEquals("Incorrect value from service registry", VALUE_TWO, registryService.getValue(KEY_A_B_C_D_2));
assertEquals("Incorrect value from service registry", VALUE_THREE, registryService.getValue(KEY_A_B_C_D_3));
assertEquals("Incorrect value from service registry", VALUE_ONE, registryService.getProperty(KEY_A_B_C_1));
assertEquals("Incorrect value from service registry", VALUE_TWO, registryService.getProperty(KEY_A_B_C_2));
assertEquals("Incorrect value from service registry", VALUE_THREE, registryService.getProperty(KEY_A_B_C_3));
assertEquals("Incorrect value from service registry", VALUE_ONE, registryService.getProperty(KEY_A_B_C_D_1));
assertEquals("Incorrect value from service registry", VALUE_TWO, registryService.getProperty(KEY_A_B_C_D_2));
assertEquals("Incorrect value from service registry", VALUE_THREE, registryService.getProperty(KEY_A_B_C_D_3));
assertNull("Missing key should return null value", registryService.getValue(KEY_A_B_C_0));
assertNull("Missing key should return null value", registryService.getValue(KEY_A_B_C_D_0));
assertNull("Missing key should return null value", registryService.getValue(KEY_X_Y_Z_0));
assertNull("Missing key should return null value", registryService.getProperty(KEY_A_B_C_0));
assertNull("Missing key should return null value", registryService.getProperty(KEY_A_B_C_D_0));
assertNull("Missing key should return null value", registryService.getProperty(KEY_X_Y_Z_0));
}
public void testGetElements() throws Exception
{
registryService.addValue(KEY_A_B_C_1, VALUE_ONE);
registryService.addValue(KEY_A_B_C_2, VALUE_TWO);
registryService.addProperty(KEY_A_B_C_1, VALUE_ONE);
registryService.addProperty(KEY_A_B_C_2, VALUE_TWO);
// Check that we get an empty list for a random query
assertEquals("Excpected empty collection for random query", 0, registryService.getChildElements(KEY_DOES_NOT_EXIST).size());
@@ -130,7 +138,67 @@ public class RegistryServiceImplTest extends TestCase
public void testSpecialCharacters()
{
registryService.addValue(KEY_SPECIAL, VALUE_THREE);
assertEquals("Incorrect value for special key", VALUE_THREE, registryService.getValue(KEY_SPECIAL));
registryService.addProperty(KEY_SPECIAL, VALUE_THREE);
assertEquals("Incorrect value for special key", VALUE_THREE, registryService.getProperty(KEY_SPECIAL));
}
public void testDelete()
{
registryService.addProperty(KEY_A_B_C_1, VALUE_ONE);
registryService.addProperty(KEY_A_B_C_2, VALUE_TWO);
// Safety check
assertEquals("Incorrect value from service registry", VALUE_ONE, registryService.getProperty(KEY_A_B_C_1));
assertEquals("Incorrect value from service registry", VALUE_TWO, registryService.getProperty(KEY_A_B_C_2));
// Property-based delete
registryService.delete(KEY_A_B_C_1);
assertNull("Expected deleted value to be null", registryService.getProperty(KEY_A_B_C_1));
// Path-based delete
registryService.delete(KEY_A_B);
assertNull("Expected deleted value to be null", registryService.getProperty(KEY_A_B_C_1));
assertNull("Expected deleted value to be null", registryService.getProperty(KEY_A_B_C_2));
Collection<String> childElements = registryService.getChildElements(KEY_A);
assertEquals("There should be no more elements within A", 0, childElements.size());
}
public void testCopy()
{
registryService.addProperty(KEY_A_B_C_1, VALUE_ONE);
registryService.addProperty(KEY_A_B_C_2, VALUE_TWO);
registryService.addProperty(KEY_A_B_C_D_1, VALUE_ONE);
registryService.addProperty(KEY_A_B_C_D_2, VALUE_TWO);
// Check illegal copy
try
{
registryService.copy(KEY_A_B_C_1, KEY_X_Y_Z);
fail("Failed to detect copy from property to path");
}
catch (Throwable e)
{
// Expected
}
try
{
registryService.copy(KEY_A_B_C, KEY_X_Y_Z_0);
fail("Failed to detect copy from path to property");
}
catch (Throwable e)
{
// Expected
}
// Property-based copy
registryService.copy(KEY_A_B_C_1, KEY_X_Y_Z_0);
assertEquals("Incorrect value after property copy", VALUE_ONE, registryService.getProperty(KEY_X_Y_Z_0));
// Path-based copy
registryService.copy(KEY_A_B_C, KEY_X_Y_Z);
assertEquals("Value not recursively copied during path copy", VALUE_ONE, registryService.getProperty(KEY_X_Y_Z_1));
assertEquals("Value not recursively copied during path copy", VALUE_TWO, registryService.getProperty(KEY_X_Y_Z_2));
assertEquals("Path not recursively copied during path copy", VALUE_ONE, registryService.getProperty(KEY_X_Y_Z_D_1));
assertEquals("Path not recursively copied during path copy", VALUE_TWO, registryService.getProperty(KEY_X_Y_Z_D_2));
}
}