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.apache.commons.lang3.StringUtils;
16 import org.junit.Before;
17 import org.junit.Ignore;
18 import org.junit.Test;
19 import org.junit.matchers.JUnitMatchers;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
23 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
24 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
25 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
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.ComplexDtoBInner;
30 import org.opendaylight.controller.config.yang.test.impl.ComplexList;
31 import org.opendaylight.controller.config.yang.test.impl.Deep;
32 import org.opendaylight.controller.config.yang.test.impl.DepTestImplModuleFactory;
33 import org.opendaylight.controller.config.yang.test.impl.DtoAInner;
34 import org.opendaylight.controller.config.yang.test.impl.DtoAInnerInner;
35 import org.opendaylight.controller.config.yang.test.impl.DtoC;
36 import org.opendaylight.controller.config.yang.test.impl.DtoD;
37 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory;
38 import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean;
39 import org.opendaylight.controller.config.yang.test.impl.Peers;
40 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
41 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
42 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;
43 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
44 import org.opendaylight.controller.netconf.confignetconfconnector.operations.DiscardChanges;
45 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
46 import org.opendaylight.controller.netconf.confignetconfconnector.operations.get.Get;
47 import org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig.GetConfig;
48 import org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc.RuntimeRpc;
49 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
50 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
51 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
52 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
53 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
54 import org.opendaylight.controller.netconf.util.xml.XmlElement;
55 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
56 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
59 import org.w3c.dom.Document;
60 import org.w3c.dom.Element;
61 import org.w3c.dom.NodeList;
62 import org.xml.sax.SAXException;
64 import javax.management.InstanceAlreadyExistsException;
65 import javax.management.InstanceNotFoundException;
66 import javax.management.ObjectName;
67 import javax.xml.parsers.ParserConfigurationException;
68 import java.io.FileNotFoundException;
69 import java.io.IOException;
70 import java.io.InputStream;
71 import java.math.BigInteger;
72 import java.net.URISyntaxException;
73 import java.util.ArrayList;
74 import java.util.Arrays;
75 import java.util.Collection;
76 import java.util.List;
79 import static org.junit.Assert.assertEquals;
80 import static org.junit.Assert.assertThat;
81 import static org.junit.Assert.fail;
82 import static org.mockito.Mockito.doNothing;
83 import static org.mockito.Mockito.doReturn;
84 import static org.mockito.Mockito.verify;
85 import static org.mockito.Mockito.verifyNoMoreInteractions;
88 public class NetconfMappingTest extends AbstractConfigTest {
89 private static final Logger logger = LoggerFactory.getLogger(NetconfMappingTest.class);
91 private static final String INSTANCE_NAME = "instance-from-code";
92 private static final String NETCONF_SESSION_ID = "foo";
93 private NetconfTestImplModuleFactory factory;
94 private DepTestImplModuleFactory factory2;
97 YangStoreSnapshot yangStoreSnapshot;
99 NetconfOperationRouter netconfOperationRouter;
101 private TransactionProvider transactionProvider;
104 public void setUp() throws Exception {
105 MockitoAnnotations.initMocks(this);
106 doReturn(getMbes()).when(this.yangStoreSnapshot).getModuleMXBeanEntryMap();
107 this.factory = new NetconfTestImplModuleFactory();
108 this.factory2 = new DepTestImplModuleFactory();
109 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.factory, this.factory2));
111 transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID);
114 private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException, InstanceNotFoundException, URISyntaxException {
115 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
117 final ObjectName on = transaction.createModule(this.factory.getImplementationName(), instanceName);
118 final NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
119 setModule(mxBean, transaction, instanceName + "_dep");
122 for (Class<? extends AbstractServiceInterface> sInterface : factory.getImplementedServiceIntefaces()) {
123 ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class);
124 transaction.saveServiceReference(
125 transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), "ref_from_code_to_" + instanceName + "_" + i++,
129 transaction.commit();
134 public void testServicePersistance() throws Exception {
135 createModule(INSTANCE_NAME);
137 edit("netconfMessages/editConfig.xml");
138 Element config = getConfigCandidate();
139 assertCorrectServiceNames(config, 6, "ref_test2", "user_to_instance_from_code", "ref_dep_user",
140 "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
141 "ref_from_code_to_instance-from-code_1");
143 edit("netconfMessages/editConfig_addServiceName.xml");
144 config = getConfigCandidate();
145 assertCorrectServiceNames(config, 7, "ref_test2", "user_to_instance_from_code", "ref_dep_user",
146 "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
147 "ref_from_code_to_instance-from-code_1", "ref_dep_user_another");
150 config = getConfigRunning();
151 assertCorrectRefNamesForDependencies(config);
152 assertCorrectServiceNames(config, 7, "ref_test2", "user_to_instance_from_code", "ref_dep_user",
153 "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
154 "ref_from_code_to_instance-from-code_1", "ref_dep_user_another");
156 edit("netconfMessages/editConfig_replace_default.xml");
157 config = getConfigCandidate();
158 assertCorrectServiceNames(config, 2, "ref_dep", "ref_dep2");
160 edit("netconfMessages/editConfig_remove.xml");
161 config = getConfigCandidate();
162 assertCorrectServiceNames(config, 0);
165 config = getConfigCandidate();
166 assertCorrectServiceNames(config, 0);
170 private void assertCorrectRefNamesForDependencies(Element config) {
171 NodeList modulesList = config.getElementsByTagName("modules");
172 assertEquals(1, modulesList.getLength());
174 Element modules = (Element) modulesList.item(0);
176 String trimmedModules = XmlUtil.toString(modules).replaceAll("\\s", "");
177 int defaultRefNameCount = StringUtils.countMatches(trimmedModules, "ref_dep2");
178 int userRefNameCount = StringUtils.countMatches(trimmedModules, "ref_dep_user_two");
180 assertEquals(0, defaultRefNameCount);
181 assertEquals(2, userRefNameCount);
184 private void assertCorrectServiceNames(Element configCandidate, int servicesSize, String... refNames) {
185 NodeList elements = configCandidate.getElementsByTagName("provider");
186 assertEquals(servicesSize, elements.getLength());
188 NodeList servicesList = configCandidate.getElementsByTagName("services");
189 assertEquals(1, servicesList.getLength());
191 Element services = (Element) servicesList.item(0);
192 String trimmedServices = XmlUtil.toString(services).replaceAll("\\s", "");
194 for (String s : refNames) {
195 assertThat(trimmedServices, JUnitMatchers.containsString(s));
200 public void testConfigNetconf() throws Exception {
202 createModule(INSTANCE_NAME);
204 edit("netconfMessages/editConfig.xml");
205 Element configCandidate = getConfigCandidate();
206 checkBinaryLeafEdited(configCandidate);
209 // default-operation:none, should not affect binary leaf
210 edit("netconfMessages/editConfig_none.xml");
211 checkBinaryLeafEdited(getConfigCandidate());
215 Element response = getConfigRunning();
217 checkBinaryLeafEdited(response);
218 checkTypeConfigAttribute(response);
219 checkTypedefs(response);
220 checkTestingDeps(response);
222 checkBigDecimal(response);
224 edit("netconfMessages/editConfig_remove.xml");
227 response = getConfigCandidate();
228 final String responseFromCandidate = XmlUtil.toString(response).replaceAll("\\s+", "");
229 // System.out.println(responseFromCandidate);
230 response = getConfigRunning();
231 final String responseFromRunning = XmlUtil.toString(response).replaceAll("\\s+", "");
232 // System.out.println(responseFromRunning);
233 assertEquals(responseFromCandidate, responseFromRunning);
235 final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml")
236 .replaceAll("\\s+", "");
238 assertEquals(expectedResult, responseFromRunning);
239 assertEquals(expectedResult, responseFromCandidate);
241 edit("netconfMessages/editConfig_none.xml");
242 doNothing().when(netconfOperationRouter).close();
244 verify(netconfOperationRouter).close();
245 verifyNoMoreInteractions(netconfOperationRouter);
248 private void checkBigDecimal(Element response) {
249 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
251 assertContainsString(responseTrimmed, "<sleep-factorxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.58</sleep-factor>");
253 assertContainsString(responseTrimmed, "<sleep-factorxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.00</sleep-factor>");
257 private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
259 DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
260 executeOp(closeOp, "netconfMessages/closeSession.xml");
263 private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
264 NetconfDocumentedException {
265 EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
267 executeOp(editOp, resource);
270 private void commit() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
271 Commit commitOp = new Commit(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
272 executeOp(commitOp, "netconfMessages/commit.xml");
275 private Element getConfigCandidate() throws ParserConfigurationException, SAXException, IOException,
276 NetconfDocumentedException {
277 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
278 configRegistryClient, NETCONF_SESSION_ID);
279 return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
282 private Element getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
283 NetconfDocumentedException {
284 GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
285 configRegistryClient, NETCONF_SESSION_ID);
286 return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
289 @Ignore("second edit message corrupted")
290 @Test(expected = NetconfDocumentedException.class)
291 public void testConfigNetconfReplaceDefaultEx() throws Exception {
293 createModule(INSTANCE_NAME);
295 edit("netconfMessages/editConfig.xml");
296 edit("netconfMessages/editConfig_replace_default_ex.xml");
300 public void testConfigNetconfReplaceDefault() throws Exception {
302 createModule(INSTANCE_NAME);
304 edit("netconfMessages/editConfig.xml");
306 Element response = getConfigRunning();
307 final int allInstances = response.getElementsByTagName("module").getLength();
309 edit("netconfMessages/editConfig_replace_default.xml");
312 response = getConfigRunning();
314 final int afterReplace = response.getElementsByTagName("module").getLength();
315 assertEquals(4, allInstances);
316 assertEquals(2, afterReplace);
319 @Test(expected = NetconfDocumentedException.class)
320 public void testSameAttrDifferentNamespaces() throws Exception {
322 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
323 } catch (NetconfDocumentedException e) {
324 String message = e.getMessage();
325 assertContainsString(message, "Element simple-long-2 present multiple times with different namespaces");
326 assertContainsString(message, "urn:opendaylight:params:xml:ns:yang:controller:test:impl");
327 assertContainsString(message, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
332 @Test(expected = NetconfDocumentedException.class)
333 public void testDifferentNamespaceInTO() throws Exception {
335 edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
336 } catch (NetconfDocumentedException e) {
337 String message = e.getMessage();
338 assertContainsString(message, "Unrecognised elements");
339 assertContainsString(message, "simple-int2");
340 assertContainsString(message, "dto_d");
345 @Test(expected = NetconfDocumentedException.class)
346 public void testSameAttrDifferentNamespacesList() throws Exception {
348 edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
349 } catch (NetconfDocumentedException e) {
350 String message = e.getMessage();
351 assertContainsString(message, "Element binaryLeaf 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);
359 public void testTypeNameConfigAttributeMatching() throws Exception {
360 edit("netconfMessages/editConfig.xml");
362 edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
365 Element response = getConfigRunning();
366 checkTypeConfigAttribute(response);
369 // TODO add <modules operation="replace"> functionality
370 @Test(expected = NetconfDocumentedException.class)
371 public void testConfigNetconfReplaceModuleEx() throws Exception {
373 createModule(INSTANCE_NAME);
375 edit("netconfMessages/editConfig.xml");
376 edit("netconfMessages/editConfig_replace_module_ex.xml");
380 public void testUnrecognisedConfigElements() throws Exception {
382 String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
383 final int TESTS_COUNT = 8;
385 for (int i = 0; i < TESTS_COUNT; i++) {
386 String file = String.format(format, i + 1);
389 } catch (NetconfDocumentedException e) {
390 assertContainsString(e.getMessage(), "Unrecognised elements");
391 assertContainsString(e.getMessage(), "unknownAttribute");
394 fail("Unrecognised test should throw exception " + file);
401 public void testConfigNetconfReplaceModule() throws Exception {
403 createModule(INSTANCE_NAME);
405 edit("netconfMessages/editConfig.xml");
407 Element response = getConfigRunning();
408 final int allInstances = response.getElementsByTagName("instance").getLength();
410 edit("netconfMessages/editConfig_replace_module.xml");
413 response = getConfigRunning();
414 final int afterReplace = response.getElementsByTagName("instance").getLength();
416 assertEquals(4 + 4 /* Instances from services */, allInstances);
417 assertEquals(3 + 3, afterReplace);
420 @Test(expected = NetconfDocumentedException.class)
421 public void testEx() throws Exception {
426 @Test(expected = NetconfDocumentedException.class)
427 public void testEx2() throws Exception {
431 private void discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
432 DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
433 executeOp(discardOp, "netconfMessages/discardChanges.xml");
436 private void checkBinaryLeafEdited(final Element response) {
437 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
438 String substring = "<binaryLeafxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">YmluYXJ5</binaryLeaf>";
439 assertContainsString(responseTrimmed, substring);
440 substring = "<binaryLeafxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ZGVmYXVsdEJpbg==</binaryLeaf>";
441 assertContainsString(responseTrimmed, substring);
444 private void checkTypedefs(final Element response) {
445 String responseTrimmed = XmlUtil.toString(response).replaceAll("\\s", "");
447 String substring = "<extendedxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">10</extended>";
448 assertContainsString(responseTrimmed, substring);
450 assertContainsString(responseTrimmed,
451 "<extendedxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">1</extended>");
453 assertContainsString(responseTrimmed,
454 "<extended-twicexmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">20</extended-twice>");
456 assertContainsString(responseTrimmed,
457 "<extended-twicexmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2</extended-twice>");
459 assertContainsString(responseTrimmed,
460 "<extended-enumxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">TWO</extended-enum>");
462 assertContainsString(responseTrimmed,
463 "<extended-enumxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ONE</extended-enum>");
466 private void assertContainsString(String string, String substring) {
467 assertThat(string, JUnitMatchers.containsString(substring));
470 private void checkEnum(final Element response) {
471 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
472 .getOnlyChildElement("modules");
474 String enumName = "extended-enum";
475 String enumContent = "TWO";
477 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
478 String name = moduleElement.getOnlyChildElement("name").getTextContent();
479 if(name.equals(INSTANCE_NAME)) {
480 XmlElement enumAttr = moduleElement.getOnlyChildElement(enumName);
481 assertEquals(enumContent, enumAttr.getTextContent());
487 fail("Enum attribute " + enumName + ":" + enumContent + " not present in " + XmlUtil.toString(response));
490 private void checkTestingDeps(Element response) {
491 int testingDepsSize = response.getElementsByTagName("testing-deps").getLength();
492 assertEquals(2, testingDepsSize);
495 private void checkTypeConfigAttribute(Element response) {
497 XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
498 .getOnlyChildElement("modules");
500 XmlElement configAttributeType = null;
501 for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
502 for (XmlElement type : moduleElement.getChildElements("type")) {
503 if (type.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY).equals("") == false) {
504 configAttributeType = type;
509 // TODO verify if should be default value
510 assertEquals("default-string", configAttributeType.getTextContent());
513 private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
514 final List<InputStream> yangDependencies = getYangs();
516 final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
517 mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap());
523 public void testConfigNetconfRuntime() throws Exception {
525 createModule(INSTANCE_NAME);
527 edit("netconfMessages/editConfig.xml");
528 checkBinaryLeafEdited(getConfigCandidate());
532 Element response = get();
534 assertEquals(2/*With runtime beans*/ + 2 /*Without runtime beans*/, getElementsSize(response, "module"));
536 assertEquals(2, getElementsSize(response, "asdf"));
537 // data from running config
538 assertEquals(2, getElementsSize(response, "simple-short"));
540 assertEquals(8, getElementsSize(response, "inner-running-data"));
541 assertEquals(8, getElementsSize(response, "deep2"));
542 assertEquals(8 * 4, getElementsSize(response, "inner-inner-running-data"));
543 assertEquals(8 * 4, getElementsSize(response, "deep3"));
544 assertEquals(8 * 4 * 2, getElementsSize(response, "list-of-strings"));
545 assertEquals(8, getElementsSize(response, "inner-running-data-additional"));
546 assertEquals(8, getElementsSize(response, "deep4"));
549 RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
551 response = executeOp(netconf, "netconfMessages/rpc.xml");
552 assertContainsString(XmlUtil.toString(response), "testarg1".toUpperCase());
554 response = executeOp(netconf, "netconfMessages/rpcInner.xml");
555 assertContainsString(XmlUtil.toString(response), "ok");
557 response = executeOp(netconf, "netconfMessages/rpcInnerInner.xml");
558 assertContainsString(XmlUtil.toString(response), "true");
560 response = executeOp(netconf, "netconfMessages/rpcInnerInner_complex_output.xml");
561 assertContainsString(XmlUtil.toString(response), "1");
562 assertContainsString(XmlUtil.toString(response), "2");
565 private Element get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
566 Get getOp = new Get(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID, transactionProvider);
567 return executeOp(getOp, "netconfMessages/get.xml");
570 private int getElementsSize(Element response, String elementName) {
571 return response.getElementsByTagName(elementName).getLength();
574 private Element executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
575 SAXException, IOException, NetconfDocumentedException {
577 final Document request = XmlFileLoader.xmlFileToDocument(filename);
579 logger.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
580 HandlingPriority priority = op.canHandle(request);
582 Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
584 final Document response = op.handle(request, netconfOperationRouter);
585 logger.debug("Got response\n{}", XmlUtil.toString(response));
586 return response.getDocumentElement();
589 private List<InputStream> getYangs() throws FileNotFoundException {
590 List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
591 "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/test-types.yang",
592 "/META-INF/yang/ietf-inet-types.yang");
593 final Collection<InputStream> yangDependencies = new ArrayList<>();
594 for (String path : paths) {
595 final InputStream is = Preconditions
596 .checkNotNull(getClass().getResourceAsStream(path), path + " not found");
597 yangDependencies.add(is);
599 return Lists.newArrayList(yangDependencies);
602 private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction, String depName)
603 throws InstanceAlreadyExistsException, InstanceNotFoundException {
604 mxBean.setSimpleInt((long) 44);
605 mxBean.setBinaryLeaf(new byte[] { 8, 7, 9 });
606 final DtoD dtob = getDtoD();
607 mxBean.setDtoD(dtob);
609 final DtoC dtoa = getDtoC();
610 mxBean.setDtoC(dtoa);
611 mxBean.setSimpleBoolean(false);
613 final Peers p1 = new Peers();
616 p1.setSimpleInt3(456);
617 final Peers p2 = new Peers();
619 p2.setPort("port23");
620 p2.setSimpleInt3(456);
621 mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
623 mxBean.setSimpleLong(454545L);
624 mxBean.setSimpleLong2(44L);
625 mxBean.setSimpleBigInteger(BigInteger.valueOf(999L));
626 mxBean.setSimpleByte(new Byte((byte) 4));
627 mxBean.setSimpleShort(new Short((short) 4));
628 mxBean.setSimpleTest(545);
630 mxBean.setComplexList(Lists.<ComplexList> newArrayList());
631 mxBean.setSimpleList(Lists.<Integer> newArrayList());
633 final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), depName);
635 for (Class<? extends AbstractServiceInterface> sInterface : factory2.getImplementedServiceIntefaces()) {
636 ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class);
637 transaction.saveServiceReference(
638 transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), "ref_from_code_to_" + depName + "_" + i++,
642 mxBean.setTestingDep(testingDepOn);
645 private static DtoD getDtoD() {
646 final DtoD dtob = new DtoD();
647 dtob.setSimpleInt1((long) 444);
648 dtob.setSimpleInt2((long) 4444);
649 dtob.setSimpleInt3(454);
650 final ComplexDtoBInner dtobInner = new ComplexDtoBInner();
651 final Deep deep = new Deep();
652 deep.setSimpleInt3(4);
653 dtobInner.setDeep(deep);
654 dtobInner.setSimpleInt3(44);
655 dtobInner.setSimpleList(Lists.newArrayList(4));
656 dtob.setComplexDtoBInner(Lists.newArrayList(dtobInner));
657 dtob.setSimpleList(Lists.newArrayList(4));
661 private static DtoC getDtoC() {
662 final DtoC dtoa = new DtoC();
663 // dtoa.setSimpleArg((long) 55);
664 final DtoAInner dtoAInner = new DtoAInner();
665 final DtoAInnerInner dtoAInnerInner = new DtoAInnerInner();
666 dtoAInnerInner.setSimpleArg(456L);
667 dtoAInner.setDtoAInnerInner(dtoAInnerInner);
668 dtoAInner.setSimpleArg(44L);
669 dtoa.setDtoAInner(dtoAInner);