Search in sources :

Example 1 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test150CreateWrapperShadow.

@Test
public void test150CreateWrapperShadow() throws Exception {
    PrismObject<ShadowType> shadow = getShadowModel(accountJackOid);
    shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
    display("Shadow", shadow);
    PrismObject<ShadowType> shadowOld = shadow.clone();
    when();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ModelServiceLocator modelServiceLocator = getServiceLocator(task);
    PrismObjectWrapperFactory<ShadowType> factory = modelServiceLocator.findObjectWrapperFactory(shadow.getDefinition());
    assertTrue("Wrong object factory found, expected shadow factory but got " + factory.getClass().getSimpleName(), factory instanceof ShadowWrapperFactoryImpl);
    WrapperContext context = new WrapperContext(task, result);
    context.setCreateIfEmpty(true);
    PrismObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper(shadow, ItemStatus.NOT_CHANGED, context);
    assertTrue("Wrong wrapper created. Expected ShadowWrapper but got " + objectWrapper.getClass().getSimpleName(), objectWrapper instanceof ShadowWrapper);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "shadow description", shadow, shadowOld, ItemStatus.NOT_CHANGED);
    assertContainersPaths(objectWrapper, BASIC_SHADOW_CONTAINERS_PATHS);
    PrismContainerWrapper<ShadowAttributesType> attributesContainerWrapper = objectWrapper.findContainer(ShadowType.F_ATTRIBUTES);
    assertEquals("wrong number of values in " + attributesContainerWrapper, 1, attributesContainerWrapper.getValues().size());
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    WrapperTestUtil.assertWrapper(attributesContainerWrapper, "Attributes", ShadowType.F_ATTRIBUTES, attributesContainer, false, ItemStatus.NOT_CHANGED);
    PrismContainerValueWrapper<ShadowAttributesType> attributesContainerValueWrapper = attributesContainerWrapper.getValue();
    WrapperTestUtil.assertPropertyWrapperByName(attributesContainerValueWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_JACK_FULL_NAME);
    WrapperTestUtil.assertPropertyWrapperByName(attributesContainerValueWrapper, SchemaConstants.ICFS_NAME, USER_JACK_USERNAME);
    assertEquals("wrong number of items in " + attributesContainerWrapper, 18, attributesContainerValueWrapper.getItems().size());
    PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(ShadowType.F_ACTIVATION);
    assertEquals("wrong number of values in " + activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
    PrismContainerValueWrapper<ActivationType> activationContainerValueWrapper = activationContainerWrapper.getValues().iterator().next();
    WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ShadowType.activation"), UserType.F_ACTIVATION, shadow, ItemStatus.NOT_CHANGED);
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    assertEquals("Wrong attributes container wrapper readOnly", Boolean.FALSE, (Boolean) attributesContainerValueWrapper.isReadOnly());
    PrismPropertyWrapper<String> fullnameWrapper = attributesContainerValueWrapper.findProperty(ItemPath.create(dummyResourceCtl.getAttributeFullnameQName()));
    // Is this OK?
    assertEquals("Wrong attribute fullname readOnly", Boolean.FALSE, (Boolean) fullnameWrapper.isReadOnly());
    assertEquals("Wrong attribute fullname visible", Boolean.TRUE, (Boolean) fullnameWrapper.isVisible(attributesContainerValueWrapper, null));
    displayDumpable("fullname attribute definition", fullnameWrapper);
    assertEquals("Wrong attribute fullname definition.canRead", Boolean.TRUE, (Boolean) fullnameWrapper.canRead());
    assertEquals("Wrong attribute fullname definition.canAdd", Boolean.TRUE, (Boolean) fullnameWrapper.canAdd());
    assertEquals("Wrong attribute fullname definition.canModify", Boolean.TRUE, (Boolean) fullnameWrapper.canModify());
    // MID-3144
    if (fullnameWrapper.getDisplayOrder() == null || fullnameWrapper.getDisplayOrder() < 100 || fullnameWrapper.getDisplayOrder() > 400) {
        AssertJUnit.fail("Wrong fullname definition.displayOrder: " + fullnameWrapper.getDisplayOrder());
    }
    assertEquals("Wrong attribute fullname definition.displayName", "Full Name", fullnameWrapper.getDisplayName());
    ObjectDelta<ShadowType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-empty delta produced from wrapper: " + objectDelta, objectDelta.isEmpty());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ShadowWrapperFactoryImpl(com.evolveum.midpoint.gui.impl.factory.wrapper.ShadowWrapperFactoryImpl) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test112CreateWrapperUserNewman.

/**
 * Create wrapper for brand new user, but "fill in" some data.
 */
@Test
public void test112CreateWrapperUserNewman() throws Exception {
    PrismObject<UserType> user = getUserDefinition().instantiate();
    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.ADDED, context);
    PrismObjectValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_USERNAME));
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_GIVEN_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_GIVEN_NAME));
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_FAMILY_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_FAMILY_NAME));
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, UserType.F_EMPLOYEE_NUMBER, USER_NEWMAN_EMPLOYEE_NUMBER);
    WrapperTestUtil.fillInPropertyWrapper(modelServiceLocator, mainContainerValueWrapper, extensionPath(PIRACY_SHIP), USER_NEWMAN_SHIP);
    then();
    displayDumpable("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, getUserDefinition().instantiate(), ItemStatus.ADDED);
    assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
    WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), null, user, ItemStatus.ADDED);
    assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_USERNAME));
    WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
    WrapperTestUtil.assertPropertyWrapper(mainContainerValueWrapper, extensionPath(PIRACY_SHIP), USER_NEWMAN_SHIP);
    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());
    assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
    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);
    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, true);
    // empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, true);
    when();
    mainContainerValueWrapper.setShowEmpty(false);
    then();
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
    // not visible, because it is empty
    assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false);
    ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
    displayDumpable("Delta", objectDelta);
    assertTrue("non-add delta produced from wrapper: " + objectDelta, objectDelta.isAdd());
    PrismObject<UserType> objectToAdd = objectDelta.getObjectToAdd();
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_USERNAME));
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_GIVEN_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_GIVEN_NAME));
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_FAMILY_NAME, PrismTestUtil.createPolyString(USER_NEWMAN_FAMILY_NAME));
    PrismAsserts.assertPropertyValue(objectToAdd, UserType.F_EMPLOYEE_NUMBER, USER_NEWMAN_EMPLOYEE_NUMBER);
    PrismAsserts.assertPropertyValue(objectToAdd, extensionPath(PIRACY_SHIP), USER_NEWMAN_SHIP);
    PrismAsserts.assertItems(objectToAdd, 5);
}
Also used : 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) 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 3 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test242OrgScummBarAddTransform.

