- public void testIdentityrefDefaultNmspcInParrentElement() {
- testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-default-nmspc-in-parrent-element.xml",
- "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "iden", "identityref:module");
- }
-
- /**
- *
- * Test case like <cont1 xmlns="namespace1" xmlns:x="namespace">
- * <lf11>x:identity</lf11> </cont1>
- */
- @Test
- public void testIdentityrefNmspcInParrentElement() {
- testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-nmspc-in-parrent-element.xml",
- "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "iden", "z:namespace");
-
- }
-
- /**
- *
- * Test case like (without namespace in xml) <cont1> <lf11>x:identity</lf11>
- * </cont1>
- */
- @Test
- public void testIdentityrefNoNmspcValueWithPrefix() {
- testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-no-nmspc-value-with-prefix.xml",
- "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "x:iden", "identityref:module");
- }
-
- /**
- *
- * Test case like (without namespace in xml) <cont1> <lf11>identity</lf11>
- * </cont1>
- */
- @Test
- public void testIdentityrefNoNmspcValueWithoutPrefix() {
- testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-no-nmspc-value-without-prefix.xml",
- "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "iden", "identityref:module");
- }
-
- private void verifyCommonPartAOfXml(CompositeNode compNode, String suf, String nameSpace) {
- SimpleNode<?> lf1suf = null;
- SimpleNode<?> lflst1suf_1 = null;
- SimpleNode<?> lflst1suf_2 = null;
- SimpleNode<?> lflst1suf_3 = null;
- CompositeNode cont1suf = null;
- CompositeNode lst1suf = null;
-
- int lflstCount = 0;
-
- for (Node<?> node : compNode.getChildren()) {
- String localName = node.getNodeType().getLocalName();
- if (localName.equals("lf1" + suf)) {
- assertTrue(node instanceof SimpleNode<?>);
- lf1suf = (SimpleNode<?>) node;
- } else if (localName.equals("lflst1" + suf)) {
- assertTrue(node instanceof SimpleNode<?>);
- switch (lflstCount++) {
- case 0:
- lflst1suf_1 = (SimpleNode<?>) node;
- break;
- case 1:
- lflst1suf_2 = (SimpleNode<?>) node;
- break;
- case 2:
- lflst1suf_3 = (SimpleNode<?>) node;
- break;
- }
- } else if (localName.equals("lst1" + suf)) {
- assertTrue(node instanceof CompositeNode);
- lst1suf = (CompositeNode) node;
- } else if (localName.equals("cont1" + suf)) {
- assertTrue(node instanceof CompositeNode);
- cont1suf = (CompositeNode) node;
- }
- assertEquals(nameSpace, node.getNodeType().getNamespace().toString());
- }
-
- assertNotNull(lf1suf);
- assertNotNull(lflst1suf_1);
- assertNotNull(lflst1suf_2);
- assertNotNull(lflst1suf_3);
- assertNotNull(lst1suf);
- assertNotNull(cont1suf);
-
- assertEquals("str0", lf1suf.getValue());
- assertEquals("121", lflst1suf_1.getValue());
- assertEquals("131", lflst1suf_2.getValue());
- assertEquals("str1", lflst1suf_3.getValue());
-
- assertEquals(1, lst1suf.getChildren().size());
-
- assertTrue(lst1suf.getChildren().get(0) instanceof SimpleNode<?>);
- SimpleNode<?> lst11_lf11 = (SimpleNode<?>) lst1suf.getChildren().get(0);
- assertEquals(nameSpace, lst11_lf11.getNodeType().getNamespace().toString());
- assertEquals("lf11" + suf, lst11_lf11.getNodeType().getLocalName());
- assertEquals("str2", lst11_lf11.getValue());
-
- assertTrue(cont1suf.getChildren().get(0) instanceof SimpleNode<?>);
- SimpleNode<?> cont1_lf11 = (SimpleNode<?>) cont1suf.getChildren().get(0);
- assertEquals(nameSpace, cont1_lf11.getNodeType().getNamespace().toString());
- assertEquals("lf11" + suf, cont1_lf11.getNodeType().getLocalName());
- assertEquals((short) 100, cont1_lf11.getValue());
- }
-
- private CompositeNode compositeNodeFromXml(String xmlPath, boolean dummyNamespaces) {
- XmlToCompositeNodeProvider xmlToCompositeNodeProvider = XmlToCompositeNodeProvider.INSTANCE;
- try {
- InputStream xmlStream = XmlToCnSnTest.class.getResourceAsStream(xmlPath);
- CompositeNode compositeNode = xmlToCompositeNodeProvider.readFrom(null, null, null, null, null, xmlStream);
- if (dummyNamespaces) {
- try {
- TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode);
- return ((CompositeNodeWrapper) compositeNode).unwrap();
- } catch (URISyntaxException e) {
- LOG.error(e.getMessage());
- assertTrue(e.getMessage(), false);
- }