Skip to content

Commit

Permalink
Fixing tests after reference cleanup (MID-5000)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Aug 21, 2019
1 parent 44edcef commit 79b9c75
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 82 deletions.
Expand Up @@ -279,6 +279,7 @@ public static void setReferenceValueAsRef(PrismContainerValue<?> parentValue, QN
reference.getValue().setTargetType(value.getTargetType());
reference.getValue().setFilter(value.getFilter());
reference.getValue().setDescription(value.getDescription());
reference.getValue().setObject(value.getObject());
}
}
}
Expand Down
Expand Up @@ -39,6 +39,8 @@
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.Validate;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -54,6 +56,8 @@
*/
@Component
public class ExpressionHandler {

private static final Trace LOGGER = TraceManager.getTrace(ExpressionHandler.class);

@Autowired @Qualifier("cacheRepositoryService") private RepositoryService repositoryService;
@Autowired private ExpressionFactory expressionFactory;
Expand Down Expand Up @@ -134,7 +138,7 @@ private ResourceType resolveResource(ShadowType shadow, OperationResult result)
if (ref == null) {
throw new ExpressionEvaluationException("Resource shadow object " + shadow + " doesn't have defined resource.");
}
PrismObject<ResourceType> resource = ref.asReferenceValue().getObject();
PrismObject<ResourceType> resource = ref.getObject();
if (resource != null) {
return resource.asObjectable();
}
Expand Down
Expand Up @@ -367,6 +367,9 @@ public class AbstractConfiguredModelIntegrationTest extends AbstractModelIntegra
static final File USER_CAPSIZE_FILE = new File(COMMON_DIR, "user-capsize.xml");
protected static final String USER_CAPSIZE_OID = "c0c010c0-d34d-b33f-f00d-11c1c1c1c11c";
protected static final String USER_CAPSIZE_USERNAME = "capsize";
static final File ACCOUNT_CAPSIZE_DUMMY_DEFAULT_FILE = new File(COMMON_DIR, "account-capsize-dummy-default.xml");
static final File ACCOUNT_CAPSIZE_DUMMY_RED_FILE = new File(COMMON_DIR, "account-capsize-dummy-red.xml");
static final File ACCOUNT_CAPSIZE_DUMMY_BLUE_FILE = new File(COMMON_DIR, "account-capsize-dummy-blue.xml");

protected static final File USER_DRAKE_FILE = new File(COMMON_DIR, "user-drake.xml");
protected static final String USER_DRAKE_OID = "c0c010c0-d34d-b33f-f00d-11d1d1d1d1d1";
Expand Down
Expand Up @@ -322,6 +322,7 @@ public void test150AddUserBlackbeardWithAccount() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);

PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_CONTRACT_DIR, "user-blackbeard-account-dummy.xml"));
addAccountLinkRef(user, new File(TEST_CONTRACT_DIR, "account-blackbeard-dummy.xml"));

// WHEN
modelCrudService.addObject(user , null, task, result);
Expand Down
Expand Up @@ -22,6 +22,7 @@
import static org.testng.AssertJUnit.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -2937,10 +2938,7 @@ public void test200AddUserBlackbeardWithAccount() throws Exception {
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);

PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_DIR, "user-blackbeard-account-dummy.xml"));
PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_DIR, "account-blackbeard-dummy.xml"));
ObjectReferenceType linkRef = new ObjectReferenceType();
linkRef.asReferenceValue().setObject(account);
user.asObjectable().getLinkRef().add(linkRef);
addAccountLinkRef(user,new File(TEST_DIR, "account-blackbeard-dummy.xml"));
ObjectDelta<UserType> userDelta = DeltaFactory.Object.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);

Expand Down Expand Up @@ -3013,7 +3011,6 @@ public void test200AddUserBlackbeardWithAccount() throws Exception {
assertSteadyResources();
}