@Test
public void test242OrgScummBarAddTransform() throws Exception {
    PrismObject<OrgType> org = getObject(OrgType.class, ORG_SCUMM_BAR_OID);
    Task task = getTestTask();
    PrismObjectWrapper<OrgType> objectWrapper = createObjectWrapper(task, org, ItemStatus.NOT_CHANGED);
    displayDumpable("Wrapper before", objectWrapper);
    PrismContainerValueWrapper<OrgType> mainContainerValueWrapper = objectWrapper.getValue();
    PrismContainerWrapper<Containerable> transformContainerWrapper = mainContainerValueWrapper.findContainer(extensionPath(PIRACY_TRANSFORM));
    List<PrismContainerValueWrapper<Containerable>> transformValueWrappers = transformContainerWrapper.getValues();
    assertEquals("Unexpected number of transform value wrappers", 3, transformValueWrappers.size());
    ModelServiceLocator modelServiceLocator = getServiceLocator(task);
    WrapperContext context = new WrapperContext(task, task.getResult());
    context.setShowEmpty(true);
    context.setCreateIfEmpty(true);
    PrismContainerValueWrapper<Containerable> newContainerValueWrapper = modelServiceLocator.createValueWrapper(transformContainerWrapper, transformContainerWrapper.getItem().createNewValue(), ValueStatus.ADDED, context);
    transformContainerWrapper.getValues().add(newContainerValueWrapper);
    modifyTransformProp(newContainerValueWrapper, PIRACY_PATTERN, "D");
    modifyTransformProp(newContainerValueWrapper, PIRACY_REPLACEMENT, "Doubloon");
    displayDumpable("Wrapper after", objectWrapper);
    when();
    ObjectDelta<OrgType> objectDelta = objectWrapper.getObjectDelta();
    then();
    displayDumpable("Delta", objectDelta);
    ItemPath transformPath = ItemPath.create(ObjectType.F_EXTENSION, PIRACY_TRANSFORM);
    PrismAsserts.assertModifications(objectDelta, 1);
    ContainerDelta<Containerable> transformDelta = (ContainerDelta) objectDelta.getModifications().iterator().next();
    assertTrue("Wrong container delta path. Expected " + transformPath + " but was " + transformDelta.getPath(), transformDelta.getPath().equivalent(transformPath));
    PrismAsserts.assertNoDelete(transformDelta);
    PrismAsserts.assertNoReplace(transformDelta);
    Collection<PrismContainerValue<Containerable>> valuesToAdd = transformDelta.getValuesToAdd();
    assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
    PrismContainerValue<Containerable> containerValueToAdd = valuesToAdd.iterator().next();
    assertEquals("Unexpected number of items in value to add", 2, containerValueToAdd.size());
    PrismProperty<String> patternProp = (PrismProperty) containerValueToAdd.findItem(PIRACY_PATTERN);
    PrismAsserts.assertPropertyValue(patternProp, "D");
    PrismProperty<String> replacementProp = (PrismProperty) containerValueToAdd.findItem(PIRACY_REPLACEMENT);
    PrismAsserts.assertPropertyValue(replacementProp, "Doubloon");
    OperationResult result = task.getResult();
    executeChanges(objectDelta, null, task, result);
    assertSuccess(result);
    PrismObject<OrgType> orgAfter = getObject(OrgType.class, ORG_MINISTRY_OF_RUM_OID);
    display("Org after", orgAfter);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath) 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 4 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestWrapperDelta method createObjectWrapper.

