Update StmtTestUtils
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6491Test.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.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.DEFAULT_DATE_REV;
13 import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.getRevisionFormat;
14
15 import java.text.ParseException;
16 import java.util.Date;
17 import java.util.Set;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23
24 public class Bug6491Test {
25     private Date date;
26
27     @Before
28     public void setup() throws ParseException {
29         date = getRevisionFormat().parse("2016-01-01");
30     }
31
32     @Test
33     public void tetststs() throws Exception {
34         testRevision("withoutRevision", DEFAULT_DATE_REV, DEFAULT_DATE_REV);
35         testRevision("withRevision", date, date);
36         testRevision("importedModuleRevisionOnly", DEFAULT_DATE_REV, date);
37         testRevision("moduleRevisionOnly", date, DEFAULT_DATE_REV);
38     }
39
40     private static void testRevision(final String path, final Date moduleRevision, final Date importedRevision)
41             throws Exception {
42         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6491/".concat(path));
43         assertNotNull(context);
44         final Module module = context.findModuleByName("bar", moduleRevision);
45         assertNotNull(module);
46         final Set<ModuleImport> imports = module.getImports();
47         assertNotNull(imports);
48         assertEquals(1, imports.size());
49         assertEquals(importedRevision, imports.iterator().next().getRevision());
50     }
51 }