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 static org.junit.Assert.fail;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
15 import com.google.common.collect.Maps;
16 import com.google.common.collect.Sets;
19 import java.text.ParseException;
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.junit.matchers.JUnitMatchers;
28 import org.opendaylight.controller.config.api.LookupRegistry;
29 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
30 import org.opendaylight.yangtools.yang.common.QName;
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(final 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(final String qname) {
104 ModuleMXBeanEntry mock = mock(ModuleMXBeanEntry.class);
105 QName q = getQName(qname);
106 doReturn(q).when(mock).getYangModuleQName();
110 private QName getQName(final String qname) {
111 return QName.create(URI.create("namespace"), date1970_01_01, qname);
114 private LookupRegistry mockJmxClient(final 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();