Search in sources :

Example 21 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class AbstractImportTest method assertDummyResource.

private void assertDummyResource(PrismObject<ResourceType> resource, boolean fromRepo) {
    PrismContainer<Containerable> configurationPropertiesContainer = assertResource(resource, "Dummy Resource", RESOURCE_DUMMY_NAMESPACE, dummyConnector.getOid());
    PrismProperty<ProtectedStringType> guardedProperty = configurationPropertiesContainer.findProperty(new ItemName(CONNECTOR_DUMMY_NAMESPACE, "uselessGuardedString"));
    // The resource was pulled from the repository. Therefore it does not have the right schema here. We should proceed with caution
    // and inspect the DOM elements there
    assertNotNull("No uselessGuardedString property in configuration properties", guardedProperty);
    PrismPropertyValue<ProtectedStringType> guardedPVal = guardedProperty.getValue();
    if (fromRepo) {
        Object passwordRawElement = guardedPVal.getRawElement();
        if (!(passwordRawElement instanceof MapXNode)) {
            AssertJUnit.fail("Expected password value of type " + MapXNode.class + " but got " + passwordRawElement.getClass());
        }
        MapXNode passwordXNode = (MapXNode) passwordRawElement;
        assertTrue("uselessGuardedString was not encrypted (clearValue)", passwordXNode.get(new QName("clearValue")) == null);
        assertTrue("uselessGuardedString was not encrypted (no encryptedData)", passwordXNode.get(new QName("encryptedData")) != null);
    } else {
        ProtectedStringType psType = guardedPVal.getValue();
        assertNull("uselessGuardedString was not encrypted (clearValue)", psType.getClearValue());
        assertNotNull("uselessGuardedString was not encrypted (no EncryptedData)", psType.getEncryptedDataType());
    }
}
Also used : QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 22 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class ExpressionHandlerImplTest method testEvaluateExpression.

@Test
public void testEvaluateExpression() throws Exception {
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account.xml"));
    ShadowType accountType = account.asObjectable();
    PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(TEST_FOLDER_COMMON, "resource-dummy.xml"));
    ResourceType resourceType = resource.asObjectable();
    ObjectReferenceType resourceRef = new ObjectReferenceType();
    resourceRef.asReferenceValue().setObject(resource);
    accountType.setResourceRef(resourceRef);
    ObjectSynchronizationType synchronization = resourceType.getSynchronization().getObjectSynchronization().get(0);
    for (ConditionalSearchFilterType filter : synchronization.getCorrelation()) {
        MapXNode clauseXNode = filter.getFilterClauseXNode();
        // key = q:equal, value = map (path + expression)
        RootXNode expressionNode = ((MapXNode) clauseXNode.getSingleSubEntry("filter value").getValue()).getEntryAsRoot(new QName(SchemaConstants.NS_C, "expression"));
        ExpressionType expression = PrismTestUtil.getPrismContext().parserFor(expressionNode).parseRealValue(ExpressionType.class);
        logger.debug("Expression: {}", SchemaDebugUtil.prettyPrint(expression));
        OperationResult result = createOperationResult();
        String name = expressionHandler.evaluateExpression(accountType, expression, "test expression", null, result);
        logger.info(result.debugDump());
        assertEquals("Wrong expression result", "hbarbossa", name);
    }
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) File(java.io.File) Test(org.testng.annotations.Test) AbstractSpringTest(com.evolveum.midpoint.test.util.AbstractSpringTest)

Example 23 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class TestParseResource method assertResourceJaxb.

