use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class MappingTestEvaluator method createMappingBuilder.
public <T> Mapping.Builder<PrismPropertyValue<T>, PrismPropertyDefinition<T>> createMappingBuilder(String filename, String testName, final StringPolicyType policy, ItemPath defaultTargetPropertyPath, ObjectDelta<UserType> userDelta, PrismObject<UserType> userOld) throws SchemaException, IOException, JAXBException {
MappingType mappingType = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, filename), MappingType.COMPLEX_TYPE);
Mapping.Builder<PrismPropertyValue<T>, PrismPropertyDefinition<T>> mappingBuilder = mappingFactory.createMappingBuilder(mappingType, testName);
// Source context: user
ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(userOld, userDelta, null);
userOdo.recompute();
mappingBuilder.setSourceContext(userOdo);
// Variable $user
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_USER, userOdo);
// Variable $account
PrismObject<ShadowType> account = getAccount();
ObjectDeltaObject<ShadowType> accountOdo = new ObjectDeltaObject<ShadowType>(account, null, null);
accountOdo.recompute();
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, accountOdo);
// Target context: user
PrismObjectDefinition<UserType> userDefinition = getUserDefinition();
mappingBuilder.setTargetContext(userDefinition);
StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {
ItemPath outputPath;
ItemDefinition outputDefinition;
@Override
public void setOutputPath(ItemPath outputPath) {
this.outputPath = outputPath;
}
@Override
public void setOutputDefinition(ItemDefinition outputDefinition) {
this.outputDefinition = outputDefinition;
}
@Override
public StringPolicyType resolve() {
return policy;
}
};
mappingBuilder.setStringPolicyResolver(stringPolicyResolver);
// Default target
if (defaultTargetPropertyPath != null) {
PrismPropertyDefinition<T> targetDefDefinition = userDefinition.findItemDefinition(defaultTargetPropertyPath);
if (targetDefDefinition == null) {
throw new IllegalArgumentException("The item path '" + defaultTargetPropertyPath + "' does not have a definition in " + userDefinition);
}
mappingBuilder.setDefaultTargetDefinition(targetDefDefinition);
}
return mappingBuilder;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class MappingTestEvaluator method evaluateMappingDynamicReplace.
public <T, I> PrismValueDeltaSetTriple<PrismPropertyValue<T>> evaluateMappingDynamicReplace(String filename, String testName, String defaultTargetPropertyName, String changedPropertyName, I... valuesToReplace) throws SchemaException, IOException, JAXBException, ExpressionEvaluationException, ObjectNotFoundException, EncryptionException {
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_OLD_OID, toPath(changedPropertyName), prismContext, valuesToReplace);
Mapping<PrismPropertyValue<T>, PrismPropertyDefinition<T>> mapping = createMapping(filename, testName, defaultTargetPropertyName, userDelta);
OperationResult opResult = new OperationResult(testName);
mapping.evaluate(null, opResult);
assertResult(opResult);
PrismValueDeltaSetTriple<PrismPropertyValue<T>> outputTriple = mapping.getOutputTriple();
if (outputTriple != null) {
outputTriple.checkConsistence();
}
return outputTriple;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class TestMappingComplex method testModifyObjectSetAdditionalName.
@Test
public void testModifyObjectSetAdditionalName() throws Exception {
final String TEST_NAME = "testModifyObjectSetAdditionalName";
System.out.println("===[ " + TEST_NAME + "]===");
// GIVEN
ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_ADDITIONAL_NAME, evaluator.getPrismContext(), "Jackie");
delta.addModificationReplaceProperty(UserType.F_EMPLOYEE_NUMBER, "321");
Mapping<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)"));
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class TestMappingDomain method testReplaceMixedMultiValue.
@Test
public void testReplaceMixedMultiValue() throws Exception {
final String TEST_NAME = "testReplaceMixedMultiValue";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
PrismObject<UserType> userOld = evaluator.getUserOld();
List<String> employeeTypeOld = userOld.asObjectable().getEmployeeType();
employeeTypeOld.clear();
employeeTypeOld.add("001");
employeeTypeOld.add("A02");
employeeTypeOld.add("B03");
employeeTypeOld.add("004");
ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_ADDITIONAL_NAME, evaluator.getPrismContext(), "Jackie");
delta.addModificationReplaceProperty(UserType.F_EMPLOYEE_TYPE, "X91", "992", "Y93", "994");
Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping(MAPPING_DOMAIN_FILENAME, TEST_NAME, "organization", delta, userOld);
OperationResult opResult = new OperationResult(TEST_NAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
mapping.evaluate(null, opResult);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
display("Output triple", outputTriple);
outputTriple.checkConsistence();
PrismAsserts.assertTripleNoZero(outputTriple);
PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("Pirate Jackie (992)"), PrismTestUtil.createPolyString("Pirate Jackie (994)"));
PrismAsserts.assertTripleMinus(outputTriple, PrismTestUtil.createPolyString("Pirate null (001)"), PrismTestUtil.createPolyString("Pirate null (004)"));
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class TestMappingDomain method testAddMixedMultiValue.
@Test
public void testAddMixedMultiValue() throws Exception {
final String TEST_NAME = "testAddMixedMultiValue";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
PrismObject<UserType> userOld = evaluator.getUserOld();
userOld.asObjectable().setAdditionalName(PrismTestUtil.createPolyStringType("Jackie"));
List<String> employeeTypeOld = userOld.asObjectable().getEmployeeType();
employeeTypeOld.clear();
employeeTypeOld.add("001");
employeeTypeOld.add("A02");
employeeTypeOld.add("B03");
employeeTypeOld.add("004");
ObjectDelta<UserType> delta = ObjectDelta.createModificationAddProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_EMPLOYEE_TYPE, evaluator.getPrismContext(), "X91", "992", "Y93", "994");
Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping(MAPPING_DOMAIN_FILENAME, TEST_NAME, "organization", delta, userOld);
OperationResult opResult = new OperationResult(TEST_NAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
mapping.evaluate(null, opResult);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
display("Output triple", outputTriple);
outputTriple.checkConsistence();
PrismAsserts.assertTripleZero(outputTriple, PrismTestUtil.createPolyString("Pirate Jackie (001)"), PrismTestUtil.createPolyString("Pirate Jackie (004)"));
PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("Pirate Jackie (992)"), PrismTestUtil.createPolyString("Pirate Jackie (994)"));
PrismAsserts.assertTripleNoMinus(outputTriple);
}
Aggregations