Merge "Do not require namespace repairing"
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / SchemaContextUtilTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import org.junit.Test;
11 import org.mockito.Mock;
12 import org.mockito.MockitoAnnotations;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
18 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
19
20 import java.util.Collections;
21
22 import static org.junit.Assert.assertEquals;
23
24 public class SchemaContextUtilTest {
25     @Mock private SchemaContext mockSchemaContext;
26     @Mock private Module mockModule;
27
28     @Test
29     public void testFindDummyData() {
30         MockitoAnnotations.initMocks(this);
31
32         QName qName = QName.create("TestQName");
33         SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
34         assertEquals("Should be null. Module TestQName not found", null,
35                 SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
36
37         RevisionAwareXPath xPath = new RevisionAwareXPathImpl("/bookstore/book/title", true);
38         assertEquals("Should be null. Module bookstore not found", null,
39                 SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
40
41         SchemaNode schemaNode = Int32.getInstance();
42         RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
43         assertEquals("Should be null, Module prefix not found", null,
44                 SchemaContextUtil.findDataSchemaNodeForRelativeXPath(
45                         mockSchemaContext, mockModule, schemaNode, xPathRelative));
46
47         assertEquals("Should be null. Module TestQName not found", null,
48                 SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName)));
49
50         assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));
51     }
52 }