Skip to content

Commit

Permalink
TestRecomputeTask and delta tests - disabled, work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 28, 2014
1 parent b645e45 commit 70a7d06
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
Expand Up @@ -884,6 +884,17 @@ public static <O extends Objectable, C extends Containerable> ObjectDelta<O> cre
return createModificationDeleteContainer(type, oid, new ItemPath(containerName), prismContext, containerValues);
}

/**
* Supposed to work with containers that are completely identified by path (container ID present in path).
*/
public static <O extends Objectable, C extends Containerable> ObjectDelta<O> createModificationDeleteContainer(Class<O> type, String oid, ItemPath containerPath,
PrismContext prismContext) {
ObjectDelta<O> objectDelta = new ObjectDelta<O>(type, ChangeType.MODIFY, prismContext);
objectDelta.setOid(oid);
fillInModificationDeleteContainer(objectDelta, containerPath);
return objectDelta;
}

public static <O extends Objectable, C extends Containerable> ObjectDelta<O> createModificationDeleteContainer(Class<O> type, String oid, ItemPath containerPath,
PrismContext prismContext, PrismContainerValue<C>... containerValues) {
ObjectDelta<O> objectDelta = new ObjectDelta<O>(type, ChangeType.MODIFY, prismContext);
Expand Down
Expand Up @@ -133,7 +133,71 @@ public void testAddInducementConstructionSameNullIdApplyToObject() throws Except
assertEquals("Unexpected number of inducement values", 2, assignment.size());
}

@Test
@Test(enabled=false) // work in progress
public void testDeleteInducementValidIdSameValueApplyToObject() throws Exception {
final String TEST_NAME = "testDeleteInducementValidIdSameValueApplyToObject";
displayTestTile(TEST_NAME);

// GIVEN
PrismObject<RoleType> role = PrismTestUtil.parseObject(ROLE_CONSTRUCTION_FILE);

//Delta
ConstructionType construction = new ConstructionType();
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.setOid(ROLE_CONSTRUCTION_RESOURCE_OID);
construction.setResourceRef(resourceRef);
AssignmentType inducement = new AssignmentType();
inducement.setConstruction(construction);
ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, ROLE_CONSTRUCTION_OID,
new ItemPath(
new NameItemPathSegment(RoleType.F_INDUCEMENT),
new IdItemPathSegment(ROLE_CONSTRUCTION_INDUCEMENT_ID)),
PrismTestUtil.getPrismContext(), inducement);

// WHEN
roleDelta.applyTo(role);

// THEN
System.out.println("Role after delta application:");
System.out.println(role.debugDump());
assertEquals("Wrong OID", ROLE_CONSTRUCTION_OID, role.getOid());
PrismAsserts.assertPropertyValue(role, UserType.F_NAME, PrismTestUtil.createPolyString("Construction"));
PrismContainer<AssignmentType> assignment = role.findContainer(RoleType.F_INDUCEMENT);
assertNull("Unexpected inducement", assignment);
}

@Test(enabled=false) // work in progress
public void testDeleteInducementValidIdNoValueApplyToObject() throws Exception {
final String TEST_NAME = "testDeleteInducementValidIdNoValueApplyToObject";
displayTestTile(TEST_NAME);

// GIVEN
PrismObject<RoleType> role = PrismTestUtil.parseObject(ROLE_CONSTRUCTION_FILE);

//Delta
ConstructionType construction = new ConstructionType();
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.setOid(ROLE_CONSTRUCTION_RESOURCE_OID);
construction.setResourceRef(resourceRef);
ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, ROLE_CONSTRUCTION_OID,
new ItemPath(
new NameItemPathSegment(RoleType.F_INDUCEMENT),
new IdItemPathSegment(ROLE_CONSTRUCTION_INDUCEMENT_ID)),
PrismTestUtil.getPrismContext());

// WHEN
roleDelta.applyTo(role);

// THEN
System.out.println("Role after delta application:");
System.out.println(role.debugDump());
assertEquals("Wrong OID", ROLE_CONSTRUCTION_OID, role.getOid());
PrismAsserts.assertPropertyValue(role, UserType.F_NAME, PrismTestUtil.createPolyString("Construction"));
PrismContainer<AssignmentType> assignment = role.findContainer(RoleType.F_INDUCEMENT);
assertNull("Unexpected inducement", assignment);
}

@Test(enabled=false) // work in progress
public void testDeleteInducementConstructionSameNullIdApplyToObject() throws Exception {
final String TEST_NAME = "testDeleteInducementConstructionSameNullIdApplyToObject";
displayTestTile(TEST_NAME);
Expand Down Expand Up @@ -164,6 +228,9 @@ public void testDeleteInducementConstructionSameNullIdApplyToObject() throws Exc
PrismContainer<AssignmentType> assignment = role.findContainer(RoleType.F_INDUCEMENT);
assertNotNull("No inducement", assignment);
assertEquals("Unexpected number of inducement values", 1, assignment.size());

// TODO: construction should be gone, check for it
// (the error is that it is empty and not gone)
}

}
1 change: 1 addition & 0 deletions infra/schema/testng.xml
Expand Up @@ -42,6 +42,7 @@
<class name="com.evolveum.midpoint.schema.TestQueryConvertor"/>
<class name="com.evolveum.midpoint.schema.TestDynamicSchema"/>
<class name="com.evolveum.midpoint.schema.TestJsonParsing"/>
<class name="com.evolveum.midpoint.schema.TestSchemaDelta"/>
</classes>
</test>
</suite>
Expand Up @@ -263,7 +263,7 @@ public void test110RecomputeSome() throws Exception {
TestUtil.assertSuccess(result);

// Now do something evil, remove "red" construction from judge role
modifyRoleDeleteConstruction(ROLE_JUDGE_OID, 1111L, RESOURCE_DUMMY_RED_OID);
modifyRoleDeleteInducement(ROLE_JUDGE_OID, 1111L, RESOURCE_DUMMY_RED_OID);

PrismObject<RoleType> roleJudge = getRole(ROLE_JUDGE_OID);
display("Role judge after modification", roleJudge);
Expand Down Expand Up @@ -317,20 +317,21 @@ private void modifyRoleAddConstruction(String roleOid, long inducementId, String
TestUtil.assertSuccess(result);
}

private void modifyRoleDeleteConstruction(String roleOid, long inducementId, String resourceOid) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
private void modifyRoleDeleteInducement(String roleOid, long inducementId, String resourceOid) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
Task task = createTask(TestRecomputeTask.class.getName() + ".modifyRoleDefinition");
OperationResult result = task.getResult();

ConstructionType construction = new ConstructionType();
ObjectReferenceType resourceRedRef = new ObjectReferenceType();
resourceRedRef.setOid(resourceOid);
construction.setResourceRef(resourceRedRef);
AssignmentType inducement = new AssignmentType();
inducement.setConstruction(construction);
ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, roleOid,
new ItemPath(
new NameItemPathSegment(RoleType.F_INDUCEMENT),
new IdItemPathSegment(inducementId),
new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)),
prismContext, construction);
new IdItemPathSegment(inducementId)),
prismContext, inducement);
modelService.executeChanges(MiscSchemaUtil.createCollection(roleDelta), null, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
Expand Down

0 comments on commit 70a7d06

Please sign in to comment.