* @throws InstantiationException
*/
@Test
public void testTypeCRUD() throws InstantiationException, IllegalAccessException {
// C
Type type = getDataObjectClass().newInstance();
String name = "test type";
type.setName(name);
populateAdditionalFieldsForCrud(type);
getBoSvc().save(type);
// R
type.refresh();
assertEquals("name does not match", name, type.getName());
// save scope and see if it can be seen from the base detail/type side
boolean scopeAdded = false;
if (ScopedKeyValue.class.isAssignableFrom(getDataObjectClass())) {
Scope scope = getScopeClass().newInstance();
final String qualifiedClassName = Matter.class.getCanonicalName();
scope.setQualifiedClassName(qualifiedClassName);
scope.setTypeId(type.getId());
getBoSvc().save(scope);
type.refresh();
ScopedKeyValue scoped = (ScopedKeyValue)type;
assertNotNull("scope should not be null", scoped.getScope());
assertFalse("scope should not be empty", scoped.getScope().isEmpty());
assertEquals("qualified class name differs", qualifiedClassName, scoped.getScope().get(0).getQualifiedClassName());
// insert boolean to indicate that a scope has been set, to be used at the delete section below
scopeAdded = true;
}
testCrudCreated(type);
// U
type.setDescription("test description");
type.refresh();
assertNotNull("description should not be null", type.getDescription());
// D
getBoSvc().delete(type);
assertNull(getBoSvc().findBySinglePrimaryKey(getDataObjectClass(), type.getId()));
if (scopeAdded) {
Map<String, String> criteria = new HashMap<String, String>();
criteria.put("typeId", String.valueOf(type.getId()));
assertTrue("scope should have been deleted", getBoSvc().findMatching(Scope.class, criteria).isEmpty());
}
testCrudDeleted(type);
}