From 1e19652dd897da57a3955dfb48db63f5fa42df59 Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Thu, 19 Mar 2020 03:30:10 +0100 Subject: [PATCH] fixing GUI test TestWrapperDelta.test111modifyUserAssignemnt, adding more tests for delta computation --- .../impl/prism/PrismPropertyValueWrapper.java | 18 ++-- .../midpoint/gui/TestWrapperDelta.java | 93 ++++++++++++++++++- 2 files changed, 101 insertions(+), 10 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/PrismPropertyValueWrapper.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/PrismPropertyValueWrapper.java index 7c4a254b8e9..553c11b7824 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/PrismPropertyValueWrapper.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/prism/PrismPropertyValueWrapper.java @@ -35,32 +35,32 @@ public PrismPropertyValueWrapper(ItemWrapper parent, PrismPropertyVa private static final long serialVersionUID = 1L; @Override - public void setRealValue(T realValue) { + public void setRealValue(T newRealValue) { - realValue = trimValueIfNeeded(realValue); + newRealValue = trimValueIfNeeded(newRealValue); - if (realValue == null) { + if (newRealValue == null) { getNewValue().setValue(null); setStatus(ValueStatus.DELETED); return; } - if (realValue instanceof QName) { - if (QNameUtil.match((QName) realValue, (QName) getNewValue())) { + if (newRealValue instanceof QName) { + if (QNameUtil.match((QName) newRealValue, (QName) getRealValue())) { return; } - } else if (realValue instanceof ItemPath) { - if (((ItemPath) realValue).equivalent((ItemPath) getNewValue())) { + } else if (newRealValue instanceof ItemPath) { + if (((ItemPath) newRealValue).equivalent((ItemPath) getRealValue())) { return; } } else { - if (realValue.equals(getNewValue())) { + if (newRealValue.equals(getRealValue())) { return; } } - getNewValue().setValue(realValue); + getNewValue().setValue(newRealValue); setStatus(ValueStatus.MODIFIED); } diff --git a/gui/admin-gui/src/test/java/com/evolveum/midpoint/gui/TestWrapperDelta.java b/gui/admin-gui/src/test/java/com/evolveum/midpoint/gui/TestWrapperDelta.java index fb2ac3fca67..afdeed085d5 100644 --- a/gui/admin-gui/src/test/java/com/evolveum/midpoint/gui/TestWrapperDelta.java +++ b/gui/admin-gui/src/test/java/com/evolveum/midpoint/gui/TestWrapperDelta.java @@ -10,6 +10,7 @@ import com.evolveum.midpoint.gui.api.prism.PrismContainerWrapper; import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper; import com.evolveum.midpoint.gui.api.util.ModelServiceLocator; +import com.evolveum.midpoint.gui.api.util.WebPrismUtil; import com.evolveum.midpoint.gui.impl.factory.PrismObjectWrapperFactory; import com.evolveum.midpoint.gui.impl.factory.ProfilingClassLoggerWrapperFactoryImpl; import com.evolveum.midpoint.gui.impl.factory.WrapperContext; @@ -33,8 +34,10 @@ import com.evolveum.midpoint.schema.util.ObjectTypeUtil; import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.test.asserter.UserAsserter; +import com.evolveum.midpoint.util.QNameUtil; import com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest; import com.evolveum.midpoint.web.component.prism.ValueStatus; +import com.evolveum.midpoint.web.page.admin.reports.dto.ReportDeleteDialogDto; import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; import com.evolveum.prism.xml.ns._public.types_3.ModificationTypeType; @@ -323,7 +326,7 @@ public void test301ModifyProfilingClassLoggerOfSystemConfig() throws Exception { SystemConfigurationType systemConfigBefore = getSystemConfiguration(); WrapperContext ctx = new WrapperContext(task, result); - PrismObjectWrapper objectWrapper =createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx); + PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx); PrismContainerWrapper loggingConfig = objectWrapper.findContainer(SystemConfigurationType.F_LOGGING); PrismContainerWrapper profilingClassLogger = loggingConfig.findContainer(ItemName.fromQName(ProfilingClassLoggerWrapperFactoryImpl.PROFILING_LOGGER_PATH)); @@ -359,6 +362,94 @@ public void test301ModifyProfilingClassLoggerOfSystemConfig() throws Exception { } + @Test + public void test310modifySystemConfigurationAddCollectionView() throws Exception { + Task task = getTestTask(); + OperationResult result = task.getResult(); + + ModelServiceLocator locator = getServiceLocator(task); + + SystemConfigurationType systemConfigBefore = getSystemConfiguration(); + + WrapperContext ctx = new WrapperContext(task, result); + PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx); + ItemPath guiObjectViewPath = ItemPath.create(SystemConfigurationType.F_ADMIN_GUI_CONFIGURATION, AdminGuiConfigurationType.F_OBJECT_COLLECTION_VIEWS, GuiObjectListViewsType.F_OBJECT_COLLECTION_VIEW); + PrismContainerWrapper collections = objectWrapper.findContainer(guiObjectViewPath); + + //GIVEN + PrismContainerValue newCollection = collections.getItem().createNewValue(); + ctx.setShowEmpty(true); + PrismContainerValueWrapper newCollectionValueWrapper = locator.createValueWrapper(collections, newCollection, ValueStatus.ADDED, ctx); + collections.getValues().add(newCollectionValueWrapper); + + PrismPropertyWrapper type = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_TYPE); + type.getValue().setRealValue(new QName("RoleType")); + + PrismPropertyWrapper identifier = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_IDENTIFIER); + identifier.getValue().setRealValue("my-roles-collection"); + + // WHEN + ObjectDelta delta = objectWrapper.getObjectDelta(); + GuiObjectListViewType expectedValue = new GuiObjectListViewType(prismContext); + expectedValue.setIdentifier("my-roles-collection"); + expectedValue.setType(new QName("RoleType")); + assertModification(delta, guiObjectViewPath, ModificationTypeType.ADD, expectedValue); + + executeChanges(delta, null, task, result); + + //THEN + SystemConfigurationType systemConfigAfter = getSystemConfiguration(); + AdminGuiConfigurationType adminGuiConfig = systemConfigAfter.getAdminGuiConfiguration(); + assertNotNull("Unexpecteed empty admin gui configuration.", adminGuiConfig); + + GuiObjectListViewsType collectionViews = adminGuiConfig.getObjectCollectionViews(); + assertNotNull("Unexpected empty gui obejct collection views", collectionViews); + + GuiObjectListViewType myRolesCollection = null; + for (GuiObjectListViewType collectionView : collectionViews.getObjectCollectionView()) { + if ("my-roles-collection".equals(collectionView.getIdentifier())) { + myRolesCollection = collectionView; + } + } + + assertNotNull("Newly added collection view not present in system configuration, something strange", myRolesCollection); + assertFalse("c:RoleType should not be eqals to RoleType", RoleType.COMPLEX_TYPE.equals(myRolesCollection.getType())); + assertTrue("c:RoleType should match RoleType", QNameUtil.match(RoleType.COMPLEX_TYPE, myRolesCollection.getType())); + + } + + @Test + public void test311modifySystemConfigurationModifyCollectionType() throws Exception { + Task task = getTestTask(); + OperationResult result = task.getResult(); + + ModelServiceLocator locator = getServiceLocator(task); + + SystemConfigurationType systemConfigBefore = getSystemConfiguration(); + + WrapperContext ctx = new WrapperContext(task, result); + PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx); + ItemPath guiObjectViewPath = ItemPath.create(SystemConfigurationType.F_ADMIN_GUI_CONFIGURATION, AdminGuiConfigurationType.F_OBJECT_COLLECTION_VIEWS, GuiObjectListViewsType.F_OBJECT_COLLECTION_VIEW); + PrismContainerWrapper collections = objectWrapper.findContainer(guiObjectViewPath); + + PrismContainerValueWrapper foundCollection = null; + for (PrismContainerValueWrapper collection : collections.getValues()) { + GuiObjectListViewType collectionRealValue = collection.getRealValue(); + if ("my-roles-collection".equals(collectionRealValue.getIdentifier())) { + foundCollection = collection; + break; + } + } + // GIVEN + PrismPropertyWrapper collectionType = foundCollection.findProperty(GuiObjectListViewType.F_TYPE); + collectionType.getValue().setRealValue(RoleType.COMPLEX_TYPE); + + // WHEN + ObjectDelta systemConfigDelta = objectWrapper.getObjectDelta(); + assertTrue("Delta should be empty!", systemConfigDelta.isEmpty()); + + } + private PrismContainerValue createDummyResourceAssignment(PrismObjectWrapper objectWrapper, int existingAssignments, Task task, OperationResult result) throws Exception { PrismContainerWrapper assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT); assertNotNull("unexpected null assignment wrapper", assignment);