50e1d4bb6a9d7c92ea4916313a39c00922934903
[controller.git] / opendaylight / config / yang-test / src / test / org / opendaylight / controller / config / yang / test / impl / NetconfTestImplModuleTest.java
1 package org.opendaylight.controller.config.yang.test.impl;
2
3 import com.google.common.collect.Lists;
4 import junit.framework.Assert;
5 import org.junit.Before;
6 import org.junit.Test;
7 import org.opendaylight.controller.config.api.ConflictingVersionException;
8 import org.opendaylight.controller.config.api.ValidationException;
9 import org.opendaylight.controller.config.api.jmx.CommitStatus;
10 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
11 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
12 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
13 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
14
15 import javax.management.InstanceAlreadyExistsException;
16 import javax.management.ObjectName;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 public class NetconfTestImplModuleTest  extends AbstractConfigTest {
21
22     public static final String TESTING_DEP_PREFIX = "testing-dep";
23     private NetconfTestImplModuleFactory factory;
24     private final String instanceName = "n1";
25
26     @Before
27     public void setUp() {
28
29         factory = new NetconfTestImplModuleFactory();
30         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory,
31                 new DepTestImplModuleFactory()));
32     }
33
34     @Test
35     public void testDependencyList() throws InstanceAlreadyExistsException, ValidationException,
36             ConflictingVersionException {
37         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
38
39         ObjectName on = createInstance(transaction, instanceName, 4);
40         transaction.validateConfig();
41         CommitStatus status = transaction.commit();
42
43         assertBeanCount(1, factory.getImplementationName());
44         assertBeanCount(4 + 1, DepTestImplModuleFactory.NAME);
45         assertStatus(status, 1 + 4 + 1, 0, 0);
46
47         transaction = configRegistryClient.createTransaction();
48
49         NetconfTestImplModuleMXBean proxy = transaction.newMXBeanProxy(ObjectNameUtil.withoutTransactionName(on),
50                 NetconfTestImplModuleMXBean.class);
51         proxy.getComplexList();
52         List<ObjectName> testingDeps = proxy.getTestingDeps();
53         ObjectName testingDep = proxy.getTestingDep();
54
55         Assert.assertEquals(TESTING_DEP_PREFIX, ObjectNameUtil.getInstanceName(testingDep));
56         assertTestingDeps(testingDeps, 4);
57
58         transaction.abortConfig();
59     }
60
61     private void assertTestingDeps(List<ObjectName> testingDeps, int i) {
62         Assert.assertEquals(i, testingDeps.size());
63
64         int c = 1;
65         for (ObjectName testingDep : testingDeps) {
66             Assert.assertEquals(TESTING_DEP_PREFIX + Integer.toString(c++), ObjectNameUtil.getInstanceName(testingDep));
67         }
68     }
69
70
71     private ObjectName createInstance(ConfigTransactionJMXClient transaction, String instanceName, int depsCount)
72             throws InstanceAlreadyExistsException {
73         ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
74         NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, NetconfTestImplModuleMXBean.class);
75
76         ObjectName dep = transaction.createModule(DepTestImplModuleFactory.NAME, TESTING_DEP_PREFIX);
77         mxBean.setTestingDep(dep);
78
79         ArrayList<ObjectName> testingDeps = Lists.newArrayList();
80         for (int i = 0; i < depsCount; i++) {
81             dep = transaction.createModule(DepTestImplModuleFactory.NAME, TESTING_DEP_PREFIX + Integer.toString(i + 1));
82             testingDeps.add(dep);
83         }
84         mxBean.setTestingDeps(testingDeps);
85
86         return nameCreated;
87     }
88
89 }

©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.