/
DummyComponentContext.java
105 lines (83 loc) · 2.32 KB
/
DummyComponentContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package io.openems.edge.common.test;
import java.lang.reflect.InvocationTargetException;
import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.ComponentInstance;
import io.openems.common.test.AbstractComponentConfig;
/**
* Simulates a {@link ComponentContext} for the OpenEMS Component test
* framework.
*/
public class DummyComponentContext implements ComponentContext {
/**
* Build a {@link DummyComponentContext} from a configuration.
*
* @param configuration the {@link AbstractComponentConfig}
* @return the DummyComponentContextn
* @throws IllegalAccessException on error
* @throws IllegalArgumentException on error
* @throws InvocationTargetException on error
*/
public static DummyComponentContext from(AbstractComponentConfig configuration)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
return new DummyComponentContext(configuration.getAsProperties());
}
private final Dictionary<String, Object> properties;
public DummyComponentContext(Dictionary<String, Object> properties) {
this.properties = properties;
}
public DummyComponentContext() {
this(new Hashtable<>());
}
/**
* Add a configuration property.
*
* @param key the property key
* @param value the property value
*/
public void addProperty(String key, Object value) {
this.properties.put(key, value);
}
@Override
public Dictionary<String, Object> getProperties() {
return this.properties;
}
@Override
public <S> S locateService(String name) {
return null;
}
@Override
public <S> S locateService(String name, ServiceReference<S> reference) {
return null;
}
@Override
public Object[] locateServices(String name) {
return new Object[] {};
}
@Override
public BundleContext getBundleContext() {
return null;
}
@Override
public Bundle getUsingBundle() {
return null;
}
@Override
public <S> ComponentInstance<S> getComponentInstance() {
return null;
}
@Override
public void enableComponent(String name) {
}
@Override
public void disableComponent(String name) {
}
@Override
public ServiceReference<?> getServiceReference() {
return null;
}
}