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 DeleteTest method test100DeleteObjects.
@Test
public void test100DeleteObjects() throws Exception {
// PrismDomProcessor domProcessor = prismContext.getPrismDomProcessor();
List<PrismObject<? extends Objectable>> objects = prismContext.parserFor(new File(FOLDER_BASIC, "objects.xml")).parseObjects();
OperationResult result = new OperationResult("add objects");
List<String> oids = new ArrayList<>();
for (PrismObject object : objects) {
oids.add(repositoryService.addObject(object, null, result));
}
result.recomputeStatus();
AssertJUnit.assertTrue(result.isSuccess());
for (int i = 0; i < objects.size(); i++) {
repositoryService.deleteObject((Class) objects.get(i).getCompileTimeClass(), oids.get(i), result);
}
result.recomputeStatus();
AssertJUnit.assertTrue(result.isSuccess());
}
use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.
the class ListAccountShadowOwnerTest method listExistingOwner.
@Test
public void listExistingOwner() throws Exception {
OperationResult result = new OperationResult("List owner");
//insert sample data
final File OBJECTS_FILE = new File(FOLDER_BASIC, "objects.xml");
List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(OBJECTS_FILE).parseObjects();
for (int i = 0; i < elements.size(); i++) {
PrismObject object = elements.get(i);
repositoryService.addObject(object, null, result);
}
//look for account owner
PrismObject<UserType> user = repositoryService.listAccountShadowOwner("1234", result);
assertNotNull("No owner for account 1234", user);
PrismProperty name = user.findProperty(ObjectType.F_NAME);
AssertJUnit.assertNotNull(name);
AssertJUnit.assertEquals("atestuserX00003", ((PolyString) name.getRealValue()).getOrig());
}
use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.
the class SearchShadowOwnerTest method initSystem.
@Override
public void initSystem() throws Exception {
super.initSystem();
OperationResult result = new OperationResult("Add sample data");
//insert sample data
final File OBJECTS_FILE = new File(FOLDER_BASIC, "objects.xml");
List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(OBJECTS_FILE).parseObjects();
for (int i = 0; i < elements.size(); i++) {
PrismObject object = elements.get(i);
repositoryService.addObject(object, null, result);
}
result.computeStatus();
AssertJUnit.assertTrue(result.isSuccess());
}
use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.
the class CleanupTest method testTasksCleanup.
@Test
public void testTasksCleanup() throws Exception {
// GIVEN
final File file = new File(FOLDER_REPO, "tasks-for-cleanup.xml");
List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(file).parseObjects();
OperationResult result = new OperationResult("tasks cleanup");
for (PrismObject<? extends Objectable> object : elements) {
String oid = repositoryService.addObject((PrismObject) object, null, result);
AssertJUnit.assertTrue(StringUtils.isNotEmpty(oid));
}
// WHEN
// because now we can't move system time (we're not using DI for it) we create policy
// which should always point to 2013-05-07T12:00:00.000+02:00
final long NOW = System.currentTimeMillis();
Calendar when = create_2013_07_12_12_00_Calendar();
CleanupPolicyType policy = createPolicy(when, NOW);
taskManager.cleanupTasks(policy, taskManager.createTaskInstance(), result);
// THEN
List<PrismObject<TaskType>> tasks = repositoryService.searchObjects(TaskType.class, null, null, result);
AssertJUnit.assertNotNull(tasks);
display("tasks", tasks);
AssertJUnit.assertEquals(1, tasks.size());
PrismObject<TaskType> task = tasks.get(0);
XMLGregorianCalendar timestamp = task.getPropertyRealValue(TaskType.F_COMPLETION_TIMESTAMP, XMLGregorianCalendar.class);
Date finished = XMLGregorianCalendarType.asDate(timestamp);
Date mark = new Date(NOW);
Duration duration = policy.getMaxAge();
duration.addTo(mark);
AssertJUnit.assertTrue("finished: " + finished + ", mark: " + mark, finished.after(mark));
}
Aggregations