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.util.Date;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.mock;
29 public class NetconfOperationServiceImplTest {
31 private Date date = new Date(0);
34 public void testCheckConsistencyBetweenYangStoreAndConfig_ok() throws Exception {
35 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
36 mockJmxClient("qname1", "qname2"),
37 mockYangStoreSnapshot("qname2", "qname1"));
41 public void testCheckConsistencyBetweenYangStoreAndConfig_ok2() throws Exception {
42 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
43 mockJmxClient("qname1", "qname2", "qname4", "qname5"),
44 mockYangStoreSnapshot("qname2", "qname1"));
48 public void testCheckConsistencyBetweenYangStoreAndConfig_ok3() throws Exception {
49 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
51 mockYangStoreSnapshot());
54 @Test(expected = IllegalStateException.class)
55 public void testCheckConsistencyBetweenYangStoreAndConfig_yangStoreMore() throws Exception {
57 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(mockJmxClient("qname1"),
58 mockYangStoreSnapshot("qname2", "qname1"));
59 } catch (IllegalStateException e) {
60 String message = e.getMessage();
64 .containsString(" missing from config subsystem but present in yangstore: [(namespace?revision=1970-01-01)qname2]"));
68 .containsString("All modules present in config: [(namespace?revision=1970-01-01)qname1]"));
73 private YangStoreSnapshot mockYangStoreSnapshot(String... qnames) {
74 YangStoreSnapshot mock = mock(YangStoreSnapshot.class);
76 Map<String, Map<String, ModuleMXBeanEntry>> map = Maps.newHashMap();
78 Map<String, ModuleMXBeanEntry> innerMap = Maps.newHashMap();
81 for (String qname : qnames) {
82 innerMap.put(Integer.toString(i++), mockMBeanEntry(qname));
85 map.put("1", innerMap);
87 doReturn(map).when(mock).getModuleMXBeanEntryMap();
92 private ModuleMXBeanEntry mockMBeanEntry(String qname) {
93 ModuleMXBeanEntry mock = mock(ModuleMXBeanEntry.class);
94 QName q = getQName(qname);
95 doReturn(q).when(mock).getYangModuleQName();
99 private QName getQName(String qname) {
100 return new QName(URI.create("namespace"), date, qname);
103 private LookupRegistry mockJmxClient(String... visibleQNames) {
104 LookupRegistry mock = mock(LookupRegistry.class);
105 Set<String> qnames = Sets.newHashSet();
106 for (String visibleQName : visibleQNames) {
107 QName q = getQName(visibleQName);
108 qnames.add(q.toString());
110 doReturn(qnames).when(mock).getAvailableModuleFactoryQNames();