Search in sources :

Example 1 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 2 with ObjectModificationType

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

the class TestJaxbSanity method testAssignmentEquals.

@Test
public void testAssignmentEquals() throws JAXBException, SchemaException, FileNotFoundException {
    System.out.println("\n\n ===[testAssnignmentEquals]===\n");
    // GIVEN
    JAXBElement<UserType> userEl1 = JaxbTestUtil.getInstance().unmarshalElement(new File(USER_BARBOSSA_FILENAME), UserType.class);
    UserType user = userEl1.getValue();
    assertNotNull(user);
    AssignmentType userAssignmentType = user.getAssignment().get(0);
    assertNotNull(userAssignmentType);
    System.out.println("\n*** user assignment");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(userAssignmentType));
    JAXBElement<ObjectModificationType> modEl = JaxbTestUtil.getInstance().unmarshalElement(new File(TEST_DIR, "user-barbossa-modify-delete-assignment-account-opendj-attr.xml"), ObjectModificationType.class);
    ObjectModificationType mod = modEl.getValue();
    assertNotNull(mod);
    //FIXME : modification value -> rawType...
    RawType rawType = mod.getItemDelta().get(0).getValue().get(0);
    ItemDefinition assignmentDefinition = PrismTestUtil.getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class);
    assertNotNull(assignmentDefinition);
    AssignmentType assignmentType = ((PrismContainerValue<AssignmentType>) rawType.getParsedValue(assignmentDefinition, null)).getValue();
    //                was: (JAXBElement<AssignmentType>) mod.getItemDelta().get(0).getValue().get(0).getContent().get(0);
    assertNotNull(assignmentType);
    System.out.println("\n*** assignment");
    System.out.println(PrismTestUtil.serializeAnyDataWrapped(assignmentType));
    // WHEN, THEN
    assertTrue("Assignment not equals", userAssignmentType.equals(assignmentType));
    assertTrue("HashCode does not match", userAssignmentType.hashCode() == assignmentType.hashCode());
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 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 4 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 5 with ObjectModificationType

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

the class ModifyAssignmentTest method test31DeleteInducement.

@Test
public void test31DeleteInducement() throws Exception {
    //given
    //when
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "modify-delete-inducement.xml"), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta delta = DeltaConvertor.createObjectDelta(modification, RoleType.class, prismContext);
    OperationResult result = new OperationResult("delete inducement");
    repositoryService.modifyObject(RoleType.class, delta.getOid(), delta.getModifications(), result);
    result.recomputeStatus();
    result.recordSuccessIfUnknown();
    //then
    AssertJUnit.assertTrue(result.isSuccess());
    result = new OperationResult("get role");
    PrismObject repoRole = repositoryService.getObject(RoleType.class, ROLE_OID, null, result);
    result.recomputeStatus();
    result.recordSuccessIfUnknown();
    AssertJUnit.assertTrue(result.isSuccess());
    PrismContainer inducement = repoRole.findContainer(new ItemPath(RoleType.F_INDUCEMENT));
    AssertJUnit.assertNotNull(inducement);
    AssertJUnit.assertEquals(2, inducement.getValues().size());
    AssertJUnit.assertNotNull(inducement.getValue(2L));
    AssertJUnit.assertNotNull(inducement.getValue(5L));
    PrismContainer assignment = repoRole.findContainer(new ItemPath(AbstractRoleType.F_ASSIGNMENT));
    AssertJUnit.assertNotNull(assignment);
    AssertJUnit.assertEquals(1, assignment.getValues().size());
    AssertJUnit.assertNotNull(assignment.getValue(1L));
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)50 Test (org.testng.annotations.Test)44 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)34 File (java.io.File)32 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 Task (com.evolveum.midpoint.task.api.Task)9 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)5 QName (javax.xml.namespace.QName)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)2 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2