@Test
public void test210AddUserMorganWithAssignment() throws Exception {
final String TEST_NAME = "test210AddUserMorganWithAssignment";
Expand All @@ -3026,18 +3023,16 @@ public void test210AddUserMorganWithAssignment() throws Exception {

PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_DIR, "user-morgan-assignment-dummy.xml"));
ObjectDelta<UserType> userDelta = DeltaFactory.Object.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);

XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();

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

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);

Expand Down Expand Up @@ -3114,8 +3109,7 @@ public void test212RenameUserMorgan() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess(result);
// Strong mappings
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 1);

Expand Down
Expand Up @@ -73,6 +73,8 @@ public class TestPreviewChanges extends AbstractInitializedModelIntegrationTest
private static final String USER_BLACKBEARD_OID = "c0c010c0-d34d-b33f-f00d-161161116666";

static final File USER_ROGERS_FILE = new File(TEST_DIR, "user-rogers.xml");
static final File ACCOUNT_ROGERS_DUMMY_DEFAULT_FILE = new File(TEST_DIR, "account-rogers-dummy-default.xml");
static final File ACCOUNT_ROGERS_DUMMY_LEMON_FILE = new File(TEST_DIR, "account-rogers-dummy-lemon.xml");

private static String accountOid;

Expand Down Expand Up @@ -1734,6 +1736,9 @@ public void test620AddUserCapsize() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);

PrismObject<UserType> user = PrismTestUtil.parseObject(USER_CAPSIZE_FILE);
addAccountLinkRef(user, ACCOUNT_CAPSIZE_DUMMY_DEFAULT_FILE);
addAccountLinkRef(user, ACCOUNT_CAPSIZE_DUMMY_RED_FILE);
addAccountLinkRef(user, ACCOUNT_CAPSIZE_DUMMY_BLUE_FILE);
ObjectDelta<UserType> userDelta = DeltaFactory.Object.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);

Expand All @@ -1744,8 +1749,7 @@ public void test620AddUserCapsize() throws Exception {
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);

result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
Expand Down Expand Up @@ -1823,6 +1827,8 @@ public void test630AddUserRogers() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);

PrismObject<UserType> user = PrismTestUtil.parseObject(USER_ROGERS_FILE);
addAccountLinkRef(user, ACCOUNT_ROGERS_DUMMY_DEFAULT_FILE);
addAccountLinkRef(user, ACCOUNT_ROGERS_DUMMY_LEMON_FILE);
ObjectDelta<UserType> userDelta = DeltaFactory.Object.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);

Expand Down
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 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.
-->
<shadow
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:t='http://prism.evolveum.com/xml/ns/public/types-3'
xmlns:ridummy="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<resourceRef oid="10000000-0000-0000-0000-000000000204"/>
<objectClass>ri:AccountObjectClass</objectClass>
<attributes>
<ri:fullname>Captain Kate Capsize</ri:fullname>
</attributes>
</shadow>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 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.
-->
<shadow
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:t='http://prism.evolveum.com/xml/ns/public/types-3'
xmlns:ridummy="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<resourceRef oid="10000000-0000-0000-0000-000000000004"/>
<objectClass>ridummy:AccountObjectClass</objectClass>
<attributes>
<ridummy:fullname>Captain Kate Capsize</ridummy:fullname>
</attributes>
</shadow>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 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.
-->
<shadow
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:t='http://prism.evolveum.com/xml/ns/public/types-3'
xmlns:ridummy="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<resourceRef oid="10000000-0000-0000-0000-000000000104"/>
<objectClass>ri:AccountObjectClass</objectClass>
<attributes>
<ri:fullname>Captain Kate Capsize</ri:fullname>
</attributes>
</shadow>
24 changes: 0 additions & 24 deletions model/model-intest/src/test/resources/common/user-capsize.xml
Expand Up @@ -24,30 +24,6 @@
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<name>capsize</name>

