protected ObjectDelta<ShadowType> createAccountInitializationDelta(String accountOid, String newAccountPassword) { ObjectDelta<ShadowType> shadowDelta = prismContext.deltaFactory().object() .createEmptyModifyDelta(ShadowType.class, accountOid); ProtectedStringType passwordPs = new ProtectedStringType(); passwordPs.setClearValue(newAccountPassword); shadowDelta.addModificationReplaceProperty(SchemaConstants.PATH_PASSWORD_VALUE, passwordPs); shadowDelta.addModificationReplaceProperty(ObjectType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_ACTIVE); return shadowDelta; }
@Test public void test290ReplacePhoto() throws Exception { OperationResult result = new OperationResult("test290ReplacePhoto"); ObjectDelta delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid ); delta.addModificationReplaceProperty(UserType.F_JPEG_PHOTO, new byte[]{4,5,6}); queryCountInterceptor.startCounter(); repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); if (baseHelper.getConfiguration().isUsingH2()) { AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount()); } LOGGER.info("test290ReplacePhoto check"); Session session = factory.openSession(); try { RUser u = session.get(RUser.class, userOid); Set<RFocusPhoto> p = u.getJpegPhoto(); AssertJUnit.assertEquals(1, p.size()); RFocusPhoto photo = p.iterator().next(); AssertJUnit.assertTrue(Arrays.equals(new byte[]{4,5,6}, photo.getPhoto())); } finally { session.close(); } }
@Test public void test170ModifyEmployeeTypeAndMetadataCreateChannel() throws Exception { OperationResult result = new OperationResult("test170ModifyEmployeeTypeAndMetadataCreateChannel"); ObjectDelta delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid ); delta.addModificationAddProperty(UserType.F_EMPLOYEE_TYPE, "one", "two"); delta.addModificationReplaceProperty(ItemPath.create(UserType.F_METADATA, MetadataType.F_CREATE_CHANNEL), "asdf"); queryCountInterceptor.startCounter(); repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); if (baseHelper.getConfiguration().isUsingH2()) { AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount()); } Session session = factory.openSession(); RUser u = session.get(RUser.class, userOid); AssertJUnit.assertEquals("asdf", u.getCreateChannel()); Set set = new HashSet<>(); set.add("one"); set.add("two"); AssertJUnit.assertEquals(u.getEmployeeType(), set); }
@Test public void test110ReplaceNonIndexedExtensionProperty() throws Exception { OperationResult result = new OperationResult("test110ReplaceExtensionProperty"); ObjectDelta<?> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid ); delta.addModificationReplaceProperty(ItemPath.create(UserType.F_EXTENSION, LOOT), 34); queryCountInterceptor.startCounter(); repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); if (baseHelper.getConfiguration().isUsingH2()) { AssertJUnit.assertEquals(2, queryCountInterceptor.getQueryCount()); } Session session = factory.openSession(); try { //RUser u = session.get(RUser.class, userOid); RExtItem extItemDef = extItemDictionary .findItemByDefinition(delta.getModifications().iterator().next().getDefinition()); assertNull("ext item definition for loot exists", extItemDef); } finally { session.close(); } }
@Test public void test120AddExtensionProperty() throws Exception { OperationResult result = new OperationResult("test120AddExtensionProperty"); ObjectDelta<?> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid ); delta.addModificationReplaceProperty(ItemPath.create(UserType.F_EXTENSION, WEAPON), "weapon1", "weapon2"); queryCountInterceptor.startCounter(); repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); if (baseHelper.getConfiguration().isUsingH2()) { AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount()); } Session session = factory.openSession(); try { RUser u = session.get(RUser.class, userOid); RExtItem extItemDef = extItemDictionary.findItemByDefinition(delta.getModifications().iterator().next().getDefinition()); assertAnyValues(u.getStrings(), extItemDef.getId(), "weapon1", "weapon2"); } finally { session.close(); } }
@Test public void testModifyObjectSetAdditionalNameFalse() throws Exception { final String TEST_NAME = "testModifyObjectSetAdditionalNameFalse"; System.out.println("===[ "+TEST_NAME+"]==="); // GIVEN ObjectDelta<UserType> delta = evaluator.getPrismContext().deltaFactory().object() .createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_ADDITIONAL_NAME, "Jackie"); delta.addModificationReplaceProperty(UserType.F_EMPLOYEE_NUMBER, "321"); PrismObject<UserType> userOld = evaluator.getUserOld(); userOld.asObjectable().getEmployeeType().clear(); userOld.asObjectable().getEmployeeType().add("WHATEVER"); MappingImpl<PrismPropertyValue<PolyString>,PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping( MAPPING_COMPLEX_FILENAME, TEST_NAME, "title", delta, userOld); OperationResult opResult = new OperationResult(TEST_NAME); // WHEN mapping.evaluate(null, opResult); // THEN PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple(); assertNull("Unexpected value in outputTriple: "+outputTriple, outputTriple); }
@Test public void test100UpdateGivenNameAndActivation() throws Exception { OperationResult result = new OperationResult("test100UpdateGivenNameAndActivation"); ObjectDelta delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid ); delta.addModificationReplaceProperty(UserType.F_NAME, new PolyString("ášdf", "asdf")); delta.addModificationReplaceProperty(UserType.F_GIVEN_NAME, new PolyString("ášdf", "asdf")); delta.addModificationReplaceProperty(UserType.F_LOCALE, "en-US"); delta.addModificationReplaceProperty( ItemPath.create(UserType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), ActivationStatusType.DISABLED); queryCountInterceptor.startCounter(); repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); if (baseHelper.getConfiguration().isUsingH2()) { AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount()); } Session session = factory.openSession(); try { RUser u = session.get(RUser.class, userOid); AssertJUnit.assertEquals(new RPolyString("ášdf", "asdf"), u.getName()); AssertJUnit.assertEquals(new RPolyString("ášdf", "asdf"), u.getNameCopy()); AssertJUnit.assertEquals(new RPolyString("ášdf", "asdf"), u.getGivenName()); AssertJUnit.assertEquals(u.getLocale(), "en-US"); AssertJUnit.assertEquals(RActivationStatus.DISABLED, u.getActivation().getAdministrativeStatus()); } finally { session.close(); } }
@Test public void test120ModifyUserJackCaptain() throws Exception { final String TEST_NAME = "test120ModifyUserJackCaptain"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ObjectDelta<UserType> objectDelta = createModifyUserReplaceDelta(USER_JACK_OID, UserType.F_TITLE, createPolyString("Captain")); objectDelta.addModificationReplaceProperty(UserType.F_DESCRIPTION, "Hermit on Monkey Island"); objectDelta.addModificationReplaceProperty(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED); // WHEN displayWhen(TEST_NAME); modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result); // THEN displayThen(TEST_NAME); assertSuccess(result); jackCaptainTs = getTimeSafely(); jackCaptainEid = assertObjectAuditRecords(USER_JACK_OID, 6); assertRecordsFromPrevious(hermanMaroonedTs, jackCaptainTs, 2); assertRecordsFromPrevious(jackSailorTs, jackCaptainTs, 4); assertRecordsFromInitial(jackCaptainTs, 10); }
@Test public void test110ModifyUserJackSailor() throws Exception { final String TEST_NAME = "test110ModifyUserJackSailor"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ObjectDelta<UserType> objectDelta = createModifyUserReplaceDelta(USER_JACK_OID, UserType.F_TITLE, createPolyString("Sailor")); objectDelta.addModificationReplaceProperty(UserType.F_DESCRIPTION, "Hermit on Monkey Island"); objectDelta.addModificationReplaceProperty(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, ActivationStatusType.DISABLED); // WHEN displayWhen(TEST_NAME); modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result); // THEN displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess(result); jackSailorTs = getTimeSafely(); jackSailorEid = assertObjectAuditRecords(USER_JACK_OID, 4); assertRecordsFromPrevious(hermanCreatedTs, jackSailorTs, 2); assertRecordsFromPrevious(jackKidTs, jackSailorTs, 4); assertRecordsFromInitial(jackSailorTs, 6); }
@Test public void test125ModifyUserHermanHermit() throws Exception { final String TEST_NAME = "test125ModifyUserHermanHermit"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ObjectDelta<UserType> objectDelta = createModifyUserReplaceDelta(USER_HERMAN_OID, UserType.F_TITLE, createPolyString("Hermit")); objectDelta.addModificationReplaceProperty(UserType.F_DESCRIPTION, "Hermit on Monkey Island"); objectDelta.addModificationReplaceProperty(UserType.F_HONORIFIC_PREFIX, createPolyString("His Loneliness")); objectDelta.addModificationReplaceProperty(UserType.F_NICK_NAME); objectDelta.addModification(createAssignmentModification(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null, false)); objectDelta.addModification(createAssignmentModification(ROLE_JUDGE_OID, RoleType.COMPLEX_TYPE, null, null, null, true)); objectDelta.addModification(createAssignmentModification(ROLE_RED_SAILOR_OID, RoleType.COMPLEX_TYPE, null, null, null, true)); // WHEN displayWhen(TEST_NAME); modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result); // THEN displayThen(TEST_NAME); assertSuccess(result); PrismObject<UserType> user = getUser(USER_HERMAN_OID); display("Herman (hermit)", user); hermanHermitTs = getTimeSafely(); hermanHermitEid = assertObjectAuditRecords(USER_HERMAN_OID, 6); assertRecordsFromInitial(hermanHermitTs, 12); }
userDelta.addModificationReplaceProperty(UserType.F_FULL_NAME, PrismTestUtil.createPolyString(USER_JACK_FULL_NAME)); userDelta.addModificationReplaceProperty(UserType.F_ORGANIZATIONAL_UNIT); deltas.add(userDelta);
@Test public void testModifyObjectSetAdditionalName() throws Exception { final String TEST_NAME = "testModifyObjectSetAdditionalName"; System.out.println("===[ "+TEST_NAME+"]==="); // GIVEN ObjectDelta<UserType> delta = evaluator.getPrismContext().deltaFactory().object() .createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_ADDITIONAL_NAME, "Jackie"); delta.addModificationReplaceProperty(UserType.F_EMPLOYEE_NUMBER, "321"); MappingImpl<PrismPropertyValue<PolyString>,PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping( MAPPING_COMPLEX_FILENAME, TEST_NAME, "title", delta); OperationResult opResult = new OperationResult(TEST_NAME); // WHEN mapping.evaluate(null, opResult); // THEN PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple(); outputTriple.checkConsistence(); PrismAsserts.assertTripleNoZero(outputTriple); PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("Pirate Jackie (#321)")); PrismAsserts.assertTripleMinus(outputTriple, PrismTestUtil.createPolyString("Pirate null (#null)")); }
.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_ADDITIONAL_NAME, "Jackie"); delta.addModificationReplaceProperty(UserType.F_EMPLOYEE_TYPE, "321");
USER_JACK_OID, UserType.F_SUBTYPE, "PIRATE"); userDelta.addModificationReplaceProperty(UserType.F_EMPLOYEE_NUMBER); userDelta.addModificationAddProperty(SchemaConstants.PATH_ACTIVATION_VALID_FROM, XmlTypeConverter .createXMLGregorianCalendar(System.currentTimeMillis()));
@Test public void test180ModifyMetadataChannel() throws Exception { OperationResult result = new OperationResult("test170ModifyEmployeeTypeAndMetadataCreateChannel"); ObjectDelta delta = prismContext.deltaFactory().object().createEmptyModifyDelta(UserType.class, userOid ); ObjectReferenceType ref = createRef(UserType.COMPLEX_TYPE, "111"); delta.addModificationReplaceReference(ItemPath.create(UserType.F_METADATA, MetadataType.F_CREATE_APPROVER_REF), ref.asReferenceValue()); delta.addModificationReplaceProperty(ItemPath.create(UserType.F_METADATA, MetadataType.F_CREATE_CHANNEL), "zxcv"); queryCountInterceptor.startCounter(); repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); if (baseHelper.getConfiguration().isUsingH2()) { AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount()); } Session session = factory.openSession(); RUser u = session.get(RUser.class, userOid); AssertJUnit.assertEquals("zxcv", u.getCreateChannel()); AssertJUnit.assertEquals(1, u.getCreateApproverRef().size()); assertReferences((Collection) u.getCreateApproverRef(), RObjectReference.copyFromJAXB(createRef(UserType.COMPLEX_TYPE, "111", SchemaConstants.ORG_DEFAULT), new RObjectReference(), relationRegistry)); }
@Test public void test135ModifyUserHermanCivilisedHermit() throws Exception { final String TEST_NAME = "test135ModifyUserHermanCivilisedHermit"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ObjectDelta<UserType> objectDelta = createModifyUserReplaceDelta(USER_HERMAN_OID, UserType.F_TITLE, createPolyString("Civilised Hermit")); objectDelta.addModificationReplaceProperty(UserType.F_DESCRIPTION, "Civilised Hermit on Monkey Island"); objectDelta.addModification(createAssignmentModification(ROLE_RED_SAILOR_OID, RoleType.COMPLEX_TYPE, null, null, null, false)); // WHEN displayWhen(TEST_NAME); modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result); // THEN displayThen(TEST_NAME); assertSuccess(result); PrismObject<UserType> user = getUser(USER_HERMAN_OID); display("Herman (civilised hermit)", user); hermanCivilisedHermitTs = getTimeSafely(); hermanCivilisedHermitEid = assertObjectAuditRecords(USER_HERMAN_OID, 8); assertRecordsFromInitial(hermanCivilisedHermitTs, 14); }
@Test public void test115ModifyUserHermanMarooned() throws Exception { final String TEST_NAME = "test115ModifyUserHermanMarooned"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ObjectDelta<UserType> objectDelta = createModifyUserReplaceDelta(USER_HERMAN_OID, UserType.F_TITLE, createPolyString("Marooned")); objectDelta.addModificationReplaceProperty(UserType.F_DESCRIPTION, "Marooned on Monkey Island"); objectDelta.addModification(createAssignmentModification(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null, true)); // WHEN displayWhen(TEST_NAME); modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result); // THEN displayThen(TEST_NAME); assertSuccess(result); PrismObject<UserType> user = getUser(USER_HERMAN_OID); display("Herman (marooned)", user); hermanMaroonedTs = getTimeSafely(); hermanMaroonedEid = assertObjectAuditRecords(USER_HERMAN_OID, 4); assertRecordsFromInitial(hermanMaroonedTs, 8); }
ProtectedStringType ps = new ProtectedStringType(); ps.setClearValue(USER_WILL_PASSWORD_NEW); delta.addModificationReplaceProperty(SchemaConstants.PATH_PASSWORD_VALUE, ps); display("ObjectDelta", delta);
private ObjectDelta<UserType> createDeltaForFindItem(boolean containerReplace) throws SchemaException { ObjectDelta<UserType> userDelta = PrismTestUtil.getPrismContext().deltaFactory().object() .createModificationAddProperty(UserType.class, USER_FOO_OID, UserType.F_LOCALITY, "Caribbean"); userDelta.addModificationReplaceProperty(UserType.F_GIVEN_NAME, "Guybrush"); ContainerDelta<ActivationType> activationDelta = userDelta.createContainerModification(UserType.F_ACTIVATION); PrismContainerValue<ActivationType> activationCVal = getPrismContext().itemFactory().createContainerValue(); if (containerReplace) { activationDelta.addValueToReplace(activationCVal); } else { activationDelta.addValueToAdd(activationCVal); } PrismProperty<Boolean> enabledProperty = activationCVal.createProperty(ActivationType.F_ENABLED); enabledProperty.setRealValue(Boolean.TRUE); PrismProperty<XMLGregorianCalendar> validFromProperty = activationCVal.createProperty(ActivationType.F_VALID_FROM); validFromProperty.setRealValue(XmlTypeConverter.createXMLGregorianCalendar(20016, 5, 16, 19, 8, 33)); userDelta.addModification(activationDelta); return userDelta; }
AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), ActivationStatusType.DISABLED); objectDelta.addModificationReplaceProperty(ItemPath.create(UserType.F_ASSIGNMENT, sailorAssignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), ActivationStatusType.DISABLED);