Skip to content

Commit

Permalink
Fixing dependency NPE (MID-3522). Also improvement of Dummy resource …
Browse files Browse the repository at this point in the history
…handling in the intests.
  • Loading branch information
semancik committed Dec 5, 2016
1 parent d06d9c1 commit 543eb3a
Show file tree
Hide file tree
Showing 32 changed files with 571 additions and 246 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,10 @@ public PrismObject<ResourceType> getResource() {
public void setResource(PrismObject<ResourceType> resource) {
this.resource = resource;
}

public ResourceType getResourceType() {
return resource.asObjectable();
}

public QName getAttributeQName(String attributeName) {
return new QName(getNamespace(), attributeName);
Expand Down
@@ -0,0 +1,26 @@
/*
* 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.util;

/**
* @author semancik
*
*/
public interface FailableProcessor<T> {

void process(T object) throws Exception;

}
Expand Up @@ -36,6 +36,7 @@
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyStrictnessType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyType;
Expand Down Expand Up @@ -255,7 +256,12 @@ private void checkForCircular(List<ResourceObjectTypeDependencyType> depPath,
Iterator<ResourceObjectTypeDependencyType> iterator = depPath.iterator();
while (iterator.hasNext()) {
ResourceObjectTypeDependencyType el = iterator.next();
sb.append(el.getResourceRef().getOid());
ObjectReferenceType resourceRef = el.getResourceRef();
if (resourceRef != null) {
sb.append(resourceRef.getOid());
}
sb.append("(").append(el.getKind()).append("/");
sb.append(el.getIntent()).append(")");
if (iterator.hasNext()) {
sb.append("->");
}
Expand Down
Expand Up @@ -86,10 +86,7 @@ public class AbstractInitializedModelIntegrationTest extends AbstractConfiguredM
protected UserType userTypeGuybrush;
protected UserType userTypeElaine;

protected DummyResource dummyResource;
protected DummyResourceContoller dummyResourceCtl;
protected ResourceType resourceDummyType;
protected PrismObject<ResourceType> resourceDummy;

protected DummyResource dummyResourceRed;
protected DummyResourceContoller dummyResourceCtlRed;
Expand Down Expand Up @@ -160,14 +157,14 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti

// Resources

dummyResourceCtl = DummyResourceContoller.create(null);
dummyResourceCtl.extendSchemaPirate();
dummyResource = dummyResourceCtl.getDummyResource();
dummyResourceCtl.addAttrDef(dummyResource.getAccountObjectClass(),
DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME, String.class, false, false);
resourceDummy = importAndGetObjectFromFile(ResourceType.class, getResourceDummyFile(), RESOURCE_DUMMY_OID, initTask, initResult);
resourceDummyType = resourceDummy.asObjectable();
dummyResourceCtl.setResource(resourceDummy);
dummyResourceCtl = initDummyResource(null, getResourceDummyFile(), RESOURCE_DUMMY_OID,
controller -> {
controller.extendSchemaPirate();
controller.addAttrDef(controller.getDummyResource().getAccountObjectClass(),
DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME, String.class, false, false);
},
initTask, initResult);


dummyResourceCtlRed = DummyResourceContoller.create(RESOURCE_DUMMY_RED_NAME, resourceDummyRed);
dummyResourceCtlRed.extendSchemaPirate();
Expand Down Expand Up @@ -361,19 +358,19 @@ protected void assertUserJack(PrismObject<UserType> user, String fullName, Strin
}

protected void assertDummyAccountShadowRepo(PrismObject<ShadowType> accountShadow, String oid, String username) throws SchemaException {
assertAccountShadowRepo(accountShadow, oid, username, resourceDummyType);
assertAccountShadowRepo(accountShadow, oid, username, dummyResourceCtl.getResource().asObjectable());
}

protected void assertDummyGroupShadowRepo(PrismObject<ShadowType> accountShadow, String oid, String username) throws SchemaException {
assertShadowRepo(accountShadow, oid, username, resourceDummyType, getGroupObjectClass(resourceDummyType));
assertShadowRepo(accountShadow, oid, username, dummyResourceCtl.getResourceType(), dummyResourceCtl.getGroupObjectClass());
}

protected void assertDummyAccountShadowModel(PrismObject<ShadowType> accountShadow, String oid, String username) throws SchemaException {
assertShadowModel(accountShadow, oid, username, resourceDummyType, getAccountObjectClass(resourceDummyType));
assertShadowModel(accountShadow, oid, username, dummyResourceCtl.getResourceType(), dummyResourceCtl.getAccountObjectClass());
}

protected void assertDummyGroupShadowModel(PrismObject<ShadowType> accountShadow, String oid, String username) throws SchemaException {
assertShadowModel(accountShadow, oid, username, resourceDummyType, getGroupObjectClass(resourceDummyType));
assertShadowModel(accountShadow, oid, username, dummyResourceCtl.getResourceType(), dummyResourceCtl.getGroupObjectClass());
}

protected void assertDummyAccountShadowModel(PrismObject<ShadowType> accountShadow, String oid, String username, String fullname) throws SchemaException {
Expand Down
Expand Up @@ -663,7 +663,7 @@ public void test114ModifyUserJackEnable() throws Exception {

assertAccounts(USER_JACK_OID, 1);
PrismObject<ShadowType> account = getShadowModel(accountOid);
assertAccountShadowModel(account, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyType);
assertAccountShadowModel(account, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, getDummyResourceType());
assertAdministrativeStatusEnabled(account);
assertEnableTimestampShadow(account, startTime, endTime);
}
Expand Down Expand Up @@ -704,7 +704,7 @@ public void test115ModifyUserJackAdministrativeStatusNull() throws Exception {

assertAccounts(USER_JACK_OID, 1);
PrismObject<ShadowType> shadow = getShadowModel(accountOid);
assertAccountShadowModel(shadow, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyType);
assertAccountShadowModel(shadow, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, getDummyResourceType());
assertAdministrativeStatus(shadow, ActivationStatusType.ENABLED);
}

Expand All @@ -723,7 +723,7 @@ public void test118ModifyJackActivationUserAndAccount() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

ObjectDelta<UserType> userDelta = createModifyUserReplaceDelta(USER_JACK_OID, ACTIVATION_ADMINISTRATIVE_STATUS_PATH, ActivationStatusType.ENABLED);
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceDelta(accountOid, resourceDummy,
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceDelta(accountOid, getDummyResourceObject(),
ACTIVATION_ADMINISTRATIVE_STATUS_PATH, ActivationStatusType.DISABLED);

Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta, accountDelta);
Expand All @@ -748,7 +748,7 @@ public void test118ModifyJackActivationUserAndAccount() throws Exception {
assertDummyDisabled("jack");
assertAccounts(USER_JACK_OID, 1);
PrismObject<ShadowType> account = getShadowModel(accountOid);
assertAccountShadowModel(account, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyType);
assertAccountShadowModel(account, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, getDummyResourceType());
assertAdministrativeStatusDisabled(account);
assertDisableTimestampShadow(account, startTime, endTime);
assertDisableReasonShadow(account, SchemaConstants.MODEL_DISABLE_REASON_EXPLICIT);
Expand Down Expand Up @@ -821,7 +821,7 @@ public void test121ModifyJackUserAndAccountRed() throws Exception {

ObjectDelta<UserType> userDelta = createModifyUserReplaceDelta(USER_JACK_OID, ACTIVATION_ADMINISTRATIVE_STATUS_PATH, ActivationStatusType.DISABLED);

ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceDelta(accountRedOid, resourceDummy,
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceDelta(accountRedOid, getDummyResourceObject(),
ACTIVATION_ADMINISTRATIVE_STATUS_PATH, ActivationStatusType.ENABLED);

Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta, accountDelta);
Expand Down Expand Up @@ -862,7 +862,7 @@ public void test130ModifyAccountDefaultAndRed() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

ObjectDelta<ShadowType> accountDeltaDefault = createModifyAccountShadowReplaceDelta(accountOid,
resourceDummy, ACTIVATION_ADMINISTRATIVE_STATUS_PATH, ActivationStatusType.ENABLED);
getDummyResourceObject(), ACTIVATION_ADMINISTRATIVE_STATUS_PATH, ActivationStatusType.ENABLED);
ObjectDelta<ShadowType> accountDeltaRed = createModifyAccountShadowReplaceDelta(accountRedOid,
resourceDummyRed, ACTIVATION_ADMINISTRATIVE_STATUS_PATH, ActivationStatusType.ENABLED);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDeltaDefault, accountDeltaRed);
Expand Down Expand Up @@ -1099,7 +1099,7 @@ private void checkAdminStatusFor15x(PrismObject<UserType> user, boolean userStat
PrismObject<ShadowType> account = getShadowModel(accountOid);
PrismObject<ShadowType> accountYellow = getShadowModel(accountYellowOid);

assertAccountShadowModel(account, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyType);
assertAccountShadowModel(account, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, getDummyResourceType());
assertAdministrativeStatus(account, accountStatus ? ActivationStatusType.ENABLED : ActivationStatusType.DISABLED);
if (!accountStatus) {
assertDisableReasonShadow(account, SchemaConstants.MODEL_DISABLE_REASON_EXPLICIT);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -753,7 +753,7 @@ private void preTestCleanup(AssignmentPolicyEnforcementType enforcementPolicy) t
}

private void purgeScriptHistory() {
dummyResource.purgeScriptHistory();
getDummyResource().purgeScriptHistory();
}

}
Expand Up @@ -73,7 +73,7 @@ private enum ShadowOperation { KEEP, DELETE, UNLINK, UNLINK_AND_TOMBSTONE }
private enum ResourceObjectOperation { KEEP, DELETE }

private ObjectClassComplexTypeDefinition getAccountObjectClassDefinition() throws SchemaException {
ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resourceDummyType, prismContext);
ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(getDummyResourceObject(), prismContext);
return schema.findObjectClassDefinition(dummyResourceCtl.getAccountObjectClassQName());
}

Expand Down Expand Up @@ -200,7 +200,7 @@ private void executeTest(final String TEST_NAME, FocusOperation focusOperation,
}

if (resourceObjectOperation == ResourceObjectOperation.DELETE) {
dummyResource.deleteAccountByName("jack");
getDummyResource().deleteAccountByName("jack");
assertNoDummyAccount(null, "jack");
} else {
assertDummyAccount(null, "jack");
Expand Down

0 comments on commit 543eb3a

Please sign in to comment.