BUG-4688: eliminate SimpleDateFormatUtil.DEFAULT_DATE_REV
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / IncludeRevisionsTest.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
16
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
23 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
25
26 public class IncludeRevisionsTest {
27
28     private static final StatementStreamSource EQUAL_ROOT = sourceForResource("/revisions/equal-root.yang");
29     private static final StatementStreamSource EQUAL_REV = sourceForResource("/revisions/equal-rev.yang");
30     private static final StatementStreamSource UNEQUAL_ROOT = sourceForResource("/revisions/unequal-root.yang");
31     private static final StatementStreamSource UNEQUAL_REV = sourceForResource("/revisions/unequal-rev.yang");
32     private static final StatementStreamSource SUBMOD_ONLY_ROOT = sourceForResource("/revisions/submod-only-root.yang");
33     private static final StatementStreamSource SUBMOD_ONLY_REV = sourceForResource("/revisions/submod-only-rev.yang");
34     private static final StatementStreamSource MOD_ONLY_ROOT = sourceForResource("/revisions/mod-only-root.yang");
35     private static final StatementStreamSource MOD_ONLY_REV = sourceForResource("/revisions/mod-only-rev.yang");
36     private static final StatementStreamSource NOWHERE_ROOT = sourceForResource("/revisions/nowhere-root.yang");
37     private static final StatementStreamSource NOWHERE_REV = sourceForResource("/revisions/nowhere-rev.yang");
38
39     @Test
40     public void revsEqualTest() throws ReactorException {
41
42         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
43         addSources(reactor, EQUAL_REV, EQUAL_ROOT);
44
45         EffectiveModelContext result = reactor.build();
46         assertNotNull(result);
47     }
48
49     @Test
50     public void revsUnequalTest() throws ReactorException {
51
52         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
53         addSources(reactor, UNEQUAL_REV, UNEQUAL_ROOT);
54
55         try {
56             reactor.build();
57             fail("reactor.process should fail due to unequal revisions in include and submodule");
58         } catch (ReactorException e) {
59             assertTrue(e instanceof SomeModifiersUnresolvedException);
60             assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
61         }
62     }
63
64     @Test
65     public void revIncludeOnly() throws ReactorException {
66
67         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
68         addSources(reactor, SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT);
69
70         EffectiveModelContext result = reactor.build();
71         assertNotNull(result);
72     }
73
74     @Test
75     public void revInModuleOnly() throws ReactorException {
76
77         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
78         addSources(reactor, MOD_ONLY_REV, MOD_ONLY_ROOT);
79
80         try {
81             reactor.build();
82             fail("reactor.process should fail due to missing revision in included submodule");
83         } catch (ReactorException e) {
84             assertTrue(e instanceof SomeModifiersUnresolvedException);
85             assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
86         }
87     }
88
89     @Test
90     public void revNowhereTest() throws ReactorException {
91
92         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
93         addSources(reactor, NOWHERE_REV, NOWHERE_ROOT);
94
95         EffectiveModelContext result = reactor.build();
96         assertNotNull(result);
97     }
98
99     private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final StatementStreamSource... sources) {
100         for (StatementStreamSource source : sources) {
101             reactor.addSource(source);
102         }
103     }
104 }