use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestParseMappingConst method testParseSerialize.
@Test
public void testParseSerialize() throws Exception {
displayTestTitle("testParseSerialize");
PrismContext prismContext = getPrismContext();
PrismParser parser = prismContext.parserFor(getFile());
PrismPropertyValue<MappingType> mappingPval = parser.parseItemValue();
System.out.println("\nmappingPval:\n" + mappingPval.debugDump(1));
PrismSerializer<RootXNode> xserializer = prismContext.xnodeSerializer();
RootXNode xnode = xserializer.root(new QName("dummy")).serialize(mappingPval);
System.out.println("\nSerialized xnode:\n" + xnode.debugDump(1));
MapXNode xexpression = (MapXNode) ((MapXNode) xnode.getSubnode()).get(new QName("expression"));
ListXNode xconstList = (ListXNode) xexpression.get(new QName("const"));
XNode xconst = xconstList.get(0);
if (!(xconst instanceof PrimitiveXNode<?>)) {
AssertJUnit.fail("const is not primitive: " + xconst);
}
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestSchemaSanity method testRoleDefinition.
@Test
public void testRoleDefinition() {
System.out.println("===[ testRoleDefinition ]===");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
// WHEN
PrismObjectDefinition<RoleType> roleDefinition = schemaRegistry.findObjectDefinitionByElementName(new QName(SchemaConstantsGenerated.NS_COMMON, "role"));
// THEN
assertNotNull("No role definition", roleDefinition);
System.out.println("Role definition:");
System.out.println(roleDefinition.debugDump());
PrismObjectDefinition<RoleType> roleDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(RoleType.class);
assertTrue("Different role def", roleDefinition == roleDefinitionByClass);
assertEquals("Wrong compile-time class in role definition", RoleType.class, roleDefinition.getCompileTimeClass());
PrismAsserts.assertPropertyDefinition(roleDefinition, ObjectType.F_NAME, PolyStringType.COMPLEX_TYPE, 0, 1);
PrismAsserts.assertItemDefinitionDisplayName(roleDefinition, ObjectType.F_NAME, "ObjectType.name");
PrismAsserts.assertItemDefinitionDisplayOrder(roleDefinition, ObjectType.F_NAME, 0);
PrismAsserts.assertPropertyDefinition(roleDefinition, ObjectType.F_DESCRIPTION, DOMUtil.XSD_STRING, 0, 1);
PrismAsserts.assertItemDefinitionDisplayName(roleDefinition, ObjectType.F_DESCRIPTION, "ObjectType.description");
PrismAsserts.assertItemDefinitionDisplayOrder(roleDefinition, ObjectType.F_DESCRIPTION, 10);
PrismAsserts.assertPropertyDefinition(roleDefinition, RoleType.F_REQUESTABLE, DOMUtil.XSD_BOOLEAN, 0, 1);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestSchemaSanity method testExtensionSchema.
/**
* Extension schema should be loaded from src/test/resources/schema during test initialization.
*/
@Test
public void testExtensionSchema() {
System.out.println("===[ testExtensionSchema ]===");
// WHEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
assertNotNull("No prism context", prismContext);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
assertNotNull("No schema registry in context", schemaRegistry);
PrismSchema extensionSchema = schemaRegistry.findSchemaByNamespace(SchemaTestConstants.NS_EXTENSION);
assertNotNull("No extension schema", extensionSchema);
System.out.println("Extension schema:");
System.out.println(extensionSchema.debugDump());
PrismPropertyDefinition locationsProperty = extensionSchema.findPropertyDefinitionByElementName(EXTENSION_LOCATIONS_ELEMENT);
PrismAsserts.assertDefinition(locationsProperty, EXTENSION_LOCATIONS_ELEMENT, EXTENSION_LOCATIONS_TYPE, 0, -1);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestParsePasswordPolicy method testParsePolicyRoundtrip.
@Test
public void testParsePolicyRoundtrip() throws Exception {
System.out.println("===[ testParsePolicyRoundtrip ]===");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
PrismObject<ValuePolicyType> policy = prismContext.parseObject(FILE);
System.out.println("Parsed policy:");
System.out.println(policy.debugDump());
assertPolicy(policy);
// SERIALIZE
String serializedPolicy = prismContext.serializeObjectToString(policy, PrismContext.LANG_XML);
System.out.println("serialized policy:");
System.out.println(serializedPolicy);
// RE-PARSE
PrismObject<ValuePolicyType> reparsedPolicy = prismContext.parseObject(serializedPolicy);
System.out.println("Re-parsed policy:");
System.out.println(reparsedPolicy.debugDump());
// Cannot assert here. It will cause parsing of some of the raw values and diff will fail
assertPolicy(reparsedPolicy);
ObjectDelta<ValuePolicyType> objectDelta = policy.diff(reparsedPolicy);
System.out.println("Delta:");
System.out.println(objectDelta.debugDump());
assertTrue("Delta is not empty", objectDelta.isEmpty());
PrismAsserts.assertEquivalent("Policy re-parsed equivalence", policy, reparsedPolicy);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class PageDebugView method loadObject.
private ObjectViewDto loadObject() {
StringValue objectOid = getPageParameters().get(PARAM_OBJECT_ID);
if (objectOid == null || StringUtils.isEmpty(objectOid.toString())) {
getSession().error(getString("pageDebugView.message.oidNotDefined"));
throw new RestartResponseException(PageDebugList.class);
}
Task task = createSimpleTask(OPERATION_LOAD_OBJECT);
//todo is this result != null ?
OperationResult result = task.getResult();
ObjectViewDto dto = null;
try {
MidPointApplication application = PageDebugView.this.getMidpointApplication();
GetOperationOptions rootOptions = GetOperationOptions.createRaw();
rootOptions.setResolveNames(true);
rootOptions.setTolerateRawData(true);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(rootOptions);
// FIXME: ObjectType.class will not work well here. We need more specific type.
//todo on page debug list create page params, put there oid and class for object type and send that to this page....read it here
Class type = ObjectType.class;
StringValue objectType = getPageParameters().get(PARAM_OBJECT_TYPE);
if (objectType != null && StringUtils.isNotBlank(objectType.toString())) {
type = getPrismContext().getSchemaRegistry().determineCompileTimeClass(new QName(SchemaConstantsGenerated.NS_COMMON, objectType.toString()));
}
// TODO make this configurable (or at least do not show campaign cases in production)
if (UserType.class.isAssignableFrom(type)) {
options.add(SelectorOptions.create(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE)));
}
if (LookupTableType.class.isAssignableFrom(type)) {
options.add(SelectorOptions.create(LookupTableType.F_ROW, GetOperationOptions.createRetrieve(new RelationalValueSearchQuery(ObjectPaging.createPaging(PrismConstants.T_ID, OrderDirection.ASCENDING)))));
}
if (AccessCertificationCampaignType.class.isAssignableFrom(type)) {
options.add(SelectorOptions.create(AccessCertificationCampaignType.F_CASE, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE)));
}
PrismObject<ObjectType> object = getModelService().getObject(type, objectOid.toString(), options, task, result);
PrismContext context = application.getPrismContext();
String lex = context.serializerFor(dataLanguage).serialize(object);
dto = new ObjectViewDto(object.getOid(), WebComponentUtil.getName(object), object, lex);
result.recomputeStatus();
} catch (Exception ex) {
result.recordFatalError("Couldn't load object.", ex);
}
if (dto == null) {
showResult(result);
throw new RestartResponseException(PageDebugList.class);
}
showResult(result, false);
if (!WebComponentUtil.isSuccessOrHandledErrorOrWarning(result)) {
showResult(result, false);
throw new RestartResponseException(PageDebugList.class);
}
return dto;
}
Aggregations