Skip to content

Commit

Permalink
some assignment update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 6, 2018
1 parent d9eb061 commit 0a42867
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 31 deletions.
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.repo.sql.data.common.RUser;
import com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue;
import com.evolveum.midpoint.repo.sql.data.common.container.RAssignment;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.enums.RActivationStatus;
import com.evolveum.midpoint.repo.sql.testing.QueryCountInterceptor;
Expand All @@ -46,14 +47,8 @@

import javax.xml.namespace.QName;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.*;
import java.util.Objects;
import java.util.Set;

//import com.evolveum.midpoint.repo.sql.helpers.EntityModificationRegistry;
//import com.evolveum.midpoint.repo.sql.helpers.ObjectDeltaUpdater;

/**
* Created by Viliam Repan (lazyman).
Expand Down Expand Up @@ -129,6 +124,32 @@ public void test100UpdateGivenNameAndActivation() throws Exception {
}
}

@Test
public void test115DeleteActivation() throws Exception {
OperationResult result = new OperationResult("test115DeleteActivation");

ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);

ActivationType activation = new ActivationType();
activation.setAdministrativeStatus(ActivationStatusType.DISABLED);

delta.addModificationDeleteContainer(UserType.F_ACTIVATION, activation.asPrismContainerValue());

queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(3, queryCountInterceptor.getQueryCount());

Session session = factory.openSession();
try {
RUser u = session.get(RUser.class, userOid);

AssertJUnit.assertNull(u.getActivation());
} finally {
session.close();
}
}

@Test
public void test110ReplaceExtensionProperty() throws Exception {
OperationResult result = new OperationResult("test110ReplaceExtensionProperty");
Expand Down Expand Up @@ -249,12 +270,73 @@ public void test140AddDeleteAssignment() throws Exception {
}
}

@Test
public void test145AddActivationToAssignment() throws Exception {
OperationResult result = new OperationResult("test145AddActivationToAssignment");

ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);

ActivationType activation = new ActivationType();
activation.setAdministrativeStatus(ActivationStatusType.ENABLED);
delta.addModificationAddContainer(
new ItemPath(UserType.F_ASSIGNMENT, 2, AssignmentType.F_ACTIVATION), activation.asPrismContainerValue());

queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount());

Session session = factory.openSession();
try {
RUser u = session.get(RUser.class, userOid);

Set<RAssignment> assignments = u.getAssignments();
AssertJUnit.assertEquals(1, assignments.size());

RAssignment a = assignments.iterator().next();
RActivation act = a.getActivation();
AssertJUnit.assertNotNull(act);

AssertJUnit.assertEquals(RActivationStatus.ENABLED, act.getAdministrativeStatus());
} finally {
session.close();
}
}

@Test
public void test150AddDeleteLinkRef() throws Exception {
OperationResult result = new OperationResult("test150AddDeleteLinkRef");

ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
ObjectReferenceType linkRef = createRef(ShadowType.COMPLEX_TYPE, "456");
delta.addModificationDeleteReference(UserType.F_LINK_REF, linkRef.asReferenceValue());

linkRef = createRef(ShadowType.COMPLEX_TYPE, "789");
delta.addModificationAddReference(UserType.F_LINK_REF, linkRef.asReferenceValue());

queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount());

Session session = factory.openSession();
try {
RUser u = session.get(RUser.class, userOid);

assertReferences((Collection) u.getLinkRef(),
RObjectReference.copyFromJAXB(createRef(ShadowType.COMPLEX_TYPE, "123", SchemaConstants.ORG_DEFAULT), new RObjectReference()),
RObjectReference.copyFromJAXB(createRef(ShadowType.COMPLEX_TYPE, "789", SchemaConstants.ORG_DEFAULT), new RObjectReference()));
} finally {
session.close();
}
}

@Test
public void test160AddDeleteParentRef() throws Exception {
OperationResult result = new OperationResult("test160AddDeleteParentRef");

ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
ObjectReferenceType parentOrgRef = createRef(OrgType.COMPLEX_TYPE, "123");
ObjectReferenceType parentOrgRef = createRef(OrgType.COMPLEX_TYPE, "456");
delta.addModificationDeleteReference(UserType.F_PARENT_ORG_REF, parentOrgRef.asReferenceValue());

parentOrgRef = createRef(OrgType.COMPLEX_TYPE, "789");
Expand All @@ -270,7 +352,7 @@ public void test160AddDeleteParentRef() throws Exception {
RUser u = session.get(RUser.class, userOid);

assertReferences((Collection) u.getParentOrgRef(),
RObjectReference.copyFromJAXB(createRef(OrgType.COMPLEX_TYPE, "456", SchemaConstants.ORG_DEFAULT), new RObjectReference()),
RObjectReference.copyFromJAXB(createRef(OrgType.COMPLEX_TYPE, "123", SchemaConstants.ORG_DEFAULT), new RObjectReference()),
RObjectReference.copyFromJAXB(createRef(OrgType.COMPLEX_TYPE, "789", SchemaConstants.ORG_DEFAULT), new RObjectReference()));
} finally {
session.close();
Expand Down Expand Up @@ -310,7 +392,6 @@ private void assertReferences(Collection<ObjectReference> collection, ObjectRefe
}
}


@Test
public void test170ModifyEmployeeTypeAndMetadataCreateChannel() throws Exception {
OperationResult result = new OperationResult("test170ModifyEmployeeTypeAndMetadataCreateChannel");
Expand Down Expand Up @@ -357,22 +438,4 @@ public void test180ModifyMetadataChannel() throws Exception {
assertReferences((Collection) u.getCreateApproverRef(),
RObjectReference.copyFromJAXB(createRef(UserType.COMPLEX_TYPE, "111", SchemaConstants.ORG_DEFAULT), new RObjectReference()));
}

public <T extends ObjectType> void addLinkRef() throws Exception {
String oid = null;

// ObjectDelta delta = ObjectDelta.createModificationAddReference(UserType.class, oid, UserType.F_LINK_REF,
// prismContext, "123");

ObjectDelta delta = ObjectDelta.createModificationReplaceProperty(UserType.class, oid, UserType.F_GIVEN_NAME,
prismContext, new PolyString("asdf", "asdf"));

// delta.addModificationReplaceProperty(
// new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), ActivationStatusType.DISABLED);

// ActivationType activation = new ActivationType();
// activation.setAdministrativeStatus(ActivationStatusType.ENABLED);
// delta.addModificationAddContainer(
// new ItemPath(UserType.F_ASSIGNMENT, 1, AssignmentType.F_ACTIVATION), activation.asPrismContainerValue());
}
}
8 changes: 5 additions & 3 deletions repo/repo-sql-impl-test/src/test/resources/update/user.xml
Expand Up @@ -20,9 +20,9 @@
xmlns:p="http://example.com/p">
<name>add link user</name>
<fullName>Add Link</fullName>
<!--<activation>-->
<!--<administrativeStatus>enabled</administrativeStatus>-->
<!--</activation>-->
<activation>
<administrativeStatus>enabled</administrativeStatus>
</activation>
<extension>
<p:weapon>sig</p:weapon>
</extension>
Expand All @@ -31,4 +31,6 @@
</assignment>
<parentOrgRef oid="123" type="c:OrgType"/>
<parentOrgRef oid="456" type="c:OrgType"/>
<linkRef oid="123" type="c:ShadowType"/>
<linkRef oid="456" type="c:ShadowType"/>
</user>

0 comments on commit 0a42867

Please sign in to comment.