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 com.google.common.collect.Sets;
16 import org.apache.commons.lang3.StringUtils;
17 import org.junit.Before;
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.junit.matchers.JUnitMatchers;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
24 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
25 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
26 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
27 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
28 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
29 import org.opendaylight.controller.config.yang.store.impl.MbeParser;
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.DepTestImplModuleFactory;
34 import org.opendaylight.controller.config.yang.test.impl.DtoAInner;
35 import org.opendaylight.controller.config.yang.test.impl.DtoAInnerInner;
36 import org.opendaylight.controller.config.yang.test.impl.DtoC;
37 import org.opendaylight.controller.config.yang.test.impl.DtoD;
38 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory;
39 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean;
40 import org.opendaylight.controller.config.yang.test.impl.Peers;
41 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
42 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
43 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;
44 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
45 import org.opendaylight.controller.netconf.confignetconfconnector.operations.DiscardChanges;
46 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
47 import org.opendaylight.controller.netconf.confignetconfconnector.operations.get.Get;
48 import org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig.GetConfig;
49 import org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc.RuntimeRpc;
50 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
51 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
52 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
53 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
54 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
55 import org.opendaylight.controller.netconf.util.xml.XmlElement;
56 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
57 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
60 import org.w3c.dom.Document;
61 import org.w3c.dom.Element;
62 import org.w3c.dom.NodeList;
63 import org.xml.sax.SAXException;
65 import javax.management.InstanceAlreadyExistsException;
66 import javax.management.InstanceNotFoundException;
67 import javax.management.ObjectName;
68 import javax.xml.parsers.ParserConfigurationException;
69 import java.io.FileNotFoundException;
70 import java.io.IOException;
71 import java.io.InputStream;
72 import java.math.BigInteger;
73 import java.net.URISyntaxException;
74 import java.util.ArrayList;
75 import java.util.Arrays;
76 import java.util.Collection;
77 import java.util.List;
81 import static org.junit.Assert.assertEquals;
82 import static org.junit.Assert.assertThat;
83 import static org.junit.Assert.assertTrue;
84 import static org.junit.Assert.fail;
85 import static org.mockito.Mockito.doNothing;
86 import static org.mockito.Mockito.doReturn;
87 import static org.mockito.Mockito.verify;
88 import static org.mockito.Mockito.verifyNoMoreInteractions;
91 public class NetconfMappingTest extends AbstractConfigTest {
92 private static final Logger logger = LoggerFactory.getLogger(NetconfMappingTest.class);
94 private static final String INSTANCE_NAME = "instance-from-code";
95 private static final String NETCONF_SESSION_ID = "foo";
96 private NetconfTestImplModuleFactory factory;
97 private DepTestImplModuleFactory factory2;
100 YangStoreSnapshot yangStoreSnapshot;
102 NetconfOperationRouter netconfOperationRouter;
104 private TransactionProvider transactionProvider;
107 public void setUp() throws Exception {
108 MockitoAnnotations.initMocks(this);
109 doReturn(getMbes()).when(this.yangStoreSnapshot).getModuleMXBeanEntryMap();
110 this.factory = new NetconfTestImplModuleFactory();
111 this.factory2 = new DepTestImplModuleFactory();
112 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.factory, this.factory2));
114 transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID);
117 private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException, InstanceNotFoundException, URISyntaxException {
118 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
120 final ObjectName on = transaction.createModule(this.factory.getImplementationName(), instanceName);
121 final NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
122 setModule(mxBean, transaction, instanceName + "_dep");
125 for (Class<? extends AbstractServiceInterface> sInterface : factory.getImplementedServiceIntefaces()) {
126 ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class);
127 transaction.saveServiceReference(
128 transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), "ref_from_code_to_" + instanceName + "_" + i++,
132 transaction.commit();
137 public void testServicePersistance() throws Exception {
138 createModule(INSTANCE_NAME);
140 edit("netconfMessages/editConfig.xml");
141 Element config = getConfigCandidate();
142 assertCorrectServiceNames(config, 6, "ref_test2", "user_to_instance_from_code", "ref_dep_user",
143 "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
144 "ref_from_code_to_instance-from-code_1");
146 edit("netconfMessages/editConfig_addServiceName.xml");
147 config = getConfigCandidate();
148 assertCorrectServiceNames(config, 7, "ref_test2", "user_to_instance_from_code", "ref_dep_user",
149 "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
150 "ref_from_code_to_instance-from-code_1", "ref_dep_user_another");
153 config = getConfigRunning();
154 assertCorrectRefNamesForDependencies(config);
155 assertCorrectServiceNames(config, 7, "ref_test2", "user_to_instance_from_code", "ref_dep_user",
156 "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
157 "ref_from_code_to_instance-from-code_1", "ref_dep_user_another");
159 edit("netconfMessages/editConfig_replace_default.xml");
160 config = getConfigCandidate();
161 assertCorrectServiceNames(config, 2, "ref_dep", "ref_dep2");
163 edit("netconfMessages/editConfig_remove.xml");
164 config = getConfigCandidate();
165 assertCorrectServiceNames(config, 0);
168 config = getConfigCandidate();
169 assertCorrectServiceNames(config, 0);
173 private void assertCorrectRefNamesForDependencies(Element config) {
174 NodeList modulesList = config.getElementsByTagName("modules");
175 assertEquals(1, modulesList.getLength());
177 Element modules = (Element) modulesList.item(0);
179 String trimmedModules = XmlUtil.toString(modules).replaceAll("\\s", "");
180 int defaultRefNameCount = StringUtils.countMatches(trimmedModules, "ref_dep2");
181 int userRefNameCount = StringUtils.countMatches(trimmedModules, "ref_dep_user_two");
183 assertEquals(0, defaultRefNameCount);
184 assertEquals(2, userRefNameCount);
187 private void assertCorrectServiceNames(Element configCandidate, int servicesSize, String... refNames) {
188 NodeList elements = configCandidate.getElementsByTagName("provider");
189 assertEquals(servicesSize, elements.getLength());
191 NodeList servicesList = configCandidate.getElementsByTagName("services");
192 assertEquals(1, servicesList.getLength());
194 Element services = (Element) servicesList.item(0);
195 String trimmedServices = XmlUtil.toString(services).replaceAll("\\s", "");
197 for (String s : refNames) {
198 assertThat(trimmedServices, JUnitMatchers.containsString(s));
203 public void testConfigNetconf() throws Exception {
205 createModule(INSTANCE_NAME);
207 edit("netconfMessages/editConfig.xml");
208 Element configCandidate = getConfigCandidate();
209 checkBinaryLeafEdited(configCandidate);
212 // default-operation:none, should not affect binary leaf
213 edit("netconfMessages/editConfig_none.xml");
214 checkBinaryLeafEdited(getConfigCandidate());
218 Element response = getConfigRunning();
220 checkBinaryLeafEdited(response);
221 checkTypeConfigAttribute(response);
222 checkTypedefs(response);
223 checkTestingDeps(response);
225 checkBigDecimal(response);
227 edit("netconfMessages/editConfig_remove.xml");
230 response = getConfigCandidate();
231 final String responseFromCandidate = XmlUtil.toString(response).replaceAll("\\s+", "");
232 // System.out.println(responseFromCandidate);
233 response = getConfigRunning();
234 final String responseFromRunning = XmlUtil.toString(response).replaceAll("\\s+", "");
235 // System.out.println(responseFromRunning);
236 assertEquals(responseFromCandidate, responseFromRunning);
238 final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml")
239 .replaceAll("\\s+", "");
241 assertEquals(expectedResult, responseFromRunning);
242 assertEquals(expectedResult, responseFromCandidate);
244 edit("netconfMessages/editConfig_none.xml");
245 doNothing().when(netconfOperationRouter).close();
247 verify(netconfOperationRouter).close();
248 verifyNoMoreInteractions(netconfOperationRouter);
251 private void checkBigDecimal(Element response) {
252 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
254 assertContainsString(responseTrimmed, "<sleep-factorxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.58</sleep-factor>");
256 assertContainsString(responseTrimmed, "<sleep-factorxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.00</sleep-factor>");
260 private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
262 DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
263 executeOp(closeOp, "netconfMessages/closeSession.xml");
266 private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
267 NetconfDocumentedException {
268 EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
270 executeOp(editOp, resource);
273 private void commit() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
274 Commit commitOp = new Commit(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
275 executeOp(commitOp, "netconfMessages/commit.xml");
278 private Element getConfigCandidate() throws ParserConfigurationException, SAXException, IOException,
279 NetconfDocumentedException {
280 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
281 configRegistryClient, NETCONF_SESSION_ID);
282 return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
285 private Element getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
286 NetconfDocumentedException {
287 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
288 configRegistryClient, NETCONF_SESSION_ID);
289 return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
292 @Ignore("second edit message corrupted")
293 @Test(expected = NetconfDocumentedException.class)
294 public void testConfigNetconfReplaceDefaultEx() throws Exception {
296 createModule(INSTANCE_NAME);
298 edit("netconfMessages/editConfig.xml");
299 edit("netconfMessages/editConfig_replace_default_ex.xml");
303 public void testConfigNetconfReplaceDefault() throws Exception {
305 createModule(INSTANCE_NAME);
307 edit("netconfMessages/editConfig.xml");
309 Element response = getConfigRunning();
310 final int allInstances = response.getElementsByTagName("module").getLength();
312 edit("netconfMessages/editConfig_replace_default.xml");
315 response = getConfigRunning();
317 final int afterReplace = response.getElementsByTagName("module").getLength();
318 assertEquals(4, allInstances);
319 assertEquals(2, afterReplace);
322 @Test(expected = NetconfDocumentedException.class)
323 public void testSameAttrDifferentNamespaces() throws Exception {
325 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
326 } catch (NetconfDocumentedException e) {
327 String message = e.getMessage();
328 assertContainsString(message, "Element simple-long-2 present multiple times with different namespaces");
329 assertContainsString(message, "urn:opendaylight:params:xml:ns:yang:controller:test:impl");
330 assertContainsString(message, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
335 @Test(expected = NetconfDocumentedException.class)
336 public void testDifferentNamespaceInTO() throws Exception {
338 edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
339 } catch (NetconfDocumentedException e) {
340 String message = e.getMessage();
341 assertContainsString(message, "Unrecognised elements");
342 assertContainsString(message, "simple-int2");
343 assertContainsString(message, "dto_d");
348 @Test(expected = NetconfDocumentedException.class)
349 public void testSameAttrDifferentNamespacesList() throws Exception {
351 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
352 } catch (NetconfDocumentedException e) {
353 String message = e.getMessage();
354 assertContainsString(message, "Element binaryLeaf present multiple times with different namespaces");
355 assertContainsString(message, "urn:opendaylight:params:xml:ns:yang:controller:test:impl");
356 assertContainsString(message, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
362 public void testTypeNameConfigAttributeMatching() throws Exception {
363 edit("netconfMessages/editConfig.xml");
365 edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
368 Element response = getConfigRunning();
369 checkTypeConfigAttribute(response);
372 // TODO add <modules operation="replace"> functionality
373 @Test(expected = NetconfDocumentedException.class)
374 public void testConfigNetconfReplaceModuleEx() throws Exception {
376 createModule(INSTANCE_NAME);
378 edit("netconfMessages/editConfig.xml");
379 edit("netconfMessages/editConfig_replace_module_ex.xml");
383 public void testUnrecognisedConfigElements() throws Exception {
385 String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
386 final int TESTS_COUNT = 8;
388 for (int i = 0; i < TESTS_COUNT; i++) {
389 String file = String.format(format, i + 1);
392 } catch (NetconfDocumentedException e) {
393 assertContainsString(e.getMessage(), "Unrecognised elements");
394 assertContainsString(e.getMessage(), "unknownAttribute");
397 fail("Unrecognised test should throw exception " + file);
404 public void testConfigNetconfReplaceModule() throws Exception {
406 createModule(INSTANCE_NAME);
408 edit("netconfMessages/editConfig.xml");
410 Element response = getConfigRunning();
411 final int allInstances = response.getElementsByTagName("instance").getLength();
413 edit("netconfMessages/editConfig_replace_module.xml");
416 response = getConfigRunning();
417 final int afterReplace = response.getElementsByTagName("instance").getLength();
419 assertEquals(4 + 4 /* Instances from services */, allInstances);
420 assertEquals(3 + 3, afterReplace);
423 @Test(expected = NetconfDocumentedException.class)
424 public void testEx() throws Exception {
429 @Test(expected = NetconfDocumentedException.class)
430 public void testEx2() throws Exception {
434 private void discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
435 DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
436 executeOp(discardOp, "netconfMessages/discardChanges.xml");
439 private void checkBinaryLeafEdited(final Element response) {
440 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
441 String substring = "<binaryLeafxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">YmluYXJ5</binaryLeaf>";
442 assertContainsString(responseTrimmed, substring);
443 substring = "<binaryLeafxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ZGVmYXVsdEJpbg==</binaryLeaf>";
444 assertContainsString(responseTrimmed, substring);
447 private void checkTypedefs(final Element response) {
448 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
450 String substring = "<extendedxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">10</extended>";
451 assertContainsString(responseTrimmed, substring);
453 assertContainsString(responseTrimmed,
454 "<extendedxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">1</extended>");
456 assertContainsString(responseTrimmed,
457 "<extended-twicexmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">20</extended-twice>");
459 assertContainsString(responseTrimmed,
460 "<extended-twicexmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2</extended-twice>");
462 assertContainsString(responseTrimmed,
463 "<extended-enumxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">TWO</extended-enum>");
465 assertContainsString(responseTrimmed,
466 "<extended-enumxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ONE</extended-enum>");
469 private void assertContainsString(String string, String substring) {
470 assertThat(string, JUnitMatchers.containsString(substring));
473 private void checkEnum(final Element response) {
474 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
475 .getOnlyChildElement("modules");
477 String enumName = "extended-enum";
478 String enumContent = "TWO";
480 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
481 String name = moduleElement.getOnlyChildElement("name").getTextContent();
482 if(name.equals(INSTANCE_NAME)) {
483 XmlElement enumAttr = moduleElement.getOnlyChildElement(enumName);
484 assertEquals(enumContent, enumAttr.getTextContent());
490 fail("Enum attribute " + enumName + ":" + enumContent + " not present in " + XmlUtil.toString(response));
493 private void checkTestingDeps(Element response) {
494 int testingDepsSize = response.getElementsByTagName("testing-deps").getLength();
495 assertEquals(2, testingDepsSize);
498 private void checkTypeConfigAttribute(Element response) {
500 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
501 .getOnlyChildElement("modules");
503 List<String> expectedValues = Lists.newArrayList("default-string", "configAttributeType");
504 Set<String> configAttributeType = Sets.newHashSet();
506 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
507 for (XmlElement type : moduleElement.getChildElements("type")) {
508 if (type.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY).equals("") == false) {
509 configAttributeType.add(type.getTextContent());
514 for (String expectedValue : expectedValues) {
515 assertTrue(configAttributeType.contains(expectedValue));
519 private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
520 final List<InputStream> yangDependencies = getYangs();
522 final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
523 mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap());
529 public void testConfigNetconfRuntime() throws Exception {
531 createModule(INSTANCE_NAME);
533 edit("netconfMessages/editConfig.xml");
534 checkBinaryLeafEdited(getConfigCandidate());
538 Element response = get();
540 assertEquals(2/*With runtime beans*/ + 2 /*Without runtime beans*/, getElementsSize(response, "module"));
542 assertEquals(2, getElementsSize(response, "asdf"));
543 // data from running config
544 assertEquals(2, getElementsSize(response, "simple-short"));
546 assertEquals(8, getElementsSize(response, "inner-running-data"));
547 assertEquals(8, getElementsSize(response, "deep2"));
548 assertEquals(8 * 4, getElementsSize(response, "inner-inner-running-data"));
549 assertEquals(8 * 4, getElementsSize(response, "deep3"));
550 assertEquals(8 * 4 * 2, getElementsSize(response, "list-of-strings"));
551 assertEquals(8, getElementsSize(response, "inner-running-data-additional"));
552 assertEquals(8, getElementsSize(response, "deep4"));
555 RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
557 response = executeOp(netconf, "netconfMessages/rpc.xml");
558 assertContainsString(XmlUtil.toString(response), "testarg1".toUpperCase());
560 response = executeOp(netconf, "netconfMessages/rpcInner.xml");
561 assertContainsString(XmlUtil.toString(response), "ok");
563 response = executeOp(netconf, "netconfMessages/rpcInnerInner.xml");
564 assertContainsString(XmlUtil.toString(response), "true");
566 response = executeOp(netconf, "netconfMessages/rpcInnerInner_complex_output.xml");
567 assertContainsString(XmlUtil.toString(response), "1");
568 assertContainsString(XmlUtil.toString(response), "2");
571 private Element get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
572 Get getOp = new Get(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID, transactionProvider);
573 return executeOp(getOp, "netconfMessages/get.xml");
576 private int getElementsSize(Element response, String elementName) {
577 return response.getElementsByTagName(elementName).getLength();
580 private Element executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
581 SAXException, IOException, NetconfDocumentedException {
583 final Document request = XmlFileLoader.xmlFileToDocument(filename);
585 logger.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
586 HandlingPriority priority = op.canHandle(request);
588 Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
590 final Document response = op.handle(request, netconfOperationRouter);
591 logger.debug("Got response\n{}", XmlUtil.toString(response));
592 return response.getDocumentElement();
595 private List<InputStream> getYangs() throws FileNotFoundException {
596 List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
597 "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/test-types.yang",
598 "/META-INF/yang/ietf-inet-types.yang");
599 final Collection<InputStream> yangDependencies = new ArrayList<>();
600 for (String path : paths) {
601 final InputStream is = Preconditions
602 .checkNotNull(getClass().getResourceAsStream(path), path + " not found");
603 yangDependencies.add(is);
605 return Lists.newArrayList(yangDependencies);
608 private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction, String depName)
609 throws InstanceAlreadyExistsException, InstanceNotFoundException {
610 mxBean.setSimpleInt((long) 44);
611 mxBean.setBinaryLeaf(new byte[] { 8, 7, 9 });
612 final DtoD dtob = getDtoD();
613 mxBean.setDtoD(dtob);
615 final DtoC dtoa = getDtoC();
616 mxBean.setDtoC(dtoa);
617 mxBean.setSimpleBoolean(false);
619 final Peers p1 = new Peers();
622 p1.setSimpleInt3(456);
623 final Peers p2 = new Peers();
625 p2.setPort("port23");
626 p2.setSimpleInt3(456);
627 mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
629 mxBean.setSimpleLong(454545L);
630 mxBean.setSimpleLong2(44L);
631 mxBean.setSimpleBigInteger(BigInteger.valueOf(999L));
632 mxBean.setSimpleByte(new Byte((byte) 4));
633 mxBean.setSimpleShort(new Short((short) 4));
634 mxBean.setSimpleTest(545);
636 mxBean.setComplexList(Lists.<ComplexList> newArrayList());
637 mxBean.setSimpleList(Lists.<Integer> newArrayList());
639 final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), depName);
641 for (Class<? extends AbstractServiceInterface> sInterface : factory2.getImplementedServiceIntefaces()) {
642 ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class);
643 transaction.saveServiceReference(
644 transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), "ref_from_code_to_" + depName + "_" + i++,
648 mxBean.setTestingDep(testingDepOn);
651 private static DtoD getDtoD() {
652 final DtoD dtob = new DtoD();
653 dtob.setSimpleInt1((long) 444);
654 dtob.setSimpleInt2((long) 4444);
655 dtob.setSimpleInt3(454);
656 final ComplexDtoBInner dtobInner = new ComplexDtoBInner();
657 final Deep deep = new Deep();
658 deep.setSimpleInt3(4);
659 dtobInner.setDeep(deep);
660 dtobInner.setSimpleInt3(44);
661 dtobInner.setSimpleList(Lists.newArrayList(4));
662 dtob.setComplexDtoBInner(Lists.newArrayList(dtobInner));
663 dtob.setSimpleList(Lists.newArrayList(4));
667 private static DtoC getDtoC() {
668 final DtoC dtoa = new DtoC();
669 // dtoa.setSimpleArg((long) 55);
670 final DtoAInner dtoAInner = new DtoAInner();
671 final DtoAInnerInner dtoAInnerInner = new DtoAInnerInner();
672 dtoAInnerInner.setSimpleArg(456L);
673 dtoAInner.setDtoAInnerInner(dtoAInnerInner);
674 dtoAInner.setSimpleArg(44L);
675 dtoa.setDtoAInner(dtoAInner);