Search in sources :

Example 76 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.

the class TestDummy method test110SeachIterative.

@Test
public void test110SeachIterative() throws Exception {
    final String TEST_NAME = "test110SeachIterative";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    // Make sure there is an account on resource that the provisioning has
    // never seen before, so there is no shadow
    // for it yet.
    DummyAccount newAccount = new DummyAccount("meathook");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Meathook");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Sea Monkey");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    newAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 666L);
    newAccount.setEnabled(true);
    newAccount.setPassword("parrotMonster");
    dummyResource.addAccount(newAccount);
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_DUMMY_OID, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME), prismContext);
    final XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    final Holder<Boolean> seenMeathookHolder = new Holder<Boolean>(false);
    final List<PrismObject<ShadowType>> foundObjects = new ArrayList<PrismObject<ShadowType>>();
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            foundObjects.add(object);
            display("Found", object);
            XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
            assertTrue(object.canRepresent(ShadowType.class));
            try {
                checkAccountShadow(object, parentResult, true, startTs, endTs);
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            assertCachingMetadata(object, false, startTs, endTs);
            if (object.asObjectable().getName().getOrig().equals("meathook")) {
                meathookAccountOid = object.getOid();
                seenMeathookHolder.setValue(true);
                try {
                    Long loot = ShadowUtil.getAttributeValue(object, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME));
                    assertEquals("Wrong meathook's loot", (Long) 666L, loot);
                } catch (SchemaException e) {
                    throw new SystemException(e.getMessage(), e);
                }
            }
            return true;
        }
    };
    rememberShadowFetchOperationCount();
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
    // THEN
    XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
    result.computeStatus();
    display("searchObjectsIterative result", result);
    TestUtil.assertSuccess(result);
    assertShadowFetchOperationCountIncrement(1);
    assertEquals(4, foundObjects.size());
    checkConsistency(foundObjects);
    assertProtected(foundObjects, 1);
    PrismObject<ShadowType> shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    assertRepoShadowCachedAttributeValue(shadowWillRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Flying Dutchman");
    checkRepoAccountShadowWill(shadowWillRepo, startTs, endTs);
    PrismObject<ShadowType> shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
    display("Meathook shadow", shadowMeathook);
    assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    assertRepoCachingMetadata(shadowMeathook, startTs, endTs);
    // And again ...
    foundObjects.clear();
    rememberShadowFetchOperationCount();
    XMLGregorianCalendar startTs2 = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
    // THEN
    XMLGregorianCalendar endTs2 = clock.currentTimeXMLGregorianCalendar();
    assertShadowFetchOperationCountIncrement(1);
    display("Found shadows", foundObjects);
    assertEquals(4, foundObjects.size());
    checkConsistency(foundObjects);
    assertProtected(foundObjects, 1);
    shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWill(shadowWillRepo, startTs2, endTs2);
    shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
    assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    assertRepoCachingMetadata(shadowMeathook, startTs2, endTs2);
    assertSteadyResource();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(com.evolveum.midpoint.util.Holder) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 77 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.

the class TestDummy method test107AGetModifiedAccountFromCacheMax.

// test102-test106 in the superclasses
/**
	 * Make a native modification to an account and read it with max staleness option.
	 * As there is no caching enabled this should throw an error.
	 * 
	 * Note: This test is overridden in TestDummyCaching
	 * 
	 * MID-3481
	 */
@Test
public void test107AGetModifiedAccountFromCacheMax() throws Exception {
    final String TEST_NAME = "test107AGetModifiedAccountFromCacheMax";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    rememberShadowFetchOperationCount();
    DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Nice Pirate");
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Interceptor");
    accountWill.setEnabled(true);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createMaxStaleness());
    XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    try {
        ShadowType shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, null, result).asObjectable();
        AssertJUnit.fail("Unexpected success");
    } catch (ConfigurationException e) {
        // Caching is disabled, this is expected.
        TestUtil.displayThen(TEST_NAME);
        display("Expected exception", e);
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
    PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWillBasic(shadowRepo, null, startTs, null);
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Sword", "LOVE");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    assertRepoShadowCacheActivation(shadowRepo, ActivationStatusType.DISABLED);
    assertShadowFetchOperationCountIncrement(0);
    assertSteadyResource();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 78 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.

the class TestDummyCaching method test107BGetModifiedAccountFromCacheHighStaleness.

/**
	 * Make a native modification to an account and read it with high staleness option.
	 * This should return cached data.
	 * MID-3481
	 */
@Test
@Override
public void test107BGetModifiedAccountFromCacheHighStaleness() throws Exception {
    final String TEST_NAME = "test107BGetModifiedAccountFromCacheHighStaleness";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    rememberShadowFetchOperationCount();
    DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
    accountWill.setEnabled(true);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createStaleness(1000000L));
    XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, null, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    assertShadowFetchOperationCountIncrement(0);
    XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
    display("Retrieved account shadow", shadow);
    assertNotNull("No dummy account", shadow);
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadow);
    assertEquals("Unexpected number of attributes", 7, attributes.size());
    PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWillBasic(shadowRepo, null, startTs, null);
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    assertRepoShadowCacheActivation(shadowRepo, ActivationStatusType.DISABLED);
    checkConsistency(shadow);
    assertCachingMetadata(shadow, true, null, startTs);
    assertShadowFetchOperationCountIncrement(0);
    assertSteadyResource();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 79 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.

