Search in sources :

Example 51 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class PrismInternalTestUtil method assertUserJack.

public static void assertUserJack(PrismObject<UserType> user, boolean expectRawInConstructions) throws SchemaException {
    user.checkConsistence();
    user.assertDefinitions("test");
    assertUserJackContent(user, expectRawInConstructions);
    assertUserJackExtension(user);
    assertVisitor(user, 71);
    assertPathVisitor(user, new ItemPath(UserType.F_ASSIGNMENT), true, 9);
    assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_1_ID)), true, 3);
    assertPathVisitor(user, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), true, 2);
    assertPathVisitor(user, new ItemPath(UserType.F_EXTENSION), true, 15);
    assertPathVisitor(user, new ItemPath(UserType.F_ASSIGNMENT), false, 1);
    assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_1_ID)), false, 1);
    assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), IdItemPathSegment.WILDCARD), false, 2);
    assertPathVisitor(user, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), false, 1);
    assertPathVisitor(user, new ItemPath(UserType.F_EXTENSION), false, 1);
    assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_EXTENSION), NameItemPathSegment.WILDCARD), false, 5);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 52 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestCompare method testDiffJackLiteral.

/**
	 * Parse original jack and modified Jack. Diff and assert if the resulting
	 * delta is OK.
	 * This is literal diff. All the changes should be part of the resulting delta.
	 */
