2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.util;
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;
20 import java.util.Collections;
22 import static org.junit.Assert.assertEquals;
24 public class SchemaContextUtilTest {
25 @Mock private SchemaContext mockSchemaContext;
26 @Mock private Module mockModule;
29 public void testFindDummyData() {
30 MockitoAnnotations.initMocks(this);
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));
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));
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));
47 assertEquals("Should be null. Module TestQName not found", null,
48 SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName)));
50 assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));