Search in sources :

Example 16 with Objectable

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

Example 17 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 18 with Objectable

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());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) 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) 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