Search in sources :

Example 11 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractIntegrationTest method assertShadowCommon.

protected void assertShadowCommon(PrismObject<ShadowType> shadow, String oid, String username, ResourceType resourceType, QName objectClass, final MatchingRule<String> nameMatchingRule, boolean requireNormalizedIdentfiers, boolean useMatchingRuleForShadowName) throws SchemaException {
    assertShadow(shadow);
    if (oid != null) {
        assertEquals("Shadow OID mismatch (prism)", oid, shadow.getOid());
    }
    ShadowType resourceObjectShadowType = shadow.asObjectable();
    if (oid != null) {
        assertEquals("Shadow OID mismatch (jaxb)", oid, resourceObjectShadowType.getOid());
    }
    assertEquals("Shadow objectclass", objectClass, resourceObjectShadowType.getObjectClass());
    assertEquals("Shadow resourceRef OID", resourceType.getOid(), shadow.asObjectable().getResourceRef().getOid());
    PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    assertNotNull("Null attributes in shadow for " + username, attributesContainer);
    assertFalse("Empty attributes in shadow for " + username, attributesContainer.isEmpty());
    if (useMatchingRuleForShadowName) {
        MatchingRule<PolyString> polyMatchingRule = new MatchingRule<PolyString>() {

            @Override
            public QName getName() {
                return nameMatchingRule.getName();
            }

            @Override
            public boolean isSupported(QName xsdType) {
                return nameMatchingRule.isSupported(xsdType);
            }

            @Override
            public boolean match(PolyString a, PolyString b) throws SchemaException {
                return nameMatchingRule.match(a.getOrig(), b.getOrig());
            }

            @Override
            public boolean matchRegex(PolyString a, String regex) throws SchemaException {
                return nameMatchingRule.matchRegex(a.getOrig(), regex);
            }

            @Override
            public PolyString normalize(PolyString original) throws SchemaException {
                return new PolyString(nameMatchingRule.normalize(original.getOrig()));
            }
        };
        PrismAsserts.assertPropertyValueMatch(shadow, ShadowType.F_NAME, polyMatchingRule, PrismTestUtil.createPolyString(username));
    } else {
        PrismAsserts.assertPropertyValue(shadow, ShadowType.F_NAME, PrismTestUtil.createPolyString(username));
    }
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
    ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(objectClass);
    if (ocDef.getSecondaryIdentifiers().isEmpty()) {
        ResourceAttributeDefinition idDef = ocDef.getPrimaryIdentifiers().iterator().next();
        PrismProperty<String> idProp = attributesContainer.findProperty(idDef.getName());
        assertNotNull("No primary identifier (" + idDef.getName() + ") attribute in shadow for " + username, idProp);
        if (nameMatchingRule == null) {
            assertEquals("Unexpected primary identifier in shadow for " + username, username, idProp.getRealValue());
        } else {
            if (requireNormalizedIdentfiers) {
                assertEquals("Unexpected primary identifier in shadow for " + username, nameMatchingRule.normalize(username), idProp.getRealValue());
            } else {
                PrismAsserts.assertEquals("Unexpected primary identifier in shadow for " + username, nameMatchingRule, username, idProp.getRealValue());
            }
        }
    } else {
        ResourceAttributeDefinition idSecDef = ocDef.getSecondaryIdentifiers().iterator().next();
        PrismProperty<String> idProp = attributesContainer.findProperty(idSecDef.getName());
        assertNotNull("No secondary identifier (" + idSecDef.getName() + ") attribute in shadow for " + username, idProp);
        if (nameMatchingRule == null) {
            assertEquals("Unexpected secondary identifier in shadow for " + username, username, idProp.getRealValue());
        } else {
            if (requireNormalizedIdentfiers) {
                assertEquals("Unexpected secondary identifier in shadow for " + username, nameMatchingRule.normalize(username), idProp.getRealValue());
            } else {
                PrismAsserts.assertEquals("Unexpected secondary identifier in shadow for " + username, nameMatchingRule, username, idProp.getRealValue());
            }
        }
    }
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Containerable(com.evolveum.midpoint.prism.Containerable) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule)

Example 12 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractIntegrationTest method repoAddShadowFromFile.

