Search in sources :

Example 1 with Driver

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

the class DeviceManagerTest method DriverRemoved.

/**
 * does not really test anything special, but ensures that the internal
 * structure is able to parse the addition/ removal
 * @throws Exception
 */
@Test
public void DriverRemoved() throws Exception {
    Driver driver = tstCreateDriver("org.apache.felix.driver-1.0", 1);
    ServiceReference ref = m_osgi.getReference(driver);
    m_manager.driverAdded(ref, driver);
    m_manager.driverRemoved(ref);
}
Also used : Driver(org.osgi.service.device.Driver) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with Driver

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

the class DeviceManagerTest method DriverAdded.

/**
 * does not really test anything special, but ensures that the internal
 * structure is able to parse the addition
 * @throws Exception
 */
@Test
public void DriverAdded() throws Exception {
    Driver driver = tstCreateDriver("org.apache.felix.driver-1.0", 1);
    m_manager.driverAdded(m_osgi.getReference(driver), driver);
}
Also used : Driver(org.osgi.service.device.Driver) Test(org.junit.Test)

Example 3 with Driver

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

the class DeviceManagerTest method DeviceAddedNoDriverLocatorSuccessfulAttach.

/**
 * 	We add a device, but there are no driver locators, however, there is a driver
 *  that matches. Thus an attach must follow.
 * @throws Exception
 */
@Test
public void DeviceAddedNoDriverLocatorSuccessfulAttach() throws Exception {
    Device device = tstCreateDevice(new String[] { "org.apache.felix" });
    Driver driver = tstCreateDriver("org.apache.felix.driver-1.0", 1);
    CountDownLatch attachLatch = tstExpectAttach(driver, device);
    m_manager.driverAdded(m_osgi.getReference(driver), driver);
    m_manager.deviceAdded(m_osgi.getReference(device), device);
    if (!attachLatch.await(5, TimeUnit.SECONDS)) {
        Assert.fail("expected attach");
    }
}
Also used : Device(org.osgi.service.device.Device) Driver(org.osgi.service.device.Driver) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with Driver

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

the class DeviceManagerTest method tstExpectDriverLocatorFor.

/**
 * This method generates behavior on the provided DriverLocator.
 *
 * The given driver Ids and their matches are expected as drivers found
 * by this driver locator.
 * Also, if a driver is found, we can also expect that loadDriver is called;
 * resulting in an InputStream. That particular input stream should, when installed
 * using a bundle context, lead to the registration of a driver with
 * the correcsponding driver id.
 *
 * @param locator
 * @param driverIds
 * @param matches
 * @return
 * @throws Exception
 */
private Map<String, Driver> tstExpectDriverLocatorFor(final DriverLocator locator, final String[] driverIds, int[] matches) throws Exception {
    Mockito.when(locator.findDrivers(Mockito.isA(Dictionary.class))).thenReturn(driverIds);
    Map<String, Driver> drivers = new HashMap<String, Driver>();
    final Map<String, InputStream> streams = new HashMap<String, InputStream>();
    for (String driverId : driverIds) {
        InputStream in = Mockito.mock(InputStream.class, "[InputStream for: " + driverId + "]");
        streams.put(driverId, in);
    }
    Answer<InputStream> answer = new Answer<InputStream>() {

        public InputStream answer(InvocationOnMock invocation) throws Throwable {
            final String id = invocation.getArguments()[0].toString();
            for (String driverId : driverIds) {
                if (id.equals(driverId)) {
                    return streams.get(id);
                }
            }
            throw new IOException("no such driverId defined in this locator: " + locator);
        }
    };
    Mockito.when(locator.loadDriver(Mockito.isA(String.class))).thenAnswer(answer);
    int i = 0;
    for (String driverId : driverIds) {
        Driver driver = tstExpectInstallDriverBundle(driverId, matches[i], streams.get(driverId));
        drivers.put(driverId, driver);
        i++;
    }
    return drivers;
}
Also used : Dictionary(java.util.Dictionary) Answer(org.mockito.stubbing.Answer) HashMap(java.util.HashMap) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Driver(org.osgi.service.device.Driver) IOException(java.io.IOException)

Example 5 with Driver

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

the class DeviceManagerTest method DeviceAddedNoDriverLocatorAttachFails.

/**
 * 	We add a device, but there are no driver locators, however, there is a driver
 *  but it sadly doesn't match. Thus a <code>noDriverFound()</code> is called.
 *
 * @throws Exception
 */
@Test
public void DeviceAddedNoDriverLocatorAttachFails() throws Exception {
    Device device = tstCreateDevice(new String[] { "org.apache.felix" });
    Driver driver = tstCreateDriver("org.apache.felix.driver-1.0", Device.MATCH_NONE);
    CountDownLatch attachLatch = tstExpectNoDriverFound(device);
    m_manager.driverAdded(m_osgi.getReference(driver), driver);
    m_manager.deviceAdded(m_osgi.getReference(device), device);
    if (!attachLatch.await(5, TimeUnit.SECONDS)) {
        Assert.fail("expected attach");
    }
}
Also used : Device(org.osgi.service.device.Device) Driver(org.osgi.service.device.Driver) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Driver (org.osgi.service.device.Driver)15 Test (org.junit.Test)8 ServiceReference (org.osgi.framework.ServiceReference)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 Device (org.osgi.service.device.Device)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 Bundle (org.osgi.framework.Bundle)4 DriverLocator (org.osgi.service.device.DriverLocator)4 InputStream (java.io.InputStream)2 Dictionary (java.util.Dictionary)2 BundleException (org.osgi.framework.BundleException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 DriverAttributes (org.apache.felix.das.DriverAttributes)1 Ignore (org.junit.Ignore)1 DriverSelector (org.osgi.service.device.DriverSelector)1