use of org.osgi.service.device.Match in project felix by apache.
the class DriverMatcherTest method GetBestMatchWithDifferentRanking.
@Test
public void GetBestMatchWithDifferentRanking() throws Exception {
add("org.apache.felix.driver.a-1.0", 1, 2);
add("org.apache.felix.driver.b-1.0", 1);
Match match = m_matcherImpl.getBestMatch();
Assert.assertNotNull(match);
final String driverId = "org.apache.felix.driver.a-1.0";
Assert.assertEquals(driverId, tstDriverId(match));
Assert.assertEquals(1, match.getMatchValue());
}
use of org.osgi.service.device.Match in project felix by apache.
the class DriverMatcherTest method GetBestMatchWithSameRanking.
@Test
public void GetBestMatchWithSameRanking() throws Exception {
add("org.apache.felix.driver.a-1.0", 1);
add("org.apache.felix.driver.b-1.0", 1);
Match match = m_matcherImpl.getBestMatch();
Assert.assertNotNull(match);
Assert.assertEquals("org.apache.felix.driver.a-1.0", tstDriverId(match));
Assert.assertEquals(1, match.getMatchValue());
}
use of org.osgi.service.device.Match in project felix by apache.
the class DriverMatcherTest method selectBestDriver.
@Test
public void selectBestDriver() throws Exception {
DriverSelector selector = Mockito.mock(DriverSelector.class);
ServiceReference deviceRef = Mockito.mock(ServiceReference.class);
add("org.apache.felix.driver-1.0", 1);
add("org.apache.felix.driver-1.1", 1);
add("org.apache.felix.driver-1.2", 1);
add("org.apache.felix.driver-1.3", 1);
add("org.apache.felix.driver-1.4", 1);
add("org.apache.felix.driver-1.5", 1);
// this is the actual driverselector implementation
Mockito.when(selector.select(Mockito.isA(ServiceReference.class), Mockito.isA(Match[].class))).thenAnswer(new Answer<Integer>() {
public Integer answer(InvocationOnMock invocation) throws Throwable {
Match[] matches = (Match[]) invocation.getArguments()[1];
int index = 0;
for (Match m : matches) {
if (tstDriverId(m).endsWith("1.3")) {
return index;
}
index++;
}
Assert.fail("expected unreachable");
return null;
}
});
Match match = m_matcherImpl.selectBestMatch(deviceRef, selector);
Assert.assertNotNull("no match returned", match);
String driverId = tstDriverId(match);
Assert.assertEquals("org.apache.felix.driver-1.3", driverId);
}
use of org.osgi.service.device.Match in project felix by apache.
the class DriverMatcherTest method GetSelectBestMatchThrowsException.
@Test
public void GetSelectBestMatchThrowsException() throws Exception {
ServiceReference deviceRef = Mockito.mock(ServiceReference.class);
DriverSelector selector = Mockito.mock(DriverSelector.class);
Mockito.when(selector.select(Mockito.eq(deviceRef), Mockito.isA(Match[].class))).thenThrow(new IllegalArgumentException("test"));
Match match = m_matcherImpl.selectBestMatch(deviceRef, selector);
Assert.assertNull(match);
}
use of org.osgi.service.device.Match in project felix by apache.
the class DriverMatcherTest method selectFails.
@Test
public void selectFails() throws Exception {
DriverSelector selector = Mockito.mock(DriverSelector.class);
ServiceReference deviceRef = Mockito.mock(ServiceReference.class);
Mockito.when(selector.select(Mockito.eq(deviceRef), Mockito.isA(Match[].class))).thenThrow(new RuntimeException("test exception"));
add("org.apache.felix.driver-1.5", 1);
Match match = m_matcherImpl.selectBestMatch(deviceRef, selector);
Assert.assertNull(match);
}
Aggregations