use of com.evolveum.midpoint.prism.impl.schema.PrismSchemaImpl in project midpoint by Evolveum.
the class SchemaProcessorTest method testRoundTripGeneric.
@Test
public void testRoundTripGeneric() throws SchemaException {
// GIVEN
PrismSchemaImpl schema = new PrismSchemaImpl(MidPointConstants.NS_RI);
// Ordinary property
schema.createPropertyDefinition("number1", DOMUtil.XSD_INT);
// Property container
MutablePrismContainerDefinition<?> containerDefinition = schema.createContainerDefinition("ContainerType");
// ... in it ordinary property
containerDefinition.createPropertyDefinition("login", DOMUtil.XSD_STRING);
// ... and local property with a type from another schema
containerDefinition.createPropertyDefinition("password", ProtectedStringType.COMPLEX_TYPE);
// ... property reference
containerDefinition.createPropertyDefinition(SchemaConstants.C_CREDENTIALS, CredentialsType.COMPLEX_TYPE);
// ... read-only int property
PrismPropertyDefinition counterProperty = containerDefinition.createPropertyDefinition("counter", DOMUtil.XSD_INT);
counterProperty.toMutable().toMutable().setReadOnly();
System.out.println("Generic schema before serializing to XSD: ");
System.out.println(schema.debugDump());
System.out.println();
// WHEN
Document xsd = schema.serializeToXsd();
String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
System.out.println("Generic schema after serializing to XSD: ");
System.out.println(stringXmlSchema);
System.out.println();
Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext());
System.out.println("Generic schema after parsing from XSD: ");
System.out.println(newSchema.debugDump());
System.out.println();
// THEN
PrismPropertyDefinition number1def = newSchema.findItemDefinitionByElementName(new ItemName(MidPointConstants.NS_RI, "number1"), PrismPropertyDefinition.class);
assertEquals(new ItemName(MidPointConstants.NS_RI, "number1"), number1def.getItemName());
assertEquals(DOMUtil.XSD_INT, number1def.getTypeName());
PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new ItemName(MidPointConstants.NS_RI, "ContainerType"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "ContainerType"), newContainerDef.getTypeName());
PrismPropertyDefinition loginDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "login"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "login"), loginDef.getItemName());
assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
assertTrue("Read flag is wrong", loginDef.canRead());
assertTrue("Create flag is wrong", loginDef.canAdd());
assertTrue("Update flag is wrong", loginDef.canModify());
PrismPropertyDefinition passwdDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "password"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "password"), passwdDef.getItemName());
assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
PrismPropertyDefinition credDef = newContainerDef.findPropertyDefinition(new ItemName(SchemaConstants.NS_C, "credentials"));
assertEquals(new ItemName(SchemaConstants.NS_C, "credentials"), credDef.getItemName());
assertEquals(new ItemName(SchemaConstants.NS_C, "CredentialsType"), credDef.getTypeName());
PrismPropertyDefinition countDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "counter"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "counter"), countDef.getItemName());
assertEquals(DOMUtil.XSD_INT, countDef.getTypeName());
assertTrue("Read flag is wrong", countDef.canRead());
assertFalse("Create flag is wrong", countDef.canAdd());
assertFalse("Update flag is wrong", countDef.canModify());
}
Aggregations