Add support for enums as configuration attributes in config and netconf subsystem.
[controller.git] / opendaylight / netconf / config-netconf-connector / src / test / java / org / opendaylight / controller / netconf / confignetconfconnector / NetconfMappingTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.confignetconfconnector;
10
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;
78
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;
90 import java.util.Map;
91
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;
99
100
101 public class NetconfMappingTest extends AbstractConfigTest {
102     private static final Logger logger = LoggerFactory.getLogger(NetconfMappingTest.class);
103
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;
108
109     @Mock
110     YangStoreSnapshot yangStoreSnapshot;
111     @Mock
112     NetconfOperationRouter netconfOperationRouter;
113
114     private TransactionProvider transactionProvider;
115
116     @Before
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));
123
124         transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID);
125     }
126
127     private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException {
128         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
129
130         final ObjectName on = transaction.createModule(this.factory.getImplementationName(), instanceName);
131         final NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
132         setModule(mxBean, transaction);
133
134         transaction.commit();
135         return on;
136     }
137
138     @Test
139     public void testConfigNetconf() throws Exception {
140
141         createModule(INSTANCE_NAME);
142
143         edit("netconfMessages/editConfig.xml");
144         checkBinaryLeafEdited(getConfigCandidate());
145
146         // default-operation:none, should not affect binary leaf
147         edit("netconfMessages/editConfig_none.xml");
148         checkBinaryLeafEdited(getConfigCandidate());
149
150         // check after edit
151         commit();
152         Element response = getConfigRunning();
153
154         checkBinaryLeafEdited(response);
155         checkTypeConfigAttribute(response);
156         checkTypedefs(response);
157         checkEnum(response);
158
159         edit("netconfMessages/editConfig_remove.xml");
160
161         commit();
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);
169
170         final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml")
171                 .replaceAll("\\s+", "");
172
173         assertEquals(expectedResult, responseFromRunning);
174         assertEquals(expectedResult, responseFromCandidate);
175
176         edit("netconfMessages/editConfig_none.xml");
177         doNothing().when(netconfOperationRouter).close();
178         closeSession();
179         verify(netconfOperationRouter).close();
180         verifyNoMoreInteractions(netconfOperationRouter);
181     }
182
183     private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
184             IOException {
185         DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
186         executeOp(closeOp, "netconfMessages/closeSession.xml");
187     }
188
189     private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
190             NetconfDocumentedException {
191         EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
192                 NETCONF_SESSION_ID);
193         executeOp(editOp, resource);
194     }
195
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");
199     }
200
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");
206     }
207
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");
213     }
214
215     @Test(expected = NetconfDocumentedException.class)
216     public void testConfigNetconfReplaceDefaultEx() throws Exception {
217
218         createModule(INSTANCE_NAME);
219
220         edit("netconfMessages/editConfig.xml");
221         edit("netconfMessages/editConfig_replace_default_ex.xml");
222     }
223
224     @Test
225     public void testConfigNetconfReplaceDefault() throws Exception {
226
227         createModule(INSTANCE_NAME);
228
229         edit("netconfMessages/editConfig.xml");
230         commit();
231         Element response = getConfigRunning();
232         final int allInstances = response.getElementsByTagName("module").getLength();
233
234         edit("netconfMessages/editConfig_replace_default.xml");
235
236         commit();
237         response = getConfigRunning();
238
239         final int afterReplace = response.getElementsByTagName("module").getLength();
240         assertEquals(4, allInstances);
241         assertEquals(2, afterReplace);
242     }
243
244     @Test(expected = NetconfDocumentedException.class)
245     public void testSameAttrDifferentNamespaces() throws Exception {
246         try {
247             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
248         } catch (NetconfDocumentedException e) {
249             String message = e.getMessage();
250             assertThat(message,
251                     JUnitMatchers
252                             .containsString("Element simple-long-2 present multiple times with different namespaces"));
253             assertThat(message,
254                     JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
255             assertThat(message,
256                     JUnitMatchers
257                             .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
258             throw e;
259         }
260     }
261
262     @Test(expected = NetconfDocumentedException.class)
263     public void testDifferentNamespaceInTO() throws Exception {
264         try {
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"));
271             throw e;
272         }
273     }
274
275     @Test(expected = NetconfDocumentedException.class)
276     public void testSameAttrDifferentNamespacesList() throws Exception {
277         try {
278             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
279         } catch (NetconfDocumentedException e) {
280             String message = e.getMessage();
281             assertThat(message,
282                     JUnitMatchers.containsString("Element binaryLeaf present multiple times with different namespaces"));
283             assertThat(message,
284                     JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
285             assertThat(message,
286                     JUnitMatchers
287                             .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
288             throw e;
289         }
290     }
291
292     @Test
293     public void testTypeNameConfigAttributeMatching() throws Exception {
294         edit("netconfMessages/editConfig.xml");
295         commit();
296         edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
297         commit();
298
299         Element response = getConfigRunning();
300         checkTypeConfigAttribute(response);
301     }
302
303     // TODO add <modules operation="replace"> functionality
304     @Test(expected = NetconfDocumentedException.class)
305     public void testConfigNetconfReplaceModuleEx() throws Exception {
306
307         createModule(INSTANCE_NAME);
308
309         edit("netconfMessages/editConfig.xml");
310         edit("netconfMessages/editConfig_replace_module_ex.xml");
311     }
312
313     @Test
314     public void testUnrecognisedConfigElements() throws Exception {
315
316         String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
317         final int TESTS_COUNT = 8;
318
319         for (int i = 0; i < TESTS_COUNT; i++) {
320             String file = String.format(format, i + 1);
321             try {
322                 edit(file);
323             } catch (NetconfDocumentedException e) {
324                 assertThat(e.getMessage(), JUnitMatchers.containsString("Unrecognised elements"));
325                 assertThat(e.getMessage(), JUnitMatchers.containsString("unknownAttribute"));
326                 continue;
327             }
328             fail("Unrecognised test should throw exception " + file);
329         }
330     }
331
332     @Test
333     @Ignore
334     // FIXME
335     public void testConfigNetconfReplaceModule() throws Exception {
336
337         createModule(INSTANCE_NAME);
338
339         edit("netconfMessages/editConfig.xml");
340         commit();
341         Element response = getConfigRunning();
342         final int allInstances = response.getElementsByTagName("instance").getLength();
343
344         edit("netconfMessages/editConfig_replace_module.xml");
345
346         commit();
347         response = getConfigRunning();
348         final int afterReplace = response.getElementsByTagName("instance").getLength();
349
350         assertEquals(4 + 4 /* Instances from services */, allInstances);
351         assertEquals(3 + 3, afterReplace);
352     }
353
354     @Test(expected = NetconfDocumentedException.class)
355     public void testEx() throws Exception {
356
357         commit();
358     }
359
360     @Test(expected = NetconfDocumentedException.class)
361     public void testEx2() throws Exception {
362         discard();
363     }
364
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");
368     }
369
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());
377         }
378         assertEquals("810", buf.toString());
379     }
380
381     private void checkTypedefs(final Element response) {
382         NodeList children = response.getElementsByTagName("extended");
383         assertEquals(1, children.getLength());
384
385         children = response.getElementsByTagName("extended-twice");
386         assertEquals(1, children.getLength());
387     }
388
389     private void checkEnum(final Element response) {
390         XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
391                 .getOnlyChildElement("modules");
392
393         String enumName = "extended-enum";
394         String enumContent = "TWO";
395
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());
401
402                 return;
403             }
404         }
405
406         fail("Enum attribute " + enumName + ":" + enumContent + " not present in " + XmlUtil.toString(response));
407     }
408
409     private void checkTypeConfigAttribute(Element response) {
410
411         XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
412                 .getOnlyChildElement("modules");
413
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;
419                 }
420             }
421         }
422
423         assertEquals("configAttributeType", configAttributeType.getTextContent());
424     }
425
426     private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
427         final List<InputStream> yangDependencies = getYangs();
428
429         final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
430         mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap());
431
432         return mBeanEntries;
433     }
434
435     @Test
436     public void testConfigNetconfRuntime() throws Exception {
437
438         ModuleIdentifier id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance");
439         RootRuntimeBeanRegistrator rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
440         NetconfTestImplRuntimeRegistrator registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
441
442         NetconfTestImplRuntimeRegistration a = registerRoot(registrator);
443         InnerRunningDataRuntimeRegistration reg = registerInner(a);
444         registerInner2(reg);
445
446         id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance2");
447         rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
448         registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
449
450         a = registerRoot(registrator);
451         registerAdditional(a);
452         registerAdditional(a);
453         registerAdditional(a);
454         registerAdditional(a);
455         reg = registerInner(a);
456         registerInner2(reg);
457         reg = registerInner(a);
458         registerInner2(reg);
459         registerInner2(reg);
460         reg = registerInner(a);
461         registerInner2(reg);
462         registerInner2(reg);
463         registerInner2(reg);
464         reg = registerInner(a);
465         registerInner2(reg);
466         registerInner2(reg);
467         registerInner2(reg);
468         registerInner2(reg);
469
470         Element response = get();
471
472         System.err.println(XmlUtil.toString(response));
473
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"));
483         // TODO assert keys
484
485         RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
486
487         response = executeOp(netconf, "netconfMessages/rpc.xml");
488         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("testarg1".toUpperCase()));
489
490         response = executeOp(netconf, "netconfMessages/rpcInner.xml");
491         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("ok"));
492
493         response = executeOp(netconf, "netconfMessages/rpcInnerInner.xml");
494         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("true"));
495
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"));
499     }
500
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");
504     }
505
506     private int getElementsSize(Element response, String elementName) {
507         return response.getElementsByTagName(elementName).getLength();
508     }
509
510     private Object registerAdditional(final NetconfTestImplRuntimeRegistration a) {
511         class InnerRunningDataAdditionalRuntimeMXBeanTest implements InnerRunningDataAdditionalRuntimeMXBean {
512
513             private final int simpleInt;
514             private final String simpleString;
515
516             public InnerRunningDataAdditionalRuntimeMXBeanTest(final int simpleInt, final String simpleString) {
517                 this.simpleInt = simpleInt;
518                 this.simpleString = simpleString;
519             }
520
521             @Override
522             public Integer getSimpleInt3() {
523                 return this.simpleInt;
524             }
525
526             @Override
527             public Deep4 getDeep4() {
528                 final Deep4 d = new Deep4();
529                 d.setBoool(false);
530                 return d;
531             }
532
533             @Override
534             public String getSimpleString() {
535                 return this.simpleString;
536             }
537
538             @Override
539             public void noArgInner() {
540             }
541
542         }
543
544         final int simpleInt = counter++;
545         return a.register(new InnerRunningDataAdditionalRuntimeMXBeanTest(simpleInt, "randomString_" + simpleInt));
546     }
547
548     private void registerInner2(final InnerRunningDataRuntimeRegistration reg) {
549         class InnerInnerRunningDataRuntimeMXBeanTest implements InnerInnerRunningDataRuntimeMXBean {
550
551             private final int simpleInt;
552
553             public InnerInnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
554                 this.simpleInt = simpleInt;
555             }
556
557             @Override
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);
563             }
564
565             @Override
566             public Integer getSimpleInt3() {
567                 return this.simpleInt;
568             }
569
570             @Override
571             public Deep3 getDeep3() {
572                 return new Deep3();
573             }
574
575             @Override
576             public List<String> getListOfStrings() {
577                 return Lists.newArrayList("l1", "l2");
578             }
579
580             @Override
581             public List<RetValList> listOutput() {
582                 return Lists.newArrayList(new RetValList());
583             }
584
585             @Override
586             public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
587                 return aBoolean;
588             }
589
590             @Override
591             public RetValContainer containerOutput() {
592                 return new RetValContainer();
593             }
594
595             @Override
596             public List<String> leafListOutput() {
597                 return Lists.newArrayList("1", "2");
598             }
599
600         }
601
602         reg.register(new InnerInnerRunningDataRuntimeMXBeanTest(counter++));
603
604     }
605
606     private static int counter = 1000;
607
608     private InnerRunningDataRuntimeRegistration registerInner(final NetconfTestImplRuntimeRegistration a) {
609
610         class InnerRunningDataRuntimeMXBeanTest implements InnerRunningDataRuntimeMXBean {
611
612             private final int simpleInt;
613
614             public InnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
615                 this.simpleInt = simpleInt;
616             }
617
618             @Override
619             public Integer getSimpleInt3() {
620                 return this.simpleInt;
621             }
622
623             @Override
624             public Deep2 getDeep2() {
625                 return new Deep2();
626             }
627
628         }
629         return a.register(new InnerRunningDataRuntimeMXBeanTest(counter++));
630     }
631
632     private NetconfTestImplRuntimeRegistration registerRoot(final NetconfTestImplRuntimeRegistrator registrator) {
633         final NetconfTestImplRuntimeRegistration a = registrator.register(new NetconfTestImplRuntimeMXBean() {
634
635             @Override
636             public Long getCreatedSessions() {
637                 return 11L;
638             }
639
640             @Override
641             public Asdf getAsdf() {
642                 final Asdf asdf = new Asdf();
643                 asdf.setSimpleInt(55);
644                 asdf.setSimpleString("asdf");
645                 return asdf;
646             }
647
648             @Override
649             public String noArg(final String arg1) {
650                 return arg1.toUpperCase();
651             }
652
653         });
654         return a;
655     }
656
657     private Element executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
658             SAXException, IOException, NetconfDocumentedException {
659
660         final Document request = XmlFileLoader.xmlFileToDocument(filename);
661
662         logger.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
663         HandlingPriority priority = op.canHandle(request);
664
665         Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
666
667         final Document response = op.handle(request, netconfOperationRouter);
668         logger.debug("Got response\n{}", XmlUtil.toString(response));
669         return response.getDocumentElement();
670     }
671
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);
681         }
682         return Lists.newArrayList(yangDependencies);
683     }
684
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);
691         //
692         final DtoC dtoa = getDtoC();
693         mxBean.setDtoC(dtoa);
694         mxBean.setSimpleBoolean(false);
695         //
696         final Peers p1 = new Peers();
697         p1.setCoreSize(44L);
698         p1.setPort("port1");
699         p1.setSimpleInt3(456);
700         final Peers p2 = new Peers();
701         p2.setCoreSize(44L);
702         p2.setPort("port23");
703         p2.setSimpleInt3(456);
704         mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
705         // //
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);
712
713         mxBean.setComplexList(Lists.<ComplexList> newArrayList());
714         mxBean.setSimpleList(Lists.<Integer> newArrayList());
715
716         final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), "dep");
717         mxBean.setTestingDep(testingDepOn);
718     }
719
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));
733         return dtob;
734     }
735
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);
745         return dtoa;
746     }
747
748 }