2 * Copyright (c) 2014 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.parser.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
13 import com.google.common.collect.ImmutableSet;
16 import java.net.URISyntaxException;
17 import java.text.ParseException;
18 import java.util.Collections;
19 import java.util.Date;
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;
31 public class SchemaContextTest {
33 private Module oldModule;
36 private Module newModule;
38 private Map<ModuleIdentifier, String> sources;
45 public void setUp() throws ParseException, URISyntaxException {
46 MockitoAnnotations.initMocks(this);
48 ns = new URI("http://abc");
49 oldDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-20");
50 newDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-22");
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();
59 sources = Collections.emptyMap();
63 public void testModuleOrdering() {
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());
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());