f390440db4ef37e20d363d882ebd000cd993c1fb
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6961Test.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 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.assertTrue;
13
14 import com.google.common.collect.Sets;
15 import java.net.URI;
16 import java.util.Date;
17 import java.util.Optional;
18 import java.util.Set;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
22 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
25 import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
26
27 public class Bug6961Test {
28
29     @Test
30     public void testBug6961SchemaContext() throws Exception {
31         final Optional<Date> date = Optional.of(SimpleDateFormatUtil.getRevisionFormat().parse("2016-01-01"));
32         final ModuleIdentifier foo = ModuleIdentifierImpl.create("foo", Optional.of(new URI("foo")), date);
33         final ModuleIdentifier sub1Foo = ModuleIdentifierImpl.create("sub1-foo", Optional.of(new URI("foo")), date);
34         final ModuleIdentifier sub2Foo = ModuleIdentifierImpl.create("sub2-foo", Optional.of(new URI("foo")), date);
35         final ModuleIdentifier bar = ModuleIdentifierImpl.create("bar", Optional.of(new URI("bar")), date);
36         final ModuleIdentifier sub1Bar = ModuleIdentifierImpl.create("sub1-bar", Optional.of(new URI("bar")), date);
37         final ModuleIdentifier baz = ModuleIdentifierImpl.create("baz", Optional.of(new URI("baz")), date);
38         final Set<ModuleIdentifier> testSet = Sets.newHashSet(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz);
39         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6961/");
40         assertNotNull(context);
41         final Set<ModuleIdentifier> allModuleIdentifiers = context.getAllModuleIdentifiers();
42         assertNotNull(allModuleIdentifiers);
43         assertEquals(6, allModuleIdentifiers.size());
44         final SchemaContext schemaContext = SimpleSchemaContext.forModules(context.getModules());
45         assertNotNull(schemaContext);
46         final Set<ModuleIdentifier> allModuleIdentifiersResolved = schemaContext.getAllModuleIdentifiers();
47         assertNotNull(allModuleIdentifiersResolved);
48         assertEquals(6, allModuleIdentifiersResolved.size());
49         assertEquals(allModuleIdentifiersResolved, allModuleIdentifiers);
50         assertEquals(allModuleIdentifiers, testSet);
51         assertTrue(allModuleIdentifiers.contains(foo));
52         final QNameModule fooQNameModule = foo.getQNameModule();
53         final QNameModule fooQNameModuleCreated = QNameModule.create(new URI("foo"), date.orElse(null));
54         assertEquals(fooQNameModule, fooQNameModuleCreated);
55     }
56 }