RepositoryConnection connection = createConnection();
// ------------------------------------------------------------
// boolean
// ------------------------------------------------------------
DefaultPolicyDescriptor descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(
connection, "mmssupp", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (boolean)",
descriptor.getPolicyDescriptiveName(),
"Supports MMS");
assertEquals("Help should match (boolean)",
descriptor.getPolicyHelp(),
"Indicates whether the device supports the Multimedia" +
" Messaging Service (MMS)");
assertEquals("Category should match (boolean)",
descriptor.getCategoryName(),
"system");
// Ensure the type is of the correct type (try a cast!)
BooleanPolicyType booleanType =
(BooleanPolicyType) descriptor.getPolicyType();
// ------------------------------------------------------------
// int
// ------------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(
connection, "cpuclock", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (int)",
descriptor.getPolicyDescriptiveName(),
"Processor clock rate");
assertEquals("Help should match (int)",
descriptor.getPolicyHelp(),
"Processor speed in MHz. A value -1 indicates that the" +
" speed is unknown");
assertEquals("Category should match (int)",
descriptor.getCategoryName(),
"system");
// Ensure the type is of the correct type (try a cast!)
IntPolicyType intType = (IntPolicyType) descriptor.getPolicyType();
// ------------------------------------------------------------
// range
// ------------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(
connection, "localsec", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (range)",
descriptor.getPolicyDescriptiveName(),
"Local data security");
assertEquals("Help should match (range)",
descriptor.getPolicyHelp(),
"An indication of the level of security built into the" +
" device for securing user data");
assertEquals("Category should match (range)",
descriptor.getCategoryName(),
"security");
// Ensure the type is of the correct type (try a cast!)
RangePolicyType rangeType = (RangePolicyType) descriptor.getPolicyType();
assertEquals("Max should match", 100, rangeType.getMaxInclusive());
assertEquals("Min should match", -1, rangeType.getMinInclusive());
// ------------------------------------------------------------
// selection
// ------------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(
connection, "J2MEconf", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (selection)",
descriptor.getPolicyDescriptiveName(),
"J2ME configuration");
assertEquals("Help should match (selection)",
descriptor.getPolicyHelp(),
"Describes the specific J2ME configuration implemented" +
" on the device");
assertEquals("Category should match (selection)",
descriptor.getCategoryName(),
"system");
// Ensure the type is of the correct type (try a cast!)
SelectionPolicyType selectionType =
(SelectionPolicyType) descriptor.getPolicyType();
String[] expected = new String[]{"none", "CLDC-1.0", "CDC-1.0"};
List keywords = selectionType.getKeywords();
int size = keywords.size();
for (int i = 0; i < size; i++) {
assertEquals("Keyword " + i + " should match",
(String) keywords.get(i),
expected[i]);
}
// ------------------------------------------------------------
// text
// ------------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(
connection, "cpumfgr", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (text)",
descriptor.getPolicyDescriptiveName(),
"Processor manufacturer");
assertEquals("Help should match (text)",
descriptor.getPolicyHelp(),
"The manufacturer of the device processor");
assertEquals("Category should match (text)",
descriptor.getCategoryName(),
"system");
// Ensure the type is of the correct type (try a cast!)
TextPolicyType textType = (TextPolicyType) descriptor.getPolicyType();
// ------------------------------------------------------------
// structure
// ------------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(connection,
"protocol.wml.emulate.bigTag", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (structure)",
descriptor.getPolicyDescriptiveName(),
"Emulate WML big tag");
assertEquals("Help should match (structure)",
descriptor.getPolicyHelp(),
"Controls markup or textual substitution for the WML" +
" <big> element");
assertEquals("Category should match (structure)",
descriptor.getCategoryName(),
"protocol");
// Ensure the type is of the correct type (try a cast!)
StructurePolicyType structureType =
(StructurePolicyType) descriptor.getPolicyType();
Map fields = structureType.getFieldTypes();
Set keys = fields.keySet();
String[] expectedKeys = new String[]{
"enable", "prefix", "suffix", "altTag"
};
size = expectedKeys.length;
for (int i = 0; i < size; i++) {
assertTrue("Key " + i + " should be in the key set",
keys.contains(expectedKeys[i]));
assertNotNull("Key " + i + " should map to a non-null value",
fields.get(expectedKeys[i]));
}
// ------------------------------------------------------------
// ordered set
// ------------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(
connection, "protocol", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (ordered set)",
descriptor.getPolicyDescriptiveName(),
"Protocol");
assertEquals("Help should match (ordered set)",
descriptor.getPolicyHelp(),
"The protocol (markup language) to be used to" +
" communicate with the browser");
assertEquals("Category should match (ordered set)",
descriptor.getCategoryName(),
"browser");
// Ensure the type is of the correct type (try a cast!)
OrderedSetPolicyType orderedSetType =
(OrderedSetPolicyType) descriptor.getPolicyType();
PolicyType memberType = orderedSetType.getMemberPolicyType();
assertTrue("Type of set values should match",
memberType instanceof SelectionPolicyType);
// ------------------------------------------------------------
// unordered set
// ------------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(connection,
"UAProf.Push-Accept", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (unordered set)",
descriptor.getPolicyDescriptiveName(),
"Push content types supported");
assertEquals("Help should match (unordered set)",
descriptor.getPolicyHelp(),
"List of content types the device supports for push");
assertEquals("Category should match (unordered set)",
descriptor.getCategoryName(),
"message");
// Ensure the type is of the correct type (try a cast!)
UnorderedSetPolicyType unorderedSetType =
(UnorderedSetPolicyType) descriptor.getPolicyType();
memberType = unorderedSetType.getMemberPolicyType();
assertTrue("Type of set values should match",
memberType instanceof TextPolicyType);
{
// -------------------------------------------------------
// fallback (fake)
// -------------------------------------------------------
descriptor = (DefaultPolicyDescriptor)
accessor.retrievePolicyDescriptor(connection,
"fallback", locale);
// Ensure the names and help match as expected
assertEquals("Descriptive name should match (fallback)",
descriptor.getPolicyDescriptiveName(), "fallback");
assertEquals("Help should match (fallback)",
descriptor.getPolicyHelp(), "fallback");
assertEquals("Category should match (fallback)",
descriptor.getCategoryName(),
"identification");
// Ensure the type is of the correct type
assertTrue(descriptor.getPolicyType() instanceof
TextPolicyType);
}
}
});