Search in sources :

Example 6 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class AbstractModelImplementationIntegrationTest method addFocusModificationToContext.

protected <O extends ObjectType> ObjectDelta<O> addFocusModificationToContext(LensContext<O> context, File file) throws JAXBException, SchemaException, IOException {
    ObjectModificationType modElement = PrismTestUtil.parseAtomicValue(file, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<O> focusDelta = DeltaConvertor.createObjectDelta(modElement, context.getFocusClass(), prismContext);
    return addFocusDeltaToContext(context, focusDelta);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)

Example 7 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class XPathTest method xpathTest.

/**
     * This is now a proper test yet.
     * It does some operations with XPath. If it does not die, then the
     * code some somehow consistent.
     *
     * It should be improved later.
     */
@Test
public void xpathTest() throws JAXBException, FileNotFoundException, IOException, ParserConfigurationException, SchemaException {
    ObjectModificationType objectModification = PrismTestUtil.parseAtomicValue(new File(FILENAME_CHANGETYPE), ObjectModificationType.COMPLEX_TYPE);
    for (ItemDeltaType change : objectModification.getItemDelta()) {
        ItemPathType pathType = change.getPath();
        System.out.println("  path=" + pathType + " (" + pathType.getClass().getName() + ") " + pathType.toString());
        //            NamedNodeMap attributes = path.getAttributes();
        //            for (int i = 0; i < attributes.getLength(); i++) {
        //                Node n = attributes.item(i);
        //                System.out.println("   A: " + n.getClass().getName() + " " + n.getNodeName() + "(" + n.getPrefix() + " : " + n.getLocalName() + ") = " + n.getNodeValue());
        //            }
        //            List<Object> any = change.getValue().getAny();
        //            for (Object e : any) {
        //                if (e instanceof Element) {
        //                    System.out.println("  E: " + ((Element) e).getLocalName());
        //                }
        //            }
        ItemPath path = pathType.getItemPath();
        XPathHolder xpath = new XPathHolder(path);
        AssertJUnit.assertEquals("c:extension/piracy:ship[2]/c:name", xpath.getXPathWithoutDeclarations());
        System.out.println("XPATH: " + xpath);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder loader = factory.newDocumentBuilder();
        Document doc = loader.newDocument();
        Element xpathElement = xpath.toElement("http://elelel/", "path", doc);
        Attr nsC = xpathElement.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "c");
        Attr nsPiracy = xpathElement.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "piracy");
        System.out.println("c: " + nsC);
        System.out.println("piracy: " + nsPiracy);
        //            AssertJUnit.assertEquals("http://midpoint.evolveum.com/xml/ns/public/common/common-3", nsC.getValue());
        //            AssertJUnit.assertEquals("http://midpoint.evolveum.com/xml/ns/samples/piracy", nsPiracy.getValue());
        System.out.println("XPATH Element: " + xpathElement);
        XPathHolder xpathFromElement = new XPathHolder(xpathElement);
        AssertJUnit.assertEquals(xpath, xpathFromElement);
        //            attributes = xpathElement.getAttributes();
        //            for (int i = 0; i < attributes.getLength(); i++) {
        //                Node n = attributes.item(i);
        //                System.out.println(" A: " + n.getNodeName() + "(" + n.getPrefix() + " : " + n.getLocalName() + ") = " + n.getNodeValue());
        //            }
        List<XPathSegment> segments = xpath.toSegments();
        System.out.println("XPATH segments: " + segments);
        XPathHolder xpathFromSegments = new XPathHolder(segments);
        System.out.println("XPath from segments: " + xpathFromSegments);
        AssertJUnit.assertEquals("c:extension/piracy:ship[2]/c:name", xpathFromSegments.getXPathWithoutDeclarations());
    }
}
Also used : XPathSegment(com.evolveum.midpoint.prism.marshaller.XPathSegment) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Attr(org.w3c.dom.Attr) XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 8 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class AbstractWfTestLegacy method encryptAndAddFocusModificationToContext.

