Remove unused SchemaUtils methods
[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.assertNull;
11 import static org.junit.Assert.assertThrows;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
16 import com.google.common.base.Splitter;
17 import java.util.Collections;
18 import java.util.Optional;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.common.QNameModule;
25 import org.opendaylight.yangtools.yang.common.Revision;
26 import org.opendaylight.yangtools.yang.common.XMLNamespace;
27 import org.opendaylight.yangtools.yang.model.api.Module;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
29 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
30 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
31
32 @RunWith(MockitoJUnitRunner.StrictStubs.class)
33 public class SchemaContextUtilTest {
34     public static final Splitter SPACE_SPLITTER = Splitter.on(' ');
35     public static final XMLNamespace NAMESPACE = XMLNamespace.of("abc");
36
37     @Mock
38     public SchemaContext mockSchemaContext;
39     @Mock
40     public Module mockModule;
41     @Mock
42     public SchemaNode schemaNode;
43
44     @Test
45     public void testFindDummyData() {
46         doReturn(Optional.empty()).when(mockSchemaContext).findModule(any(QNameModule.class));
47
48         QName qname = QName.create("namespace", "localname");
49         SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qname), true);
50         assertNull("Should be null. Module TestQName not found",
51                 SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
52
53         assertNull("Should be null. Module TestQName not found",
54                 SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qname)));
55     }
56
57     @Test
58     public void findParentModuleIllegalArgumentTest() {
59         assertThrows(NullPointerException.class,
60             () -> SchemaContextUtil.findParentModule(mock(SchemaContext.class), null));
61     }
62
63     @Test
64     public void findParentModuleIllegalArgumentTest2() {
65         doReturn(QName.create("foo", "bar")).when(schemaNode).getQName();
66         assertThrows(NullPointerException.class, () -> SchemaContextUtil.findParentModule(null, schemaNode));
67     }
68
69     @Test
70     public void findDataSchemaNodeIllegalArgumentTest() {
71         assertThrows(NullPointerException.class,
72             () -> SchemaContextUtil.findDataSchemaNode(mock(SchemaContext.class), (SchemaPath) null));
73     }
74
75     @Test
76     public void findDataSchemaNodeIllegalArgumentTest2() {
77         assertThrows(NullPointerException.class, () -> SchemaContextUtil.findDataSchemaNode(null,
78             SchemaPath.create(true, QName.create(XMLNamespace.of("uri:my-module"), Revision.of("2014-10-07"), "foo"))));
79     }
80 }