public void testEnumeratePolicyNamesWithCategory() throws Exception {
try {
InternalJDBCRepository repository = createRepository(defaultProject);
JDBCDeviceRepositoryAccessor accessor =
new JDBCDeviceRepositoryAccessor(repository, location);
RepositoryEnumeration repositoryEnumeration =
accessor.enumeratePolicyNames(connection, "unknown");
assertNotNull("Repository enumeration expected", repositoryEnumeration);
assertFalse("No values expected in enumeration.",
repositoryEnumeration.hasNext());
// Populate with one value.
Connection sqlConnection =
((JDBCRepositoryConnection) connection).getConnection();
Statement st = sqlConnection.createStatement();
execute(st, "insert into VMPOLICY_TYPE values " +
"(" + "'" + defaultProject + "', 'PolicyName1', 0, 0)");
execute(st, "insert into VMPOLICY_CATEGORY values " +
"(" + "'" + defaultProject + "',0,'CategoryName', " +
"'<default>')");
st.close();
// Retrieve the unknown value shouldn't find a match.
repositoryEnumeration = accessor.enumeratePolicyNames(connection,
"unknown");
assertNotNull("Repository enumeration expected", repositoryEnumeration);
assertFalse("No values expected in enumeration.",
repositoryEnumeration.hasNext());
// Retrieve the PolicyName with the matching category name should
// find a match.
repositoryEnumeration = accessor.enumeratePolicyNames(connection,
"CategoryName");
assertNotNull("Values expected", repositoryEnumeration);
assertTrue("Values expected in enumeration.",
repositoryEnumeration.hasNext());
String result = (String)repositoryEnumeration.next();
assertEquals("Result should match", "PolicyName1", result);
assertFalse("Only one value expected.",
repositoryEnumeration.hasNext());
} finally {
removeRepository();
}
}