@Test
public void testDiffJackLiteral() throws Exception {
    System.out.println("===[ testDiffJackLiteral ]===");
    // GIVEN
    PrismContext prismContext = constructInitializedPrismContext();
    PrismObject<UserType> jackOriginal = prismContext.parseObject(getFile(USER_JACK_FILE_BASENAME));
    PrismObject<UserType> jackModified = prismContext.parseObject(getFile(USER_JACK_MODIFIED_FILE_BASENAME));
    // WHEN
    ObjectDelta<UserType> jackDelta = jackOriginal.diff(jackModified, true, true);
    // THEN
    System.out.println("Jack delta:");
    System.out.println(jackDelta.debugDump());
    jackDelta.assertDefinitions();
    jackDelta.checkConsistence(true, true, true);
    assertEquals("Wrong delta type", ChangeType.MODIFY, jackDelta.getChangeType());
    assertEquals("Wrong delta OID", USER_JACK_OID, jackDelta.getOid());
    assertEquals("Wrong number of modificaitions", 10, jackDelta.getModifications().size());
    PrismAsserts.assertPropertyReplace(jackDelta, USER_FULLNAME_QNAME, "Jack Sparrow");
    PrismAsserts.assertPropertyDelete(jackDelta, new ItemPath(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "dva");
    PrismAsserts.assertPropertyAdd(jackDelta, new ItemPath(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "osem");
    // TODO: assert BAR
    PrismAsserts.assertPropertyDelete(jackDelta, USER_ADDITIONALNAMES_QNAME, "Captain");
    PrismAsserts.assertPropertyAdd(jackDelta, USER_LOCALITY_QNAME, "World's End");
    PrismAsserts.assertPropertyReplace(jackDelta, USER_ENABLED_PATH, false);
    PrismAsserts.assertPropertyDelete(jackDelta, USER_VALID_FROM_PATH, USER_JACK_VALID_FROM);
    PrismAsserts.assertPropertyReplace(jackDelta, new ItemPath(new NameItemPathSegment(USER_ASSIGNMENT_QNAME), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(USER_DESCRIPTION_QNAME)), "Assignment II");
    ContainerDelta<?> assignment3Delta = PrismAsserts.assertContainerAddGetContainerDelta(jackDelta, new ItemPath(USER_ASSIGNMENT_QNAME));
    PrismContainerValue<?> assignment3DeltaAddValue = assignment3Delta.getValuesToAdd().iterator().next();
    assertEquals("Assignment 3 wrong ID", USER_ASSIGNMENT_3_ID, assignment3DeltaAddValue.getId());
// TODO assert assignment[i1112]/accountConstruction
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 53 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestParseResource method assertResourcePrism.

private void assertResourcePrism(PrismObject<ResourceType> resource, boolean isSimple) throws SchemaException {
    PrismContext prismContext = getPrismContext();
    AssertJUnit.assertEquals("Wrong oid (prism)", TestConstants.RESOURCE_OID, resource.getOid());
    //		assertEquals("Wrong version", "42", resource.getVersion());
    PrismObjectDefinition<ResourceType> resourceDefinition = resource.getDefinition();
    assertNotNull("No resource definition", resourceDefinition);
    PrismAsserts.assertObjectDefinition(resourceDefinition, new QName(SchemaConstantsGenerated.NS_COMMON, "resource"), ResourceType.COMPLEX_TYPE, ResourceType.class);
    assertEquals("Wrong class in resource", ResourceType.class, resource.getCompileTimeClass());
    ResourceType resourceType = resource.asObjectable();
    assertNotNull("asObjectable resulted in null", resourceType);
    assertPropertyValue(resource, "name", PrismTestUtil.createPolyString("Embedded Test OpenDJ"));
    assertPropertyDefinition(resource, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
    if (!isSimple) {
        assertPropertyValue(resource, "namespace", TestConstants.RESOURCE_NAMESPACE);
        assertPropertyDefinition(resource, "namespace", DOMUtil.XSD_ANYURI, 0, 1);
    }
    PrismReference connectorRef = resource.findReference(ResourceType.F_CONNECTOR_REF);
    assertNotNull("No connectorRef", connectorRef);
    PrismReferenceValue connectorRefVal = connectorRef.getValue();
    assertNotNull("No connectorRef value", connectorRefVal);
    assertEquals("Wrong type in connectorRef value", ConnectorType.COMPLEX_TYPE, connectorRefVal.getTargetType());
    SearchFilterType filter = connectorRefVal.getFilter();
    assertNotNull("No filter in connectorRef value", filter);
    if (!isSimple) {
        ObjectFilter objectFilter = QueryConvertor.parseFilter(filter, ConnectorType.class, prismContext);
        assertTrue("Wrong kind of filter: " + objectFilter, objectFilter instanceof EqualFilter);
        EqualFilter equalFilter = (EqualFilter) objectFilter;
        // should be extension/x:extConnType
        ItemPath path = equalFilter.getPath();
        PrismAsserts.assertPathEqualsExceptForPrefixes("Wrong filter path", namespaces ? new ItemPath(new QName("extension"), new QName("http://x/", "extConnType")) : new ItemPath(new QName("extension"), new QName("extConnType")), path);
        PrismPropertyValue filterValue = (PrismPropertyValue) equalFilter.getValues().get(0);
        assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((RawType) filterValue.getValue()).getParsedRealValue(String.class).trim());
    //assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((String) filterValue.getValue()).trim());
    }
    EvaluationTimeType resolutionTime = connectorRefVal.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.IMPORT, resolutionTime);
    }
    PrismContainer<?> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertContainerDefinition(configurationContainer, "configuration", ConnectorConfigurationType.COMPLEX_TYPE, 1, 1);
    PrismContainerValue<?> configContainerValue = configurationContainer.getValue();
    List<Item<?, ?>> configItems = configContainerValue.getItems();
    assertEquals("Wrong number of config items", isSimple ? 1 : 4, configItems.size());
    PrismContainer<?> ldapConfigPropertiesContainer = configurationContainer.findContainer(ICFC_CONFIGURATION_PROPERTIES);
    assertNotNull("No icfcldap:configurationProperties container", ldapConfigPropertiesContainer);
    PrismContainerDefinition<?> ldapConfigPropertiesContainerDef = ldapConfigPropertiesContainer.getDefinition();
    assertNotNull("No icfcldap:configurationProperties container definition", ldapConfigPropertiesContainerDef);
    assertEquals("icfcldap:configurationProperties container definition maxOccurs", 1, ldapConfigPropertiesContainerDef.getMaxOccurs());
    List<Item<?, ?>> ldapConfigPropItems = ldapConfigPropertiesContainer.getValue().getItems();
    assertEquals("Wrong number of ldapConfigPropItems items", 7, ldapConfigPropItems.size());
    PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    if (isSimple) {
        assertNull("Schema sneaked in", schemaContainer);
    } else {
        assertNotNull("No schema container", schemaContainer);
    }
    PrismContainer<?> schemaHandlingContainer = resource.findContainer(ResourceType.F_SCHEMA_HANDLING);
    if (isSimple) {
        assertNull("SchemaHandling sneaked in", schemaHandlingContainer);
    } else {
        assertNotNull("No schemaHandling container", schemaHandlingContainer);
    }
    if (!isSimple) {
        PrismProperty<SynchronizationType> synchronizationProp = resource.findProperty(ResourceType.F_SYNCHRONIZATION);
        SynchronizationType synchronizationType = synchronizationProp.getRealValue();
        ObjectSynchronizationType objectSynchronizationType = synchronizationType.getObjectSynchronization().get(0);
        List<ConditionalSearchFilterType> correlations = objectSynchronizationType.getCorrelation();
        assertEquals("Wrong number of correlation expressions", 1, correlations.size());
        ConditionalSearchFilterType correlationFilterType = correlations.get(0);
        System.out.println("\nCorrelation filter");
        System.out.println(correlationFilterType.debugDump());
        ObjectFilter objectFilter = QueryConvertor.parseFilter(correlationFilterType.serializeToXNode(), prismContext);
        PrismAsserts.assertAssignableFrom(EqualFilter.class, objectFilter);
        EqualFilter equalsFilter = (EqualFilter) objectFilter;
        equalsFilter.getFullPath();
        assertNull("Unexpected values in correlation expression", equalsFilter.getValues());
        ExpressionWrapper expression = equalsFilter.getExpression();
        assertNotNull("No expressions in correlation expression", expression);
        ExpressionType expressionType = (ExpressionType) expression.getExpression();
        assertEquals("Wrong number of expression evaluators in correlation expression", 1, expressionType.getExpressionEvaluator().size());
        ItemPathType itemPathType = (ItemPathType) expressionType.getExpressionEvaluator().get(0).getValue();
        // $account/c:attributes/my:yyy
        PrismAsserts.assertPathEqualsExceptForPrefixes("path in correlation expression", namespaces ? new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName(SchemaConstantsGenerated.NS_COMMON, "attributes")), new NameItemPathSegment(new QName("http://myself.me/schemas/whatever", "yyy"))) : new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName("attributes")), new NameItemPathSegment(new QName("yyy"))), itemPathType.getItemPath());
    //PrismAsserts.assertAllParsedNodes(expression);
    // TODO
    }
}
Also used : NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 54 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestSchemaDelta method testDeleteUserAssignmentActivationSameNullIdApplyToObject.

