Enable checkstyle in yang-model-util
[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 static org.junit.Assert.assertEquals;
11
12 import java.util.Collections;
13 import org.junit.Test;
14 import org.mockito.Mock;
15 import org.mockito.MockitoAnnotations;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
23
24 public class SchemaContextUtilTest {
25     @Mock
26     private SchemaContext mockSchemaContext;
27     @Mock
28     private Module mockModule;
29
30     @Test
31     public void testFindDummyData() {
32         MockitoAnnotations.initMocks(this);
33
34         QName qname = QName.create("TestQName");
35         SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qname), true);
36         assertEquals("Should be null. Module TestQName not found", null,
37                 SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
38
39         RevisionAwareXPath xpath = new RevisionAwareXPathImpl("/bookstore/book/title", true);
40         assertEquals("Should be null. Module bookstore not found", null,
41                 SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xpath));
42
43         SchemaNode schemaNode = BaseTypes.int32Type();
44         RevisionAwareXPath xpathRelative = new RevisionAwareXPathImpl("../prefix", false);
45         assertEquals("Should be null, Module prefix not found", null,
46                 SchemaContextUtil.findDataSchemaNodeForRelativeXPath(
47                         mockSchemaContext, mockModule, schemaNode, xpathRelative));
48
49         assertEquals("Should be null. Module TestQName not found", null,
50                 SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qname)));
51
52         assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));
53     }
54 }