YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-parser-rfc7950 / 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.Optional;
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.Revision;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21
22 public class Bug8597Test {
23     @Test
24     public void test() throws Exception {
25         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8597");
26         assertNotNull(context);
27
28         final Module foo = context.findModule("foo").get();
29         final Set<ModuleImport> imports = foo.getImports();
30
31         for (final ModuleImport moduleImport : imports) {
32             switch (moduleImport.getModuleName()) {
33                 case "bar":
34                     assertEquals(Revision.ofNullable("1970-01-01"), moduleImport.getRevision());
35                     assertEquals(Optional.of("bar-ref"), moduleImport.getReference());
36                     assertEquals(Optional.of("bar-desc"), moduleImport.getDescription());
37                     break;
38                 case "baz":
39                     assertEquals(Revision.ofNullable("2010-10-10"), moduleImport.getRevision());
40                     assertEquals(Optional.of("baz-ref"), moduleImport.getReference());
41                     assertEquals(Optional.of("baz-desc"), moduleImport.getDescription());
42                     break;
43                 default:
44                     fail("Module 'foo' should only contains import of module 'bar' and 'baz'");
45             }
46         }
47     }
48 }