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.yangjmxgenerator.ModuleMXBeanEntry;
18 import org.opendaylight.yangtools.yang.common.QName;
21 import java.text.ParseException;
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
27 import static org.junit.Assert.fail;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.mock;
31 public class NetconfOperationServiceImplTest {
33 private static final Date date1970_01_01;
37 date1970_01_01 = new SimpleDateFormat("yyyy-MM-dd").parse("1970-01-01");
38 } catch (ParseException e) {
39 throw new IllegalStateException(e);
44 public void testCheckConsistencyBetweenYangStoreAndConfig_ok() throws Exception {
45 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
46 mockJmxClient("qname1", "qname2"),
47 mockYangStoreSnapshot("qname2", "qname1"));
51 public void testCheckConsistencyBetweenYangStoreAndConfig_ok2() throws Exception {
52 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
53 mockJmxClient("qname1", "qname2", "qname4", "qname5"),
54 mockYangStoreSnapshot("qname2", "qname1"));
58 public void testCheckConsistencyBetweenYangStoreAndConfig_ok3() throws Exception {
59 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(
61 mockYangStoreSnapshot());
65 public void testCheckConsistencyBetweenYangStoreAndConfig_yangStoreMore() throws Exception {
67 NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(mockJmxClient("qname1"),
68 mockYangStoreSnapshot("qname2", "qname1"));
69 fail("An exception of type " + IllegalStateException.class + " was expected");
70 } catch (IllegalStateException e) {
71 String message = e.getMessage();
75 .containsString("missing from config subsystem but present in yangstore: [(namespace?revision=1970-01-01)qname2]"));
79 .containsString("All modules present in config: [(namespace?revision=1970-01-01)qname1]"));
83 private YangStoreSnapshot mockYangStoreSnapshot(String... qnames) {
84 YangStoreSnapshot mock = mock(YangStoreSnapshot.class);
86 Map<String, Map<String, ModuleMXBeanEntry>> map = Maps.newHashMap();
88 Map<String, ModuleMXBeanEntry> innerMap = Maps.newHashMap();
91 for (String qname : qnames) {
92 innerMap.put(Integer.toString(i++), mockMBeanEntry(qname));
95 map.put("1", innerMap);
97 doReturn(map).when(mock).getModuleMXBeanEntryMap();
102 private ModuleMXBeanEntry mockMBeanEntry(String qname) {
103 ModuleMXBeanEntry mock = mock(ModuleMXBeanEntry.class);
104 QName q = getQName(qname);
105 doReturn(q).when(mock).getYangModuleQName();
109 private QName getQName(String qname) {
110 return new QName(URI.create("namespace"), date1970_01_01, qname);
113 private LookupRegistry mockJmxClient(String... visibleQNames) {
114 LookupRegistry mock = mock(LookupRegistry.class);
115 Set<String> qnames = Sets.newHashSet();
116 for (String visibleQName : visibleQNames) {
117 QName q = getQName(visibleQName);
118 qnames.add(q.toString());
120 doReturn(qnames).when(mock).getAvailableModuleFactoryQNames();