protected PrismObject<ShadowType> repoAddShadowFromFile(File file, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, EncryptionException, IOException {
    OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".repoAddShadowFromFile");
    result.addParam("file", file);
    LOGGER.debug("addShadowFromFile: {}", file);
    PrismObject<ShadowType> object = prismContext.parseObject(file);
    PrismContainer<Containerable> attrCont = object.findContainer(ShadowType.F_ATTRIBUTES);
    for (PrismProperty<?> attr : attrCont.getValue().getProperties()) {
        if (attr.getDefinition() == null) {
            ResourceAttributeDefinition<String> attrDef = new ResourceAttributeDefinitionImpl<>(attr.getElementName(), DOMUtil.XSD_STRING, prismContext);
            attr.setDefinition((PrismPropertyDefinition) attrDef);
        }
    }
    addBasicMetadata(object);
    LOGGER.trace("Adding object:\n{}", object.debugDump());
    repoAddObject(object, "from file " + file, result);
    result.recordSuccess();
    return object;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Containerable(com.evolveum.midpoint.prism.Containerable) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 13 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class ConsistencyTest method checkOpenResourceConfiguration.

private void checkOpenResourceConfiguration(PrismObject<ResourceType> resource, String connectorNamespace, String credentialsPropertyName, int numConfigProps, String source) {
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No configuration container in " + resource + " from " + source, configurationContainer);
    PrismContainer<Containerable> configPropsContainer = configurationContainer.findContainer(SchemaTestConstants.ICFC_CONFIGURATION_PROPERTIES);
    assertNotNull("No configuration properties container in " + resource + " from " + source, configPropsContainer);
    List<? extends Item<?, ?>> configProps = configPropsContainer.getValue().getItems();
    assertEquals("Wrong number of config properties in " + resource + " from " + source, numConfigProps, configProps.size());
    PrismProperty<Object> credentialsProp = configPropsContainer.findProperty(new QName(connectorNamespace, credentialsPropertyName));
    if (credentialsProp == null) {
        // The is the heisenbug we are looking for. Just dump the entire
        // damn thing.
        display("Configuration with the heisenbug", configurationContainer.debugDump());
    }
    assertNotNull("No credentials property in " + resource + " from " + source, credentialsProp);
    assertEquals("Wrong number of credentials property value in " + resource + " from " + source, 1, credentialsProp.getValues().size());
    PrismPropertyValue<Object> credentialsPropertyValue = credentialsProp.getValues().iterator().next();
    assertNotNull("No credentials property value in " + resource + " from " + source, credentialsPropertyValue);
    Object rawElement = credentialsPropertyValue.getRawElement();
}
Also used : QName(javax.xml.namespace.QName) Containerable(com.evolveum.midpoint.prism.Containerable) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 14 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class TestOpenDj method test004ResourceAndConnectorCaching.

@Test
public void test004ResourceAndConnectorCaching() throws Exception {
    final String TEST_NAME = "test004ResourceAndConnectorCaching";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    resource = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, null, result);
    resourceType = resource.asObjectable();
    ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    assertNotNull("No resource schema", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    // THEN
    ResourceType resourceTypeAgain = resourceAgain.asObjectable();
    assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
    assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
    assertTrue("Configurations not equals", configurationContainer.equals(configurationContainerAgain));
    ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
    assertNotNull("No resource schema (again)", resourceSchemaAgain);
    assertEquals("Schema serial number mismatch", resourceType.getSchema().getCachingMetadata().getSerialNumber(), resourceTypeAgain.getSchema().getCachingMetadata().getSerialNumber());
    assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
    // Now we stick our nose deep inside the provisioning impl. But we need to make sure that the
    // configured connector is properly cached
    ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
    assertTrue("Connector instance was not cached", configuredConnectorInstance == configuredConnectorInstanceAgain);
    assertShadows(1);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Example 15 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractManualResourceTest method test004Configuration.

@Test
public void test004Configuration() throws Exception {
    final String TEST_NAME = "test004Configuration";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME);
    // WHEN
    resource = provisioningService.getObject(ResourceType.class, getResourceOid(), null, null, result);
    resourceType = resource.asObjectable();
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No configuration container", configurationContainer);
    PrismContainerDefinition confContDef = configurationContainer.getDefinition();
    assertNotNull("No configuration container definition", confContDef);
    PrismProperty<String> propDefaultAssignee = configurationContainer.findProperty(CONF_PROPERTY_DEFAULT_ASSIGNEE_QNAME);
    assertNotNull("No defaultAssignee conf prop", propDefaultAssignee);
//		assertNotNull("No configuration properties container", confingurationPropertiesContainer);
//		PrismContainerDefinition confPropDef = confingurationPropertiesContainer.getDefinition();
//		assertNotNull("No configuration properties container definition", confPropDef);
}
Also used : PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)

Aggregations

Containerable (com.evolveum.midpoint.prism.Containerable)30 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Test (org.testng.annotations.Test)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)9 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 QName (javax.xml.namespace.QName)7 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 Task (com.evolveum.midpoint.task.api.Task)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 ArrayList (java.util.ArrayList)6 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 Item (com.evolveum.midpoint.prism.Item)4 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)4 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)4 Collection (java.util.Collection)4