the class TestDummy method test107BGetModifiedAccountFromCacheHighStaleness.

/**
	 * Make a native modification to an account and read it with high staleness option.
	 * In this test there is no caching enabled, so this should return fresh data.
	 * 
	 * Note: This test is overridden in TestDummyCaching
	 * 
	 * MID-3481
	 */
@Test
public void test107BGetModifiedAccountFromCacheHighStaleness() throws Exception {
    final String TEST_NAME = "test107BGetModifiedAccountFromCacheHighStaleness";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    rememberShadowFetchOperationCount();
    DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
    accountWill.setEnabled(true);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createStaleness(1000000L));
    XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, null, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
    PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWillBasic(shadowRepo, null, startTs, null);
    assertShadowFetchOperationCountIncrement(1);
    assertSteadyResource();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 80 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.

the class TestDummy method test108GetAccountLowStaleness.

/**
	 * Staleness of one millisecond is too small for the cache to work.
	 * Fresh data should be returned - both in case the cache is enabled and disabled.
	 * MID-3481
	 */
@Test
public void test108GetAccountLowStaleness() throws Exception {
    final String TEST_NAME = "test106GetModifiedAccount";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    rememberShadowFetchOperationCount();
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createStaleness(1L));
    XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, null, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    assertShadowFetchOperationCountIncrement(1);
    XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
    display("Retrieved account shadow", shadow);
    assertNotNull("No dummy account", shadow);
    checkAccountShadow(shadow, result, true, startTs, endTs);
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Interceptor");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Sword", "LOVE");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadow);
    assertEquals("Unexpected number of attributes", 7, attributes.size());
    PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWillBasic(shadowRepo, startTs, endTs, null);
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Very Nice Pirate");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Interceptor");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    checkConsistency(shadow);
    assertCachingMetadata(shadow, false, startTs, endTs);
    assertSteadyResource();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) Test(org.testng.annotations.Test)

Aggregations

XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)336 Test (org.testng.annotations.Test)159 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)130 Task (com.evolveum.midpoint.task.api.Task)104 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)72 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)52 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)44 Date (java.util.Date)36 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)32 ArrayList (java.util.ArrayList)32 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)31 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)30 AbstractSynchronizationStoryTest (com.evolveum.midpoint.model.intest.sync.AbstractSynchronizationStoryTest)23 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)21 GregorianCalendar (java.util.GregorianCalendar)18 QName (javax.xml.namespace.QName)18 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)15 Duration (javax.xml.datatype.Duration)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14