<O extends ObjectType> ObjectDelta<O> encryptAndAddFocusModificationToContext(LensContext<O> context, File file) throws JAXBException, SchemaException, IOException {
    ObjectModificationType modElement = PrismTestUtil.parseAtomicValue(file, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<O> focusDelta = DeltaConvertor.createObjectDelta(modElement, context.getFocusClass(), prismContext);
    Utils.encrypt((Collection) Arrays.asList(focusDelta), protector, null, new OperationResult("dummy"));
    return addFocusDeltaToContext(context, focusDelta);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 9 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class TestAddAssociationLegacy method test100AddJackToGuests.

/**
     * Add entitlement for 'guests' to user jack - should be created without starting wf process
     */
@Test
public void test100AddJackToGuests() throws Exception {
    final String TEST_NAME = "test100AddJackToGuests";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task modelTask = taskManager.createTaskInstance(TEST_NAME);
    OperationResult result = new OperationResult(TEST_NAME);
    modelTask.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_JACK_OID, result);
    UserType jack = context.getFocusContext().getObjectCurrent().asObjectable();
    AssertJUnit.assertEquals("Jack has wrong number of accounts", 1, jack.getLinkRef().size());
    jackAccountShadowOid = jack.getLinkRef().get(0).getOid();
    ShadowType accountBefore = getObject(ShadowType.class, jackAccountShadowOid).asObjectable();
    assertEquals("Wrong # of jack's account associations", 1, accountBefore.getAssociation().size());
    assertHasAssociation(accountBefore, new QName("group"), GROUP_TESTERS_OID);
    LensProjectionContext accountContext = fillContextWithAccount(context, jackAccountShadowOid, modelTask, result);
    ObjectModificationType modElement = PrismTestUtil.parseAtomicValue(REQ_SHADOW_MODIFY_ADD_ENTITLEMENT_GUESTS, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta shadowDelta = DeltaConvertor.createObjectDelta(modElement, ShadowType.class, prismContext);
    shadowDelta.setOid(jackAccountShadowOid);
    accountContext.setPrimaryDelta(shadowDelta);
    HookOperationMode mode = clockwork.run(context, modelTask, result);
    assertEquals("Unexpected state of the context - workflow was started even if it should not", ModelState.FINAL, context.getState());
    assertEquals("Wrong mode after clockwork.run in " + context.getState(), HookOperationMode.FOREGROUND, mode);
    ShadowType accountAfter = getObject(ShadowType.class, jackAccountShadowOid).asObjectable();
    assertEquals("Wrong # of jack's account associations", 2, accountAfter.getAssociation().size());
    assertHasAssociation(accountAfter, new QName("group"), GROUP_TESTERS_OID);
    assertHasAssociation(accountAfter, new QName("group"), GROUP_GUESTS_OID);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Task(com.evolveum.midpoint.task.api.Task) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 10 with ObjectModificationType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.

the class OrgStructTest method test003modifyOrgStructDeleteRef.

@SuppressWarnings("unchecked")
@Test
public void test003modifyOrgStructDeleteRef() throws Exception {
    // test modification of org ref - delete org ref
    OperationResult opResult = new OperationResult("test003modifyOrgStructDeleteRef");
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_DELETE_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    Session session = open();
    try {
        LOGGER.info("==>before modify - delete<==");
        List<ROrgClosure> orgClosure = getOrgClosure(ORG_F003_OID, MODIFY_ORG_DELETE_REF_OID, session);
        AssertJUnit.assertEquals(1, orgClosure.size());
        session.getTransaction().commit();
        repositoryService.modifyObject(OrgType.class, MODIFY_ORG_DELETE_REF_OID, delta.getModifications(), opResult);
        session.clear();
        session.beginTransaction();
        LOGGER.info("==>after modify - delete<==");
        orgClosure = getOrgClosure(ORG_F003_OID, MODIFY_ORG_DELETE_REF_OID, session);
        AssertJUnit.assertEquals(0, orgClosure.size());
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)45 Test (org.testng.annotations.Test)40 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)31 File (java.io.File)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)8 Task (com.evolveum.midpoint.task.api.Task)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 Session (org.hibernate.Session)6 ROrgClosure (com.evolveum.midpoint.repo.sql.data.common.ROrgClosure)5 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)5 Entry (org.opends.server.types.Entry)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)3 QName (javax.xml.namespace.QName)3 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2