7872aa4d68dd8642909b2cef0f804d422a66ba91
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug8597Test.java
1 /*
2  * Copyright (c) 2017 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.stmt;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.fail;
13
14 import java.util.Set;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20
21 public class Bug8597Test {
22     @Test
23     public void test() throws Exception {
24         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8597");
25         assertNotNull(context);
26
27         final Module foo = context.findModuleByName("foo",
28                 SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
29         assertNotNull(foo);
30
31         final Set<ModuleImport> imports = foo.getImports();
32
33         for (final ModuleImport moduleImport : imports) {
34             switch (moduleImport.getModuleName()) {
35             case "bar":
36                 assertEquals(SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"), moduleImport.getRevision());
37                 assertEquals("bar-ref", moduleImport.getReference());
38                 assertEquals("bar-desc", moduleImport.getDescription());
39                 break;
40             case "baz":
41                 assertEquals(SimpleDateFormatUtil.getRevisionFormat().parse("2010-10-10"), moduleImport.getRevision());
42                 assertEquals("baz-ref", moduleImport.getReference());
43                 assertEquals("baz-desc", moduleImport.getDescription());
44                 break;
45             default:
46                 fail("Module 'foo' should only contains import of module 'bar' and 'baz'");
47             }
48         }
49     }
50 }