use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.
the class OrgStructTest method test001addOrgStructObjects.
@Test
public void test001addOrgStructObjects() throws Exception {
OperationResult opResult = new OperationResult("test001addOrgStructObjects");
List<PrismObject<? extends Objectable>> orgStruct = prismContext.parserFor(new File(ORG_STRUCT_OBJECTS)).parseObjects();
for (PrismObject<? extends Objectable> o : orgStruct) {
repositoryService.addObject((PrismObject<ObjectType>) o, null, opResult);
}
opResult.computeStatusIfUnknown();
AssertJUnit.assertTrue(opResult.isSuccess());
List<PrismObject<OrgType>> orgTypes = repositoryService.searchObjects(OrgType.class, new ObjectQuery(), null, opResult);
AssertJUnit.assertNotNull(orgTypes);
AssertJUnit.assertEquals(9, orgTypes.size());
OrgType pRoot = repositoryService.getObject(OrgType.class, ORG_PROJECT_ROOT_OID, null, opResult).asObjectable();
AssertJUnit.assertEquals("PRoot", pRoot.getName().getOrig());
PrismObjectDefinition<UserType> userObjectDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_NAME).eq(ELAINE_NAME).build();
List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, opResult);
AssertJUnit.assertEquals(1, users.size());
ELAINE_OID = users.get(0).getOid();
testMonkeySubordinate();
Session session = open();
try {
Query qCount = session.createQuery("select count(*) from ROrgClosure");
assertCount(qCount, 19);
// check descendants for F0001 org unit
qCount = session.createQuery("select count(*) from ROrgClosure where ancestorOid = :ancestorOid");
qCount.setParameter("ancestorOid", ORG_F001_OID);
assertCount(qCount, 6);
qCount = session.createQuery("select count(*) from ROrgClosure where ancestorOid = :ancestorOid and descendantOid = :descendantOid");
qCount.setParameter("ancestorOid", ORG_F001_OID);
qCount.setParameter("descendantOid", ORG_F006_OID);
assertCount(qCount, 1);
} finally {
close(session);
}
}
use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.
the class TestSamples method validate.
private void validate(File file) throws FileNotFoundException {
System.out.println("===> Validating file " + file.getPath());
EventHandler handler = new EventHandler() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
return EventResult.cont();
}
@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
// Try to marshall it back. This may detect some JAXB miscofiguration problems.
try {
String serializedString = PrismTestUtil.serializeObjectToString(object, PrismContext.LANG_XML);
} catch (SchemaException e) {
objectResult.recordFatalError("Object serialization failed", e);
}
return EventResult.cont();
}
@Override
public void handleGlobalError(OperationResult currentResult) {
// no reaction
}
};
Validator validator = new Validator(PrismTestUtil.getPrismContext());
validator.setVerbose(false);
validator.setAllowAnyType(true);
validator.setHandler(handler);
FileInputStream fis = new FileInputStream(file);
OperationResult result = new OperationResult(RESULT_OPERATION_NAME);
validator.validate(fis, result, OBJECT_RESULT_OPERATION_NAME);
if (!result.isSuccess()) {
// The error is most likely the first inner result. Therefore let's pull it out for convenience
String errorMessage = result.getMessage();
if (result.getSubresults() != null && !result.getSubresults().isEmpty()) {
if (result.getSubresults().get(0).getMessage() != null) {
errorMessage = result.getSubresults().get(0).getMessage();
}
}
System.out.println("ERROR: " + errorMessage);
System.out.println(result.debugDump());
Assert.fail(file.getPath() + ": " + errorMessage);
} else {
System.out.println("OK");
//System.out.println(result.dump());
}
System.out.println();
}
use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.
the class BasicValidatorTest method resource1Valid.
@Test
public void resource1Valid() throws Exception {
System.out.println("\n===[ resource1Valid ]=====");
OperationResult result = new OperationResult(this.getClass().getName() + ".resource1Valid");
EventHandler handler = new EventHandler() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
return EventResult.cont();
}
@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
System.out.println("Validating resorce:");
System.out.println(object.debugDump());
object.checkConsistence();
PrismContainer<?> extensionContainer = object.getExtension();
PrismProperty<Integer> menProp = extensionContainer.findProperty(new QName("http://myself.me/schemas/whatever", "menOnChest"));
assertNotNull("No men on a dead man chest!", menProp);
assertEquals("Wrong number of men on a dead man chest", (Integer) 15, menProp.getAnyRealValue());
PrismPropertyDefinition menPropDef = menProp.getDefinition();
assertNotNull("Men on a dead man chest NOT defined", menPropDef);
assertEquals("Wrong type for men on a dead man chest definition", DOMUtil.XSD_INT, menPropDef.getTypeName());
assertTrue("Men on a dead man chest definition not dynamic", menPropDef.isDynamic());
return EventResult.cont();
}
@Override
public void handleGlobalError(OperationResult currentResult) {
/* nothing */
}
};
validateFile("resource-1-valid.xml", handler, result);
AssertJUnit.assertTrue(result.isSuccess());
}
Aggregations