Search in sources :

Example 31 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class TestSanity method checkOpenDjSchema.

private void checkOpenDjSchema(ResourceType resource, String source) throws SchemaException {
    ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition accountDefinition = schema.findObjectClassDefinition(RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    assertNotNull("Schema does not define any account (resource from " + source + ")", accountDefinition);
    Collection<? extends ResourceAttributeDefinition> identifiers = accountDefinition.getPrimaryIdentifiers();
    assertFalse("No account identifiers (resource from " + source + ")", identifiers == null || identifiers.isEmpty());
    // TODO: check for naming attributes and display names, etc
    ActivationCapabilityType capActivation = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
    if (capActivation != null && capActivation.getStatus() != null && capActivation.getStatus().getAttribute() != null) {
        // There is simulated activation capability, check if the attribute is in schema.
        QName enableAttrName = capActivation.getStatus().getAttribute();
        ResourceAttributeDefinition enableAttrDef = accountDefinition.findAttributeDefinition(enableAttrName);
        display("Simulated activation attribute definition", enableAttrDef);
        assertNotNull("No definition for enable attribute " + enableAttrName + " in account (resource from " + source + ")", enableAttrDef);
        assertTrue("Enable attribute " + enableAttrName + " is not ignored (resource from " + source + ")", enableAttrDef.isIgnored());
    }
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) QName(javax.xml.namespace.QName) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)

Example 32 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class TestUcfDummyMulti method test100AddAccount.

@Test
public void test100AddAccount() throws Exception {
    final String TEST_NAME = "test100AddAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
    ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
    ShadowType shadowType = new ShadowType();
    PrismTestUtil.getPrismContext().adopt(shadowType);
    shadowType.setName(PrismTestUtil.createPolyStringType(ACCOUNT_JACK_USERNAME));
    ObjectReferenceType resourceRef = new ObjectReferenceType();
    resourceRef.setOid(resource.getOid());
    shadowType.setResourceRef(resourceRef);
    shadowType.setObjectClass(defaultAccountDefinition.getTypeName());
    PrismObject<ShadowType> shadow = shadowType.asPrismObject();
    ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, defaultAccountDefinition);
    ResourceAttribute<String> icfsNameProp = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME);
    icfsNameProp.setRealValue(ACCOUNT_JACK_USERNAME);
    // WHEN
    cc.addObject(shadow, null, null, result);
    // THEN
    DummyAccount dummyAccount = dummyResource.getAccountByUsername(ACCOUNT_JACK_USERNAME);
    assertNotNull("Account " + ACCOUNT_JACK_USERNAME + " was not created", dummyAccount);
    assertNotNull("Account " + ACCOUNT_JACK_USERNAME + " has no username", dummyAccount.getName());
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 33 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class TestUcfDummyMulti method test200BlockingSearch.

