Added support for list, leaf-list and container in output under rpc node in yang...
[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.Assert;
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.ModuleIdentifier;
23 import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator;
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.manager.impl.jmx.RootRuntimeBeanRegistratorImpl;
27 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
28 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
29 import org.opendaylight.controller.config.yang.store.impl.MbeParser;
30 import org.opendaylight.controller.config.yang.test.impl.*;
31 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
32 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
33 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;
34 import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
35 import org.opendaylight.controller.netconf.confignetconfconnector.operations.DiscardChanges;
36 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
37 import org.opendaylight.controller.netconf.confignetconfconnector.operations.get.Get;
38 import org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig.GetConfig;
39 import org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc.RuntimeRpc;
40 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
41 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
42 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
43 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
44 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
45 import org.opendaylight.controller.netconf.util.xml.XmlElement;
46 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
47 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.w3c.dom.Document;
51 import org.w3c.dom.Element;
52 import org.w3c.dom.NodeList;
53 import org.xml.sax.SAXException;
54
55 import javax.management.InstanceAlreadyExistsException;
56 import javax.management.ObjectName;
57 import javax.xml.parsers.ParserConfigurationException;
58 import java.io.FileNotFoundException;
59 import java.io.IOException;
60 import java.io.InputStream;
61 import java.math.BigInteger;
62 import java.util.*;
63
64 import static org.junit.Assert.*;
65 import static org.mockito.Mockito.*;
66
67 public class NetconfMappingTest extends AbstractConfigTest {
68     private static final Logger logger = LoggerFactory.getLogger(NetconfMappingTest.class);
69
70     private static final String INSTANCE_NAME = "test1";
71     private static final String NETCONF_SESSION_ID = "foo";
72     private NetconfTestImplModuleFactory factory;
73     private DepTestImplModuleFactory factory2;
74
75     @Mock
76     YangStoreSnapshot yangStoreSnapshot;
77     @Mock
78     NetconfOperationRouter netconfOperationRouter;
79
80     private TransactionProvider transactionProvider;
81
82     @Before
83     public void setUp() throws Exception {
84         MockitoAnnotations.initMocks(this);
85         doReturn(getMbes()).when(this.yangStoreSnapshot).getModuleMXBeanEntryMap();
86         this.factory = new NetconfTestImplModuleFactory();
87         this.factory2 = new DepTestImplModuleFactory();
88         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.factory, this.factory2));
89
90         transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID);
91     }
92
93     private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException {
94         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
95
96         final ObjectName on = transaction.createModule(this.factory.getImplementationName(), instanceName);
97         final NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
98         setModule(mxBean, transaction);
99
100         transaction.commit();
101         return on;
102     }
103
104     @Test
105     public void testConfigNetconf() throws Exception {
106
107         createModule(INSTANCE_NAME);
108
109         edit("netconfMessages/editConfig.xml");
110         checkBinaryLeafEdited(getConfigCandidate());
111
112         // default-operation:none, should not affect binary leaf
113         edit("netconfMessages/editConfig_none.xml");
114         checkBinaryLeafEdited(getConfigCandidate());
115
116         // check after edit
117         commit();
118         Element response = getConfigRunning();
119         // System.out.println(Xml.toString(response));
120
121         checkBinaryLeafEdited(response);
122         checkTypeConfigAttribute(response);
123
124         edit("netconfMessages/editConfig_remove.xml");
125
126         commit();
127         response = getConfigCandidate();
128         final String responseFromCandidate = XmlUtil.toString(response).replaceAll("\\s+", "");
129         // System.out.println(responseFromCandidate);
130         response = getConfigRunning();
131         final String responseFromRunning = XmlUtil.toString(response).replaceAll("\\s+", "");
132         // System.out.println(responseFromRunning);
133         assertEquals(responseFromCandidate, responseFromRunning);
134
135         final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml")
136                 .replaceAll("\\s+", "");
137
138         assertEquals(expectedResult, responseFromRunning);
139         assertEquals(expectedResult, responseFromCandidate);
140
141         edit("netconfMessages/editConfig_none.xml");
142         doNothing().when(netconfOperationRouter).close();
143         closeSession();
144         verify(netconfOperationRouter).close();
145         verifyNoMoreInteractions(netconfOperationRouter);
146     }
147
148     private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
149             IOException {
150         DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
151         executeOp(closeOp, "netconfMessages/closeSession.xml");
152     }
153
154     private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
155             NetconfDocumentedException {
156         EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
157                 NETCONF_SESSION_ID);
158         executeOp(editOp, resource);
159     }
160
161     private void commit() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
162         Commit commitOp = new Commit(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
163         executeOp(commitOp, "netconfMessages/commit.xml");
164     }
165
166     private Element getConfigCandidate() throws ParserConfigurationException, SAXException, IOException,
167             NetconfDocumentedException {
168         GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
169                 configRegistryClient, NETCONF_SESSION_ID);
170         return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
171     }
172
173     private Element getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
174             NetconfDocumentedException {
175         GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
176                 configRegistryClient, NETCONF_SESSION_ID);
177         return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
178     }
179
180     @Test(expected = NetconfDocumentedException.class)
181     public void testConfigNetconfReplaceDefaultEx() throws Exception {
182
183         createModule(INSTANCE_NAME);
184
185         edit("netconfMessages/editConfig.xml");
186         edit("netconfMessages/editConfig_replace_default_ex.xml");
187     }
188
189     @Test
190     public void testConfigNetconfReplaceDefault() throws Exception {
191
192         createModule(INSTANCE_NAME);
193
194         edit("netconfMessages/editConfig.xml");
195         commit();
196         Element response = getConfigRunning();
197         final int allInstances = response.getElementsByTagName("module").getLength();
198
199         edit("netconfMessages/editConfig_replace_default.xml");
200
201         commit();
202         response = getConfigRunning();
203
204         final int afterReplace = response.getElementsByTagName("module").getLength();
205         assertEquals(4, allInstances);
206         assertEquals(2, afterReplace);
207     }
208
209     @Test(expected = NetconfDocumentedException.class)
210     public void testSameAttrDifferentNamespaces() throws Exception {
211         try {
212             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
213         } catch (NetconfDocumentedException e) {
214             String message = e.getMessage();
215             assertThat(message,
216                     JUnitMatchers
217                             .containsString("Element simple-long-2 present multiple times with different namespaces"));
218             assertThat(message,
219                     JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
220             assertThat(message,
221                     JUnitMatchers
222                             .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
223             throw e;
224         }
225     }
226
227     @Test(expected = NetconfDocumentedException.class)
228     public void testDifferentNamespaceInTO() throws Exception {
229         try {
230             edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
231         } catch (NetconfDocumentedException e) {
232             String message = e.getMessage();
233             assertThat(message, JUnitMatchers.containsString("Unrecognised elements"));
234             assertThat(message, JUnitMatchers.containsString("simple-int2"));
235             assertThat(message, JUnitMatchers.containsString("dto_d"));
236             throw e;
237         }
238     }
239
240     @Test(expected = NetconfDocumentedException.class)
241     public void testSameAttrDifferentNamespacesList() throws Exception {
242         try {
243             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
244         } catch (NetconfDocumentedException e) {
245             String message = e.getMessage();
246             assertThat(message,
247                     JUnitMatchers.containsString("Element binaryLeaf present multiple times with different namespaces"));
248             assertThat(message,
249                     JUnitMatchers.containsString("urn:opendaylight:params:xml:ns:yang:controller:test:impl"));
250             assertThat(message,
251                     JUnitMatchers
252                             .containsString(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
253             throw e;
254         }
255     }
256
257     @Test
258     public void testTypeNameConfigAttributeMatching() throws Exception {
259         edit("netconfMessages/editConfig.xml");
260         commit();
261         edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
262         commit();
263
264         Element response = getConfigRunning();
265         checkTypeConfigAttribute(response);
266     }
267
268     // TODO add <modules operation="replace"> functionality
269     @Test(expected = NetconfDocumentedException.class)
270     public void testConfigNetconfReplaceModuleEx() throws Exception {
271
272         createModule(INSTANCE_NAME);
273
274         edit("netconfMessages/editConfig.xml");
275         edit("netconfMessages/editConfig_replace_module_ex.xml");
276     }
277
278     @Test
279     public void testUnrecognisedConfigElements() throws Exception {
280
281         String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
282         final int TESTS_COUNT = 8;
283
284         for (int i = 0; i < TESTS_COUNT; i++) {
285             String file = String.format(format, i + 1);
286             try {
287                 edit(file);
288             } catch (NetconfDocumentedException e) {
289                 Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("Unrecognised elements"));
290                 Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("unknownAttribute"));
291                 continue;
292             }
293             fail("Unrecognised test should throw exception " + file);
294         }
295     }
296
297     @Test
298     @Ignore
299     // FIXME
300     public void testConfigNetconfReplaceModule() throws Exception {
301
302         createModule(INSTANCE_NAME);
303
304         edit("netconfMessages/editConfig.xml");
305         commit();
306         Element response = getConfigRunning();
307         final int allInstances = response.getElementsByTagName("instance").getLength();
308
309         edit("netconfMessages/editConfig_replace_module.xml");
310
311         commit();
312         response = getConfigRunning();
313         final int afterReplace = response.getElementsByTagName("instance").getLength();
314
315         Assert.assertEquals(4 + 4 /* Instances from services */, allInstances);
316         Assert.assertEquals(3 + 3, afterReplace);
317     }
318
319     @Test(expected = NetconfDocumentedException.class)
320     public void testEx() throws Exception {
321
322         commit();
323     }
324
325     @Test(expected = NetconfDocumentedException.class)
326     public void testEx2() throws Exception {
327         discard();
328     }
329
330     private void discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
331         DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
332         executeOp(discardOp, "netconfMessages/discardChanges.xml");
333     }
334
335     private void checkBinaryLeafEdited(final Element response) {
336         final NodeList children = response.getElementsByTagName("binaryLeaf");
337         assertEquals(3, children.getLength());
338         final StringBuffer buf = new StringBuffer();
339         for (int i = 0; i < 3; i++) {
340             final Element e = (Element) children.item(i);
341             buf.append(XmlElement.fromDomElement(e).getTextContent());
342         }
343         assertEquals("810", buf.toString());
344
345     }
346
347     private void checkTypeConfigAttribute(Element response) {
348
349         XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
350                 .getOnlyChildElement("modules");
351
352         XmlElement configAttributeType = null;
353         for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
354             for (XmlElement type : moduleElement.getChildElements("type")) {
355                 if (type.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY).equals("") == false) {
356                     configAttributeType = type;
357                 }
358             }
359         }
360
361         assertEquals("configAttributeType", configAttributeType.getTextContent());
362     }
363
364     private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
365         final List<InputStream> yangDependencies = getYangs();
366
367         final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
368         mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap());
369
370         return mBeanEntries;
371     }
372
373     @Test
374     public void testConfigNetconfRuntime() throws Exception {
375
376         ModuleIdentifier id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance");
377         RootRuntimeBeanRegistrator rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
378         NetconfTestImplRuntimeRegistrator registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
379
380         NetconfTestImplRuntimeRegistration a = registerRoot(registrator);
381         InnerRunningDataRuntimeRegistration reg = registerInner(a);
382         registerInner2(reg);
383
384         id = new ModuleIdentifier(NetconfTestImplModuleFactory.NAME, "instance2");
385         rootReg = new RootRuntimeBeanRegistratorImpl(internalJmxRegistrator, id);
386         registrator = new NetconfTestImplRuntimeRegistrator(rootReg);
387
388         a = registerRoot(registrator);
389         registerAdditional(a);
390         registerAdditional(a);
391         registerAdditional(a);
392         registerAdditional(a);
393         reg = registerInner(a);
394         registerInner2(reg);
395         reg = registerInner(a);
396         registerInner2(reg);
397         registerInner2(reg);
398         reg = registerInner(a);
399         registerInner2(reg);
400         registerInner2(reg);
401         registerInner2(reg);
402         reg = registerInner(a);
403         registerInner2(reg);
404         registerInner2(reg);
405         registerInner2(reg);
406         registerInner2(reg);
407
408         Element response = get();
409
410         System.err.println(XmlUtil.toString(response));
411
412         assertEquals(2, getElementsSize(response, "instance"));
413         assertEquals(2, getElementsSize(response, "asdf"));
414         assertEquals(5, getElementsSize(response, "inner-running-data"));
415         assertEquals(5, getElementsSize(response, "deep2"));
416         assertEquals(11, getElementsSize(response, "inner-inner-running-data"));
417         assertEquals(11, getElementsSize(response, "deep3"));
418         assertEquals(11 * 2, getElementsSize(response, "list-of-strings"));
419         assertEquals(4, getElementsSize(response, "inner-running-data-additional"));
420         assertEquals(4, getElementsSize(response, "deep4"));
421         // TODO assert keys
422
423         RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
424
425         response = executeOp(netconf, "netconfMessages/rpc.xml");
426         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("testarg1".toUpperCase()));
427
428         response = executeOp(netconf, "netconfMessages/rpcInner.xml");
429         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("ok"));
430
431         response = executeOp(netconf, "netconfMessages/rpcInnerInner.xml");
432         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("true"));
433
434         response = executeOp(netconf, "netconfMessages/rpcInnerInner_complex_output.xml");
435         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("1"));
436         assertThat(XmlUtil.toString(response), JUnitMatchers.containsString("2"));
437     }
438
439     private Element get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
440         Get getOp = new Get(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
441         return executeOp(getOp, "netconfMessages/get.xml");
442     }
443
444     private int getElementsSize(Element response, String elementName) {
445         return response.getElementsByTagName(elementName).getLength();
446     }
447
448     private Object registerAdditional(final NetconfTestImplRuntimeRegistration a) {
449         class InnerRunningDataAdditionalRuntimeMXBeanTest implements InnerRunningDataAdditionalRuntimeMXBean {
450
451             private final int simpleInt;
452             private final String simpleString;
453
454             public InnerRunningDataAdditionalRuntimeMXBeanTest(final int simpleInt, final String simpleString) {
455                 this.simpleInt = simpleInt;
456                 this.simpleString = simpleString;
457             }
458
459             @Override
460             public Integer getSimpleInt3() {
461                 return this.simpleInt;
462             }
463
464             @Override
465             public Deep4 getDeep4() {
466                 final Deep4 d = new Deep4();
467                 d.setBoool(false);
468                 return d;
469             }
470
471             @Override
472             public String getSimpleString() {
473                 return this.simpleString;
474             }
475
476             @Override
477             public void noArgInner() {
478             }
479
480         }
481
482         final int simpleInt = counter++;
483         return a.register(new InnerRunningDataAdditionalRuntimeMXBeanTest(simpleInt, "randomString_" + simpleInt));
484     }
485
486     private void registerInner2(final InnerRunningDataRuntimeRegistration reg) {
487         class InnerInnerRunningDataRuntimeMXBeanTest implements InnerInnerRunningDataRuntimeMXBean {
488
489             private final int simpleInt;
490
491             public InnerInnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
492                 this.simpleInt = simpleInt;
493             }
494
495             @Override
496             public List<NotStateBean> getNotStateBean() {
497                 final NotStateBean notStateBean = new NotStateBean();
498                 final NotStateBeanInternal notStateBeanInternal = new NotStateBeanInternal();
499                 notStateBean.setNotStateBeanInternal(Lists.newArrayList(notStateBeanInternal));
500                 return Lists.newArrayList(notStateBean);
501             }
502
503             @Override
504             public Integer getSimpleInt3() {
505                 return this.simpleInt;
506             }
507
508             @Override
509             public Deep3 getDeep3() {
510                 return new Deep3();
511             }
512
513             @Override
514             public List<String> getListOfStrings() {
515                 return Lists.newArrayList("l1", "l2");
516             }
517
518             @Override
519             public List<RetValList> listOutput() {
520                 return Lists.newArrayList(new RetValList());
521             }
522
523             @Override
524             public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
525                 return aBoolean;
526             }
527
528             @Override
529             public RetValContainer containerOutput() {
530                 return new RetValContainer();
531             }
532
533             @Override
534             public List<String> leafListOutput() {
535                 return Lists.newArrayList("1", "2");
536             }
537
538         }
539
540         reg.register(new InnerInnerRunningDataRuntimeMXBeanTest(counter++));
541
542     }
543
544     private static int counter = 1000;
545
546     private InnerRunningDataRuntimeRegistration registerInner(final NetconfTestImplRuntimeRegistration a) {
547
548         class InnerRunningDataRuntimeMXBeanTest implements InnerRunningDataRuntimeMXBean {
549
550             private final int simpleInt;
551
552             public InnerRunningDataRuntimeMXBeanTest(final int simpleInt) {
553                 this.simpleInt = simpleInt;
554             }
555
556             @Override
557             public Integer getSimpleInt3() {
558                 return this.simpleInt;
559             }
560
561             @Override
562             public Deep2 getDeep2() {
563                 return new Deep2();
564             }
565
566         }
567         return a.register(new InnerRunningDataRuntimeMXBeanTest(counter++));
568     }
569
570     private NetconfTestImplRuntimeRegistration registerRoot(final NetconfTestImplRuntimeRegistrator registrator) {
571         final NetconfTestImplRuntimeRegistration a = registrator.register(new NetconfTestImplRuntimeMXBean() {
572
573             @Override
574             public Long getCreatedSessions() {
575                 return 11L;
576             }
577
578             @Override
579             public Asdf getAsdf() {
580                 final Asdf asdf = new Asdf();
581                 asdf.setSimpleInt(55);
582                 asdf.setSimpleString("asdf");
583                 return asdf;
584             }
585
586             @Override
587             public String noArg(final String arg1) {
588                 return arg1.toUpperCase();
589             }
590
591         });
592         return a;
593     }
594
595     private Element executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
596             SAXException, IOException, NetconfDocumentedException {
597
598         final Document request = XmlFileLoader.xmlFileToDocument(filename);
599
600         logger.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
601         HandlingPriority priority = op.canHandle(request);
602
603         Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
604
605         final Document response = op.handle(request, netconfOperationRouter);
606         logger.debug("Got response\n{}", XmlUtil.toString(response));
607         return response.getDocumentElement();
608     }
609
610     private List<InputStream> getYangs() throws FileNotFoundException {
611         List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
612                 "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang",
613                 "/META-INF/yang/ietf-inet-types.yang");
614         final Collection<InputStream> yangDependencies = new ArrayList<>();
615         for (String path : paths) {
616             final InputStream is = Preconditions
617                     .checkNotNull(getClass().getResourceAsStream(path), path + " not found");
618             yangDependencies.add(is);
619         }
620         return Lists.newArrayList(yangDependencies);
621     }
622
623     private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction)
624             throws InstanceAlreadyExistsException {
625         mxBean.setSimpleInt((long) 44);
626         mxBean.setBinaryLeaf(new byte[] { 8, 7, 9 });
627         final DtoD dtob = getDtoD();
628         mxBean.setDtoD(dtob);
629         //
630         final DtoC dtoa = getDtoC();
631         mxBean.setDtoC(dtoa);
632         mxBean.setSimpleBoolean(false);
633         //
634         final Peers p1 = new Peers();
635         p1.setCoreSize(44L);
636         p1.setPort("port1");
637         p1.setSimpleInt3(456);
638         final Peers p2 = new Peers();
639         p2.setCoreSize(44L);
640         p2.setPort("port23");
641         p2.setSimpleInt3(456);
642         mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
643         // //
644         mxBean.setSimpleLong(454545L);
645         mxBean.setSimpleLong2(44L);
646         mxBean.setSimpleBigInteger(BigInteger.valueOf(999L));
647         mxBean.setSimpleByte(new Byte((byte) 4));
648         mxBean.setSimpleShort(new Short((short) 4));
649         mxBean.setSimpleTest(545);
650
651         mxBean.setComplexList(Lists.<ComplexList> newArrayList());
652         mxBean.setSimpleList(Lists.<Integer> newArrayList());
653
654         final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), "dep");
655         mxBean.setTestingDep(testingDepOn);
656     }
657
658     private static DtoD getDtoD() {
659         final DtoD dtob = new DtoD();
660         dtob.setSimpleInt1((long) 444);
661         dtob.setSimpleInt2((long) 4444);
662         dtob.setSimpleInt3(454);
663         final ComplexDtoBInner dtobInner = new ComplexDtoBInner();
664         final Deep deep = new Deep();
665         deep.setSimpleInt3(4);
666         dtobInner.setDeep(deep);
667         dtobInner.setSimpleInt3(44);
668         dtobInner.setSimpleList(Lists.newArrayList(4));
669         dtob.setComplexDtoBInner(Lists.newArrayList(dtobInner));
670         dtob.setSimpleList(Lists.newArrayList(4));
671         return dtob;
672     }
673
674     private static DtoC getDtoC() {
675         final DtoC dtoa = new DtoC();
676         // dtoa.setSimpleArg((long) 55);
677         final DtoAInner dtoAInner = new DtoAInner();
678         final DtoAInnerInner dtoAInnerInner = new DtoAInnerInner();
679         dtoAInnerInner.setSimpleArg(456L);
680         dtoAInner.setDtoAInnerInner(dtoAInnerInner);
681         dtoAInner.setSimpleArg(44L);
682         dtoa.setDtoAInner(dtoAInner);
683         return dtoa;
684     }
685
686 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.