InternalJDBCRepository repository = createRepository(defaultProject);
JDBCDeviceRepositoryAccessor accessor =
new JDBCDeviceRepositoryAccessor(repository, location);
Locale locale = new Locale("en", "GB");
PolicyDescriptor policyDescriptor;
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "Policy1", locale);
assertNull("No policy descriptor expected", policyDescriptor);
// Test the retrieval of a policy descriptor from VMTYPES
int id = populateWithSimpleTypes(0);
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "Policy1", locale);
assertNotNull("Policy Descriptor should be found", policyDescriptor);
PolicyType policyType = policyDescriptor.getPolicyType();
assertTrue("Type should match",
policyType instanceof BooleanPolicyType);
assertEquals("PolicyDescName1",
policyDescriptor.getPolicyDescriptiveName());
assertEquals("PolicyHelp1", policyDescriptor.getPolicyHelp());
assertEquals("en_GB_", policyDescriptor.getLanguage());
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "Policy2", locale);
policyType = policyDescriptor.getPolicyType();
assertNotNull("Policy Descriptor should be found", policyDescriptor);
assertTrue("Type should match",
policyType instanceof IntPolicyType);
assertEquals("PolicyDescName2",
policyDescriptor.getPolicyDescriptiveName());
assertEquals("PolicyHelp2", policyDescriptor.getPolicyHelp());
assertEquals("en_GB_", policyDescriptor.getLanguage());
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "Policy3", locale);
policyType = policyDescriptor.getPolicyType();
assertNotNull("Policy Descriptor should be found", policyDescriptor);
assertTrue("Type should match",
policyType instanceof TextPolicyType);
assertEquals("PolicyDescName3",
policyDescriptor.getPolicyDescriptiveName());
assertEquals("PolicyHelp3", policyDescriptor.getPolicyHelp());
assertEquals("en_GB_", policyDescriptor.getLanguage());
// Test the retrieval of a policy descriptor from VMTYPES_SELECTION
id = populateWithSelections(id);
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "SelectionPolicy", locale);
assertNotNull("Policy Descriptor should be found", policyDescriptor);
policyType = policyDescriptor.getPolicyType();
assertTrue("Type should match",
policyType instanceof SelectionPolicyType);
assertEquals("SelectionPolicyDescName",
policyDescriptor.getPolicyDescriptiveName());
assertEquals("SelectionPolicyHelp", policyDescriptor.getPolicyHelp());
assertEquals("en_GB_", policyDescriptor.getLanguage());
SelectionPolicyType selectionType =
(SelectionPolicyType)policyType;
assertEquals("Selections size should match", 2,
selectionType.getKeywords().size());
assertEquals("Selections size should match",
"keyword1", selectionType.getKeywords().get(0));
assertEquals("Selections size should match",
"keyword2", selectionType.getKeywords().get(1));
// Test the retrieval of a policy descriptor from VMTYPES_RANGE
id = populateWithRanges(id);
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "RangesPolicy", locale);
policyType = policyDescriptor.getPolicyType();
assertNotNull("Policy Descriptor should be found", policyDescriptor);
assertTrue("Type should match: " + policyType,
policyType instanceof RangePolicyType);
RangePolicyType rangeType =
(RangePolicyType)policyType;
assertEquals("Selections size should match", 77,
rangeType.getMinInclusive());
assertEquals("Selections size should match", 188,
rangeType.getMaxInclusive());
// Test the retrieval of a policy descriptor from VMTYPES_STRUCTURE
id = populateWithStructure(id);
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "StructurePolicy", locale);
policyType = policyDescriptor.getPolicyType();
assertNotNull("Policy Descriptor should be found", policyDescriptor);
assertTrue("Type should match: " + policyType,
policyType instanceof StructurePolicyType);
StructurePolicyType structureType =
(StructurePolicyType)policyType;
assertTrue("Should contain key: " + "TestFieldname",
structureType.getFieldTypes().containsKey("TestFieldname"));
policyType = (PolicyType)structureType.getFieldTypes().get("TestFieldname");
assertTrue("Type should match: " + policyType,
policyType instanceof BooleanPolicyType);
// Test the retrieval of a policy descriptor from VMTYPES_SET
id = populateWithOrderedSet(id);
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "OrderedSetPolicy", locale);
policyType = policyDescriptor.getPolicyType();
assertNotNull("Policy Descriptor should be found", policyDescriptor);
assertTrue("Type should match: " + policyType,
policyType instanceof OrderedSetPolicyType);
OrderedSetPolicyType orderedSetType =
(OrderedSetPolicyType)policyType;
policyType = orderedSetType.getMemberPolicyType();
assertTrue("Type should match: " + policyType,
policyType instanceof IntPolicyType);
repository = createRepository(oneMoreProject);
accessor =
new JDBCDeviceRepositoryAccessor(repository,
new DeviceRepositoryLocationImpl(oneMoreProject));
// Test the retrieval of a policy descriptor from VMTYPES
populateWithSimpleTypes(0);
policyDescriptor = accessor.retrievePolicyDescriptor(
connection, "Policy1", locale);
assertNotNull("Policy Descriptor should be found", policyDescriptor);
policyType = policyDescriptor.getPolicyType();
assertTrue("Type should match",
policyType instanceof BooleanPolicyType);
} finally {
removeRepository();