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