try {
final InternalJDBCRepository repository = createRepository(defaultProject);
final JDBCDeviceRepositoryAccessor accessor =
new JDBCDeviceRepositoryAccessor(repository, location);
final Locale locale = Locale.getDefault();
CategoryDescriptor descriptor = accessor.
retrieveCategoryDescriptor(connection, "unknown", locale);
assertNull("Should find nothing", descriptor);
// Populate with one value.
Connection sqlConnection =
((JDBCRepositoryConnection) connection).getConnection();
Statement st = sqlConnection.createStatement();
execute(st, "insert into VMPOLICY_CATEGORY values " +
"(" + "'" + defaultProject + "',0,'CategoryName', " +
"'<default>')");
st.close();
descriptor = accessor.retrieveCategoryDescriptor(connection,
"CategoryName", locale);
assertNotNull("Should find descriptor", descriptor);
assertEquals("CategoryName", descriptor.getCategoryDescriptiveName());
st = sqlConnection.createStatement();
execute(st, "insert into VMPOLICY_CATEGORY values " +
"(" + "'" + defaultProject + "',0,'category name', 'en_GB_')");
st.close();
descriptor = accessor.retrieveCategoryDescriptor(connection,
"CategoryName", new Locale("en", "GB"));
assertNotNull("Should find descriptor", descriptor);
assertEquals("category name",
descriptor.getCategoryDescriptiveName());
assertEquals("en_GB_", descriptor.getLanguage());
descriptor = accessor.retrieveCategoryDescriptor(connection,
"CategoryName", new Locale("en", "GB", "WIN"));
assertNotNull("Should find descriptor", descriptor);
assertEquals("category name",
descriptor.getCategoryDescriptiveName());
assertEquals("en_GB_", descriptor.getLanguage());
descriptor = accessor.retrieveCategoryDescriptor(connection,
"CategoryName", new Locale("en"));
assertNotNull("Should find descriptor", descriptor);
assertEquals("CategoryName", descriptor.getCategoryDescriptiveName());
assertNull(descriptor.getLanguage());
descriptor = accessor.retrieveCategoryDescriptor(connection,
"CategoryName", new Locale("de"));
assertNotNull("Should find descriptor", descriptor);
assertEquals("CategoryName", descriptor.getCategoryDescriptiveName());
assertNull(descriptor.getLanguage());
} finally {
removeRepository();
}
}