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);
}
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);
}
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");
}
}
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;
}
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");
}
}
Aggregations