Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 25, 2022
2 parents c780ce1 + 90e6b11 commit 7a352f7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.evolveum.midpoint.schema;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.*;

import java.io.IOException;
Expand Down Expand Up @@ -321,4 +322,22 @@ private MidPointPrismContextFactory getContextFactory() {
return new MidPointPrismContextFactory();
}

/**
* See MID-7690. (Here the lookup works.)
*/
@Test
public void testMismatchedDefinitionLookup() throws SchemaException, IOException, SAXException {
given("creating schema registry and looking up ResourceType definition");
SchemaRegistry schemaRegistry = getContextFactory()
.createInitializedPrismContext()
.getSchemaRegistry();
PrismObjectDefinition<ResourceType> objectDefinition =
schemaRegistry.findObjectDefinitionByCompileTimeClass(ResourceType.class);

when("looking up a definition for 'synchronization' (now container) assuming it's a property");
PrismPropertyDefinition<?> propDef = objectDefinition.findPropertyDefinition(ResourceType.F_SYNCHRONIZATION);

then("asserting it's null");
assertThat(propDef).as("definition of property 'synchronization'").isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public ValidationResult validate(@NotNull PrismObject<ResourceType> resourceObje
checkSynchronizationDuplicateObjectTypes(ctx, synchronization);
int i = 1;
for (ObjectSynchronizationType objectSync : resource.getSynchronization().getObjectSynchronization()) {
// TODO is the path construction correct here? (meaning "i" as PCV id!)
checkObjectSynchronization(ctx, ItemPath.create(ResourceType.F_SYNCHRONIZATION, SynchronizationType.F_OBJECT_SYNCHRONIZATION, i), objectSync);
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,32 @@ public void test410RecomputeRole() throws Exception {
dummyAuditService.assertCustomColumn("foo", "test");
}

/**
* Tests the sanity of transformed schema. Currently there is a specific problem
* with looking up container definitions pretending they are properties. See
* also `TestSchemaRegistry.testMismatchedDefinitionLookup`.
*
* See MID-7690.
*
* This test is in this class because I've found no suitable test class in model-impl module.
*/
@Test(enabled = false)
public void test500MismatchedDefinitionLookupInTransformedSchema() throws CommonException {
given("obtaining ResourceType definition via model-api");
Task task = getTestTask();
OperationResult result = task.getResult();

PrismObject<ResourceType> resource =
modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result);
PrismObjectDefinition<ResourceType> objectDefinition = resource.getDefinition();

when("looking up a definition for 'synchronization' (now container) assuming it's a property");
PrismPropertyDefinition<?> propDef = objectDefinition.findPropertyDefinition(ResourceType.F_SYNCHRONIZATION);

then("asserting it's null");
assertThat(propDef).as("definition of property 'synchronization'").isNull();
}

private String addTestRole(Task task, OperationResult result) throws CommonException {
RoleType role = new RoleType(prismContext)
.name("test410");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,13 +918,21 @@ public void test700AddDummyGreenAccountXjojo() throws Exception {
notificationManager.setDisabled(true);
}

private void assumeUserTemplate(String templateOid, ResourceType resource, String syncConfigName, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
SynchronizationType resourceSync = resource.getSynchronization();
resourceSync.getObjectSynchronization().get(0).setObjectTemplateRef(ObjectTypeUtil.createObjectRef(templateOid, ObjectTypes.OBJECT_TEMPLATE));

Collection<? extends ItemDelta<?, ?>> refDelta = prismContext.deltaFactory().property()
.createModificationReplacePropertyCollection(ResourceType.F_SYNCHRONIZATION, resource.asPrismObject().getDefinition(), resourceSync);
repositoryService.modifyObject(ResourceType.class, resource.getOid(), refDelta, result);
private void assumeUserTemplate(String templateOid, ResourceType resource, String syncConfigName, OperationResult result)
throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {

repositoryService.modifyObject(
ResourceType.class,
resource.getOid(),
deltaFor(ResourceType.class)
.item(ResourceType.F_SYNCHRONIZATION,
SynchronizationType.F_OBJECT_SYNCHRONIZATION,
resource.getSynchronization().getObjectSynchronization().get(0).getId(),
ObjectSynchronizationType.F_OBJECT_TEMPLATE_REF)
.replace(
ObjectTypeUtil.createObjectRef(templateOid, ObjectTypes.OBJECT_TEMPLATE))
.asItemDeltas(),
result);

ResourceType res = repositoryService.getObject(ResourceType.class, resource.getOid(), null, result).asObjectable();
assertNotNull(res);
Expand Down

0 comments on commit 7a352f7

Please sign in to comment.