Search in sources :

Example 1 with MockServiceReference

use of org.springframework.osgi.mock.MockServiceReference in project camel by apache.

the class CamelMockBundleContext method addServicePID.

private static void addServicePID(ServiceReference[] srs, String filter) {
    for (ServiceReference sr : srs) {
        if (sr instanceof MockServiceReference) {
            Dictionary properties = new Hashtable();
            String pid = filter.replace("(" + Constants.SERVICE_PID + "=", "").replace(")", "");
            properties.put(Constants.SERVICE_PID, pid);
            for (String key : sr.getPropertyKeys()) {
                if (properties.get(key) == null) {
                    properties.put(key, sr.getProperty(key));
                }
            }
            ((MockServiceReference) sr).setProperties(properties);
        }
    }
}
Also used : MockServiceReference(org.springframework.osgi.mock.MockServiceReference) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) MockServiceReference(org.springframework.osgi.mock.MockServiceReference) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with MockServiceReference

use of org.springframework.osgi.mock.MockServiceReference in project camel by apache.

the class CamelMockBundleContext method getAllServiceReferences.

@SuppressWarnings({ "rawtypes", "unchecked" })
public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
    // just simulate when the bundle context doesn't have right service reference
    if (filter != null && filter.indexOf("name=test") > 0) {
        return null;
    }
    MockServiceReference reference = new MockServiceReference(getBundle(), new String[] { clazz });
    // setup the name property with the class name
    Dictionary properties = new Hashtable();
    properties.put("name", clazz);
    reference.setProperties(properties);
    return new ServiceReference[] { reference };
}
Also used : MockServiceReference(org.springframework.osgi.mock.MockServiceReference) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) MockServiceReference(org.springframework.osgi.mock.MockServiceReference) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Dictionary (java.util.Dictionary)2 Hashtable (java.util.Hashtable)2 ServiceReference (org.osgi.framework.ServiceReference)2 MockServiceReference (org.springframework.osgi.mock.MockServiceReference)2