2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.util;
10 import com.google.common.collect.Sets;
11 import java.util.Collections;
12 import java.util.HashMap;
15 import javax.management.InstanceAlreadyExistsException;
16 import javax.management.InstanceNotFoundException;
17 import javax.management.ObjectName;
18 import org.opendaylight.controller.config.api.ValidationException;
19 import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean;
20 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
22 public class TestingConfigTransactionController implements
23 ConfigTransactionControllerMXBean {
25 public final ObjectName conf1, conf2, conf3;
26 public ObjectName conf4;
28 Map<String, ObjectName> mapSub;
29 Map<String, Map<String, ObjectName>> map;
31 public static final String moduleName1 = "moduleA";
32 public static final String moduleName2 = "moduleB";
33 public static final String instName1 = "instA";
34 public static final String instName2 = "instB";
36 public TestingConfigTransactionController() throws Exception {
37 conf1 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
38 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
40 conf2 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
41 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
42 + "=" + moduleName1 + "," + ObjectNameUtil.INSTANCE_NAME_KEY
44 conf3 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
45 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
46 + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY
48 conf4 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
49 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
50 + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY
52 mapSub = new HashMap<String, ObjectName>();
53 map = new HashMap<String, Map<String,ObjectName>>();
57 public ObjectName createModule(String moduleName, String instanceName)
58 throws InstanceAlreadyExistsException {
60 return ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN
61 + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY
66 public void reCreateModule(ObjectName objectName) {
70 public void destroyModule(ObjectName objectName)
71 throws InstanceNotFoundException {
72 if(objectName != null){
78 public void abortConfig() {
82 public void validateConfig() throws ValidationException {
86 public String getTransactionName() {
88 return "transactionName";
92 public Set<String> getAvailableModuleNames() {
97 public Set<ObjectName> lookupConfigBeans() {
98 return Sets.newHashSet(conf1, conf2, conf3);
102 public Set<ObjectName> lookupConfigBeans(String moduleName) {
103 if (moduleName.equals(moduleName1)) {
104 return Sets.newHashSet(conf1, conf2);
105 } else if (moduleName.equals(moduleName2)) {
106 return Sets.newHashSet(conf3);
113 public ObjectName lookupConfigBean(String moduleName, String instanceName)
114 throws InstanceNotFoundException {
115 if (moduleName.equals(InstanceNotFoundException.class.getSimpleName())) {
116 throw new InstanceNotFoundException();
122 public Set<ObjectName> lookupConfigBeans(String moduleName,
123 String instanceName) {
124 if (moduleName.equals(moduleName1) && instanceName.equals(instName1)) {
125 return Sets.newHashSet(conf2);
126 } else if (moduleName.equals(moduleName2)
127 && instanceName.equals(instName2)) {
128 return Sets.newHashSet(conf3);
135 public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
136 check = "configBeanExists";
140 public ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException {
145 public void removeServiceReference(String serviceInterfaceName, String refName) {
150 public void removeAllServiceReferences() {
155 public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) {
160 public Map<String, Map<String, ObjectName>> getServiceMapping() {
161 mapSub.put("A",conf2);
162 map.put("AA", mapSub);
167 public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) {
168 mapSub.put("A",conf2);
173 public Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
174 return Sets.newHashSet("setA");
178 public String getServiceInterfaceName(String namespace, String localName) {
179 return check=namespace+localName;
183 public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException {
188 public Set<String> getAvailableModuleFactoryQNames() {
189 return Sets.newHashSet("availableModuleFactoryQNames");
193 public Set<ObjectName> lookupRuntimeBeans() {
194 return Collections.emptySet();
198 public Set<ObjectName> lookupRuntimeBeans(final String moduleName, final String instanceName) {
199 return Collections.emptySet();
203 public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException {
208 public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException {
209 check = "referenceExist";