use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class SqaleRepoBaseTest method addExtensionValue.
// region extension support
@SafeVarargs
protected final <V> void addExtensionValue(Containerable extContainer, String itemName, V... values) throws SchemaException {
PrismContainerValue<?> pcv = extContainer.asPrismContainerValue();
ItemDefinition<?> itemDefinition = pcv.getDefinition().findItemDefinition(new ItemName(itemName));
assertThat(itemDefinition).withFailMessage("No definition found for item name '%s' in %s", itemName, pcv).isNotNull();
if (itemDefinition instanceof PrismReferenceDefinition) {
PrismReference ref = (PrismReference) itemDefinition.instantiate();
for (V value : values) {
ref.add(value instanceof PrismReferenceValue ? (PrismReferenceValue) value : ((Referencable) value).asReferenceValue());
}
pcv.add(ref);
} else {
// noinspection unchecked
PrismProperty<V> property = (PrismProperty<V>) itemDefinition.instantiate();
property.setRealValues(values);
pcv.add(property);
}
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class SchemaProcessorTest method testRoundTripResource.
@Test
public void testRoundTripResource() throws SchemaException {
// GIVEN
ResourceSchemaImpl schema = new ResourceSchemaImpl();
// Property container
ResourceObjectClassDefinitionImpl objectClassDef = (ResourceObjectClassDefinitionImpl) schema.createObjectClassDefinition(new QName(MidPointConstants.NS_RI, "AccountObjectClass"));
objectClassDef.setDefaultAccountDefinition(true);
objectClassDef.setNativeObjectClass("ACCOUNT");
// ... in it ordinary attribute - an identifier
ResourceAttributeDefinition<?> xLoginDef = objectClassDef.createAttributeDefinition("login", DOMUtil.XSD_STRING, def -> def.setNativeAttributeName("LOGIN"));
objectClassDef.addPrimaryIdentifierName(xLoginDef.getItemName());
objectClassDef.setDisplayNameAttributeName(xLoginDef.getItemName());
// ... and local property with a type from another schema
objectClassDef.createAttributeDefinition("password", ProtectedStringType.COMPLEX_TYPE, def -> def.setNativeAttributeName("PASSWORD"));
// ... ignored attribute
objectClassDef.createAttributeDefinition("sep", DOMUtil.XSD_STRING, def -> def.setProcessing(ItemProcessing.IGNORE));
System.out.println("Resource 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("Resource schema after serializing to XSD: ");
System.out.println(stringXmlSchema);
System.out.println();
Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
ResourceSchema newSchema = ResourceSchemaParser.parse(DOMUtil.getFirstChildElement(parsedXsd), "serialized schema");
System.out.println("Resource schema after parsing from XSD: ");
System.out.println(newSchema.debugDump());
System.out.println();
// THEN
ResourceObjectClassDefinition newObjectClassDef = newSchema.findObjectClassDefinitionRequired(new ItemName(MidPointConstants.NS_RI, "AccountObjectClass"));
assertThat(newObjectClassDef.getTypeName()).isEqualTo(new ItemName(MidPointConstants.NS_RI, "AccountObjectClass"));
assertThat(newObjectClassDef.isDefaultAccountDefinition()).isTrue();
assertThat(newObjectClassDef.getNativeObjectClass()).isEqualTo("ACCOUNT");
assertThat(newObjectClassDef.getPrimaryIdentifiersNames()).containsExactly(xLoginDef.getItemName());
assertThat(newObjectClassDef.getDisplayNameAttributeName()).isEqualTo(xLoginDef.getItemName());
PrismPropertyDefinition<?> loginDef = newObjectClassDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "login"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "login"), loginDef.getItemName());
assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
assertFalse(loginDef.isIgnored());
PrismPropertyDefinition<?> passwdDef = newObjectClassDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "password"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "password"), passwdDef.getItemName());
assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
assertFalse(passwdDef.isIgnored());
PrismPropertyDefinition<?> sepDef = newObjectClassDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "sep"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "sep"), sepDef.getItemName());
assertEquals(DOMUtil.XSD_STRING, sepDef.getTypeName());
assertTrue(sepDef.isIgnored());
}
use of com.evolveum.midpoint.prism.path.ItemName 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());
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class RAnyConverterStaticTest method testAttributesDouble.
@Test
public void testAttributesDouble() throws Exception {
Session session = getFactory().openSession();
ItemName valueName = new ItemName(NS_FOO_RESOURCE, "uid");
ItemDefinition def = getDefinition(GenericObjectType.class, valueName);
AssertJUnit.assertNull(def);
Element value = createAttributeValue(valueName, "xsd:double", "123.1");
Object realValue = RAnyConverter.getRealRepoValue(def, value, prismContext);
AssertJUnit.assertEquals("123.1", realValue);
session.close();
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class RAnyConverterStaticTest method testAttributesString.
@Test
public void testAttributesString() throws Exception {
Session session = getFactory().openSession();
ItemName valueName = new ItemName(NS_FOO_RESOURCE, "uid");
ItemDefinition def = getDefinition(GenericObjectType.class, valueName);
AssertJUnit.assertNull(def);
Element value = createAttributeValue(valueName, "xsd:string", "some uid");
Object realValue = RAnyConverter.getRealRepoValue(def, value, prismContext);
AssertJUnit.assertEquals("some uid", realValue);
session.close();
}
Aggregations