use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestRefinedSchema method testProtectedAccount.
@Test
public void testProtectedAccount() throws JAXBException, SchemaException, SAXException, IOException {
System.out.println("\n===[ testProtectedAccount ]===\n");
// GIVEN
PrismContext prismContext = createInitializedPrismContext();
PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
ResourceType resourceType = resource.asObjectable();
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
assertNotNull("Refined schema is null", rSchema);
assertFalse("No account definitions", rSchema.getRefinedDefinitions(ShadowKindType.ACCOUNT).isEmpty());
RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
// WHEN
Collection<ResourceObjectPattern> protectedAccounts = rAccount.getProtectedObjectPatterns();
// THEN
assertNotNull("Null protectedAccounts", protectedAccounts);
assertFalse("Empty protectedAccounts", protectedAccounts.isEmpty());
assertEquals("Unexpected number of protectedAccounts", 2, protectedAccounts.size());
Iterator<ResourceObjectPattern> iterator = protectedAccounts.iterator();
assertDeprecatedProtectedAccount("first protected account", iterator.next(), "uid=idm,ou=Administrators,dc=example,dc=com", rAccount);
assertDeprecatedProtectedAccount("second protected account", iterator.next(), "uid=root,ou=Administrators,dc=example,dc=com", rAccount);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestRefinedSchema method testParseAccount.
@Test
public void testParseAccount() throws JAXBException, SchemaException, SAXException, IOException {
System.out.println("\n===[ testParseAccount ]===\n");
// GIVEN
PrismContext prismContext = createInitializedPrismContext();
PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
ResourceType resourceType = resource.asObjectable();
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
RefinedObjectClassDefinition defaultAccountDefinition = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
assertNotNull("No refined default account definition in " + rSchema, defaultAccountDefinition);
PrismObject<ShadowType> accObject = prismContext.parseObject(new File(TEST_DIR_NAME, "account-jack.xml"));
// WHEN
PrismObjectDefinition<ShadowType> objectDefinition = defaultAccountDefinition.getObjectDefinition();
System.out.println("Refined account definition:");
System.out.println(objectDefinition.debugDump());
accObject.applyDefinition(objectDefinition);
// THEN
System.out.println("Parsed account:");
System.out.println(accObject.debugDump());
assertAccountShadow(accObject, resource, prismContext);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestRefinedSchema method testParseFromResourceComplex.
@Test
public void testParseFromResourceComplex() throws Exception {
final String TEST_NAME = "testParseFromResourceComplex";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
PrismContext prismContext = createInitializedPrismContext();
PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
ResourceType resourceType = resource.asObjectable();
// WHEN
TestUtil.displayWhen(TEST_NAME);
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
// THEN
TestUtil.displayThen(TEST_NAME);
assertNotNull("Refined schema is null", rSchema);
System.out.println("Refined schema");
System.out.println(rSchema.debugDump());
assertRefinedSchema(resourceType, rSchema, null, LayerType.MODEL, true);
assertLayerRefinedSchema(resourceType, rSchema, LayerType.SCHEMA, LayerType.SCHEMA, true);
assertLayerRefinedSchema(resourceType, rSchema, LayerType.MODEL, LayerType.MODEL, true);
assertLayerRefinedSchema(resourceType, rSchema, LayerType.PRESENTATION, LayerType.PRESENTATION, true);
RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
RefinedAttributeDefinition userPasswordAttribute = rAccount.findAttributeDefinition("userPassword");
assertNotNull("No userPassword attribute", userPasswordAttribute);
assertTrue("userPassword not ignored", userPasswordAttribute.isIgnored());
}
use of com.evolveum.midpoint.prism.PrismContext 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.PrismContext in project midpoint by Evolveum.
the class TestParseFilter method testParseFilterFile.
@Test
public void testParseFilterFile() throws Exception {
System.out.println("===[ testParseFilterFile ]===");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN
SearchFilterType filter = prismContext.parserFor(FILTER_FILE).parseRealValue(SearchFilterType.class);
// THEN
System.out.println("Parsed filter:");
System.out.println(filter.debugDump());
String serialized = PrismTestUtil.serializeJaxbElementToString(new JAXBElement<SearchFilterType>(new QName(SchemaConstants.NS_QUERY, "filter"), SearchFilterType.class, filter));
System.out.println("JAXB serialization result:\n" + serialized);
// WHEN2
SearchFilterType filter2 = prismContext.parserFor(serialized).parseRealValue(SearchFilterType.class);
System.out.println("Reparsed filter:");
System.out.println(filter2.debugDump());
// THEN2
assertEquals("Parsed and serialized+parsed filters do not match", filter, filter2);
}
Aggregations