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