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 testConfigNetconfUnionTypes() throws Exception {
205 createModule(INSTANCE_NAME);
207 edit("netconfMessages/editConfig.xml");
209 Element response = getConfigRunning();
210 String trimmedResponse = XmlUtil.toString(response).replaceAll("\\s", "");
211 assertContainsString(trimmedResponse, "<ipxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">0:0:0:0:0:0:0:1</ip>");
212 assertContainsString(trimmedResponse, "<union-test-attrxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">456</union-test-attr>");
215 edit("netconfMessages/editConfig_setUnions.xml");
217 response = getConfigRunning();
219 trimmedResponse = XmlUtil.toString(response).replaceAll("\\s", "");
220 assertContainsString(trimmedResponse, "<ipxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">127.1.2.3</ip>");
221 assertContainsString(trimmedResponse, "<union-test-attrxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">randomStringForUnion</union-test-attr>");
226 public void testConfigNetconf() throws Exception {
228 createModule(INSTANCE_NAME);
230 edit("netconfMessages/editConfig.xml");
231 Element configCandidate = getConfigCandidate();
232 checkBinaryLeafEdited(configCandidate);
235 // default-operation:none, should not affect binary leaf
236 edit("netconfMessages/editConfig_none.xml");
237 checkBinaryLeafEdited(getConfigCandidate());
241 Element response = getConfigRunning();
243 checkBinaryLeafEdited(response);
244 checkTypeConfigAttribute(response);
245 checkTypedefs(response);
246 checkTestingDeps(response);
248 checkBigDecimal(response);
250 edit("netconfMessages/editConfig_remove.xml");
253 response = getConfigCandidate();
254 final String responseFromCandidate = XmlUtil.toString(response).replaceAll("\\s+", "");
255 // System.out.println(responseFromCandidate);
256 response = getConfigRunning();
257 final String responseFromRunning = XmlUtil.toString(response).replaceAll("\\s+", "");
258 // System.out.println(responseFromRunning);
259 assertEquals(responseFromCandidate, responseFromRunning);
261 final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml")
262 .replaceAll("\\s+", "");
264 assertEquals(expectedResult, responseFromRunning);
265 assertEquals(expectedResult, responseFromCandidate);
267 edit("netconfMessages/editConfig_none.xml");
268 doNothing().when(netconfOperationRouter).close();
270 verify(netconfOperationRouter).close();
271 verifyNoMoreInteractions(netconfOperationRouter);
274 private void checkBigDecimal(Element response) {
275 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
277 assertContainsString(responseTrimmed, "<sleep-factorxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.58</sleep-factor>");
279 assertContainsString(responseTrimmed, "<sleep-factorxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.00</sleep-factor>");
283 private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
285 DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
286 executeOp(closeOp, "netconfMessages/closeSession.xml");
289 private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
290 NetconfDocumentedException {
291 EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
293 executeOp(editOp, resource);
296 private void commit() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
297 Commit commitOp = new Commit(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
298 executeOp(commitOp, "netconfMessages/commit.xml");
301 private Element getConfigCandidate() throws ParserConfigurationException, SAXException, IOException,
302 NetconfDocumentedException {
303 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
304 configRegistryClient, NETCONF_SESSION_ID);
305 return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
308 private Element getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
309 NetconfDocumentedException {
310 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
311 configRegistryClient, NETCONF_SESSION_ID);
312 return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
315 @Ignore("second edit message corrupted")
316 @Test(expected = NetconfDocumentedException.class)
317 public void testConfigNetconfReplaceDefaultEx() throws Exception {
319 createModule(INSTANCE_NAME);
321 edit("netconfMessages/editConfig.xml");
322 edit("netconfMessages/editConfig_replace_default_ex.xml");
326 public void testConfigNetconfReplaceDefault() throws Exception {
328 createModule(INSTANCE_NAME);
330 edit("netconfMessages/editConfig.xml");
332 Element response = getConfigRunning();
333 final int allInstances = response.getElementsByTagName("module").getLength();
335 edit("netconfMessages/editConfig_replace_default.xml");
338 response = getConfigRunning();
340 final int afterReplace = response.getElementsByTagName("module").getLength();
341 assertEquals(4, allInstances);
342 assertEquals(2, afterReplace);
345 @Test(expected = NetconfDocumentedException.class)
346 public void testSameAttrDifferentNamespaces() throws Exception {
348 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
349 } catch (NetconfDocumentedException e) {
350 String message = e.getMessage();
351 assertContainsString(message, "Element simple-long-2 present multiple times with different namespaces");
352 assertContainsString(message, "urn:opendaylight:params:xml:ns:yang:controller:test:impl");
353 assertContainsString(message, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
358 @Test(expected = NetconfDocumentedException.class)
359 public void testDifferentNamespaceInTO() throws Exception {
361 edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
362 } catch (NetconfDocumentedException e) {
363 String message = e.getMessage();
364 assertContainsString(message, "Unrecognised elements");
365 assertContainsString(message, "simple-int2");
366 assertContainsString(message, "dto_d");
371 @Test(expected = NetconfDocumentedException.class)
372 public void testSameAttrDifferentNamespacesList() throws Exception {
374 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
375 } catch (NetconfDocumentedException e) {
376 String message = e.getMessage();
377 assertContainsString(message, "Element binaryLeaf present multiple times with different namespaces");
378 assertContainsString(message, "urn:opendaylight:params:xml:ns:yang:controller:test:impl");
379 assertContainsString(message, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
385 public void testTypeNameConfigAttributeMatching() throws Exception {
386 edit("netconfMessages/editConfig.xml");
388 edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
391 Element response = getConfigRunning();
392 checkTypeConfigAttribute(response);
395 // TODO add <modules operation="replace"> functionality
396 @Test(expected = NetconfDocumentedException.class)
397 public void testConfigNetconfReplaceModuleEx() throws Exception {
399 createModule(INSTANCE_NAME);
401 edit("netconfMessages/editConfig.xml");
402 edit("netconfMessages/editConfig_replace_module_ex.xml");
406 public void testUnrecognisedConfigElements() throws Exception {
408 String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
409 final int TESTS_COUNT = 8;
411 for (int i = 0; i < TESTS_COUNT; i++) {
412 String file = String.format(format, i + 1);
415 } catch (NetconfDocumentedException e) {
416 assertContainsString(e.getMessage(), "Unrecognised elements");
417 assertContainsString(e.getMessage(), "unknownAttribute");
420 fail("Unrecognised test should throw exception " + file);
427 public void testConfigNetconfReplaceModule() throws Exception {
429 createModule(INSTANCE_NAME);
431 edit("netconfMessages/editConfig.xml");
433 Element response = getConfigRunning();
434 final int allInstances = response.getElementsByTagName("instance").getLength();
436 edit("netconfMessages/editConfig_replace_module.xml");
439 response = getConfigRunning();
440 final int afterReplace = response.getElementsByTagName("instance").getLength();
442 assertEquals(4 + 4 /* Instances from services */, allInstances);
443 assertEquals(3 + 3, afterReplace);
446 @Test(expected = NetconfDocumentedException.class)
447 public void testEx() throws Exception {
452 @Test(expected = NetconfDocumentedException.class)
453 public void testEx2() throws Exception {
457 private void discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
458 DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
459 executeOp(discardOp, "netconfMessages/discardChanges.xml");
462 private void checkBinaryLeafEdited(final Element response) {
463 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
464 String substring = "<binaryLeafxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">YmluYXJ5</binaryLeaf>";
465 assertContainsString(responseTrimmed, substring);
466 substring = "<binaryLeafxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ZGVmYXVsdEJpbg==</binaryLeaf>";
467 assertContainsString(responseTrimmed, substring);
470 private void checkTypedefs(final Element response) {
471 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
473 String substring = "<extendedxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">10</extended>";
474 assertContainsString(responseTrimmed, substring);
476 assertContainsString(responseTrimmed,
477 "<extendedxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">1</extended>");
479 assertContainsString(responseTrimmed,
480 "<extended-twicexmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">20</extended-twice>");
482 assertContainsString(responseTrimmed,
483 "<extended-twicexmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2</extended-twice>");
485 assertContainsString(responseTrimmed,
486 "<extended-enumxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">TWO</extended-enum>");
488 assertContainsString(responseTrimmed,
489 "<extended-enumxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ONE</extended-enum>");
492 private void assertContainsString(String string, String substring) {
493 assertThat(string, JUnitMatchers.containsString(substring));
496 private void checkEnum(final Element response) {
497 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
498 .getOnlyChildElement("modules");
500 String enumName = "extended-enum";
501 String enumContent = "TWO";
503 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
504 String name = moduleElement.getOnlyChildElement("name").getTextContent();
505 if(name.equals(INSTANCE_NAME)) {
506 XmlElement enumAttr = moduleElement.getOnlyChildElement(enumName);
507 assertEquals(enumContent, enumAttr.getTextContent());
513 fail("Enum attribute " + enumName + ":" + enumContent + " not present in " + XmlUtil.toString(response));
516 private void checkTestingDeps(Element response) {
517 int testingDepsSize = response.getElementsByTagName("testing-deps").getLength();
518 assertEquals(2, testingDepsSize);
521 private void checkTypeConfigAttribute(Element response) {
523 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
524 .getOnlyChildElement("modules");
526 List<String> expectedValues = Lists.newArrayList("default-string", "configAttributeType");
527 Set<String> configAttributeType = Sets.newHashSet();
529 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
530 for (XmlElement type : moduleElement.getChildElements("type")) {
531 if (type.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY).equals("") == false) {
532 configAttributeType.add(type.getTextContent());
537 for (String expectedValue : expectedValues) {
538 assertTrue(configAttributeType.contains(expectedValue));
542 private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
543 final List<InputStream> yangDependencies = getYangs();
545 final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
546 mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap());
552 public void testConfigNetconfRuntime() throws Exception {
554 createModule(INSTANCE_NAME);
556 edit("netconfMessages/editConfig.xml");
557 checkBinaryLeafEdited(getConfigCandidate());
561 Element response = get();
563 assertEquals(2/*With runtime beans*/ + 2 /*Without runtime beans*/, getElementsSize(response, "module"));
565 assertEquals(2, getElementsSize(response, "asdf"));
566 // data from running config
567 assertEquals(2, getElementsSize(response, "simple-short"));
569 assertEquals(8, getElementsSize(response, "inner-running-data"));
570 assertEquals(8, getElementsSize(response, "deep2"));
571 assertEquals(8 * 4, getElementsSize(response, "inner-inner-running-data"));
572 assertEquals(8 * 4, getElementsSize(response, "deep3"));
573 assertEquals(8 * 4 * 2, getElementsSize(response, "list-of-strings"));
574 assertEquals(8, getElementsSize(response, "inner-running-data-additional"));
575 assertEquals(8, getElementsSize(response, "deep4"));
578 RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
580 response = executeOp(netconf, "netconfMessages/rpc.xml");
581 assertContainsString(XmlUtil.toString(response), "testarg1".toUpperCase());
583 response = executeOp(netconf, "netconfMessages/rpcInner.xml");
584 assertContainsString(XmlUtil.toString(response), "ok");
586 response = executeOp(netconf, "netconfMessages/rpcInnerInner.xml");
587 assertContainsString(XmlUtil.toString(response), "true");
589 response = executeOp(netconf, "netconfMessages/rpcInnerInner_complex_output.xml");
590 assertContainsString(XmlUtil.toString(response), "1");
591 assertContainsString(XmlUtil.toString(response), "2");
594 private Element get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
595 Get getOp = new Get(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID, transactionProvider);
596 return executeOp(getOp, "netconfMessages/get.xml");
599 private int getElementsSize(Element response, String elementName) {
600 return response.getElementsByTagName(elementName).getLength();
603 private Element executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
604 SAXException, IOException, NetconfDocumentedException {
606 final Document request = XmlFileLoader.xmlFileToDocument(filename);
608 logger.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
609 HandlingPriority priority = op.canHandle(request);
611 Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
613 final Document response = op.handle(request, netconfOperationRouter);
614 logger.debug("Got response\n{}", XmlUtil.toString(response));
615 return response.getDocumentElement();
618 private List<InputStream> getYangs() throws FileNotFoundException {
619 List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
620 "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/test-types.yang",
621 "/META-INF/yang/ietf-inet-types.yang");
622 final Collection<InputStream> yangDependencies = new ArrayList<>();
623 for (String path : paths) {
624 final InputStream is = Preconditions
625 .checkNotNull(getClass().getResourceAsStream(path), path + " not found");
626 yangDependencies.add(is);
628 return Lists.newArrayList(yangDependencies);
631 private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction, String depName)
632 throws InstanceAlreadyExistsException, InstanceNotFoundException {
633 mxBean.setSimpleInt((long) 44);
634 mxBean.setBinaryLeaf(new byte[] { 8, 7, 9 });
635 final DtoD dtob = getDtoD();
636 mxBean.setDtoD(dtob);
638 final DtoC dtoa = getDtoC();
639 mxBean.setDtoC(dtoa);
640 mxBean.setSimpleBoolean(false);
642 final Peers p1 = new Peers();
645 p1.setSimpleInt3(456);
646 final Peers p2 = new Peers();
648 p2.setPort("port23");
649 p2.setSimpleInt3(456);
650 mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
652 mxBean.setSimpleLong(454545L);
653 mxBean.setSimpleLong2(44L);
654 mxBean.setSimpleBigInteger(BigInteger.valueOf(999L));
655 mxBean.setSimpleByte(new Byte((byte) 4));
656 mxBean.setSimpleShort(new Short((short) 4));
657 mxBean.setSimpleTest(545);
659 mxBean.setComplexList(Lists.<ComplexList> newArrayList());
660 mxBean.setSimpleList(Lists.<Integer> newArrayList());
662 final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), depName);
664 for (Class<? extends AbstractServiceInterface> sInterface : factory2.getImplementedServiceIntefaces()) {
665 ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class);
666 transaction.saveServiceReference(
667 transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), "ref_from_code_to_" + depName + "_" + i++,
671 mxBean.setTestingDep(testingDepOn);
674 private static DtoD getDtoD() {
675 final DtoD dtob = new DtoD();
676 dtob.setSimpleInt1((long) 444);
677 dtob.setSimpleInt2((long) 4444);
678 dtob.setSimpleInt3(454);
679 final ComplexDtoBInner dtobInner = new ComplexDtoBInner();
680 final Deep deep = new Deep();
681 deep.setSimpleInt3(4);
682 dtobInner.setDeep(deep);
683 dtobInner.setSimpleInt3(44);
684 dtobInner.setSimpleList(Lists.newArrayList(4));
685 dtob.setComplexDtoBInner(Lists.newArrayList(dtobInner));
686 dtob.setSimpleList(Lists.newArrayList(4));
690 private static DtoC getDtoC() {
691 final DtoC dtoa = new DtoC();
692 // dtoa.setSimpleArg((long) 55);
693 final DtoAInner dtoAInner = new DtoAInner();
694 final DtoAInnerInner dtoAInnerInner = new DtoAInnerInner();
695 dtoAInnerInner.setSimpleArg(456L);
696 dtoAInner.setDtoAInnerInner(dtoAInnerInner);
697 dtoAInner.setSimpleArg(44L);
698 dtoa.setDtoAInner(dtoAInner);