@Test
public void test200BlockingSearch() throws Exception {
    final String TEST_NAME = "test200BlockingSearch";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
    final ObjectClassComplexTypeDefinition accountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
    // Determine object class from the schema
    final List<PrismObject<ShadowType>> searchResults = new ArrayList<PrismObject<ShadowType>>();
    final ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> shadow) {
            checkUcfShadow(shadow, accountDefinition);
            searchResults.add(shadow);
            return true;
        }
    };
    dummyResource.setBlockOperations(true);
    // WHEN
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                cc.search(accountDefinition, new ObjectQuery(), handler, null, null, null, null, result);
            } catch (CommunicationException | GenericFrameworkException | SchemaException | SecurityViolationException | ObjectNotFoundException e) {
                LOGGER.error("Error in the search: {}", e.getMessage(), e);
            }
        }
    });
    t.setName("search1");
    t.start();
    // Give the new thread a chance to get blocked
    Thread.sleep(500);
    ConnectorOperationalStatus opStat = cc.getOperationalStatus();
    display("stats (blocked)", opStat);
    assertEquals("Wrong pool active", (Integer) 1, opStat.getPoolStatusNumActive());
    assertEquals("Wrong pool active", (Integer) 0, opStat.getPoolStatusNumIdle());
    assertEquals("Unexpected number of search results", 0, searchResults.size());
    dummyResource.unblock();
    t.join();
    dummyResource.setBlockOperations(false);
    // THEN
    assertEquals("Unexpected number of search results", 1, searchResults.size());
    opStat = cc.getOperationalStatus();
    display("stats (final)", opStat);
    assertEquals("Wrong pool active", (Integer) 0, opStat.getPoolStatusNumActive());
    assertEquals("Wrong pool active", (Integer) 1, opStat.getPoolStatusNumIdle());
    PrismObject<ShadowType> searchResult = searchResults.get(0);
    display("Search result", searchResult);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ResultHandler(com.evolveum.midpoint.provisioning.ucf.api.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConnectorOperationalStatus(com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus) Test(org.testng.annotations.Test)

Example 34 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class AbstractIntegrationTest method assertShadowRepo.

protected void assertShadowRepo(PrismObject<ShadowType> accountShadow, String oid, String username, ResourceType resourceType, QName objectClass, MatchingRule<String> nameMatchingRule) throws SchemaException {
    assertShadowCommon(accountShadow, oid, username, resourceType, objectClass, nameMatchingRule, true);
    PrismContainer<Containerable> attributesContainer = accountShadow.findContainer(ShadowType.F_ATTRIBUTES);
    List<Item<?, ?>> attributes = attributesContainer.getValue().getItems();
    //		Collection secIdentifiers = ShadowUtil.getSecondaryIdentifiers(accountShadow);
    if (attributes == null) {
        AssertJUnit.fail("No attributes in repo shadow");
    }
    RefinedResourceSchema refinedSchema = null;
    try {
        refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
    } catch (SchemaException e) {
        AssertJUnit.fail(e.getMessage());
    }
    ObjectClassComplexTypeDefinition objClassDef = refinedSchema.getRefinedDefinition(objectClass);
    Collection secIdentifiers = objClassDef.getSecondaryIdentifiers();
    if (secIdentifiers == null) {
        AssertJUnit.fail("No secondary identifiers in repo shadow");
    }
    // repo shadow should contains all secondary identifiers + ICF_UID
    assertRepoShadowAttributes(attributes, secIdentifiers.size() + 1);
}
Also used : Item(com.evolveum.midpoint.prism.Item) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 35 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class IntegrationTestTools method checkShadow.

public static void checkShadow(ShadowType shadowType, ResourceType resourceType, RepositoryService repositoryService, ObjectChecker<ShadowType> checker, MatchingRule<String> uidMatchingRule, PrismContext prismContext, OperationResult parentResult) throws SchemaException {
    LOGGER.trace("Checking shadow:\n{}", shadowType.asPrismObject().debugDump());
    shadowType.asPrismObject().checkConsistence(true, true, ConsistencyCheckScope.THOROUGH);
    assertNotNull("no OID", shadowType.getOid());
    assertNotNull("no name", shadowType.getName());
    assertEquals(resourceType.getOid(), shadowType.getResourceRef().getOid());
    PrismContainer<?> attrs = shadowType.asPrismObject().findContainer(ShadowType.F_ATTRIBUTES);
    assertNotNull("no attributes", attrs);
    assertFalse("empty attributes", attrs.isEmpty());
    RefinedResourceSchema rschema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
    ObjectClassComplexTypeDefinition objectClassDef = rschema.findObjectClassDefinition(shadowType);
    assertNotNull("cannot determine object class for " + shadowType, objectClassDef);
    String icfUid = ShadowUtil.getSingleStringAttributeValue(shadowType, SchemaTestConstants.ICFS_UID);
    if (icfUid == null) {
        Collection<? extends ResourceAttributeDefinition> identifierDefs = objectClassDef.getPrimaryIdentifiers();
        assertFalse("No identifiers for " + objectClassDef, identifierDefs == null || identifierDefs.isEmpty());
        for (ResourceAttributeDefinition idDef : identifierDefs) {
            String id = ShadowUtil.getSingleStringAttributeValue(shadowType, idDef.getName());
            assertNotNull("No identifier " + idDef.getName() + " in " + shadowType, id);
        }
    }
    String resourceOid = ShadowUtil.getResourceOid(shadowType);
    assertNotNull("No resource OID in " + shadowType, resourceOid);
    assertNotNull("Null OID in " + shadowType, shadowType.getOid());
    PrismObject<ShadowType> repoShadow = null;
    try {
        repoShadow = repositoryService.getObject(ShadowType.class, shadowType.getOid(), null, parentResult);
    } catch (Exception e) {
        AssertJUnit.fail("Got exception while trying to read " + shadowType + ": " + e.getCause() + ": " + e.getMessage());
    }
    checkShadowUniqueness(shadowType, objectClassDef, repositoryService, uidMatchingRule, prismContext, parentResult);
    String repoResourceOid = ShadowUtil.getResourceOid(repoShadow.asObjectable());
    assertNotNull("No resource OID in the repository shadow " + repoShadow);
    assertEquals("Resource OID mismatch", resourceOid, repoResourceOid);
    try {
        repositoryService.getObject(ResourceType.class, resourceOid, null, parentResult);
    } catch (Exception e) {
        AssertJUnit.fail("Got exception while trying to read resource " + resourceOid + " as specified in current shadow " + shadowType + ": " + e.getCause() + ": " + e.getMessage());
    }
    if (checker != null) {
        checker.check(shadowType);
    }
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) IOException(java.io.IOException)

Aggregations

ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)53 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)18 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)17 Test (org.testng.annotations.Test)17 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)16 QName (javax.xml.namespace.QName)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ArrayList (java.util.ArrayList)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)8 Task (com.evolveum.midpoint.task.api.Task)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)5 Containerable (com.evolveum.midpoint.prism.Containerable)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)3 ResultHandler (com.evolveum.midpoint.provisioning.ucf.api.ResultHandler)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3