Search in sources :

Example 31 with PrismContext

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);
    }
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PrismParser(com.evolveum.midpoint.prism.PrismParser) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) Test(org.testng.annotations.Test)

Example 32 with PrismContext

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);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 33 with PrismContext

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);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 34 with PrismContext

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);
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) PrismContext(com.evolveum.midpoint.prism.PrismContext) Test(org.testng.annotations.Test)

Example 35 with PrismContext

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;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) RestartResponseException(org.apache.wicket.RestartResponseException) StringValue(org.apache.wicket.util.string.StringValue) ObjectViewDto(com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto)

Aggregations

PrismContext (com.evolveum.midpoint.prism.PrismContext)104 Test (org.testng.annotations.Test)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 QName (javax.xml.namespace.QName)15 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)13 Task (com.evolveum.midpoint.task.api.Task)11 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)10 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 File (java.io.File)8 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)7 ArrayList (java.util.ArrayList)7 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)6 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 Protector (com.evolveum.midpoint.prism.crypto.Protector)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)5