2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
23 public class Bug7480Test {
25 public void libSourcesTest() throws Exception {
26 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug7480/files", "/bugs/bug7480/lib");
27 assertNotNull(context);
29 final Set<Module> modules = context.getModules();
30 assertEquals(7, modules.size());
32 assertNotNull(context.findModuleByNamespaceAndRevision(new URI("foo-imp"), SimpleDateFormatUtil
33 .getRevisionFormat().parse("2017-01-23")));
34 assertEquals(1, context.findModuleByNamespace(new URI("foo-imp-2")).size());
35 assertEquals(1, context.findModuleByNamespace(new URI("foo-imp-imp")).size());
36 assertEquals(1, context.findModuleByNamespace(new URI("bar")).size());
37 assertEquals(1, context.findModuleByNamespace(new URI("baz")).size());
38 assertNotNull(context.findModuleByNamespaceAndRevision(new URI("baz-imp"), SimpleDateFormatUtil
39 .getRevisionFormat().parse("2002-01-01")));
40 final Set<Module> foo = context.findModuleByNamespace(new URI("foo"));
41 assertEquals(1, foo.size());
42 final Set<Module> subFoos = foo.iterator().next().getSubmodules();
43 assertEquals(1, subFoos.size());
47 public void missingRelevantImportTest() throws Exception {
49 StmtTestUtils.parseYangSources("/bugs/bug7480/files-2", "/bugs/bug7480/lib-2");
50 fail("Test should fail due to missing import of required yang source from library");
51 } catch (final SomeModifiersUnresolvedException e) {
52 final String message = e.getSuppressed().length > 0 ? e.getSuppressed()[0].getCause().getMessage() : e
53 .getCause().getCause().getMessage();
54 assertTrue(message.startsWith("Imported module [missing-lib] was not found."));