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());
}
}
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());
}
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);
}
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);
}
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));
}
Aggregations