@Test public void testUserCredentialsDiff() throws Exception { System.out.println("===[ testUserCredentialsDiff ]==="); PrismObject<UserType> userBefore = PrismTestUtil.parseObject(USER_BEFORE_FILE); userBefore.checkConsistence(); PrismObject<UserType> userAfter = PrismTestUtil.parseObject(USER_AFTER_FILE); userAfter.checkConsistence(); ObjectDelta<UserType> userDelta = userBefore.diff(userAfter); System.out.println("DELTA:"); System.out.println(userDelta.debugDump()); userBefore.checkConsistence(); userAfter.checkConsistence(); userDelta.checkConsistence(); userDelta.assertDefinitions(); ItemPath path = ItemPath.create(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS); PrismAsserts.assertPropertyAdd(userDelta, path, 1); path = ItemPath.create(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_FAILED_LOGINS); PropertyDelta propertyDelta = userDelta.findPropertyDelta(path); assertNotNull("Property delta for "+path+" not found",propertyDelta); assertEquals(1, propertyDelta.getValuesToAdd().size()); }
@Test public void testUserReal() throws SchemaException, SAXException, IOException, JAXBException { System.out.println("===[ testUserReal ]==="); String userBeforeXml = MiscUtil.readFile(new File(TEST_DIR, "user-real-before.xml")); String userAfterXml = MiscUtil.readFile(new File(TEST_DIR, "user-real-after.xml")); // WHEN ObjectDelta<UserType> userDelta = DiffUtil.diff(userBeforeXml, userAfterXml, UserType.class, getPrismContext()); // THEN System.out.println("DELTA:"); System.out.println(userDelta.debugDump()); userDelta.checkConsistence(); assertEquals("Wrong delta OID", "2f9b9299-6f45-498f-bc8e-8d17c6b93b20", userDelta.getOid()); assertEquals("Wrong change type", ChangeType.MODIFY, userDelta.getChangeType()); Collection<? extends ItemDelta> modifications = userDelta.getModifications(); assertEquals("Unexpected number of modifications", 4, modifications.size()); PrismAsserts.assertPropertyReplace(userDelta, new ItemName(SchemaConstants.NS_C,"emailAddress"), "jack@blackpearl.com"); PrismAsserts.assertPropertyReplace(userDelta, new ItemName(SchemaConstants.NS_C,"locality"), new PolyString("World's End", "worlds end")); PrismAsserts.assertPropertyReplace(userDelta, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, ActivationStatusType.DISABLED); PrismAsserts.assertPropertyAdd(userDelta, new ItemName(SchemaConstants.NS_C,"organizationalUnit"), new PolyString("Brethren of the Coast", "brethren of the coast")); }
private void assertJackAssignAccountContext(LensContext<UserType> context) { assertTrue(context.getFocusContext().getPrimaryDelta().getChangeType() == ChangeType.MODIFY); if (context.getFocusContext().getSecondaryDelta() != null) { assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED); } assertFalse("No account changes", context.getProjectionContexts().isEmpty()); Collection<LensProjectionContext> accountContexts = context.getProjectionContexts(); assertEquals(1, accountContexts.size()); LensProjectionContext accContext = accountContexts.iterator().next(); assertNull("Account primary delta sneaked in", accContext.getPrimaryDelta()); // ADD might be expected here. But projector goes over several iterations. And in the last // iteration the account already exists. Hence KEEP and not ADD. assertEquals(SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision()); ObjectDelta<?> executedDelta = getExecutedDelta(accContext); assertNotNull("No executed delta in "+accContext, executedDelta); assertEquals(ChangeType.ADD, executedDelta.getChangeType()); PrismAsserts.assertPropertyAdd(executedDelta, getIcfsNameAttributePath(), "jack"); PrismAsserts.assertPropertyAdd(executedDelta, getDummyResourceController().getAttributeFullnamePath(), "Jack Sparrow"); }
PrismAsserts.assertPropertyAdd(delta, ShadowType.F_AUXILIARY_OBJECT_CLASS, new QName(NS_TEST_RI, "bar")); PrismAsserts.assertContainerAdd(delta, ShadowType.F_ATTRIBUTES, shadow2Attrs.getValue().clone()); PrismAsserts.assertModifications(delta, 3);
PrismAsserts.assertPropertyAdd(jackDelta, ItemPath.create(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "osem"); PrismAsserts.assertPropertyAdd(jackDelta, USER_LOCALITY_QNAME, "World's End");
ObjectDelta<UserType> userSecondaryDelta = context.getFocusContext().getSecondaryDelta(); assertNotNull("No user secondary delta", userSecondaryDelta); PrismAsserts.assertPropertyAdd(userSecondaryDelta, UserType.F_DESCRIPTION, "Came from Monkey Island");
@Test public void testUserSimpleDiffMultiAdd() throws Exception { System.out.println("\n\n===[ testUserSimpleDiffMulti ]===\n"); // GIVEN PrismObjectDefinition<UserType> userDef = getUserTypeDefinition(); PrismObject<UserType> user1 = userDef.instantiate(); user1.setOid(USER_JACK_OID); PrismProperty<String> anamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); anamesProp1.addRealValue("foo"); anamesProp1.addRealValue("bar"); PrismObject<UserType> user2 = userDef.instantiate(); user2.setOid(USER_JACK_OID); PrismProperty<String> anamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); anamesProp2.addRealValue("foo"); anamesProp2.addRealValue("bar"); anamesProp2.addRealValue("baz"); // WHEN ObjectDelta<UserType> delta = user1.diff(user2); // THEN assertNotNull(delta); System.out.println(delta.debugDump()); assertEquals("Unexpected number of midifications", 1, delta.getModifications().size()); PrismAsserts.assertPropertyAdd(delta, UserType.F_ADDITIONAL_NAMES, "baz"); assertEquals("Wrong OID", USER_JACK_OID, delta.getOid()); delta.checkConsistence(); }
PrismAsserts.assertPropertyAdd(jackDelta, ItemPath.create(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "osem"); PrismAsserts.assertPropertyAdd(jackDelta, USER_LOCALITY_QNAME, "World's End");
private void assertAssignAccountToJack(LensContext<UserType> context) { display("Output context", context); // Not loading anything. The account is already loaded in the context assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0); assertTrue(context.getFocusContext().getPrimaryDelta().getChangeType() == ChangeType.MODIFY); assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED); assertFalse("No account changes", context.getProjectionContexts().isEmpty()); Collection<LensProjectionContext> accountContexts = context.getProjectionContexts(); assertEquals(1, accountContexts.size()); LensProjectionContext accContext = accountContexts.iterator().next(); assertNull("Account primary delta sneaked in", accContext.getPrimaryDelta()); ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta(); assertEquals("Wrong decision", SynchronizationPolicyDecision.ADD,accContext.getSynchronizationPolicyDecision()); assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType()); PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getIcfsNameAttributePath() , "jack"); PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getDummyResourceController().getAttributeFullnamePath() , "Jack Sparrow"); PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME) , "mouth", "pistol"); PrismAsserts.assertOrigin(accountSecondaryDelta, OriginType.OUTBOUND); }
ObjectDelta<UserType> userSecondaryDelta = context.getFocusContext().getSecondaryDelta(); display("User Secondary Delta", userSecondaryDelta); PrismAsserts.assertPropertyAdd(userSecondaryDelta, UserType.F_ORGANIZATION, PrismTestUtil.createPolyString(ORG_BRETHREN_INDUCED_ORGANIZATION));
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME), "Pirate of Caribbean");
assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType()); assertEquals("Unexpected number of account secondary changes", 3, accountSecondaryDelta.getModifications().size()); PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME) , "Arr!");
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME), "rum"); PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME), "Arr!");
assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType()); assertEquals("Unexpected number of account secondary changes", 1, accountSecondaryDelta.getModifications().size()); PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME), "Damned mutinier");
PrismAsserts.assertNoItemDelta(delta, UserType.F_FULL_NAME); PrismAsserts.assertNoItemDelta(delta, UserType.F_ADDITIONAL_NAME); PrismAsserts.assertPropertyAdd(delta, UserType.F_SUBTYPE, "SAILOR"); PrismAsserts.assertPropertyAdd(delta, UserType.F_ORGANIZATION, createPolyString("Pirate Wannabes")); PrismAsserts.assertPropertyDelete(delta, UserType.F_ORGANIZATION,
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME), "Constable");
@Test public void test450GuybrushInboundFromDelta() throws Exception { final String TEST_NAME = "test450GuybrushInboundFromDelta"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE); LensContext<UserType> context = createUserLensContext(); fillContextWithUser(context, USER_GUYBRUSH_OID, result); fillContextWithAccount(context, ACCOUNT_SHADOW_GUYBRUSH_OID, task, result); addSyncModificationToContextReplaceAccountAttribute(context, ACCOUNT_SHADOW_GUYBRUSH_OID, "ship", "Black Pearl"); context.recompute(); display("Input context", context); assertFocusModificationSanity(context); // WHEN projector.project(context, "test", task, result); // THEN display("Output context", context); assertNoUserPrimaryDelta(context); assertUserSecondaryDelta(context); ObjectDelta<UserType> userSecondaryDelta = context.getFocusContext().getSecondaryDelta(); assertTrue(userSecondaryDelta.getChangeType() == ChangeType.MODIFY); PrismAsserts.assertPropertyAdd(userSecondaryDelta, UserType.F_ORGANIZATIONAL_UNIT , PrismTestUtil.createPolyString("The crew of Black Pearl")); assertOriginWithSideEffectChanges(userSecondaryDelta, OriginType.INBOUND); }
ObjectDelta<UserType> userSecondaryDelta = context.getFocusContext().getSecondaryDelta(); assertTrue(userSecondaryDelta.getChangeType() == ChangeType.MODIFY); PrismAsserts.assertPropertyAdd(userSecondaryDelta, UserType.F_ORGANIZATIONAL_UNIT , PrismTestUtil.createPolyString("The crew of The Sea Monkey")); assertOriginWithSideEffectChanges(userSecondaryDelta, OriginType.INBOUND);
assertNotNull("No user secondary delta", userSecondaryDelta); assertEquals("Unexpected number of modifications in user secondary delta", 7, userSecondaryDelta.getModifications().size()); PrismAsserts.assertPropertyAdd(userSecondaryDelta, UserType.F_COST_CENTER, "999");
assertNotNull("No account primary delta", accountPrimaryDelta); PrismAsserts.assertModifications(accountPrimaryDelta, 1); PrismAsserts.assertPropertyAdd(accountPrimaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine Threepwood");