Add support for configuration attributes based on yang leaves with custom types ...
[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         System.err.println(XmlUtil.toString(response));
154         checkBinaryLeafEdited(response);
155         checkTypeConfigAttribute(response);
156         checkTypedefs(response);
157
158         edit("netconfMessages/editConfig_remove.xml");
159
160         commit();
161         response = getConfigCandidate();
162         final String responseFromCandidate = XmlUtil.toString(response).replaceAll("\\s+", "");
163         // System.out.println(responseFromCandidate);
164         response = getConfigRunning();
165         final String responseFromRunning = XmlUtil.toString(response).replaceAll("\\s+", "");
166         // System.out.println(responseFromRunning);
167         assertEquals(responseFromCandidate, responseFromRunning);
168
169         final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml")
170                 .replaceAll("\\s+", "");
171
172         assertEquals(expectedResult, responseFromRunning);
173         assertEquals(expectedResult, responseFromCandidate);
174
175         edit("netconfMessages/editConfig_none.xml");
176         doNothing().when(netconfOperationRouter).close();
177         closeSession();
178         verify(netconfOperationRouter).close();
179         verifyNoMoreInteractions(netconfOperationRouter);
180     }
181
182     private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
183             IOException {
184         DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
185         executeOp(closeOp, "netconfMessages/closeSession.xml");
186     }
187
188     private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
189             NetconfDocumentedException {
190         EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
191                 NETCONF_SESSION_ID);
192         executeOp(editOp, resource);
193     }
194
195     private void commit() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
196         Commit commitOp = new Commit(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
197         executeOp(commitOp, "netconfMessages/commit.xml");
198     }
199
200     private Element getConfigCandidate() throws ParserConfigurationException, SAXException, IOException,
201             NetconfDocumentedException {
202         GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
203                 configRegistryClient, NETCONF_SESSION_ID);
204         return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
205     }
206
207     private Element getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
208             NetconfDocumentedException {
209         GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
210                 configRegistryClient, NETCONF_SESSION_ID);
211         return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
212     }
213
214     @Test(expected = NetconfDocumentedException.class)
215     public void testConfigNetconfReplaceDefaultEx() throws Exception {
216
217         createModule(INSTANCE_NAME);
218
219         edit("netconfMessages/editConfig.xml");
220         edit("netconfMessages/editConfig_replace_default_ex.xml");
221     }
222
223     @Test
224     public void testConfigNetconfReplaceDefault() throws Exception {
225
226         createModule(INSTANCE_NAME);
227
228         edit("netconfMessages/editConfig.xml");
229         commit();
230         Element response = getConfigRunning();
231         final int allInstances = response.getElementsByTagName("module").getLength();
232
233         edit("netconfMessages/editConfig_replace_default.xml");
234
235         commit();
236         response = getConfigRunning();
237
238         final int afterReplace = response.getElementsByTagName("module").getLength();
239         assertEquals(4, allInstances);
240         assertEquals(2, afterReplace);
241     }
242
243     @Test(expected = NetconfDocumentedException.class)
244     public void testSameAttrDifferentNamespaces() throws Exception {
245         try {
246             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
247         } catch (NetconfDocumentedException e) {
248             String message = e.getMessage();
249             assertThat(message,
250                     JUnitMatchers
251                             .containsString("Element simple-long-2 present multiple times with different namespaces"));
252             assertThat(message,
253                     JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
254             assertThat(message,
255                     JUnitMatchers
256                             .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
257             throw e;
258         }
259     }
260
261     @Test(expected = NetconfDocumentedException.class)
262     public void testDifferentNamespaceInTO() throws Exception {
263         try {
264             edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
265         } catch (NetconfDocumentedException e) {
266             String message = e.getMessage();
267             assertThat(message, JUnitMatchers.containsString("Unrecognised elements"));
268             assertThat(message, JUnitMatchers.containsString("simple-int2"));
269             assertThat(message, JUnitMatchers.containsString("dto_d"));
270             throw e;
271         }
272     }
273
274     @Test(expected = NetconfDocumentedException.class)
275     public void testSameAttrDifferentNamespacesList() throws Exception {
276         try {
277             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
278         } catch (NetconfDocumentedException e) {
279             String message = e.getMessage();
280             assertThat(message,
281                     JUnitMatchers.containsString("Element binaryLeaf present multiple times with different namespaces"));
282             assertThat(message,
283                     JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
284             assertThat(message,
285                     JUnitMatchers
286                             .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
287             throw e;
288         }
289     }
290
291     @Test
292     public void testTypeNameConfigAttributeMatching() throws Exception {
293         edit("netconfMessages/editConfig.xml");
294         commit();
295         edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
296         commit();
297
298         Element response = getConfigRunning();
299         checkTypeConfigAttribute(response);
300     }
301
302     // TODO add <modules operation="replace"> functionality
303     @Test(expected = NetconfDocumentedException.class)
304     public void testConfigNetconfReplaceModuleEx() throws Exception {
305
306         createModule(INSTANCE_NAME);
307
308         edit("netconfMessages/editConfig.xml");
309         edit("netconfMessages/editConfig_replace_module_ex.xml");
310     }
311
312     @Test
313     public void testUnrecognisedConfigElements() throws Exception {
314
315         String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
316         final int TESTS_COUNT = 8;
317
318         for (int i = 0; i < TESTS_COUNT; i++) {
319             String file = String.format(format, i + 1);
320             try {
321                 edit(file);
322             } catch (NetconfDocumentedException e) {
323                 assertThat(e.getMessage(), JUnitMatchers.containsString("Unrecognised elements"));
324                 assertThat(e.getMessage(), JUnitMatchers.containsString("unknownAttribute"));
325                 continue;
326             }
327             fail("Unrecognised test should throw exception " + file);
328         }
329     }
330
331     @Test
332     @Ignore
333     // FIXME
334     public void testConfigNetconfReplaceModule() throws Exception {
335
336         createModule(INSTANCE_NAME);
337
338         edit("netconfMessages/editConfig.xml");
339         commit();
340         Element response = getConfigRunning();
341         final int allInstances = response.getElementsByTagName("instance").getLength();
342
343         edit("netconfMessages/editConfig_replace_module.xml");
344
345         commit();
346         response = getConfigRunning();
347         final int afterReplace = response.getElementsByTagName("instance").getLength();
348
349         assertEquals(4 + 4 /* Instances from services */, allInstances);
350         assertEquals(3 + 3, afterReplace);
351     }
352
353     @Test(expected = NetconfDocumentedException.class)
354     public void testEx() throws Exception {
355
356         commit();
357     }
358
359     @Test(expected = NetconfDocumentedException.class)
360     public void testEx2() throws Exception {
361         discard();
362     }
363
364     private void discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
365         DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
366         executeOp(discardOp, "netconfMessages/discardChanges.xml");
367     }
368
369     private void checkBinaryLeafEdited(final Element response) {
370         final NodeList children = response.getElementsByTagName("binaryLeaf");
371         assertEquals(3, children.getLength());
372         final StringBuffer buf = new StringBuffer();
373         for (int i = 0; i < 3; i++) {
374             final Element e = (Element) children.item(i);
375             buf.append(XmlElement.fromDomElement(e).getTextContent());
376         }
377         assertEquals("810", buf.toString());
378     }
379
380     private void checkTypedefs(final Element response) {
381         NodeList children = response.getElementsByTagName("extended");
382         assertEquals(1, children.getLength());
383
384         children = response.getElementsByTagName("extended-twice");
385         assertEquals(1, children.getLength());
386     }
387
388     private void checkTypeConfigAttribute(Element response) {
389
390         XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
391                 .getOnlyChildElement("modules");
392
393         XmlElement configAttributeType = null;
394         for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
395             for (XmlElement type : moduleElement.getChildElements("type")) {
396                 if (type.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY).equals("") == false) {
397                     configAttributeType = type;
398                 }
399             }
400         }
401
402         assertEquals("configAttributeType", configAttributeType.getTextContent());
403     }
404
405     private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
406         final List<InputStream> yangDependencies = getYangs();
407
408         final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
409         mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap());
410
411         return mBeanEntries;
412     }
413
414     @Test
415     public void testConfigNetconfRuntime() throws Exception {
416
417         ModuleIdentifier id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance");
418         RootRuntimeBeanRegistrator rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
419         NetconfTestImplRuntimeRegistrator registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
420
421         NetconfTestImplRuntimeRegistration a = registerRoot(registrator);
422         InnerRunningDataRuntimeRegistration reg = registerInner(a);
423         registerInner2(reg);
424
425         id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance2");
426         rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
427         registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
428
429         a = registerRoot(registrator);
430         registerAdditional(a);
431         registerAdditional(a);
432         registerAdditional(a);
433         registerAdditional(a);
434         reg = registerInner(a);
435         registerInner2(reg);
436         reg = registerInner(a);
437         registerInner2(reg);
438         registerInner2(reg);
439         reg = registerInner(a);
440         registerInner2(reg);
441         registerInner2(reg);
442         registerInner2(reg);
443         reg = registerInner(a);
444         registerInner2(reg);
445         registerInner2(reg);
446         registerInner2(reg);
447         registerInner2(reg);
448
449         Element response = get();
450
451         System.err.println(XmlUtil.toString(response));
452
453         assertEquals(2, getElementsSize(response, "module"));
454         assertEquals(2, getElementsSize(response, "asdf"));
455         assertEquals(5, getElementsSize(response, "inner-running-data"));
456         assertEquals(5, getElementsSize(response, "deep2"));
457         assertEquals(11, getElementsSize(response, "inner-inner-running-data"));
458         assertEquals(11, getElementsSize(response, "deep3"));
459         assertEquals(11 * 2, getElementsSize(response, "list-of-strings"));
460         assertEquals(4, getElementsSize(response, "inner-running-data-additional"));
461         assertEquals(4, getElementsSize(response, "deep4"));
462         // TODO assert keys
463
464         RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
465
466         response = executeOp(netconf, "netconfMessages/rpc.xml");
467         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("testarg1".toUpperCase()));
468
469         response = executeOp(netconf, "netconfMessages/rpcInner.xml");
470         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("ok"));
471
472         response = executeOp(netconf, "netconfMessages/rpcInnerInner.xml");
473         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("true"));
474
475         response = executeOp(netconf, "netconfMessages/rpcInnerInner_complex_output.xml");
476         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("1"));
477         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("2"));
478     }
479
480     private Element get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
481         Get getOp = new Get(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
482         return executeOp(getOp, "netconfMessages/get.xml");
483     }
484
485     private int getElementsSize(Element response, String elementName) {
486         return response.getElementsByTagName(elementName).getLength();
487     }
488
489     private Object registerAdditional(final NetconfTestImplRuntimeRegistration a) {
490         class InnerRunningDataAdditionalRuntimeMXBeanTest implements InnerRunningDataAdditionalRuntimeMXBean {
491
492             private final int simpleInt;
493             private final String simpleString;
494
495             public InnerRunningDataAdditionalRuntimeMXBeanTest(final int simpleInt, final String simpleString) {
496                 this.simpleInt = simpleInt;
497                 this.simpleString = simpleString;
498             }
499
500             @Override
501             public Integer getSimpleInt3() {
502                 return this.simpleInt;
503             }
504
505             @Override
506             public Deep4 getDeep4() {
507                 final Deep4 d = new Deep4();
508                 d.setBoool(false);
509                 return d;
510             }
511
512             @Override
513             public String getSimpleString() {
514                 return this.simpleString;
515             }
516
517             @Override
518             public void noArgInner() {
519             }
520
521         }
522
523         final int simpleInt = counter++;
524         return a.register(new InnerRunningDataAdditionalRuntimeMXBeanTest(simpleInt, "randomString_" + simpleInt));
525     }
526
527     private void registerInner2(final InnerRunningDataRuntimeRegistration reg) {
528         class InnerInnerRunningDataRuntimeMXBeanTest implements InnerInnerRunningDataRuntimeMXBean {
529
530             private final int simpleInt;
531
532             public InnerInnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
533                 this.simpleInt = simpleInt;
534             }
535
536             @Override
537             public List<NotStateBean> getNotStateBean() {
538                 final NotStateBean notStateBean = new NotStateBean();
539                 final NotStateBeanInternal notStateBeanInternal = new NotStateBeanInternal();
540                 notStateBean.setNotStateBeanInternal(Lists.newArrayList(notStateBeanInternal));
541                 return Lists.newArrayList(notStateBean);
542             }
543
544             @Override
545             public Integer getSimpleInt3() {
546                 return this.simpleInt;
547             }
548
549             @Override
550             public Deep3 getDeep3() {
551                 return new Deep3();
552             }
553
554             @Override
555             public List<String> getListOfStrings() {
556                 return Lists.newArrayList("l1", "l2");
557             }
558
559             @Override
560             public List<RetValList> listOutput() {
561                 return Lists.newArrayList(new RetValList());
562             }
563
564             @Override
565             public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
566                 return aBoolean;
567             }
568
569             @Override
570             public RetValContainer containerOutput() {
571                 return new RetValContainer();
572             }
573
574             @Override
575             public List<String> leafListOutput() {
576                 return Lists.newArrayList("1", "2");
577             }
578
579         }
580
581         reg.register(new InnerInnerRunningDataRuntimeMXBeanTest(counter++));
582
583     }
584
585     private static int counter = 1000;
586
587     private InnerRunningDataRuntimeRegistration registerInner(final NetconfTestImplRuntimeRegistration a) {
588
589         class InnerRunningDataRuntimeMXBeanTest implements InnerRunningDataRuntimeMXBean {
590
591             private final int simpleInt;
592
593             public InnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
594                 this.simpleInt = simpleInt;
595             }
596
597             @Override
598             public Integer getSimpleInt3() {
599                 return this.simpleInt;
600             }
601
602             @Override
603             public Deep2 getDeep2() {
604                 return new Deep2();
605             }
606
607         }
608         return a.register(new InnerRunningDataRuntimeMXBeanTest(counter++));
609     }
610
611     private NetconfTestImplRuntimeRegistration registerRoot(final NetconfTestImplRuntimeRegistrator registrator) {
612         final NetconfTestImplRuntimeRegistration a = registrator.register(new NetconfTestImplRuntimeMXBean() {
613
614             @Override
615             public Long getCreatedSessions() {
616                 return 11L;
617             }
618
619             @Override
620             public Asdf getAsdf() {
621                 final Asdf asdf = new Asdf();
622                 asdf.setSimpleInt(55);
623                 asdf.setSimpleString("asdf");
624                 return asdf;
625             }
626
627             @Override
628             public String noArg(final String arg1) {
629                 return arg1.toUpperCase();
630             }
631
632         });
633         return a;
634     }
635
636     private Element executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
637             SAXException, IOException, NetconfDocumentedException {
638
639         final Document request = XmlFileLoader.xmlFileToDocument(filename);
640
641         logger.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
642         HandlingPriority priority = op.canHandle(request);
643
644         Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
645
646         final Document response = op.handle(request, netconfOperationRouter);
647         logger.debug("Got response\n{}", XmlUtil.toString(response));
648         return response.getDocumentElement();
649     }
650
651     private List<InputStream> getYangs() throws FileNotFoundException {
652         List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
653                 "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/test-types.yang",
654                 "/META-INF/yang/ietf-inet-types.yang");
655         final Collection<InputStream> yangDependencies = new ArrayList<>();
656         for (String path : paths) {
657             final InputStream is = Preconditions
658                     .checkNotNull(getClass().getResourceAsStream(path), path + " not found");
659             yangDependencies.add(is);
660         }
661         return Lists.newArrayList(yangDependencies);
662     }
663
664     private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction)
665             throws InstanceAlreadyExistsException {
666         mxBean.setSimpleInt((long) 44);
667         mxBean.setBinaryLeaf(new byte[] { 8, 7, 9 });
668         final DtoD dtob = getDtoD();
669         mxBean.setDtoD(dtob);
670         //
671         final DtoC dtoa = getDtoC();
672         mxBean.setDtoC(dtoa);
673         mxBean.setSimpleBoolean(false);
674         //
675         final Peers p1 = new Peers();
676         p1.setCoreSize(44L);
677         p1.setPort("port1");
678         p1.setSimpleInt3(456);
679         final Peers p2 = new Peers();
680         p2.setCoreSize(44L);
681         p2.setPort("port23");
682         p2.setSimpleInt3(456);
683         mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
684         // //
685         mxBean.setSimpleLong(454545L);
686         mxBean.setSimpleLong2(44L);
687         mxBean.setSimpleBigInteger(BigInteger.valueOf(999L));
688         mxBean.setSimpleByte(new Byte((byte) 4));
689         mxBean.setSimpleShort(new Short((short) 4));
690         mxBean.setSimpleTest(545);
691
692         mxBean.setComplexList(Lists.<ComplexList> newArrayList());
693         mxBean.setSimpleList(Lists.<Integer> newArrayList());
694
695         final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), "dep");
696         mxBean.setTestingDep(testingDepOn);
697     }
698
699     private static DtoD getDtoD() {
700         final DtoD dtob = new DtoD();
701         dtob.setSimpleInt1((long) 444);
702         dtob.setSimpleInt2((long) 4444);
703         dtob.setSimpleInt3(454);
704         final ComplexDtoBInner dtobInner = new ComplexDtoBInner();
705         final Deep deep = new Deep();
706         deep.setSimpleInt3(4);
707         dtobInner.setDeep(deep);
708         dtobInner.setSimpleInt3(44);
709         dtobInner.setSimpleList(Lists.newArrayList(4));
710         dtob.setComplexDtoBInner(Lists.newArrayList(dtobInner));
711         dtob.setSimpleList(Lists.newArrayList(4));
712         return dtob;
713     }
714
715     private static DtoC getDtoC() {
716         final DtoC dtoa = new DtoC();
717         // dtoa.setSimpleArg((long) 55);
718         final DtoAInner dtoAInner = new DtoAInner();
719         final DtoAInnerInner dtoAInnerInner = new DtoAInnerInner();
720         dtoAInnerInner.setSimpleArg(456L);
721         dtoAInner.setDtoAInnerInner(dtoAInnerInner);
722         dtoAInner.setSimpleArg(44L);
723         dtoa.setDtoAInner(dtoAInner);
724         return dtoa;
725     }
726
727 }