Search in sources :

Example 11 with DriverLocator

use of org.osgi.service.device.DriverLocator in project felix by apache.

the class DeviceManagerTest method LocatorAdded.

/**
 * does not really test anything special, but ensures that the internal
 * structure is able to parse the addition
 */
@Test
public void LocatorAdded() {
    DriverLocator locator = Mockito.mock(DriverLocator.class);
    m_manager.locatorAdded(locator);
}
Also used : DriverLocator(org.osgi.service.device.DriverLocator) Test(org.junit.Test)

Example 12 with DriverLocator

use of org.osgi.service.device.DriverLocator in project felix by apache.

the class DeviceManagerTest method LocatorRemoved.

/**
 * does not really test anything special, but ensures that the internal
 * structure is able to parse the addition/ removal
 */
@Test
public void LocatorRemoved() {
    DriverLocator locator = Mockito.mock(DriverLocator.class);
    m_manager.locatorAdded(locator);
    m_manager.locatorRemoved(locator);
}
Also used : DriverLocator(org.osgi.service.device.DriverLocator) Test(org.junit.Test)

Example 13 with DriverLocator

use of org.osgi.service.device.DriverLocator in project felix by apache.

the class DriverLoaderTest method tstExpectDriverIdsFor.

private DriverLocator tstExpectDriverIdsFor(String[] ids) {
    DriverLocator dl = Mockito.mock(DriverLocator.class);
    Mockito.when(dl.findDrivers(Mockito.isA(Dictionary.class))).thenReturn(ids);
    return dl;
}
Also used : Dictionary(java.util.Dictionary) DriverLocator(org.osgi.service.device.DriverLocator)

Example 14 with DriverLocator

use of org.osgi.service.device.DriverLocator in project felix by apache.

the class DriverLoaderTest method loadDrivers.

@Test
public void loadDrivers() throws IOException, BundleException {
    List<DriverLocator> locators = new ArrayList<DriverLocator>();
    DriverLocator dl = Mockito.mock(DriverLocator.class, "dl");
    locators.add(dl);
    String[] driverIds = new String[] { "org.apache.felix.driver-1.0", "org.apache.felix.driver-1.1" };
    for (String string : driverIds) {
        Mockito.when(dl.loadDriver(Mockito.eq(string))).thenReturn(null);
        Bundle bundle = Mockito.mock(Bundle.class);
        Mockito.when(m_context.installBundle("_DD_" + string, null)).thenReturn(bundle);
        bundle.start();
        ServiceReference ref = Mockito.mock(ServiceReference.class);
        Mockito.when(ref.getProperty(Constants.DRIVER_ID)).thenReturn(string);
        Mockito.when(bundle.getRegisteredServices()).thenReturn(new ServiceReference[] { ref });
    }
    List<ServiceReference> refs = m_loader.loadDrivers(locators, driverIds);
    Assert.assertEquals("", 2, refs.size());
    for (ServiceReference serviceReference : refs) {
        String driverId = "" + serviceReference.getProperty(Constants.DRIVER_ID);
        if (!driverId.equals(driverIds[0]) && !driverId.equals(driverIds[1])) {
            Assert.fail("unexpected driverId");
        }
    }
}
Also used : DriverLocator(org.osgi.service.device.DriverLocator) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 15 with DriverLocator

use of org.osgi.service.device.DriverLocator in project felix by apache.

the class DriverLoaderTest method findDriversWithDriverLocators.

/**
 * in this test there are several driver locators, some of which return
 * driver Ids, some don't. we expect an accurate number of driver ids being returned
 * from the driverloader.
 */
@Test
public void findDriversWithDriverLocators() {
    List<DriverLocator> locators = new ArrayList<DriverLocator>();
    DriverLocator dl1 = tstExpectDriverIdsFor(new String[] { "org.apache.felix.driver-1.0", "org.apache.felix.driver-1.1" });
    locators.add(dl1);
    DriverLocator dl2 = tstExpectDriverIdsFor(new String[] { "org.apache.felix.driver-1.2", "org.apache.felix.driver-1.3" });
    locators.add(dl2);
    DriverLocator dl3 = tstExpectDriverIdsFor(null);
    locators.add(dl3);
    Properties dict = new Properties();
    Set<String> driverIds = m_loader.findDrivers(locators, dict);
    Assert.assertEquals("should not be an empty list", 4, driverIds.size());
}
Also used : DriverLocator(org.osgi.service.device.DriverLocator) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

DriverLocator (org.osgi.service.device.DriverLocator)16 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)8 ServiceReference (org.osgi.framework.ServiceReference)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Device (org.osgi.service.device.Device)5 Properties (java.util.Properties)4 Driver (org.osgi.service.device.Driver)4 Dictionary (java.util.Dictionary)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 BundleException (org.osgi.framework.BundleException)3 Bundle (org.osgi.framework.Bundle)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Ignore (org.junit.Ignore)1 DriverSelector (org.osgi.service.device.DriverSelector)1