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());
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations