Search in sources :

Example 11 with Objectable

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();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Objectable(com.evolveum.midpoint.prism.Objectable) EventHandler(com.evolveum.midpoint.common.validator.EventHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Validator(com.evolveum.midpoint.common.validator.Validator) FileInputStream(java.io.FileInputStream)

Example 12 with Objectable

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());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 13 with Objectable

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());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) Objectable(com.evolveum.midpoint.prism.Objectable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 14 with Objectable

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());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File)

Example 15 with Objectable

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));
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Calendar(java.util.Calendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Duration(javax.xml.datatype.Duration) Date(java.util.Date) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Objectable(com.evolveum.midpoint.prism.Objectable) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Objectable (com.evolveum.midpoint.prism.Objectable)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 File (java.io.File)9 Test (org.testng.annotations.Test)9 Node (org.w3c.dom.Node)7 Element (org.w3c.dom.Element)6 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 ArrayList (java.util.ArrayList)4 Validator (com.evolveum.midpoint.common.validator.Validator)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 FileInputStream (java.io.FileInputStream)2 QName (javax.xml.namespace.QName)2 Session (org.hibernate.Session)2 ResourceValidator (com.evolveum.midpoint.model.api.validator.ResourceValidator)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1