Search in sources :

Example 41 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class TestWrapperDelta method test311modifySystemConfigurationModifyCollectionType.

@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<GuiObjectListViewType> collections = objectWrapper.findContainer(guiObjectViewPath);
    PrismContainerValueWrapper<GuiObjectListViewType> foundCollection = null;
    for (PrismContainerValueWrapper<GuiObjectListViewType> collection : collections.getValues()) {
        GuiObjectListViewType collectionRealValue = collection.getRealValue();
        if ("my-roles-collection".equals(collectionRealValue.getIdentifier())) {
            foundCollection = collection;
            break;
        }
    }
    // GIVEN
    PrismPropertyWrapper<QName> collectionType = foundCollection.findProperty(GuiObjectListViewType.F_TYPE);
    collectionType.getValue().setRealValue(RoleType.COMPLEX_TYPE);
    // WHEN
    ObjectDelta<SystemConfigurationType> systemConfigDelta = objectWrapper.getObjectDelta();
    assertTrue("Delta should be empty!", systemConfigDelta.isEmpty());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObjectWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class TestWrapperDelta method test200createUser.

@Test
public void test200createUser() throws Exception {
    // Task task = getTestTask(); // TODO we don't want customized task here?
    Task task = createPlainTask();
    OperationResult result = task.getResult();
    PrismObjectDefinition<UserType> def = getServiceLocator(task).getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
    PrismObject<UserType> user = def.instantiate();
    WrapperContext ctx = new WrapperContext(task, result);
    PrismObjectWrapper<UserType> userWrapper = createObjectWrapper(user, ItemStatus.ADDED, ctx);
    PrismPropertyWrapper<PolyString> username = userWrapper.findProperty(UserType.F_NAME);
    username.getValue().setRealValue(PrismTestUtil.createPolyString("guybrush"));
    PrismPropertyWrapper<PolyString> fullName = userWrapper.findProperty(UserType.F_FULL_NAME);
    fullName.getValue().setRealValue(PrismTestUtil.createPolyString("Guybrush Threepwood"));
    PrismPropertyWrapper<ProtectedStringType> password = userWrapper.findProperty(SchemaConstants.PATH_PASSWORD_VALUE);
    ProtectedStringType pwd = new ProtectedStringType();
    pwd.setClearValue("howMuchWoodWouldWoodchuckChuckIfWoodchuckCouldChuckWood");
    password.getValue().setRealValue(pwd);
    PrismContainerValue<AssignmentType> newAssignment = createDummyResourceAssignment(userWrapper, 0, task, result);
    ObjectDelta<UserType> delta = userWrapper.getObjectDelta();
    assertModificationsSize(delta, 0);
    PrismObject<UserType> objectToAdd = delta.getObjectToAdd();
    assertNotNull("Unexpected null object to add", objectToAdd);
    assertUserProperty(objectToAdd, UserType.F_NAME, PrismTestUtil.createPolyString("guybrush"));
    assertUserProperty(objectToAdd, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Guybrush Threepwood"));
    UserAsserter.forUser(objectToAdd).assertName("guybrush").assertFullName("Guybrush Threepwood").assertAssignments(1);
    PrismProperty<ProtectedStringType> passwordBeforeSave = objectToAdd.findProperty(SchemaConstants.PATH_PASSWORD_VALUE);
    assertNotNull("Unexpected null password property", passwordBeforeSave);
    assertEquals("Unexpected password in delta: " + passwordBeforeSave.getRealValue(), pwd, passwordBeforeSave.getRealValue());
    executeChanges(delta, null, task, result);
    PrismObject<UserType> userAfter = findUserByUsername("guybrush");
    UserAsserter.forUser(userAfter).assertName("guybrush").assertFullName("Guybrush Threepwood").assertAssignments(1);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 43 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test110CreateWrapperUserNewEmpty.

/**
 * Create wrapper for brand new empty user.
 */
@Test
public void test110CreateWrapperUserNewEmpty() throws Exception {
    PrismObject<UserType> user = getUserDefinition().instantiate();
    when();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObjectWrapperFactory<UserType> factory = getServiceLocator(task).findObjectWrapperFactory(user.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    context.setCreateIfEmpty(true);
    context.setShowEmpty(true);
    PrismObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper(user, ItemStatus.ADDED, context);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, getUserDefinition().instantiate(), ItemStatus.ADDED);
    assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
    assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
    PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, null);
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
    PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(UserType.F_ACTIVATION);
    WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ActivationType.activation"), UserType.F_ACTIVATION, user, ItemStatus.ADDED);
    assertEquals("wrong number of containers in " + activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
    PrismContainerValueWrapper<ActivationType> activationContainerValueWrapper = activationContainerWrapper.getValues().iterator().next();
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, null);
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
    ItemStatus objectStatus = objectWrapper.getStatus();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, true);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_WEAPON), null);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_COLORS), ItemProcessing.AUTO);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_SECRET), ItemProcessing.IGNORE);
    assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_RANT), ItemProcessing.MINIMAL);
    when();
    mainContainerValueWrapper.setShowEmpty(false);
    then();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, false);
    ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-add delta produced from wrapper: " + objectDelta, objectDelta.isAdd());
    PrismObject<UserType> objectToAdd = objectDelta.getObjectToAdd();
    assertTrue("non-empty object in add delta produced from wrapper: " + objectDelta, objectToAdd.isEmpty());
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method modifyPropertyWrapper.

