use of org.osgi.service.device.Device in project felix by apache.
the class DeviceManagerTest method DeviceAddedNoDriverLocator.
// intended flow, various configurations
/**
* We add a device, but there are no driver locators, so
* the noDriverFound method must be called
* @throws InterruptedException
*/
@Test
public void DeviceAddedNoDriverLocator() throws InterruptedException {
// create a mocked device
Device device = tstCreateDevice(new String[] { "org.apache.felix" });
CountDownLatch latch = tstExpectNoDriverFound(device);
m_manager.deviceAdded(m_osgi.getReference(device), device);
if (!latch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected call noDriverFound");
}
}
use of org.osgi.service.device.Device 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.Device 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");
}
}
use of org.osgi.service.device.Device in project felix by apache.
the class DeviceManagerTest method DeviceAddedWithADriverLocator.
/**
* We add a device while there's one driverlocator that will successfully
* locate and load two driver bundles. We expect a <code>Driver.attach()</code> for
* the best matching driver. There's already a driver loaded that should not match.
*
* @throws Exception
*/
@Test
public void DeviceAddedWithADriverLocator() throws Exception {
final String driverId1 = "org.apache.felix.driver-1.0";
final String driverId2 = "org.apache.felix.driver-1.1";
final String notMatchingButLoadedDriverId = "dotorg.apache.felix.driver-1.0";
DriverLocator locator = Mockito.mock(DriverLocator.class);
Map<String, Driver> drivers = tstExpectDriverLocatorFor(locator, new String[] { driverId1, driverId2 }, new int[] { 30, 3 });
Driver noMatcher = tstCreateDriver(notMatchingButLoadedDriverId, 100);
Device device = tstCreateDevice(new String[] { "org.apache.felix" });
final CountDownLatch attachLatch = tstExpectAttach(drivers.get(driverId1), device);
final CountDownLatch unloadDriverLatch = tstExpectUnloadDriverBundle(drivers.get(driverId2));
m_manager.locatorAdded(locator);
m_manager.driverAdded(m_osgi.getReference(noMatcher), noMatcher);
m_manager.deviceAdded(m_osgi.getReference(device), device);
if (!attachLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected an attach");
}
// of all other (dynamically loaded) driver bundles
if (!unloadDriverLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected an unload");
}
}
use of org.osgi.service.device.Device in project felix by apache.
the class DeviceManagerTest method DriverLocator_findDriverFails.
// exceptional flow
@Test
public void DriverLocator_findDriverFails() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
Answer<String[]> answer = new Answer<String[]>() {
public String[] answer(InvocationOnMock invocation) throws Throwable {
latch.countDown();
throw new RuntimeException("test exception");
}
};
DriverLocator locator = Mockito.mock(DriverLocator.class, "locator");
Mockito.when(locator.findDrivers(Mockito.isA(Dictionary.class))).thenAnswer(answer);
Device device = tstCreateDevice(new String[] { "org.apache.felix" });
final CountDownLatch latch2 = new CountDownLatch(1);
Answer<Object> answer2 = new Answer<Object>() {
public Object answer(InvocationOnMock invocation) throws Throwable {
latch2.countDown();
return null;
}
};
Mockito.doAnswer(answer2).when(device).noDriverFound();
m_manager.locatorAdded(locator);
m_manager.deviceAdded(m_osgi.getReference(device), device);
if (!latch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected a call to DriverLocator.findDrivers");
}
if (!latch2.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected a call to Driver.noDriverFound");
}
}
Aggregations