<link>
<resourceRef oid="10000000-0000-0000-0000-000000000004"/>
<objectClass>ridummy:AccountObjectClass</objectClass>
<attributes>
<ridummy:fullname>Captain Kate Capsize</ridummy:fullname>
</attributes>
</link>

<link>
<resourceRef oid="10000000-0000-0000-0000-000000000104"/>
<objectClass>ri:AccountObjectClass</objectClass>
<attributes>
<ri:fullname>Captain Kate Capsize</ri:fullname>
</attributes>
</link>

<link>
<resourceRef oid="10000000-0000-0000-0000-000000000204"/>
<objectClass>ri:AccountObjectClass</objectClass>
<attributes>
<ri:fullname>Captain Kate Capsize</ri:fullname>
</attributes>
</link>

<assignment>
<construction>
<resourceRef oid="10000000-0000-0000-0000-000000000004"/>
Expand Down
Expand Up @@ -119,20 +119,20 @@
throw new AssertionError("No 'projection' or 'configuration' variable present") // MID-4760
}

if (assignment.target != null) {
log.info("### (title) target roleType " + assignment.target.roleType)
inRange = 'auto'.equals(assignment.target.roleType)
log.info("########## (title) inRange: " + inRange)
return inRange
}

if (assignment.targetRef != null) {
role = midpoint.getObject(RoleType.class, assignment.targetRef.oid)
log.info("### (title) role name " + role.name.orig)
log.info("### (title) role.roleType " + role.roleType)
inRange = ('auto')?.equals(role.roleType)
log.info("########## (title) inRange: " + inRange)
return inRange
if (assignment.targetRef.object == null) {
role = midpoint.getObject(RoleType.class, assignment.targetRef.oid)
log.info("### (title) role name " + role.name.orig)
log.info("### (title) role.roleType " + role.roleType)
inRange = ('auto')?.equals(role.roleType)
log.info("########## (title) inRange: " + inRange)
return inRange
} else {
log.info("### (title) target roleType " + assignment.targetRef.objectable.roleType)
inRange = 'auto'.equals(assignment.targetRef.objectable.roleType)
log.info("########## (title) inRange: " + inRange)
return inRange
}
}
</code>
</script>
Expand Down Expand Up @@ -181,20 +181,20 @@
import com.evolveum.midpoint.schema.constants.*
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;

if (assignment.target != null) {
log.info("### (association) target roleType " + assignment.target.roleType)
inRange = 'auto'.equals(assignment.target.roleType)
log.info("########## (association) inRange: " + inRange)
return inRange
}

if (assignment.targetRef != null) {
role = midpoint.getObject(RoleType.class, assignment.targetRef.oid)
log.info("### (association) role name " + role.name.orig)
log.info("### (association) role.roleType " + role.roleType)
inRange = ('auto').equals(role.roleType)
log.info("########## (association) inRange: " + inRange)
return inRange
if (assignment.targetRef.object == null) {
role = midpoint.getObject(RoleType.class, assignment.targetRef.oid)
log.info("### (association) role name " + role.name.orig)
log.info("### (association) role.roleType " + role.roleType)
inRange = ('auto').equals(role.roleType)
log.info("########## (association) inRange: " + inRange)
return inRange
} else {
log.info("### (association) target roleType " + assignment.targetRef.objectable.roleType)
inRange = 'auto'.equals(assignment.targetRef.objectable.roleType)
log.info("########## (association) inRange: " + inRange)
return inRange
}
}
</code>
</script>
Expand Down
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 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.
-->
<shadow
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:t='http://prism.evolveum.com/xml/ns/public/types-3'
xmlns:ridummy="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<resourceRef oid="10000000-0000-0000-0000-000000000004"/>
<objectClass>ridummy:AccountObjectClass</objectClass>
<attributes>
<ridummy:fullname>Rum Rogers Sr.</ridummy:fullname>
<ridummy:ship>The Sea Monkey</ridummy:ship>
</attributes>
</shadow>

0 comments on commit 79b9c75

Please sign in to comment.