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 static org.junit.Assert.assertEquals;
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;
24 public class SchemaContextUtilTest {
26 private SchemaContext mockSchemaContext;
28 private Module mockModule;
31 public void testFindDummyData() {
32 MockitoAnnotations.initMocks(this);
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));
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));
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));
49 assertEquals("Should be null. Module TestQName not found", null,
50 SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qname)));
52 assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));