use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class ConsistencyTest method test000Integrity.
/**
* Test integrity of the test setup.
*/
@Test
public void test000Integrity() throws Exception {
final String TEST_NAME = "test000Integrity";
TestUtil.displayTestTile(this, TEST_NAME);
assertNotNull(modelWeb);
assertNotNull(modelService);
assertNotNull(repositoryService);
assertTrue(isSystemInitialized());
assertNotNull(taskManager);
assertNotNull(prismContext);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
assertNotNull(schemaRegistry);
// This is defined in extra schema. So this effectively checks whether
// the extra schema was loaded
PrismPropertyDefinition shipStateDefinition = schemaRegistry.findPropertyDefinitionByElementName(MY_SHIP_STATE);
assertNotNull("No my:shipState definition", shipStateDefinition);
assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
assertNoRepoCache();
OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
// Check if OpenDJ resource was imported correctly
PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, result);
display("Imported OpenDJ resource (repository)", openDjResource);
AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
assertNoRepoCache();
String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class, ldapConnectorOid, null, result);
display("LDAP Connector: ", ldapConnector);
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class BasicValidatorTest method resource1Valid.
@Test
public void resource1Valid() throws Exception {
System.out.println("\n===[ resource1Valid ]=====");
OperationResult result = new OperationResult(this.getClass().getName() + ".resource1Valid");
EventHandler handler = new EventHandler() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
return EventResult.cont();
}
@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
System.out.println("Validating resorce:");
System.out.println(object.debugDump());
object.checkConsistence();
PrismContainer<?> extensionContainer = object.getExtension();
PrismProperty<Integer> menProp = extensionContainer.findProperty(new QName("http://myself.me/schemas/whatever", "menOnChest"));
assertNotNull("No men on a dead man chest!", menProp);
assertEquals("Wrong number of men on a dead man chest", (Integer) 15, menProp.getAnyRealValue());
PrismPropertyDefinition menPropDef = menProp.getDefinition();
assertNotNull("Men on a dead man chest NOT defined", menPropDef);
assertEquals("Wrong type for men on a dead man chest definition", DOMUtil.XSD_INT, menPropDef.getTypeName());
assertTrue("Men on a dead man chest definition not dynamic", menPropDef.isDynamic());
return EventResult.cont();
}
@Override
public void handleGlobalError(OperationResult currentResult) {
/* nothing */
}
};
validateFile("resource-1-valid.xml", handler, result);
AssertJUnit.assertTrue(result.isSuccess());
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class RawTypeUtil method getParsedItem.
public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
Item<IV, ID> subItem = null;
List<IV> parsedValues = new ArrayList<IV>();
for (RawType rawValue : values) {
if (itemDefinition == null && containerDef != null) {
itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
}
IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
if (parsed != null) {
parsedValues.add(parsed);
}
}
PrismContext prismContext = null;
if (containerDef != null) {
prismContext = containerDef.getPrismContext();
}
if (prismContext == null && itemDefinition != null) {
prismContext = itemDefinition.getPrismContext();
}
if (itemDefinition == null) {
PrismProperty property = new PrismProperty(elementQName, prismContext);
property.addAll(PrismValue.cloneCollection(parsedValues));
return property;
}
if (itemDefinition instanceof PrismPropertyDefinition<?>) {
// property
PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
property.add((PrismPropertyValue) val.clone());
}
subItem = (Item<IV, ID>) property;
} else if (itemDefinition instanceof PrismContainerDefinition<?>) {
PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
container.add((PrismContainerValue) val.clone());
}
subItem = (Item<IV, ID>) container;
} else if (itemDefinition instanceof PrismReferenceDefinition) {
// TODO
PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
for (IV val : parsedValues) {
PrismReferenceValue ref;
if (val instanceof PrismReferenceValue) {
ref = (PrismReferenceValue) val.clone();
} else if (val instanceof PrismContainerValue) {
// this is embedded (full) object
Containerable c = ((PrismContainerValue) val).asContainerable();
if (!(c instanceof Objectable)) {
throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
}
Objectable o = (Objectable) c;
ref = new PrismReferenceValue();
ref.setObject(o.asPrismObject());
} else {
throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
}
reference.merge(ref);
}
subItem = (Item<IV, ID>) reference;
} else {
throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
}
return subItem;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class PrismAsserts method assertPropertyDefinition.
public static void assertPropertyDefinition(PrismProperty property, QName type, int minOccurs, int maxOccurs, Boolean indexed) {
assertDefinition(property, type, minOccurs, maxOccurs);
PrismPropertyDefinition definition = property.getDefinition();
assert equals(indexed, definition.isIndexed()) : "Property should have indexed=" + indexed + ", but it has indexed=" + definition.isIndexed();
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinition in project midpoint by Evolveum.
the class PrismAsserts method assertPropertyDefinition.
public static void assertPropertyDefinition(PrismContainerDefinition<?> containerDef, QName propertyName, QName type, int minOccurs, int maxOccurs) {
PrismPropertyDefinition definition = containerDef.findPropertyDefinition(propertyName);
assertDefinition(definition, propertyName, type, minOccurs, maxOccurs);
}
Aggregations