@Test
public void testDeleteUserAssignmentActivationSameNullIdApplyToObject() throws Exception {
    final String TEST_NAME = "testDeleteUserAssignmentActivationSameNullIdApplyToObject";
    displayTestTile(TEST_NAME);
    // GIVEN
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
    //Delta
    ActivationType activationType = new ActivationType();
    activationType.setAdministrativeStatus(ActivationStatusType.ENABLED);
    // No container ID
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationDeleteContainer(UserType.class, USER_JACK_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_JACK_ASSIGNMENT_ID), new NameItemPathSegment(AssignmentType.F_ACTIVATION)), getPrismContext(), activationType);
    // WHEN
    userDelta.applyTo(user);
    // THEN
    System.out.println("User after delta application:");
    System.out.println(user.debugDump());
    assertEquals("Wrong OID", USER_JACK_OID, user.getOid());
    PrismAsserts.assertPropertyValue(user, UserType.F_NAME, PrismTestUtil.createPolyString(USER_JACK_NAME));
    PrismContainer<AssignmentType> assignmentContainer = user.findContainer(RoleType.F_ASSIGNMENT);
    assertNotNull("No assignment", assignmentContainer);
    assertEquals("Unexpected number of assignment values", 1, assignmentContainer.size());
    PrismContainerValue<AssignmentType> assignmentValue = assignmentContainer.getValues().iterator().next();
    AssignmentType assignment = assignmentValue.asContainerable();
    ActivationType assignmentActivation = assignment.getActivation();
    // activation should be gone (the error is that it is empty and not gone)
    assertNull("Assignment activation is not gone", assignmentActivation);
    ActivationType activation = user.asObjectable().getActivation();
    assertNotNull("Activation missing", activation);
    assertEquals("Wrong activation administrativeStatus", ActivationStatusType.ENABLED, activation.getAdministrativeStatus());
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 55 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test120DirectExpressionReplaceDescription.

@Test
public void test120DirectExpressionReplaceDescription() throws Exception {
    final String TEST_NAME = "test120DirectExpressionReplaceDescription";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = unmarshallValueFromFile(ASSIGNMENT_DIRECT_EXPRESSION_FILE, AssignmentType.class);
    user.asObjectable().getAssignment().add(assignmentType.clone());
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(123L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, path, prismContext, "captain");
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.setSubItemDeltas(userDelta.getModifications());
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment);
    assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(user);
    Construction<UserType> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
    assertNotNull("No object class definition in construction", construction.getRefinedObjectClassDefinition());
    assertEquals(1, construction.getAttributeMappings().size());
    Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>> attributeMapping = (Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>>) construction.getAttributeMappings().iterator().next();
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = attributeMapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, "The best captain the world has ever seen");
    PrismAsserts.assertTripleMinus(outputTriple, "The best pirate the world has ever seen");
    // the same using other words
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS, "The best captain the world has ever seen");
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS, "The best pirate the world has ever seen");
    assertNoConstruction(evaluatedAssignment, PLUS, "title");
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)69 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)61 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)46 Test (org.testng.annotations.Test)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 QName (javax.xml.namespace.QName)20 Task (com.evolveum.midpoint.task.api.Task)19 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)15 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)14 TestTriggerTask (com.evolveum.midpoint.model.intest.TestTriggerTask)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 UserType (com.evolveum.midpoint.prism.foo.UserType)7 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)7 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)6 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)6 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4