use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType in project midpoint by Evolveum.
the class TestJaxbConstruction method testUserConstructionReverse.
/**
* Similar to testUserConstruction, but some operations are done in a different order
* e.g. assignment is filled in first then set to the user.
*/
@Test
public void testUserConstructionReverse() throws JAXBException, SchemaException {
System.out.println("\n\n ===[ testUserConstructionReverse ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
UserType userType = new UserType(prismContext);
PrismObject<UserType> user = userType.asPrismObject();
assertNotNull("No object definition after adopt", user.getDefinition());
// Extension
ExtensionType extension = new ExtensionType();
userType.setExtension(extension);
user.checkConsistence();
PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "user extension after setExtension");
checkExtension(extension, "user extension after setExtension");
AssignmentType assignmentType = new AssignmentType(prismContext);
ExtensionType assignmentExtension = new ExtensionType();
assignmentType.setExtension(assignmentExtension);
PrismContainerValue<ExtensionType> assignmentExtensionValueFromJaxb = assignmentExtension.asPrismContainerValue();
PrismProperty<Integer> intProperty = assignmentExtensionValueFromJaxb.findOrCreateProperty(EXTENSION_INT_TYPE_ELEMENT);
intProperty.setRealValue(15);
PrismProperty<String> stringProperty = assignmentExtensionValueFromJaxb.findOrCreateItem(EXTENSION_STRING_TYPE_ELEMENT, PrismProperty.class);
stringProperty.setRealValue("fifteen men on a dead man chest");
// Adding assignemnt to the user should cause application of definitions
userType.getAssignment().add(assignmentType);
PrismAsserts.assertDefinition(assignmentType.asPrismContainerValue().getParent().getDefinition(), UserType.F_ASSIGNMENT, AssignmentType.COMPLEX_TYPE, 0, -1);
PrismAsserts.assertDefinition(assignmentExtensionValueFromJaxb.getParent().getDefinition(), AssignmentType.F_EXTENSION, ExtensionType.COMPLEX_TYPE, 0, 1);
assertTrue("assignment extension definition is not runtime", assignmentExtensionValueFromJaxb.getParent().getDefinition().isRuntimeSchema());
assertTrue("assignment extension definition is not dynamic", assignmentExtensionValueFromJaxb.getParent().getDefinition().isDynamic());
PrismAsserts.assertDefinition(intProperty.getDefinition(), EXTENSION_INT_TYPE_ELEMENT, DOMUtil.XSD_INT, 0, -1);
PrismAsserts.assertDefinition(stringProperty.getDefinition(), EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1);
user.assertDefinitions();
user.checkConsistence();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType in project midpoint by Evolveum.
the class TestJaxbConstruction method testExtensionTypeConstruction.
@Test
public void testExtensionTypeConstruction() throws Exception {
System.out.println("\n\n ===[ testExtensionTypeConstruction ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
GenericObjectType object = new GenericObjectType();
prismContext.adopt(object.asPrismObject(), GenericObjectType.class);
ExtensionType extension = new ExtensionType();
object.setExtension(extension);
PrismContainerValue extValue = extension.asPrismContainerValue();
assertNotNull("No extension definition", extValue.getParent().getDefinition());
// WHEN
Item item = extValue.findOrCreateItem(SchemaTestConstants.EXTENSION_STRING_TYPE_ELEMENT);
// THEN
assertNotNull(item);
object.asPrismObject().checkConsistence();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType in project midpoint by Evolveum.
the class TestJaxbConstruction method testGenericConstruction.
@Test
public void testGenericConstruction() throws JAXBException, SchemaException {
System.out.println("\n\n ===[ testGenericConstruction ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
GenericObjectType genericType = new GenericObjectType();
prismContext.adopt(genericType);
PrismObject<GenericObjectType> generic = genericType.asPrismObject();
assertNotNull("No object definition after adopt", generic.getDefinition());
// WHEN
ExtensionType extension = new ExtensionType();
genericType.setExtension(extension);
// THEN
generic.checkConsistence();
PrismContainer<Containerable> extensionContainer = generic.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "user extension after setExtension");
checkExtension(extension, "user extension after setExtension");
generic.checkConsistence();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType in project midpoint by Evolveum.
the class TestJaxbConstruction method testResourceConstruction.
@Test
public void testResourceConstruction() throws Exception {
System.out.println("\n\n ===[ testResourceConstruction ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
ResourceType resourceType = new ResourceType();
prismContext.adopt(resourceType);
PrismObject<ResourceType> resource = resourceType.asPrismObject();
assertNotNull("No object definition after adopt", resource.getDefinition());
// name: PolyString
resourceType.setName(new PolyStringType("Môj risórs"));
PrismProperty<PolyString> fullNameProperty = resource.findProperty(ResourceType.F_NAME);
PolyString fullName = fullNameProperty.getRealValue();
assertEquals("Wrong name orig", "Môj risórs", fullName.getOrig());
assertEquals("Wrong name norm", "moj risors", fullName.getNorm());
// description: setting null value
resourceType.setDescription(null);
PrismProperty<String> descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
// description: setting null value
resourceType.setDescription("blah blah");
descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
// description: resetting null value
resourceType.setDescription(null);
descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
// Extension
ExtensionType extension = new ExtensionType();
resourceType.setExtension(extension);
resource.checkConsistence();
PrismContainer<Containerable> extensionContainer = resource.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "resource extension after setExtension");
checkExtension(extension, "resource extension after setExtension");
// Schema
XmlSchemaType xmlSchemaType = new XmlSchemaType();
CachingMetadataType cachingMetadata = new CachingMetadataType();
cachingMetadata.setSerialNumber("serial123");
xmlSchemaType.setCachingMetadata(cachingMetadata);
resourceType.setSchema(xmlSchemaType);
SchemaDefinitionType schemaDefinition = new SchemaDefinitionType();
Element xsdSchemaElement = DOMUtil.createElement(DOMUtil.XSD_SCHEMA_ELEMENT);
schemaDefinition.getAny().add(xsdSchemaElement);
xmlSchemaType.setDefinition(schemaDefinition);
PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
assertNotNull("No schema container", schemaContainer);
// TODO
// Schema: null
resourceType.setSchema(null);
schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
assertNull("Unexpected schema container", schemaContainer);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType in project midpoint by Evolveum.
the class TestJaxbConstruction method testUserConstruction.
@Test
public void testUserConstruction() throws JAXBException, SchemaException {
System.out.println("\n\n ===[ testUserConstruction ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
UserType userType = new UserType();
prismContext.adopt(userType);
PrismObject<UserType> user = userType.asPrismObject();
assertNotNull("No object definition after adopt", user.getDefinition());
SchemaTestUtil.assertUserDefinition(user.getDefinition());
// fullName: PolyString
userType.setFullName(new PolyStringType("Čučoriedka"));
PrismProperty<PolyString> fullNameProperty = user.findProperty(UserType.F_FULL_NAME);
PolyString fullName = fullNameProperty.getRealValue();
assertEquals("Wrong fullName orig", "Čučoriedka", fullName.getOrig());
assertEquals("Wrong fullName norm", "cucoriedka", fullName.getNorm());
// description: setting null value
userType.setDescription(null);
PrismProperty<String> descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
// description: setting null value
userType.setDescription("blah blah");
descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
// description: resetting null value
userType.setDescription(null);
descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
// Extension
ExtensionType extension = new ExtensionType();
userType.setExtension(extension);
user.checkConsistence();
PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "user extension after setExtension");
checkExtension(extension, "user extension after setExtension");
AssignmentType assignmentType = new AssignmentType();
userType.getAssignment().add(assignmentType);
user.checkConsistence();
user.assertDefinitions();
// Assignment
ExtensionType assignmentExtension = new ExtensionType();
assignmentType.setExtension(assignmentExtension);
user.assertDefinitions();
user.checkConsistence();
checkExtension(assignmentExtension, "assignment extension after setExtension");
user.checkConsistence();
user.assertDefinitions();
// accountRef/account
ObjectReferenceType accountRefType = new ObjectReferenceType();
accountRefType.setOid(USER_ACCOUNT_REF_1_OID);
MapXNode filterElement = createFilter();
SearchFilterType filter = new SearchFilterType();
filter.setFilterClauseXNode(filterElement);
accountRefType.setFilter(filter);
userType.getLinkRef().add(accountRefType);
assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID);
user.checkConsistence();
user.assertDefinitions();
PrismReference accountRef = user.findReference(UserType.F_LINK_REF);
assertEquals("1/ Wrong accountRef values", 1, accountRef.getValues().size());
PrismReferenceValue accountRefVal0 = accountRef.getValue(0);
SearchFilterType prismFilter = accountRefVal0.getFilter();
assertNotNull("Filter have not passed", prismFilter);
//assertTrue("Bad filter in reference", prismFilter instanceof EqualsFilter);
// assertEquals("Difference filter", filterElement, prismFilter);
ShadowType accountShadowType = new ShadowType();
prismContext.adopt(accountShadowType);
accountShadowType.setOid(USER_ACCOUNT_REF_1_OID);
userType.getLink().add(accountShadowType);
//value still should be only one... (reference was only resolved)
assertEquals("2/ Wrong accountRef values", 1, user.findReference(UserType.F_LINK_REF).getValues().size());
accountShadowType = new ShadowType();
prismContext.adopt(accountShadowType);
accountShadowType.setOid(USER_ACCOUNT_REF_2_OID);
userType.getLink().add(accountShadowType);
assertEquals("3/ Wrong accountRef values", 2, user.findReference(UserType.F_LINK_REF).getValues().size());
assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
user.checkConsistence();
user.assertDefinitions();
assertEquals("4/ Wrong accountRef values", 2, accountRef.getValues().size());
PrismAsserts.assertReferenceValues(accountRef, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
}
Aggregations