Skip to content

Commit

Permalink
fixing tests (increase number of users) and fixing some issue with ch…
Browse files Browse the repository at this point in the history
…erry-pick
  • Loading branch information
skublik committed Mar 6, 2019
1 parent 27dca40 commit 26bbb92
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 86 deletions.
Empty file.
Expand Up @@ -119,7 +119,7 @@ public static <F extends FocusType> void assertNotAssigned(PrismObject<F> user,
if (targetRef != null) {
if (QNameUtil.match(refType, targetRef.getType())) {
if (targetOid.equals(targetRef.getOid()) &&
getPrismContext().relationMatches(targetRef.getRelation(), relation)) {
MiscSchemaUtil.compareRelation(targetRef.getRelation(), relation)) {
AssertJUnit.fail(user + " does have assigned "+refType.getLocalPart()+" "+targetOid+", relation "+relation+"while not expecting it");
}
}
Expand Down
Expand Up @@ -25,9 +25,9 @@
import com.evolveum.midpoint.prism.PrismObjectValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.RelationTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -114,10 +114,10 @@ public PipelineData execute(ActionExpressionType expression, PipelineData input,
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof AssignmentHolderType) {
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof FocusType) {
@SuppressWarnings({"unchecked", "raw"})
PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
AssignmentHolderType objectType = (AssignmentHolderType) prismObject.asObjectable();
FocusType objectType = (FocusType) prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
Expand All @@ -137,10 +137,10 @@ public PipelineData execute(ActionExpressionType expression, PipelineData input,
return input; // TODO updated objects?
}

private ObjectDelta<? extends ObjectType> createDelta(AssignmentHolderType object, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles, Collection<String> relations) throws ScriptExecutionException {
private ObjectDelta<? extends ObjectType> createDelta(FocusType object, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles, Collection<String> relations) throws ScriptExecutionException {
if (relations == null || relations.isEmpty()) {
QName defaultRelation = prismContext.getDefaultRelation() != null ?
prismContext.getDefaultRelation() : RelationTypes.MEMBER.getRelation();
prismContext.getDefaultRelation() : SchemaConstants.ORG_DEFAULT;
relations = Collections.singletonList(QNameUtil.qNameToUri(defaultRelation));
}
List<AssignmentType> assignmentsForDelete = new ArrayList<>();
Expand All @@ -154,7 +154,7 @@ private ObjectDelta<? extends ObjectType> createDelta(AssignmentHolderType objec
for (ObjectReferenceType roleRef : roles) {
if (targetRef.getOid() != null && targetRef.getOid().equals(roleRef.getOid())) {
for (String relationQuery : relations) {
if (prismContext.relationMatches(QNameUtil.uriToQName(relationQuery, true), targetRef.getRelation())) {
if (MiscSchemaUtil.compareRelation(QNameUtil.uriToQName(relationQuery, true), targetRef.getRelation())) {
assignmentsForDelete.add(oldAssignment.clone());
break outerloop;
}
Expand All @@ -176,13 +176,15 @@ private ObjectDelta<? extends ObjectType> createDelta(AssignmentHolderType objec
}
}

ObjectDelta<? extends ObjectType> delta;
// ObjectDelta<? extends ObjectType> delta;

ObjectDelta<? extends ObjectType> delta = ObjectDelta.createEmptyModifyDelta(object.getClass(), object.getOid(), prismContext);
try {
delta = prismContext.deltaFor(object.getClass())
.item(ItemPath.create(AssignmentHolderType.F_ASSIGNMENT))
.deleteRealValues(assignmentsForDelete)
.asObjectDelta(object.getOid());
delta.addModificationDeleteContainer(FocusType.F_ASSIGNMENT, assignmentsForDelete.toArray(new AssignmentType[0]));
// delta = prismContext.deltaFor(object.getClass())
// .item(new ItemPath(FocusType.F_ASSIGNMENT))
// .deleteRealValues(assignmentsForDelete)
// .asObjectDelta(object.getOid());
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't prepare modification to delete resource/role assignments", e);
}
Expand Down
Expand Up @@ -67,7 +67,7 @@ public class AbstractInitializedModelIntegrationTest extends AbstractConfiguredM

protected static final Trace LOGGER = TraceManager.getTrace(AbstractInitializedModelIntegrationTest.class);

private static final int NUMBER_OF_IMPORTED_USERS = 4;
private static final int NUMBER_OF_IMPORTED_USERS = 5;
private static final int NUMBER_OF_IMPORTED_ROLES = 16;

@Autowired(required = true)
Expand Down
Expand Up @@ -2269,7 +2269,7 @@ public void test310ImportAccountsFromDummyGreen() throws Exception {
OperationResult result = task.getResult();

// Preconditions
assertUsers(6);
assertUsers(7);
PrismObject<UserType> userMancomb = findUserByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);
assertNull("Unexpected user mancomb before import", userMancomb);

Expand All @@ -2290,7 +2290,7 @@ public void test310ImportAccountsFromDummyGreen() throws Exception {
assertNotNull("No user mancomb after import", userMancomb);
userMancombOid = userMancomb.getOid();

assertUsers(7);
assertUsers(8);

assertAdministrativeStatusEnabled(userMancomb);
assertValidFrom(userMancomb, ACCOUNT_MANCOMB_VALID_FROM_DATE);
Expand Down
Expand Up @@ -1560,7 +1560,7 @@ public void test820OtisSearchUsers() throws Exception {
result.computeStatus();
TestUtil.assertSuccess(result);

assertEquals("Unexepected number of users found", 6, users.size());
assertEquals("Unexepected number of users found", 7, users.size());

for (final PrismObject<UserType> user: users) {
assertProperty(user, UserType.F_NAME, new Validator<PrismPropertyDefinition<PolyString>>() {
Expand Down
Expand Up @@ -30,7 +30,6 @@
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.constants.RelationTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.internals.InternalMonitor;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -627,8 +626,8 @@ public void test390UnassignFromWill() throws Exception {
TestUtil.assertSuccess(result);
PrismObject<UserType> will = getUser(USER_WILL_OID);
display("will after unassign assignment", will);
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, RelationTypes.MEMBER.getRelation());
MidPointAsserts.assertAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, RelationTypes.MANAGER.getRelation());
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, SchemaConstants.ORG_DEFAULT);
MidPointAsserts.assertAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, SchemaConstants.ORG_MANAGER);
MidPointAsserts.assertAssignedResource(will, "10000000-0000-0000-0000-000000000004");
}

Expand All @@ -652,8 +651,8 @@ public void test391UnassignFromWill() throws Exception {
TestUtil.assertSuccess(result);
PrismObject<UserType> will = getUser(USER_WILL_OID);
display("will after unassign assignment", will);
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, RelationTypes.MEMBER.getRelation());
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, RelationTypes.MANAGER.getRelation());
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, SchemaConstants.ORG_DEFAULT);
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, SchemaConstants.ORG_MANAGER);
MidPointAsserts.assertAssignedResource(will, "10000000-0000-0000-0000-000000000004");
}

Expand All @@ -677,8 +676,8 @@ public void test392UnassignFromWill() throws Exception {
TestUtil.assertSuccess(result);
PrismObject<UserType> will = getUser(USER_WILL_OID);
display("will after unassign assignment", will);
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, RelationTypes.MEMBER.getRelation());
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, RelationTypes.MANAGER.getRelation());
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, SchemaConstants.ORG_DEFAULT);
MidPointAsserts.assertNotAssigned(will, "12345678-d34d-b33f-f00d-555555556666", RoleType.COMPLEX_TYPE, SchemaConstants.ORG_MANAGER);
MidPointAsserts.assertNotAssignedResource(will, "10000000-0000-0000-0000-000000000004");
}

Expand Down
Expand Up @@ -629,6 +629,7 @@ protected void cleanupAutzTest(String userOid, int expectedAssignments) throws O
cleanupDelete(UserType.class, USER_DRAKE_OID, task, result);
cleanupDelete(UserType.class, USER_RAPP_OID, task, result);
cleanupDelete(UserType.class, USER_MANCOMB_OID, task, result);
cleanupDelete(UserType.class, USER_WILL_OID, task, result);
cleanupAdd(USER_LARGO_FILE, task, result);
cleanupAdd(USER_LECHUCK_FILE, task, result);
cleanupAdd(USER_ESTEVAN_FILE, task, result);
Expand Down
Expand Up @@ -132,7 +132,7 @@ public void test110AddDummyEmeraldAccountMancomb() throws Exception {
prepareNotifications();

// Preconditions
assertUsers(5);
assertUsers(6);

DummyAccount account = new DummyAccount(ACCOUNT_MANCOMB_DUMMY_USERNAME);
account.setEnabled(true);
Expand Down Expand Up @@ -172,7 +172,7 @@ public void test110AddDummyEmeraldAccountMancomb() throws Exception {

assertLinked(userMancomb, accountMancomb);

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand All @@ -190,7 +190,7 @@ public void test120ModifyDummyEmeraldAccountMancombSeepbad() throws Exception {
prepareNotifications();

// Preconditions
assertUsers(6);
assertUsers(7);

DummyAccount account = dummyResourceEmerald.getAccountByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);

Expand Down Expand Up @@ -227,7 +227,7 @@ public void test120ModifyDummyEmeraldAccountMancombSeepbad() throws Exception {

PrismAsserts.assertPropertyValue(userAfter, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Mancomb Seepbad"));

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand All @@ -245,7 +245,7 @@ public void test122ModifyDummyEmeraldAccountMancombSeepNULL() throws Exception {
prepareNotifications();

// Preconditions
assertUsers(6);
assertUsers(7);

DummyAccount account = dummyResourceEmerald.getAccountByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);

Expand Down Expand Up @@ -282,7 +282,7 @@ public void test122ModifyDummyEmeraldAccountMancombSeepNULL() throws Exception {

PrismAsserts.assertNoItem(userAfter, UserType.F_FULL_NAME);

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand All @@ -300,7 +300,7 @@ public void test124ModifyDummyEmeraldAccountMancombSeepevil() throws Exception {
prepareNotifications();

// Preconditions
assertUsers(6);
assertUsers(7);

DummyAccount account = dummyResourceEmerald.getAccountByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);

Expand Down Expand Up @@ -337,7 +337,7 @@ public void test124ModifyDummyEmeraldAccountMancombSeepevil() throws Exception {

PrismAsserts.assertPropertyValue(userAfter, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Mancomb Seepevil"));

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand All @@ -355,7 +355,7 @@ public void test126ModifyDummyEmeraldAccountMancombTitlePirate() throws Exceptio
prepareNotifications();

// Preconditions
assertUsers(6);
assertUsers(7);

DummyAccount account = dummyResourceEmerald.getAccountByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);

Expand Down Expand Up @@ -393,7 +393,7 @@ public void test126ModifyDummyEmeraldAccountMancombTitlePirate() throws Exceptio
PrismAsserts.assertPropertyValue(userAfter, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Mancomb Seepevil"));
PrismAsserts.assertPropertyValue(userAfter, UserType.F_TITLE, PrismTestUtil.createPolyString("Pirate"));

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand All @@ -411,7 +411,7 @@ public void test127ModifyDummyEmeraldAccountMancombTitlePirateNull() throws Exce
prepareNotifications();

// Preconditions
assertUsers(6);
assertUsers(7);

DummyAccount account = dummyResourceEmerald.getAccountByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);

Expand Down Expand Up @@ -449,7 +449,7 @@ public void test127ModifyDummyEmeraldAccountMancombTitlePirateNull() throws Exce
PrismAsserts.assertPropertyValue(userAfter, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Mancomb Seepevil"));
PrismAsserts.assertNoItem(userAfter, UserType.F_TITLE);

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand All @@ -467,7 +467,7 @@ public void test129ModifyDummyEmeraldAccountMancombSeepgood() throws Exception {
prepareNotifications();

// Preconditions
assertUsers(6);
assertUsers(7);

DummyAccount account = dummyResourceEmerald.getAccountByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);

Expand Down Expand Up @@ -504,7 +504,7 @@ public void test129ModifyDummyEmeraldAccountMancombSeepgood() throws Exception {

PrismAsserts.assertPropertyValue(userAfter, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Mancomb Seepgood"));

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand Down Expand Up @@ -532,7 +532,7 @@ public void test300AddDummyEmeraldAccountPosixUser() throws Exception {
prepareNotifications();

// Preconditions
assertUsers(6);
assertUsers(7);

DummyAccount account = new DummyAccount(ACCOUNT_POSIXUSER_DUMMY_USERNAME);
account.setEnabled(true);
Expand Down Expand Up @@ -568,7 +568,7 @@ public void test300AddDummyEmeraldAccountPosixUser() throws Exception {
assertAdministrativeStatusEnabled(userPosixUser);
assertLinked(userPosixUser, accountPosixUser);

assertUsers(7);
assertUsers(8);

// notifications
notificationManager.setDisabled(true);
Expand All @@ -590,7 +590,7 @@ public void test310ModifyDummyEmeraldAccountPosixUserUidNumber() throws Exceptio
prepareNotifications();

// Preconditions
assertUsers(7);
assertUsers(8);

DummyAccount account = dummyResourceEmerald.getAccountByUsername(ACCOUNT_POSIXUSER_DUMMY_USERNAME);

Expand Down Expand Up @@ -621,7 +621,7 @@ public void test310ModifyDummyEmeraldAccountPosixUserUidNumber() throws Exceptio

assertLinked(userAfter, accountAfter);

assertUsers(7);
assertUsers(8);

// notifications
notificationManager.setDisabled(true);
Expand Down
Expand Up @@ -148,7 +148,7 @@ public void test110AddDummyByzantineAccountMancomb() throws Exception {
prepareNotifications();

// Preconditions
assertUsers(5);
assertUsers(6);

DummyAccount account = new DummyAccount(ACCOUNT_MANCOMB_DUMMY_USERNAME);
account.setEnabled(true);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void test110AddDummyByzantineAccountMancomb() throws Exception {
assertAssignedOrg(userMancomb, ORG_F0001_OID);
assertHasOrg(userMancomb, ORG_F0001_OID);

assertUsers(6);
assertUsers(7);

// notifications
notificationManager.setDisabled(true);
Expand Down

0 comments on commit 26bbb92

Please sign in to comment.