use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.
the class TestWrapperDelta method test310modifySystemConfigurationAddCollectionView.
@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<GuiObjectListViewType> collections = objectWrapper.findContainer(guiObjectViewPath);
// GIVEN
PrismContainerValue<GuiObjectListViewType> newCollection = collections.getItem().createNewValue();
ctx.setShowEmpty(true);
PrismContainerValueWrapper<GuiObjectListViewType> newCollectionValueWrapper = locator.createValueWrapper(collections, newCollection, ValueStatus.ADDED, ctx);
collections.getValues().add(newCollectionValueWrapper);
PrismPropertyWrapper<QName> type = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_TYPE);
type.getValue().setRealValue(new QName("RoleType"));
PrismPropertyWrapper<String> identifier = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_IDENTIFIER);
identifier.getValue().setRealValue("my-roles-collection");
// WHEN
ObjectDelta<SystemConfigurationType> 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("Unexpected empty admin gui configuration.", adminGuiConfig);
GuiObjectListViewsType collectionViews = adminGuiConfig.getObjectCollectionViews();
assertNotNull("Unexpected empty gui object 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 equals to RoleType", RoleType.COMPLEX_TYPE.equals(myRolesCollection.getType()));
assertTrue("c:RoleType should match RoleType", QNameUtil.match(RoleType.COMPLEX_TYPE, myRolesCollection.getType()));
}
use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.
the class TestWrapperDelta method test111modifyUserAssignment.
@Test
public void test111modifyUserAssignment() 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);
PrismContainerWrapper<AssignmentType> assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("unexpected null assignment wrapper", assignment);
assertEquals("Unexpected values for assignment " + assignment.getValues().size(), 1, assignment.getValues().size());
PrismContainerValueWrapper<AssignmentType> assignmentValue = assignment.getValues().iterator().next();
PrismContainerWrapper<ResourceAttributeDefinitionType> resourceAttrDefWrapper = assignmentValue.findContainer(ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE));
assertNotNull("unexpected null assignment wrapper", resourceAttrDefWrapper);
assertEquals("Unexpected values for assignment " + resourceAttrDefWrapper.getValues().size(), 0, resourceAttrDefWrapper.getValues().size());
ModelServiceLocator locator = getServiceLocator(task);
PrismContainerValue<ResourceAttributeDefinitionType> newAttribute = resourceAttrDefWrapper.getItem().createNewValue();
PrismContainerValueWrapper<ResourceAttributeDefinitionType> resourceAttrDefValueWrapper = locator.createValueWrapper(resourceAttrDefWrapper, newAttribute, ValueStatus.ADDED, ctx);
resourceAttrDefWrapper.getValues().add(resourceAttrDefValueWrapper);
PrismPropertyWrapper<ItemPathType> attributeRefWrapper = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_REF);
attributeRefWrapper.getValue().setRealValue(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
PrismPropertyWrapper<QName> matchingRule = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_MATCHING_RULE);
matchingRule.getValue().setRealValue(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
PrismContainerWrapper<MappingType> outbound = resourceAttrDefValueWrapper.findContainer(ResourceAttributeDefinitionType.F_OUTBOUND);
PrismContainerValueWrapper<MappingType> mapping = outbound.getValue();
MappingType mappingType = mapping.getRealValue();
mappingType.setExpression(createAsIsExpression());
ObjectDelta<UserType> delta = objectWrapper.getObjectDelta();
assertModificationsSize(delta, 1);
logger.info("Attr delta: {}", delta.debugDump());
ResourceAttributeDefinitionType expectedvalue = new ResourceAttributeDefinitionType(locator.getPrismContext());
expectedvalue.setRef(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
expectedvalue.setMatchingRule(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
MappingType expectedMapping = new MappingType();
expectedMapping.setExpression(createAsIsExpression());
expectedvalue.setOutbound(expectedMapping);
assertModification(delta, resourceAttrDefValueWrapper.getPath(), ModificationTypeType.ADD, expectedvalue);
executeChanges(delta, executeOptions().raw(), task, result);
display(result);
assertSuccess(result);
PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
PrismContainer<AssignmentType> assignmentAfter = userElaineAfter.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("Unexpected null assignment container for " + userElaineAfter, assignmentAfter);
assertEquals("Unexpected number of assignments, " + assignmentAfter.debugDump(), 1, assignmentAfter.getValues().size());
PrismContainerValue<AssignmentType> assignmentTypeAfter = assignmentAfter.getValues().iterator().next();
AssignmentType expected = new AssignmentType(locator.getPrismContext());
ConstructionType constructionType = new ConstructionType(locator.getPrismContext());
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(resourceDummy.getOid(), ObjectTypes.RESOURCE);
ref.setRelation(SchemaConstants.ORG_DEFAULT);
constructionType.setResourceRef(ref);
constructionType.setKind(ShadowKindType.ACCOUNT);
constructionType.setIntent("default");
constructionType.getAttribute().add(expectedvalue);
expected.setConstruction(constructionType);
ActivationType activationType = new ActivationType(locator.getPrismContext());
activationType.setEffectiveStatus(ActivationStatusType.ENABLED);
expected.setActivation(activationType);
// TODO assertions after
}
use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.
the class TestWrapperDelta method createDummyResourceAssignment.
private PrismContainerValue<AssignmentType> createDummyResourceAssignment(PrismObjectWrapper<UserType> objectWrapper, int existingAssignments, Task task, OperationResult result) throws Exception {
PrismContainerWrapper<AssignmentType> assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("unexpected null assignment wrapper", assignment);
assertEquals("Unexpected values for assignment " + assignment.getValues().size(), existingAssignments, assignment.getValues().size());
ModelServiceLocator locator = getServiceLocator(task);
PrismContainerValue<AssignmentType> newAssignment = assignment.getItem().createNewValue();
AssignmentType newAssignmentType = newAssignment.asContainerable();
ConstructionType constructionType = new ConstructionType(locator.getPrismContext());
constructionType.setResourceRef(ObjectTypeUtil.createObjectRef(resourceDummy, locator.getPrismContext()));
constructionType.setKind(ShadowKindType.ACCOUNT);
constructionType.setIntent("default");
newAssignmentType.setConstruction(constructionType);
PrismContainerValue<AssignmentType> newAssignmentClone = newAssignment.clone();
WrapperContext ctx = new WrapperContext(task, result);
PrismContainerValueWrapper vw = locator.createValueWrapper(assignment, newAssignment, ValueStatus.ADDED, ctx);
assignment.getValues().add(vw);
return newAssignmentClone;
}
use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.
the class AbstractGuiIntegrationTest method getServiceLocator.
protected ModelServiceLocator getServiceLocator(final Task pageTask) {
return new ModelServiceLocator() {
@Override
public ModelService getModelService() {
return modelService;
}
@Override
public ModelInteractionService getModelInteractionService() {
return modelInteractionService;
}
@Override
public DashboardService getDashboardService() {
return dashboardService;
}
@Override
public Task createSimpleTask(String operationName) {
MidPointPrincipal user = AuthUtil.getPrincipalUser();
if (user == null) {
throw new IllegalStateException("No authenticated user");
}
return WebModelServiceUtils.createSimpleTask(operationName, SchemaConstants.CHANNEL_USER_URI, user.getFocus().asPrismObject(), taskManager);
}
@Override
public PrismContext getPrismContext() {
return prismContext;
}
@Override
public SecurityEnforcer getSecurityEnforcer() {
return securityEnforcer;
}
@Override
public SecurityContextManager getSecurityContextManager() {
return securityContextManager;
}
@NotNull
@Override
public CompiledGuiProfile getCompiledGuiProfile() {
Task task = createSimpleTask("getCompiledGuiProfile");
try {
return getModelInteractionService().getCompiledGuiProfile(task, task.getResult());
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new SystemException(e.getMessage(), e);
}
}
@Override
public Task getPageTask() {
return pageTask;
}
@Override
public ExpressionFactory getExpressionFactory() {
return expressionFactory;
}
@Override
public LocalizationService getLocalizationService() {
return localizationService;
}
@Override
public Locale getLocale() {
return Locale.US;
}
@Override
public GuiComponentRegistry getRegistry() {
return registry;
}
@Override
public <O extends ObjectType> PrismObjectWrapperFactory<O> findObjectWrapperFactory(PrismObjectDefinition<O> objectDef) {
return registry.getObjectWrapperFactory(objectDef);
}
@Override
public <I extends Item, IW extends ItemWrapper> IW createItemWrapper(I item, ItemStatus status, WrapperContext ctx) throws SchemaException {
ItemWrapperFactory<IW, ?, ?> factory = registry.findWrapperFactory(item.getDefinition(), null);
ctx.setCreateIfEmpty(true);
return factory.createWrapper(null, item, status, ctx);
}
@Override
public <IW extends ItemWrapper, VW extends PrismValueWrapper, PV extends PrismValue> VW createValueWrapper(IW parentWrapper, PV newValue, ValueStatus status, WrapperContext context) throws SchemaException {
ItemWrapperFactory<IW, VW, PV> factory = registry.findWrapperFactory(parentWrapper, null);
return factory.createValueWrapper(parentWrapper, newValue, status, context);
}
@Override
public MidpointFormValidatorRegistry getFormValidatorRegistry() {
return null;
}
@Override
public AdminGuiConfigurationMergeManager getAdminGuiConfigurationMergeManager() {
return null;
}
@Override
public CorrelationService getCorrelationService() {
return null;
}
};
}
use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator 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());
}
Aggregations