Search in sources :

Example 6 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class XPathTest method dotTest.

@Test
public void dotTest() {
    XPathHolder dotPath = new XPathHolder(".");
    AssertJUnit.assertTrue(dotPath.toSegments().isEmpty());
    AssertJUnit.assertEquals(".", dotPath.getXPathWithoutDeclarations());
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) Test(org.testng.annotations.Test)

Example 7 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class XPathTest method xpathFromQNameTest.

@Test
public void xpathFromQNameTest() {
    // GIVEN
    QName qname = new QName(NS_FOO, "foo");
    XPathHolder xpath = new XPathHolder(qname);
    QName elementQName = new QName(NS_BAR, "bar");
    // WHEN
    Element element = xpath.toElement(elementQName, DOMUtil.getDocument());
    // THEN
    System.out.println("XPath from Qname:");
    System.out.println(DOMUtil.serializeDOMToString(element));
    assertEquals("Wrong element name", "bar", element.getLocalName());
    assertEquals("Wrong element namespace", NS_BAR, element.getNamespaceURI());
    Map<String, String> nsdecls = DOMUtil.getNamespaceDeclarations(element);
    //    	assertEquals("Wrong declaration for prefix "+XPathHolder.DEFAULT_PREFIX, NS_FOO, nsdecls.get(XPathHolder.DEFAULT_PREFIX));
    String prefix = nsdecls.keySet().iterator().next();
    assertEquals("Wrong element content", prefix + ":foo", element.getTextContent());
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Test(org.testng.annotations.Test)

Example 8 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class XPathTest method pureXPathRoundTripTest.

@Test
public void pureXPathRoundTripTest() {
    Map<String, String> namespaceMap = new HashMap<String, String>();
    namespaceMap.put("foo", "http://foo");
    namespaceMap.put("bar", "http://bar");
    String xpathStr = "foo:foo/bar:bar";
    XPathHolder xpath = new XPathHolder(xpathStr, namespaceMap);
    System.out.println("Pure XPath: " + xpath.getXPathWithoutDeclarations());
    AssertJUnit.assertEquals("foo:foo/bar:bar", xpath.getXPathWithoutDeclarations());
    System.out.println("ROUND TRIP: " + xpath.getXPathWithDeclarations());
    AssertJUnit.assertEquals("foo:foo/bar:bar", xpath.getXPathWithDeclarations());
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 9 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class XPathTest method xPathFromDomNode1.

@Test
public void xPathFromDomNode1() throws ParserConfigurationException, SAXException, IOException {
    // Given
    Element el1 = parseDataGetEl1();
    String xpathString = "/root/x:el1[100]";
    el1.setTextContent(xpathString);
    // When
    XPathHolder xpath = new XPathHolder(el1);
    // Then
    Map<String, String> namespaceMap = xpath.getNamespaceMap();
    //AssertJUnit.assertEquals("http://default.com/", namespaceMap.get("c"));
    List<XPathSegment> segments = xpath.toSegments();
    AssertJUnit.assertNotNull(segments);
    AssertJUnit.assertEquals(3, segments.size());
    AssertJUnit.assertEquals(new QName("", "root"), segments.get(0).getQName());
    AssertJUnit.assertFalse(segments.get(0).isVariable());
    AssertJUnit.assertFalse(segments.get(0).isIdValueFilter());
    AssertJUnit.assertEquals(new QName("http://xx.com/", "el1"), segments.get(1).getQName());
    AssertJUnit.assertFalse(segments.get(1).isVariable());
    AssertJUnit.assertFalse(segments.get(1).isIdValueFilter());
    AssertJUnit.assertNull(segments.get(2).getQName());
    AssertJUnit.assertFalse(segments.get(2).isVariable());
    AssertJUnit.assertTrue(segments.get(2).isIdValueFilter());
    AssertJUnit.assertEquals("100", segments.get(2).getValue());
}
Also used : XPathSegment(com.evolveum.midpoint.prism.marshaller.XPathSegment) XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Test(org.testng.annotations.Test)

Example 10 with XPathHolder

use of com.evolveum.midpoint.prism.marshaller.XPathHolder in project midpoint by Evolveum.

the class ItemDelta method applyDefinition.

public static void applyDefinition(Collection<? extends ItemDelta> deltas, PrismObjectDefinition definition) throws SchemaException {
    for (ItemDelta itemDelta : deltas) {
        ItemPath path = itemDelta.getPath();
        ItemDefinition itemDefinition = definition.findItemDefinition(path, ItemDefinition.class);
        if (itemDefinition == null) {
            throw new SchemaException("Object type " + definition.getTypeName() + " doesn't contain definition for path " + new XPathHolder(path).getXPathWithDeclarations(false));
        }
        itemDelta.applyDefinition(itemDefinition);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

XPathHolder (com.evolveum.midpoint.prism.marshaller.XPathHolder)18 Test (org.testng.annotations.Test)11 Element (org.w3c.dom.Element)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QName (javax.xml.namespace.QName)4 XPathSegment (com.evolveum.midpoint.prism.marshaller.XPathSegment)3 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)3 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 File (java.io.File)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)1 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)1 FileInputStream (java.io.FileInputStream)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1