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