Skip to content

Commit

Permalink
Test for model context sanity in progess listener (MID-3213)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jun 22, 2016
1 parent e063c98 commit 0f03bf2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
Expand Up @@ -25,6 +25,7 @@
import java.io.FileNotFoundException;
import java.net.ConnectException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.evolveum.midpoint.prism.query.OrgFilter;
Expand All @@ -35,9 +36,11 @@

import com.evolveum.icf.dummy.resource.DummyGroup;
import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.midpoint.model.api.ProgressListener;
import com.evolveum.midpoint.model.common.mapping.MappingFactory;
import com.evolveum.midpoint.model.impl.lens.Clockwork;
import com.evolveum.midpoint.model.impl.lens.LensDebugListener;
import com.evolveum.midpoint.model.intest.util.CheckingProgressListener;
import com.evolveum.midpoint.model.intest.util.ProfilingLensDebugListener;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
Expand Down Expand Up @@ -92,6 +95,7 @@ public class AbstractInitializedModelIntegrationTest extends AbstractConfiguredM
protected Clockwork clockwork;

protected ProfilingLensDebugListener lensDebugListener;
protected CheckingProgressListener checkingProgressListener;

protected UserType userTypeJack;
protected UserType userTypeBarbossa;
Expand Down Expand Up @@ -163,6 +167,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
mappingFactory.setProfiling(true);
lensDebugListener = new ProfilingLensDebugListener();
clockwork.setDebugListener(lensDebugListener);
checkingProgressListener = new CheckingProgressListener();

// Resources

Expand Down Expand Up @@ -461,4 +466,8 @@ protected void assertShadowOperationalData(PrismObject<ShadowType> shadow, Synch
}
// TODO: assert sync description
}

protected Collection<ProgressListener> getCheckingProgressListenerCollection() {
return Collections.singleton((ProgressListener)checkingProgressListener);
}
}
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand All @@ -46,6 +47,7 @@
import com.evolveum.icf.dummy.resource.BreakMode;
import com.evolveum.icf.dummy.resource.DummyAccount;
import com.evolveum.midpoint.model.api.PolicyViolationException;
import com.evolveum.midpoint.model.api.ProgressListener;
import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.ItemDefinition;
Expand Down Expand Up @@ -188,7 +190,7 @@ public void test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict() th
try {

// WHEN
modelService.executeChanges(deltas, null, task, result);
modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result);

AssertJUnit.fail("Unexpected executeChanges success");
} catch (ObjectAlreadyExistsException e) {
Expand Down Expand Up @@ -261,7 +263,7 @@ public void test180DeleteHalfAssignmentFromUser() throws Exception {

// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result);

// THEN
result.computeStatus();
Expand Down Expand Up @@ -309,7 +311,7 @@ public void test190DeleteHalfAssignedUser() throws Exception {

// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result);

// THEN
TestUtil.displayThen(TEST_NAME);
Expand Down Expand Up @@ -575,7 +577,7 @@ public void test301AddUserDeGhoulash() throws Exception {
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userAddDelta);

// WHEN
modelService.executeChanges(deltas, null, task, result);
modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result);

// THEN
result.computeStatus();
Expand Down Expand Up @@ -1166,7 +1168,7 @@ public void test600AddUserGuybrushAssignAccount() throws Exception {

// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result);

// THEN
TestUtil.displayThen(TEST_NAME);
Expand Down
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.model.intest.util;

import java.util.Collection;

import com.evolveum.midpoint.model.api.ProgressInformation;
import com.evolveum.midpoint.model.api.ProgressListener;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.model.impl.lens.LensProjectionContext;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
* @author semancik
*
*/
public class CheckingProgressListener implements ProgressListener {

/* (non-Javadoc)
* @see com.evolveum.midpoint.model.api.ProgressListener#onProgressAchieved(com.evolveum.midpoint.model.api.context.ModelContext, com.evolveum.midpoint.model.api.ProgressInformation)
*/
@Override
public void onProgressAchieved(ModelContext modelContext, ProgressInformation progressInformation) {
LensContext<ObjectType> lensContext = (LensContext<ObjectType>)modelContext;
lensContext.checkConsistence();
for (LensProjectionContext projectionContext: lensContext.getProjectionContexts()) {
// MID-3213
assert projectionContext.getResourceShadowDiscriminator().getResourceOid() != null;
}
}

/* (non-Javadoc)
* @see com.evolveum.midpoint.model.api.ProgressListener#isAbortRequested()
*/
@Override
public boolean isAbortRequested() {
return false;
}

}

0 comments on commit 0f03bf2

Please sign in to comment.