private void modifyPropertyWrapper(ModelServiceLocator modelServiceLocator, PrismContainerValueWrapper<OrgType> mainContainerValueWrapper, ItemPath propPath, String newValue) throws SchemaException {
    PrismPropertyWrapper propertyWrapper = mainContainerValueWrapper.findProperty(propPath);
    List<PrismPropertyValueWrapper<String>> values = propertyWrapper.getValues();
    if (values.size() == 1) {
        values.get(0).setRealValue(newValue);
    } else if (values.isEmpty()) {
        PrismPropertyValue<String> pval = prismContext.itemFactory().createPropertyValue(newValue);
        WrapperContext context = new WrapperContext(modelServiceLocator.getPageTask(), modelServiceLocator.getPageTask().getResult());
        context.setShowEmpty(true);
        context.setCreateIfEmpty(true);
        PrismValueWrapper<String> newValueWrapper = modelServiceLocator.createValueWrapper(propertyWrapper, pval, ValueStatus.ADDED, context);
        newValueWrapper.setRealValue(newValue);
        propertyWrapper.getItem().add(pval);
        propertyWrapper.getValues().add(newValueWrapper);
    } else {
        throw new IllegalArgumentException("Cannot use on multivalue props");
    }
}
Also used : PrismPropertyValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)

Example 45 with WrapperContext

use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test102CreateWrapperUserEmpty.

@Test
public void test102CreateWrapperUserEmpty() throws Exception {
    PrismObject<UserType> user = getUser(USER_EMPTY_OID);
    PrismObject<UserType> userOld = user.clone();
    when();
    Task task = createTask();
    OperationResult result = task.getResult();
    ModelServiceLocator modelServiceLocator = getServiceLocator(task);
    PrismObjectWrapperFactory<UserType> factory = modelServiceLocator.findObjectWrapperFactory(user.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    PrismObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper(user, ItemStatus.NOT_CHANGED, context);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, userOld, ItemStatus.NOT_CHANGED);
    assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), null, user, ItemStatus.NOT_CHANGED);
    assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
    PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_EMPTY_USERNAME));
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
    // Not sure about this
    // ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(ItemPath.create(UserType.F_ACTIVATION));
    // assertNull("Unexpected activation "+activationContainerWrapper, activationContainerWrapper);
    assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
    ItemStatus objectStatus = objectWrapper.getStatus();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, false);
    when();
    mainContainerValueWrapper.setShowEmpty(true);
    then();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    // emphasized
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, true);
    ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-empty delta produced from wrapper: " + objectDelta, objectDelta.isEmpty());
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)46 Task (com.evolveum.midpoint.task.api.Task)32 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 AbstractInitializedGuiIntegrationTest (com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 Test (org.testng.annotations.Test)15 ModelServiceLocator (com.evolveum.midpoint.gui.api.util.ModelServiceLocator)11 ItemStatus (com.evolveum.midpoint.gui.api.prism.ItemStatus)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)7 RestartResponseException (org.apache.wicket.RestartResponseException)5 PrismObjectWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QName (javax.xml.namespace.QName)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 NotNull (org.jetbrains.annotations.NotNull)3 PrismObjectWrapperFactory (com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory)2 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)2 ShadowWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ShadowWrapper)2 PrismPropertyValueWrapper (com.evolveum.midpoint.gui.impl.prism.wrapper.PrismPropertyValueWrapper)2