private <O extends ObjectType> PrismObjectWrapper<O> createObjectWrapper(PrismObject<O> object, ItemStatus status, WrapperContext context) throws Exception {
    ModelServiceLocator locator = getServiceLocator(context.getTask());
    PrismObjectWrapperFactory<O> objectFactory = locator.findObjectWrapperFactory(object.getDefinition());
    return objectFactory.createObjectWrapper(object, status, context);
}
Also used : ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator)

Example 5 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestWrapperDelta method test101modifyUserWeapon.

@Test
public void test101modifyUserWeapon() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
    WrapperContext ctx = new WrapperContext(task, result);
    PrismObjectWrapper<UserType> objectWrapper = createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
    PrismPropertyWrapper<String> weapon = objectWrapper.findProperty(ItemPath.create(UserType.F_EXTENSION, PIRACY_WEAPON));
    for (PrismPropertyValueWrapper<String> valueWrapper : weapon.getValues()) {
        valueWrapper.setRealValue(null);
    }
    ModelServiceLocator locator = getServiceLocator(task);
    PrismPropertyValueWrapper<String> newValue = locator.createValueWrapper(weapon, new PrismPropertyValueImpl<>("revolver"), ValueStatus.ADDED, ctx);
    weapon.getValues().add(newValue);
    ObjectDelta<UserType> elaineDelta = objectWrapper.getObjectDelta();
    assertModificationsSize(elaineDelta, 1);
    assertModification(elaineDelta, ItemPath.create(UserType.F_EXTENSION, PIRACY_WEAPON), ModificationTypeType.ADD, "revolver");
    assertModification(elaineDelta, ItemPath.create(UserType.F_EXTENSION, PIRACY_WEAPON), ModificationTypeType.DELETE, "pistol", "mouth");
    executeChanges(elaineDelta, null, task, result);
    PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
    logger.info("ELAINE AFTER: {}", userElaineAfter.debugDump());
    UserAsserter.forUser(userElaineAfter).extension().assertPropertyValuesEqual(PIRACY_WEAPON, "revolver");
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ModelServiceLocator (com.evolveum.midpoint.gui.api.util.ModelServiceLocator)12 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 Task (com.evolveum.midpoint.task.api.Task)9 AbstractInitializedGuiIntegrationTest (com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Test (org.testng.annotations.Test)8 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ItemStatus (com.evolveum.midpoint.gui.api.prism.ItemStatus)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 QName (javax.xml.namespace.QName)3 PrismObjectWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper)2 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)1 PrismValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper)1 ShadowWrapperFactoryImpl (com.evolveum.midpoint.gui.impl.factory.wrapper.ShadowWrapperFactoryImpl)1 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)1 UniformItemPath (com.evolveum.midpoint.prism.path.UniformItemPath)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 ValueStatus (com.evolveum.midpoint.web.component.prism.ValueStatus)1