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;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.Lists;
14 import com.google.common.collect.Maps;
15 import org.junit.Before;
16 import org.junit.Ignore;
17 import org.junit.Test;
18 import org.junit.matchers.JUnitMatchers;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.config.api.ModuleIdentifier;
22 import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator;
23 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
24 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
25 import org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl;
26 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
27 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
28 import org.opendaylight.controller.config.yang.store.impl.MbeParser;
29 import org.opendaylight.controller.config.yang.test.impl.Asdf;
30 import org.opendaylight.controller.config.yang.test.impl.ComplexDtoBInner;
31 import org.opendaylight.controller.config.yang.test.impl.ComplexList;
32 import org.opendaylight.controller.config.yang.test.impl.Deep;
33 import org.opendaylight.controller.config.yang.test.impl.Deep2;
34 import org.opendaylight.controller.config.yang.test.impl.Deep3;
35 import org.opendaylight.controller.config.yang.test.impl.Deep4;
36 import org.opendaylight.controller.config.yang.test.impl.DepTestImplModuleFactory;
37 import org.opendaylight.controller.config.yang.test.impl.DtoAInner;
38 import org.opendaylight.controller.config.yang.test.impl.DtoAInnerInner;
39 import org.opendaylight.controller.config.yang.test.impl.DtoC;
40 import org.opendaylight.controller.config.yang.test.impl.DtoD;
41 import org.opendaylight.controller.config.yang.test.impl.InnerInnerRunningDataRuntimeMXBean;
42 import org.opendaylight.controller.config.yang.test.impl.InnerRunningDataAdditionalRuntimeMXBean;
43 import org.opendaylight.controller.config.yang.test.impl.InnerRunningDataRuntimeMXBean;
44 import org.opendaylight.controller.config.yang.test.impl.InnerRunningDataRuntimeRegistration;
45 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory;
46 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean;
47 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplRuntimeMXBean;
48 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplRuntimeRegistration;
49 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplRuntimeRegistrator;
50 import org.opendaylight.controller.config.yang.test.impl.NotStateBean;
51 import org.opendaylight.controller.config.yang.test.impl.NotStateBeanInternal;
52 import org.opendaylight.controller.config.yang.test.impl.Peers;
53 import org.opendaylight.controller.config.yang.test.impl.RetValContainer;
54 import org.opendaylight.controller.config.yang.test.impl.RetValList;
55 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
56 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
57 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;
58 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
59 import org.opendaylight.controller.netconf.confignetconfconnector.operations.DiscardChanges;
60 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
61 import org.opendaylight.controller.netconf.confignetconfconnector.operations.get.Get;
62 import org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig.GetConfig;
63 import org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc.RuntimeRpc;
64 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
65 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
66 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
67 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
68 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
69 import org.opendaylight.controller.netconf.util.xml.XmlElement;
70 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
71 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74 import org.w3c.dom.Document;
75 import org.w3c.dom.Element;
76 import org.w3c.dom.NodeList;
77 import org.xml.sax.SAXException;
79 import javax.management.InstanceAlreadyExistsException;
80 import javax.management.ObjectName;
81 import javax.xml.parsers.ParserConfigurationException;
82 import java.io.FileNotFoundException;
83 import java.io.IOException;
84 import java.io.InputStream;
85 import java.math.BigInteger;
86 import java.util.ArrayList;
87 import java.util.Arrays;
88 import java.util.Collection;
89 import java.util.List;
92 import static org.junit.Assert.assertEquals;
93 import static org.junit.Assert.assertThat;
94 import static org.junit.Assert.fail;
95 import static org.mockito.Mockito.doNothing;
96 import static org.mockito.Mockito.doReturn;
97 import static org.mockito.Mockito.verify;
98 import static org.mockito.Mockito.verifyNoMoreInteractions;
101 public class NetconfMappingTest extends AbstractConfigTest {
102 private static final Logger logger = LoggerFactory.getLogger(NetconfMappingTest.class);
104 private static final String INSTANCE_NAME = "test1";
105 private static final String NETCONF_SESSION_ID = "foo";
106 private NetconfTestImplModuleFactory factory;
107 private DepTestImplModuleFactory factory2;
110 YangStoreSnapshot yangStoreSnapshot;
112 NetconfOperationRouter netconfOperationRouter;
114 private TransactionProvider transactionProvider;
117 public void setUp() throws Exception {
118 MockitoAnnotations.initMocks(this);
119 doReturn(getMbes()).when(this.yangStoreSnapshot).getModuleMXBeanEntryMap();
120 this.factory = new NetconfTestImplModuleFactory();
121 this.factory2 = new DepTestImplModuleFactory();
122 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.factory, this.factory2));
124 transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID);
127 private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException {
128 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
130 final ObjectName on = transaction.createModule(this.factory.getImplementationName(), instanceName);
131 final NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
132 setModule(mxBean, transaction);
134 transaction.commit();
139 public void testConfigNetconf() throws Exception {
141 createModule(INSTANCE_NAME);
143 edit("netconfMessages/editConfig.xml");
144 checkBinaryLeafEdited(getConfigCandidate());
146 // default-operation:none, should not affect binary leaf
147 edit("netconfMessages/editConfig_none.xml");
148 checkBinaryLeafEdited(getConfigCandidate());
152 Element response = getConfigRunning();
154 checkBinaryLeafEdited(response);
155 checkTypeConfigAttribute(response);
156 checkTypedefs(response);
159 edit("netconfMessages/editConfig_remove.xml");
162 response = getConfigCandidate();
163 final String responseFromCandidate = XmlUtil.toString(response).replaceAll("\\s+", "");
164 // System.out.println(responseFromCandidate);
165 response = getConfigRunning();
166 final String responseFromRunning = XmlUtil.toString(response).replaceAll("\\s+", "");
167 // System.out.println(responseFromRunning);
168 assertEquals(responseFromCandidate, responseFromRunning);
170 final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml")
171 .replaceAll("\\s+", "");
173 assertEquals(expectedResult, responseFromRunning);
174 assertEquals(expectedResult, responseFromCandidate);
176 edit("netconfMessages/editConfig_none.xml");
177 doNothing().when(netconfOperationRouter).close();
179 verify(netconfOperationRouter).close();
180 verifyNoMoreInteractions(netconfOperationRouter);
183 private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
185 DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
186 executeOp(closeOp, "netconfMessages/closeSession.xml");
189 private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
190 NetconfDocumentedException {
191 EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
193 executeOp(editOp, resource);
196 private void commit() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
197 Commit commitOp = new Commit(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
198 executeOp(commitOp, "netconfMessages/commit.xml");
201 private Element getConfigCandidate() throws ParserConfigurationException, SAXException, IOException,
202 NetconfDocumentedException {
203 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
204 configRegistryClient, NETCONF_SESSION_ID);
205 return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
208 private Element getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
209 NetconfDocumentedException {
210 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
211 configRegistryClient, NETCONF_SESSION_ID);
212 return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
215 @Test(expected = NetconfDocumentedException.class)
216 public void testConfigNetconfReplaceDefaultEx() throws Exception {
218 createModule(INSTANCE_NAME);
220 edit("netconfMessages/editConfig.xml");
221 edit("netconfMessages/editConfig_replace_default_ex.xml");
225 public void testConfigNetconfReplaceDefault() throws Exception {
227 createModule(INSTANCE_NAME);
229 edit("netconfMessages/editConfig.xml");
231 Element response = getConfigRunning();
232 final int allInstances = response.getElementsByTagName("module").getLength();
234 edit("netconfMessages/editConfig_replace_default.xml");
237 response = getConfigRunning();
239 final int afterReplace = response.getElementsByTagName("module").getLength();
240 assertEquals(4, allInstances);
241 assertEquals(2, afterReplace);
244 @Test(expected = NetconfDocumentedException.class)
245 public void testSameAttrDifferentNamespaces() throws Exception {
247 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
248 } catch (NetconfDocumentedException e) {
249 String message = e.getMessage();
252 .containsString("Element simple-long-2 present multiple times with different namespaces"));
254 JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
257 .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
262 @Test(expected = NetconfDocumentedException.class)
263 public void testDifferentNamespaceInTO() throws Exception {
265 edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
266 } catch (NetconfDocumentedException e) {
267 String message = e.getMessage();
268 assertThat(message, JUnitMatchers.containsString("Unrecognised elements"));
269 assertThat(message, JUnitMatchers.containsString("simple-int2"));
270 assertThat(message, JUnitMatchers.containsString("dto_d"));
275 @Test(expected = NetconfDocumentedException.class)
276 public void testSameAttrDifferentNamespacesList() throws Exception {
278 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
279 } catch (NetconfDocumentedException e) {
280 String message = e.getMessage();
282 JUnitMatchers.containsString("Element binaryLeaf present multiple times with different namespaces"));
284 JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
287 .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
293 public void testTypeNameConfigAttributeMatching() throws Exception {
294 edit("netconfMessages/editConfig.xml");
296 edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
299 Element response = getConfigRunning();
300 checkTypeConfigAttribute(response);
303 // TODO add <modules operation="replace"> functionality
304 @Test(expected = NetconfDocumentedException.class)
305 public void testConfigNetconfReplaceModuleEx() throws Exception {
307 createModule(INSTANCE_NAME);
309 edit("netconfMessages/editConfig.xml");
310 edit("netconfMessages/editConfig_replace_module_ex.xml");
314 public void testUnrecognisedConfigElements() throws Exception {
316 String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
317 final int TESTS_COUNT = 8;
319 for (int i = 0; i < TESTS_COUNT; i++) {
320 String file = String.format(format, i + 1);
323 } catch (NetconfDocumentedException e) {
324 assertThat(e.getMessage(), JUnitMatchers.containsString("Unrecognised elements"));
325 assertThat(e.getMessage(), JUnitMatchers.containsString("unknownAttribute"));
328 fail("Unrecognised test should throw exception " + file);
335 public void testConfigNetconfReplaceModule() throws Exception {
337 createModule(INSTANCE_NAME);
339 edit("netconfMessages/editConfig.xml");
341 Element response = getConfigRunning();
342 final int allInstances = response.getElementsByTagName("instance").getLength();
344 edit("netconfMessages/editConfig_replace_module.xml");
347 response = getConfigRunning();
348 final int afterReplace = response.getElementsByTagName("instance").getLength();
350 assertEquals(4 + 4 /* Instances from services */, allInstances);
351 assertEquals(3 + 3, afterReplace);
354 @Test(expected = NetconfDocumentedException.class)
355 public void testEx() throws Exception {
360 @Test(expected = NetconfDocumentedException.class)
361 public void testEx2() throws Exception {
365 private void discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
366 DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
367 executeOp(discardOp, "netconfMessages/discardChanges.xml");
370 private void checkBinaryLeafEdited(final Element response) {
371 final NodeList children = response.getElementsByTagName("binaryLeaf");
372 assertEquals(3, children.getLength());
373 final StringBuffer buf = new StringBuffer();
374 for (int i = 0; i < 3; i++) {
375 final Element e = (Element) children.item(i);
376 buf.append(XmlElement.fromDomElement(e).getTextContent());
378 assertEquals("810", buf.toString());
381 private void checkTypedefs(final Element response) {
382 NodeList children = response.getElementsByTagName("extended");
383 assertEquals(1, children.getLength());
385 children = response.getElementsByTagName("extended-twice");
386 assertEquals(1, children.getLength());
389 private void checkEnum(final Element response) {
390 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
391 .getOnlyChildElement("modules");
393 String enumName = "extended-enum";
394 String enumContent = "TWO";
396 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
397 String name = moduleElement.getOnlyChildElement("name").getTextContent();
398 if(name.equals("test1")) {
399 XmlElement enumAttr = moduleElement.getOnlyChildElement(enumName);
400 assertEquals(enumContent, enumAttr.getTextContent());
406 fail("Enum attribute " + enumName + ":" + enumContent + " not present in " + XmlUtil.toString(response));
409 private void checkTypeConfigAttribute(Element response) {
411 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
412 .getOnlyChildElement("modules");
414 XmlElement configAttributeType = null;
415 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
416 for (XmlElement type : moduleElement.getChildElements("type")) {
417 if (type.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY).equals("") == false) {
418 configAttributeType = type;
423 assertEquals("configAttributeType", configAttributeType.getTextContent());
426 private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
427 final List<InputStream> yangDependencies = getYangs();
429 final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
430 mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap());
436 public void testConfigNetconfRuntime() throws Exception {
438 ModuleIdentifier id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance");
439 RootRuntimeBeanRegistrator rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
440 NetconfTestImplRuntimeRegistrator registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
442 NetconfTestImplRuntimeRegistration a = registerRoot(registrator);
443 InnerRunningDataRuntimeRegistration reg = registerInner(a);
446 id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance2");
447 rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
448 registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
450 a = registerRoot(registrator);
451 registerAdditional(a);
452 registerAdditional(a);
453 registerAdditional(a);
454 registerAdditional(a);
455 reg = registerInner(a);
457 reg = registerInner(a);
460 reg = registerInner(a);
464 reg = registerInner(a);
470 Element response = get();
472 System.err.println(XmlUtil.toString(response));
474 assertEquals(2, getElementsSize(response, "module"));
475 assertEquals(2, getElementsSize(response, "asdf"));
476 assertEquals(5, getElementsSize(response, "inner-running-data"));
477 assertEquals(5, getElementsSize(response, "deep2"));
478 assertEquals(11, getElementsSize(response, "inner-inner-running-data"));
479 assertEquals(11, getElementsSize(response, "deep3"));
480 assertEquals(11 * 2, getElementsSize(response, "list-of-strings"));
481 assertEquals(4, getElementsSize(response, "inner-running-data-additional"));
482 assertEquals(4, getElementsSize(response, "deep4"));
485 RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
487 response = executeOp(netconf, "netconfMessages/rpc.xml");
488 assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("testarg1".toUpperCase()));
490 response = executeOp(netconf, "netconfMessages/rpcInner.xml");
491 assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("ok"));
493 response = executeOp(netconf, "netconfMessages/rpcInnerInner.xml");
494 assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("true"));
496 response = executeOp(netconf, "netconfMessages/rpcInnerInner_complex_output.xml");
497 assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("1"));
498 assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("2"));
501 private Element get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
502 Get getOp = new Get(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
503 return executeOp(getOp, "netconfMessages/get.xml");
506 private int getElementsSize(Element response, String elementName) {
507 return response.getElementsByTagName(elementName).getLength();
510 private Object registerAdditional(final NetconfTestImplRuntimeRegistration a) {
511 class InnerRunningDataAdditionalRuntimeMXBeanTest implements InnerRunningDataAdditionalRuntimeMXBean {
513 private final int simpleInt;
514 private final String simpleString;
516 public InnerRunningDataAdditionalRuntimeMXBeanTest(final int simpleInt, final String simpleString) {
517 this.simpleInt = simpleInt;
518 this.simpleString = simpleString;
522 public Integer getSimpleInt3() {
523 return this.simpleInt;
527 public Deep4 getDeep4() {
528 final Deep4 d = new Deep4();
534 public String getSimpleString() {
535 return this.simpleString;
539 public void noArgInner() {
544 final int simpleInt = counter++;
545 return a.register(new InnerRunningDataAdditionalRuntimeMXBeanTest(simpleInt, "randomString_" + simpleInt));
548 private void registerInner2(final InnerRunningDataRuntimeRegistration reg) {
549 class InnerInnerRunningDataRuntimeMXBeanTest implements InnerInnerRunningDataRuntimeMXBean {
551 private final int simpleInt;
553 public InnerInnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
554 this.simpleInt = simpleInt;
558 public List<NotStateBean> getNotStateBean() {
559 final NotStateBean notStateBean = new NotStateBean();
560 final NotStateBeanInternal notStateBeanInternal = new NotStateBeanInternal();
561 notStateBean.setNotStateBeanInternal(Lists.newArrayList(notStateBeanInternal));
562 return Lists.newArrayList(notStateBean);
566 public Integer getSimpleInt3() {
567 return this.simpleInt;
571 public Deep3 getDeep3() {
576 public List<String> getListOfStrings() {
577 return Lists.newArrayList("l1", "l2");
581 public List<RetValList> listOutput() {
582 return Lists.newArrayList(new RetValList());
586 public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
591 public RetValContainer containerOutput() {
592 return new RetValContainer();
596 public List<String> leafListOutput() {
597 return Lists.newArrayList("1", "2");
602 reg.register(new InnerInnerRunningDataRuntimeMXBeanTest(counter++));
606 private static int counter = 1000;
608 private InnerRunningDataRuntimeRegistration registerInner(final NetconfTestImplRuntimeRegistration a) {
610 class InnerRunningDataRuntimeMXBeanTest implements InnerRunningDataRuntimeMXBean {
612 private final int simpleInt;
614 public InnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
615 this.simpleInt = simpleInt;
619 public Integer getSimpleInt3() {
620 return this.simpleInt;
624 public Deep2 getDeep2() {
629 return a.register(new InnerRunningDataRuntimeMXBeanTest(counter++));
632 private NetconfTestImplRuntimeRegistration registerRoot(final NetconfTestImplRuntimeRegistrator registrator) {
633 final NetconfTestImplRuntimeRegistration a = registrator.register(new NetconfTestImplRuntimeMXBean() {
636 public Long getCreatedSessions() {
641 public Asdf getAsdf() {
642 final Asdf asdf = new Asdf();
643 asdf.setSimpleInt(55);
644 asdf.setSimpleString("asdf");
649 public String noArg(final String arg1) {
650 return arg1.toUpperCase();
657 private Element executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
658 SAXException, IOException, NetconfDocumentedException {
660 final Document request = XmlFileLoader.xmlFileToDocument(filename);
662 logger.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
663 HandlingPriority priority = op.canHandle(request);
665 Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
667 final Document response = op.handle(request, netconfOperationRouter);
668 logger.debug("Got response\n{}", XmlUtil.toString(response));
669 return response.getDocumentElement();
672 private List<InputStream> getYangs() throws FileNotFoundException {
673 List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
674 "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/test-types.yang",
675 "/META-INF/yang/ietf-inet-types.yang");
676 final Collection<InputStream> yangDependencies = new ArrayList<>();
677 for (String path : paths) {
678 final InputStream is = Preconditions
679 .checkNotNull(getClass().getResourceAsStream(path), path + " not found");
680 yangDependencies.add(is);
682 return Lists.newArrayList(yangDependencies);
685 private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction)
686 throws InstanceAlreadyExistsException {
687 mxBean.setSimpleInt((long) 44);
688 mxBean.setBinaryLeaf(new byte[] { 8, 7, 9 });
689 final DtoD dtob = getDtoD();
690 mxBean.setDtoD(dtob);
692 final DtoC dtoa = getDtoC();
693 mxBean.setDtoC(dtoa);
694 mxBean.setSimpleBoolean(false);
696 final Peers p1 = new Peers();
699 p1.setSimpleInt3(456);
700 final Peers p2 = new Peers();
702 p2.setPort("port23");
703 p2.setSimpleInt3(456);
704 mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
706 mxBean.setSimpleLong(454545L);
707 mxBean.setSimpleLong2(44L);
708 mxBean.setSimpleBigInteger(BigInteger.valueOf(999L));
709 mxBean.setSimpleByte(new Byte((byte) 4));
710 mxBean.setSimpleShort(new Short((short) 4));
711 mxBean.setSimpleTest(545);
713 mxBean.setComplexList(Lists.<ComplexList> newArrayList());
714 mxBean.setSimpleList(Lists.<Integer> newArrayList());
716 final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), "dep");
717 mxBean.setTestingDep(testingDepOn);
720 private static DtoD getDtoD() {
721 final DtoD dtob = new DtoD();
722 dtob.setSimpleInt1((long) 444);
723 dtob.setSimpleInt2((long) 4444);
724 dtob.setSimpleInt3(454);
725 final ComplexDtoBInner dtobInner = new ComplexDtoBInner();
726 final Deep deep = new Deep();
727 deep.setSimpleInt3(4);
728 dtobInner.setDeep(deep);
729 dtobInner.setSimpleInt3(44);
730 dtobInner.setSimpleList(Lists.newArrayList(4));
731 dtob.setComplexDtoBInner(Lists.newArrayList(dtobInner));
732 dtob.setSimpleList(Lists.newArrayList(4));
736 private static DtoC getDtoC() {
737 final DtoC dtoa = new DtoC();
738 // dtoa.setSimpleArg((long) 55);
739 final DtoAInner dtoAInner = new DtoAInner();
740 final DtoAInnerInner dtoAInnerInner = new DtoAInnerInner();
741 dtoAInnerInner.setSimpleArg(456L);
742 dtoAInner.setDtoAInnerInner(dtoAInnerInner);
743 dtoAInner.setSimpleArg(44L);
744 dtoa.setDtoAInner(dtoAInner);