private void assertResourceJaxb(ResourceType resourceType, boolean isSimple) throws SchemaException {
    assertEquals("Wrong oid (JAXB)", TestConstants.RESOURCE_OID, resourceType.getOid());
    assertEquals("Wrong name (JAXB)", PrismTestUtil.createPolyStringType("Embedded Test OpenDJ"), resourceType.getName());
    assertEquals("Wrong namespace (JAXB)", MidPointConstants.NS_RI, MidPointConstants.NS_RI);
    ObjectReferenceType connectorRef = resourceType.getConnectorRef();
    assertNotNull("No connectorRef (JAXB)", connectorRef);
    assertEquals("Wrong type in connectorRef (JAXB)", ConnectorType.COMPLEX_TYPE, connectorRef.getType());
    SearchFilterType filter = connectorRef.getFilter();
    assertNotNull("No filter in connectorRef (JAXB)", filter);
    MapXNode filterElement = filter.getFilterClauseXNode();
    assertNotNull("No filter element in connectorRef (JAXB)", filterElement);
    EvaluationTimeType resolutionTime = connectorRef.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.IMPORT, resolutionTime);
    }
    XmlSchemaType xmlSchemaType = resourceType.getSchema();
    SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
    if (isSimple) {
        assertNull("Schema sneaked in", xmlSchemaType);
        assertNull("SchemaHandling sneaked in", schemaHandling);
    } else {
        assertNotNull("No schema element (JAXB)", xmlSchemaType);
        SchemaDefinitionType definition = xmlSchemaType.getDefinition();
        assertNotNull("No definition element in schema (JAXB)", definition);
        List<Element> anyElements = definition.getAny();
        assertNotNull("Null element list in definition element in schema (JAXB)", anyElements);
        assertFalse("Empty element list in definition element in schema (JAXB)", anyElements.isEmpty());
        assertNotNull("No schema handling (JAXB)", schemaHandling);
        for (ResourceObjectTypeDefinitionType accountType : schemaHandling.getObjectType()) {
            String name = accountType.getIntent();
            assertNotNull("Account type without a name", name);
            assertNotNull("Account type " + name + " does not have an objectClass", accountType.getObjectClass());
            boolean foundDescription = false;
            boolean foundDepartmentNumber = false;
            for (ResourceAttributeDefinitionType attributeDefinitionType : accountType.getAttribute()) {
                if ("description".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDescription = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    JAXBElement<?> valueEvaluator = outbound.getExpression().getExpressionEvaluator().get(0);
                    System.out.println("value evaluator for description = " + valueEvaluator);
                    assertNotNull("no expression evaluator for description", valueEvaluator);
                    assertEquals("wrong expression evaluator element name for description", SchemaConstantsGenerated.C_VALUE, valueEvaluator.getName());
                    assertEquals("wrong expression evaluator actual type for description", RawType.class, valueEvaluator.getValue().getClass());
                } else if ("departmentNumber".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDepartmentNumber = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    VariableBindingDefinitionType source = outbound.getSource().get(0);
                    System.out.println("source for departmentNumber = " + source);
                    assertNotNull("no source for outbound mapping for departmentNumber", source);
                    // <path xmlns:z="http://z/">$user/extension/z:dept</path>
                    ItemPath expected = ItemPath.create(new VariableItemPathSegment(new QName("user")), new QName("extension"), namespaces ? new QName("http://z/", "dept") : new QName("dept"));
                    PrismAsserts.assertPathEqualsExceptForPrefixes("source for departmentNubmer", expected, source.getPath().getItemPath());
                }
            }
            assertTrue("ri:description attribute was not found", foundDescription);
            assertTrue("ri:departmentNumber attribute was not found", foundDepartmentNumber);
        }
        // checking <class> element in fetch result
        OperationResultType fetchResult = resourceType.getFetchResult();
        assertNotNull("No fetchResult (JAXB)", fetchResult);
        JAXBElement<?> value = fetchResult.getParams().getEntry().get(0).getEntryValue();
        assertNotNull("No fetchResult param value (JAXB)", value);
        assertEquals("Wrong value class", UnknownJavaObjectType.class, value.getValue().getClass());
        UnknownJavaObjectType unknownJavaObjectType = (UnknownJavaObjectType) value.getValue();
        assertEquals("Wrong value class", "my.class", unknownJavaObjectType.getClazz());
        assertEquals("Wrong value toString value", "my.value", unknownJavaObjectType.getToString());
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) VariableItemPathSegment(com.evolveum.midpoint.prism.path.VariableItemPathSegment) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class PrismTestUtil method displaySearchFilterType.

public static void displaySearchFilterType(SearchFilterType filterType) throws SchemaException {
    MapXNode mapXNode = filterType.getFilterClauseXNode();
    String dumpX = mapXNode.debugDump();
    LOGGER.info(dumpX);
    System.out.println(dumpX);
    String dumpXml = prismContext.xmlSerializer().serialize(new RootXNode(new QName("query"), mapXNode));
    System.out.println(dumpXml);
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 25 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class PrismUtil method serializeExpression.

public static MapXNode serializeExpression(ExpressionWrapper expressionWrapper, BeanMarshaller beanMarshaller) throws SchemaException {
    MapXNode xmap = new MapXNode();
    Object expressionObject = expressionWrapper.getExpression();
    if (expressionObject == null) {
        return xmap;
    }
    XNode expressionXnode = beanMarshaller.marshall(expressionObject);
    if (expressionXnode == null) {
        return xmap;
    }
    xmap.put(expressionWrapper.getElementName(), expressionXnode);
    return xmap;
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Aggregations

MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)42 QName (javax.xml.namespace.QName)24 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)21 XNode (com.evolveum.midpoint.prism.xnode.XNode)18 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)15 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)13 Test (org.testng.annotations.Test)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 Element (org.w3c.dom.Element)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)4 Protector (com.evolveum.midpoint.prism.crypto.Protector)3 EncryptedDataType (com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType)3 NotNull (org.jetbrains.annotations.NotNull)3 TestProtector (com.evolveum.midpoint.prism.crypto.TestProtector)2