use of com.evolveum.midpoint.prism.marshaller.XPathSegment in project midpoint by Evolveum.
the class XPathTest method xpathTest.
/**
* This is now a proper test yet.
* It does some operations with XPath. If it does not die, then the
* code some somehow consistent.
*
* It should be improved later.
*/
@Test
public void xpathTest() throws JAXBException, FileNotFoundException, IOException, ParserConfigurationException, SchemaException {
ObjectModificationType objectModification = PrismTestUtil.parseAtomicValue(new File(FILENAME_CHANGETYPE), ObjectModificationType.COMPLEX_TYPE);
for (ItemDeltaType change : objectModification.getItemDelta()) {
ItemPathType pathType = change.getPath();
System.out.println(" path=" + pathType + " (" + pathType.getClass().getName() + ") " + pathType.toString());
// NamedNodeMap attributes = path.getAttributes();
// for (int i = 0; i < attributes.getLength(); i++) {
// Node n = attributes.item(i);
// System.out.println(" A: " + n.getClass().getName() + " " + n.getNodeName() + "(" + n.getPrefix() + " : " + n.getLocalName() + ") = " + n.getNodeValue());
// }
// List<Object> any = change.getValue().getAny();
// for (Object e : any) {
// if (e instanceof Element) {
// System.out.println(" E: " + ((Element) e).getLocalName());
// }
// }
ItemPath path = pathType.getItemPath();
XPathHolder xpath = new XPathHolder(path);
AssertJUnit.assertEquals("c:extension/piracy:ship[2]/c:name", xpath.getXPathWithoutDeclarations());
System.out.println("XPATH: " + xpath);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder loader = factory.newDocumentBuilder();
Document doc = loader.newDocument();
Element xpathElement = xpath.toElement("http://elelel/", "path", doc);
Attr nsC = xpathElement.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "c");
Attr nsPiracy = xpathElement.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "piracy");
System.out.println("c: " + nsC);
System.out.println("piracy: " + nsPiracy);
// AssertJUnit.assertEquals("http://midpoint.evolveum.com/xml/ns/public/common/common-3", nsC.getValue());
// AssertJUnit.assertEquals("http://midpoint.evolveum.com/xml/ns/samples/piracy", nsPiracy.getValue());
System.out.println("XPATH Element: " + xpathElement);
XPathHolder xpathFromElement = new XPathHolder(xpathElement);
AssertJUnit.assertEquals(xpath, xpathFromElement);
// attributes = xpathElement.getAttributes();
// for (int i = 0; i < attributes.getLength(); i++) {
// Node n = attributes.item(i);
// System.out.println(" A: " + n.getNodeName() + "(" + n.getPrefix() + " : " + n.getLocalName() + ") = " + n.getNodeValue());
// }
List<XPathSegment> segments = xpath.toSegments();
System.out.println("XPATH segments: " + segments);
XPathHolder xpathFromSegments = new XPathHolder(segments);
System.out.println("XPath from segments: " + xpathFromSegments);
AssertJUnit.assertEquals("c:extension/piracy:ship[2]/c:name", xpathFromSegments.getXPathWithoutDeclarations());
}
}
use of com.evolveum.midpoint.prism.marshaller.XPathSegment 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.XPathSegment in project midpoint by Evolveum.
the class ObjectTypeUtil method createXPathHolder.
public static XPathHolder createXPathHolder(QName property) {
XPathSegment xpathSegment = new XPathSegment(property);
List<XPathSegment> segmentlist = new ArrayList<XPathSegment>(1);
segmentlist.add(xpathSegment);
XPathHolder xpath = new XPathHolder(segmentlist);
return xpath;
}
Aggregations