2 * Copyright (c) 2013 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
9 package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
11 import com.google.common.collect.Maps;
12 import com.google.common.collect.Sets;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.junit.matchers.JUnitMatchers;
16 import org.opendaylight.controller.config.api.LookupRegistry;
17 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
18 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
19 import org.opendaylight.yangtools.yang.common.QName;
22 import java.text.ParseException;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
28 import static org.junit.Assert.fail;
29 import static org.mockito.Mockito.doReturn;
30 import static org.mockito.Mockito.mock;
32 public class NetconfOperationServiceImplTest {
34 private static final Date date1970_01_01;
38 date1970_01_01 = new SimpleDateFormat("yyyy-MM-dd").parse("1970-01-01");
39 } catch (ParseException e) {
40 throw new IllegalStateException(e);
45 public void testCheckConsistencyBetweenYangStoreAndConfig_ok() throws Exception {
46 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
47 mockJmxClient("qname1", "qname2"),
48 mockYangStoreSnapshot("qname2", "qname1"));
52 public void testCheckConsistencyBetweenYangStoreAndConfig_ok2() throws Exception {
53 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
54 mockJmxClient("qname1", "qname2", "qname4", "qname5"),
55 mockYangStoreSnapshot("qname2", "qname1"));
59 public void testCheckConsistencyBetweenYangStoreAndConfig_ok3() throws Exception {
60 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
62 mockYangStoreSnapshot());
66 public void testCheckConsistencyBetweenYangStoreAndConfig_yangStoreMore() throws Exception {
68 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(mockJmxClient("qname1"),
69 mockYangStoreSnapshot("qname2", "qname1"));
70 fail("An exception of type " + IllegalStateException.class + " was expected");
71 } catch (IllegalStateException e) {
72 String message = e.getMessage();
76 .containsString("missing from config subsystem but present in yangstore: [(namespace?revision=1970-01-01)qname2]"));
80 .containsString("All modules present in config: [(namespace?revision=1970-01-01)qname1]"));
84 private YangStoreSnapshot mockYangStoreSnapshot(String... qnames) {
85 YangStoreSnapshot mock = mock(YangStoreSnapshot.class);
87 Map<String, Map<String, ModuleMXBeanEntry>> map = Maps.newHashMap();
89 Map<String, ModuleMXBeanEntry> innerMap = Maps.newHashMap();
92 for (String qname : qnames) {
93 innerMap.put(Integer.toString(i++), mockMBeanEntry(qname));
96 map.put("1", innerMap);
98 doReturn(map).when(mock).getModuleMXBeanEntryMap();
103 private ModuleMXBeanEntry mockMBeanEntry(String qname) {
104 ModuleMXBeanEntry mock = mock(ModuleMXBeanEntry.class);
105 QName q = getQName(qname);
106 doReturn(q).when(mock).getYangModuleQName();
110 private QName getQName(String qname) {
111 return new QName(URI.create("namespace"), date1970_01_01, qname);
114 private LookupRegistry mockJmxClient(String... visibleQNames) {
115 LookupRegistry mock = mock(LookupRegistry.class);
116 Set<String> qnames = Sets.newHashSet();
117 for (String visibleQName : visibleQNames) {
118 QName q = getQName(visibleQName);
119 qnames.add(q.toString());
121 doReturn(qnames).when(mock).getAvailableModuleFactoryQNames();