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 destroyModule(ObjectName objectName)
67 throws InstanceNotFoundException {
68 if(objectName != null){
74 public void abortConfig() {
78 public void validateConfig() throws ValidationException {
82 public String getTransactionName() {
84 return "transactionName";
88 public Set<String> getAvailableModuleNames() {
93 public Set<ObjectName> lookupConfigBeans() {
94 return Sets.newHashSet(conf1, conf2, conf3);
98 public Set<ObjectName> lookupConfigBeans(String moduleName) {
99 if (moduleName.equals(moduleName1)) {
100 return Sets.newHashSet(conf1, conf2);
101 } else if (moduleName.equals(moduleName2)) {
102 return Sets.newHashSet(conf3);
109 public ObjectName lookupConfigBean(String moduleName, String instanceName)
110 throws InstanceNotFoundException {
111 if (moduleName.equals(InstanceNotFoundException.class.getSimpleName())) {
112 throw new InstanceNotFoundException();
118 public Set<ObjectName> lookupConfigBeans(String moduleName,
119 String instanceName) {
120 if (moduleName.equals(moduleName1) && instanceName.equals(instName1)) {
121 return Sets.newHashSet(conf2);
122 } else if (moduleName.equals(moduleName2)
123 && instanceName.equals(instName2)) {
124 return Sets.newHashSet(conf3);
131 public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
132 check = "configBeanExists";
136 public ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException {
141 public void removeServiceReference(String serviceInterfaceName, String refName) {
146 public void removeAllServiceReferences() {
151 public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) {
156 public Map<String, Map<String, ObjectName>> getServiceMapping() {
157 mapSub.put("A",conf2);
158 map.put("AA", mapSub);
163 public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) {
164 mapSub.put("A",conf2);
169 public Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
170 return Sets.newHashSet("setA");
174 public String getServiceInterfaceName(String namespace, String localName) {
175 return check=namespace+localName;
179 public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException {
184 public Set<String> getAvailableModuleFactoryQNames() {
185 return Sets.newHashSet("availableModuleFactoryQNames");
189 public Set<ObjectName> lookupRuntimeBeans() {
190 return Collections.emptySet();
194 public Set<ObjectName> lookupRuntimeBeans(final String moduleName, final String instanceName) {
195 return Collections.emptySet();
199 public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException {
204 public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException {
205 check = "referenceExist";