+ assertNull("Should be null. Module TestQName not found",
+ SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qname)));
+
+ assertNull("Should be null.", SchemaContextUtil.findParentModule(mockSchemaContext, int32node));
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest() {
+ assertThrows(NullPointerException.class,
+ () -> SchemaContextUtil.findDataSchemaNode(mock(SchemaContext.class), mock(Module.class), null));
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest2() {
+ final SchemaContext mockContext = mock(SchemaContext.class);
+ final PathExpression xpath = new PathExpressionImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ assertThrows(NullPointerException.class, () -> SchemaContextUtil.findDataSchemaNode(mockContext, null, xpath));
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest3() {
+ final Module module = mock(Module.class);
+ final PathExpression xpath = new PathExpressionImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ assertThrows(NullPointerException.class, () -> SchemaContextUtil.findDataSchemaNode(null, module, xpath));
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest4() {
+ final SchemaContext mockContext = mock(SchemaContext.class);
+ final Module module = mock(Module.class);
+ final PathExpression xpath = new PathExpressionImpl("my:my-grouping[@con='NULL']/my:my-leaf-in-gouping2", true);
+
+ assertThrows(IllegalArgumentException.class,
+ () -> SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+ }
+
+ @Test
+ public void findParentModuleIllegalArgumentTest() {
+ assertThrows(NullPointerException.class,
+ () -> SchemaContextUtil.findParentModule(mock(SchemaContext.class), null));
+ }
+
+ @Test
+ public void findParentModuleIllegalArgumentTest2() {
+ doReturn(SchemaPath.create(true, QName.create("foo", "bar"))).when(schemaNode).getPath();
+ assertThrows(NullPointerException.class, () -> SchemaContextUtil.findParentModule(null, schemaNode));
+ }
+
+ @Test
+ public void findDataSchemaNodeIllegalArgumentTest() {
+ assertThrows(NullPointerException.class,
+ () -> SchemaContextUtil.findDataSchemaNode(mock(SchemaContext.class), (SchemaPath) null));
+ }
+
+ @Test
+ public void findDataSchemaNodeIllegalArgumentTest2() {
+ assertThrows(NullPointerException.class, () -> SchemaContextUtil.findDataSchemaNode(null,
+ SchemaPath.create(true, QName.create(URI.create("uri:my-module"), Revision.of("2014-10-07"), "foo"))));
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathNullTest2() {
+ final SchemaContext mockContext = mock(SchemaContext.class);
+ final Module module = mock(Module.class);
+ final PathExpression xpath = new PathExpressionImpl("my:my-grouping/my:my-leaf-in-gouping2", false);
+
+ assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+ }
+
+ @Test
+ public void testNormalizeXPath() {
+ assertNormalizedPath(0, ImmutableList.of(""), "");
+ assertNormalizedPath(0, ImmutableList.of("a"), "a");
+ assertNormalizedPath(0, ImmutableList.of("a", "b"), "a b");
+ assertNormalizedPath(1, ImmutableList.of("..", "b"), ".. b");
+ assertNormalizedPath(0, ImmutableList.of(), "a ..");
+ assertNormalizedPath(0, ImmutableList.of("b"), "a .. b");
+ assertNormalizedPath(2, ImmutableList.of("..", "..", "a", "c"), ".. .. a b .. c");
+ assertNormalizedPath(3, ImmutableList.of("..", "..", "..", "b"), ".. .. a .. .. b");
+ }