Address FIXME for QueuedNotificationManager
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / SchemaContextTest.java
1 /*
2  * Copyright (c) 2014 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.parser.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12
13 import com.google.common.collect.ImmutableSet;
14
15 import java.net.URI;
16 import java.net.URISyntaxException;
17 import java.text.ParseException;
18 import java.util.Collections;
19 import java.util.Date;
20 import java.util.Map;
21
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
27 import org.opendaylight.yangtools.yang.model.api.Module;
28 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
30
31 public class SchemaContextTest {
32     @Mock
33     private Module oldModule;
34
35     @Mock
36     private Module newModule;
37
38     private Map<ModuleIdentifier, String> sources;
39
40     private URI ns;
41     private Date oldDate;
42     private Date newDate;
43
44     @Before
45     public void setUp() throws ParseException, URISyntaxException {
46         MockitoAnnotations.initMocks(this);
47
48         ns = new URI("http://abc");
49         oldDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-20");
50         newDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-22");
51
52         doReturn("abc").when(oldModule).getName();
53         doReturn(oldDate).when(oldModule).getRevision();
54         doReturn(ns).when(oldModule).getNamespace();
55         doReturn("abc").when(newModule).getName();
56         doReturn(newDate).when(newModule).getRevision();
57         doReturn(ns).when(newModule).getNamespace();
58
59         sources = Collections.emptyMap();
60     }
61
62     @Test
63     public void testModuleOrdering() {
64         SchemaContext sc;
65         Module m;
66
67         sc = new SchemaContextImpl(ImmutableSet.of(newModule, oldModule), sources);
68         m = sc.findModuleByName("abc", null);
69         assertEquals(newDate, m.getRevision());
70         m = sc.findModuleByNamespaceAndRevision(ns, null);
71         assertEquals(newDate, m.getRevision());
72
73         sc = new SchemaContextImpl(ImmutableSet.of(oldModule, newModule), sources);
74         m = sc.findModuleByName("abc", null);
75         assertEquals(newDate, m.getRevision());
76         m = sc.findModuleByNamespaceAndRevision(ns, null);
77         assertEquals(newDate, m.getRevision());
78     }
79
80
81 }