Fix checkstyle warnings in config-util
[controller.git] / opendaylight / config / config-util / src / test / java / org / opendaylight / controller / config / util / TestingConfigTransactionController.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 package org.opendaylight.controller.config.util;
9
10 import com.google.common.collect.Sets;
11 import java.util.HashMap;
12 import java.util.Map;
13 import java.util.Set;
14 import javax.management.InstanceAlreadyExistsException;
15 import javax.management.InstanceNotFoundException;
16 import javax.management.ObjectName;
17 import org.opendaylight.controller.config.api.ValidationException;
18 import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean;
19 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
20
21 public class TestingConfigTransactionController implements
22         ConfigTransactionControllerMXBean {
23
24     public final ObjectName conf1, conf2, conf3;
25     public ObjectName conf4;
26     public String check;
27     Map<String, ObjectName> mapSub;
28     Map<String, Map<String, ObjectName>> map;
29
30     public static final String moduleName1 = "moduleA";
31     public static final String moduleName2 = "moduleB";
32     public static final String instName1 = "instA";
33     public static final String instName2 = "instB";
34
35     public TestingConfigTransactionController() throws Exception {
36         conf1 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
37                 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
38                 + "=" + moduleName1);
39         conf2 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
40                 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
41                 + "=" + moduleName1 + "," + ObjectNameUtil.INSTANCE_NAME_KEY
42                 + "=" + instName1);
43         conf3 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
44                 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
45                 + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY
46                 + "=" + instName2);
47         conf4 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
48                 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
49                 + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY
50                 + "=" + instName2);
51         mapSub = new HashMap<String, ObjectName>();
52         map = new HashMap<String, Map<String,ObjectName>>();
53     }
54
55     @Override
56     public ObjectName createModule(String moduleName, String instanceName)
57             throws InstanceAlreadyExistsException {
58         //return null;
59         return ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
60                 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
61                 + "=" + moduleName);
62     }
63
64     @Override
65     public void destroyModule(ObjectName objectName)
66             throws InstanceNotFoundException {
67         if(objectName != null){
68             conf4 = null;
69         }
70     }
71
72     @Override
73     public void abortConfig() {
74     }
75
76     @Override
77     public void validateConfig() throws ValidationException {
78     }
79
80     @Override
81     public String getTransactionName() {
82         //return null;
83         return "transactionName";
84     }
85
86     @Override
87     public Set<String> getAvailableModuleNames() {
88         return null;
89     }
90
91     @Override
92     public Set<ObjectName> lookupConfigBeans() {
93         return Sets.newHashSet(conf1, conf2, conf3);
94     }
95
96     @Override
97     public Set<ObjectName> lookupConfigBeans(String moduleName) {
98         if (moduleName.equals(moduleName1)) {
99             return Sets.newHashSet(conf1, conf2);
100         } else if (moduleName.equals(moduleName2)) {
101             return Sets.newHashSet(conf3);
102         } else {
103             return null;
104         }
105     }
106
107     @Override
108     public ObjectName lookupConfigBean(String moduleName, String instanceName)
109             throws InstanceNotFoundException {
110         if (moduleName.equals(InstanceNotFoundException.class.getSimpleName())) {
111             throw new InstanceNotFoundException();
112         }
113         return conf3;
114     }
115
116     @Override
117     public Set<ObjectName> lookupConfigBeans(String moduleName,
118             String instanceName) {
119         if (moduleName.equals(moduleName1) && instanceName.equals(instName1)) {
120             return Sets.newHashSet(conf2);
121         } else if (moduleName.equals(moduleName2)
122                 && instanceName.equals(instName2)) {
123             return Sets.newHashSet(conf3);
124         } else {
125             return null;
126         }
127     }
128
129     @Override
130     public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
131         check = "configBeanExists";
132     }
133
134     @Override
135     public ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException {
136         return moduleON;
137     }
138
139     @Override
140     public void removeServiceReference(String serviceInterfaceName, String refName) {
141         check = refName;
142     }
143
144     @Override
145     public void removeAllServiceReferences() {
146         check = null;
147     }
148
149     @Override
150     public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) {
151         return conf3;
152     }
153
154     @Override
155     public Map<String, Map<String, ObjectName>> getServiceMapping() {
156         mapSub.put("A",conf2);
157         map.put("AA", mapSub);
158         return map;
159     }
160
161     @Override
162     public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) {
163         mapSub.put("A",conf2);
164         return mapSub;
165     }
166
167     @Override
168     public Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
169         return Sets.newHashSet("setA");
170     }
171
172     @Override
173     public String getServiceInterfaceName(String namespace, String localName) {
174         return check=namespace+localName;
175     }
176
177     @Override
178     public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException {
179         return true;
180     }
181
182     @Override
183     public Set<String> getAvailableModuleFactoryQNames() {
184         return Sets.newHashSet("availableModuleFactoryQNames");
185     }
186
187     @Override
188     public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException {
189         return conf3;
190     }
191
192     @Override
193     public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException {
194         check = "referenceExist";
195     }
196 }