1 package org.opendaylight.controller.yang.model.parser.impl;
3 import static org.junit.Assert.*;
4 import static org.junit.matchers.JUnitMatchers.*;
5 import static org.mockito.Mockito.*;
7 import org.antlr.v4.runtime.tree.ParseTree;
8 import org.junit.Before;
10 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Belongs_to_stmtContext;
11 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext;
12 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext;
13 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext;
14 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Submodule_header_stmtsContext;
15 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Submodule_stmtContext;
17 public class YangModelValidationListenerTest_SubModule {
19 private YangModelValidationListener valid;
20 private Submodule_stmtContext ctx;
24 valid = new YangModelValidationListener();
27 @Test(expected = YangValidationException.class)
28 public void testNoRevision() {
30 Submodule_stmtContext ctx = mock(Submodule_stmtContext.class);
31 doReturn(1).when(ctx).getChildCount();
32 YangModelValidationListenerTest_Module.mockName(ctx, "submodule1");
35 valid.enterSubmodule_stmt(ctx);
36 } catch (YangValidationException e) {
39 containsString("Missing revision statements in submodule:submodule1"));
44 @Test(expected = YangValidationException.class)
45 public void testNoHeaderStmts() {
46 mockSubmoduleWithRevision(2, "1999-4-5", "submodule");
49 valid.enterSubmodule_stmt(ctx);
50 } catch (YangValidationException e) {
53 containsString("Missing header statements in submodule:submodule"));
58 @Test(expected = YangValidationException.class)
59 public void testNoBelongsTo() {
60 Submodule_header_stmtsContext header = mock(Submodule_header_stmtsContext.class);
61 mockSubmoduleParent(2, header, "submodule");
64 valid.enterSubmodule_header_stmts(header);
65 } catch (YangValidationException e) {
68 containsString("Missing belongs-to statement in submodule:submodule"));
73 @Test(expected = YangValidationException.class)
74 public void testBelongsToNoPrefix() {
75 Belongs_to_stmtContext belongsTo = mock(Belongs_to_stmtContext.class);
76 doReturn(1).when(belongsTo).getChildCount();
77 YangModelValidationListenerTest_Module.mockName(belongsTo,
80 mockSubmoduleParent(2, belongsTo, "submodule");
83 valid.enterBelongs_to_stmt(belongsTo);
84 } catch (YangValidationException e) {
87 containsString("Missing prefix statement in belongs-to:supermodule, in (sub)module:submodule"));
93 public void testBelongsTo() {
94 Belongs_to_stmtContext belongsTo = mock(Belongs_to_stmtContext.class);
95 doReturn(2).when(belongsTo).getChildCount();
96 YangModelValidationListenerTest_Module.mockName(belongsTo,
99 Prefix_stmtContext prefix = mock(Prefix_stmtContext.class);
100 doReturn(prefix).when(belongsTo).getChild(1);
101 doReturn(belongsTo).when(prefix).getParent();
103 mockSubmoduleParent(2, belongsTo, "submodule");
104 valid.enterBelongs_to_stmt(belongsTo);
108 private Revision_stmtContext mockSubmoduleWithRevision(int moduleChildren,
109 String date, String nameOfSubmodule) {
110 Revision_stmtContext mockedRev = mock(Revision_stmtContext.class);
111 doReturn(1).when(mockedRev).getChildCount();
112 YangModelValidationListenerTest_Module.mockName(mockedRev, date);
114 Revision_stmtsContext revs = YangModelValidationListenerTest_Module
115 .mockRevisionsParent(2, mockedRev);
117 mockSubmoduleParent(moduleChildren, revs, nameOfSubmodule);
121 private void mockSubmoduleParent(int moduleChildren, ParseTree child,
123 ctx = mock(Submodule_stmtContext.class);
124 doReturn(moduleChildren).when(ctx).getChildCount();
125 YangModelValidationListenerTest_Module.mockName(ctx, moduleName);
126 doReturn(child).when(ctx).getChild(1);
127 doReturn(ctx).when(child).getParent();