Search in sources :

Example 6 with Match

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());
}
Also used : Match(org.osgi.service.device.Match) Test(org.junit.Test)

Example 7 with Match

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());
}
Also used : Match(org.osgi.service.device.Match) Test(org.junit.Test)

Example 8 with Match

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);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) DriverSelector(org.osgi.service.device.DriverSelector) ServiceReference(org.osgi.framework.ServiceReference) Match(org.osgi.service.device.Match) Test(org.junit.Test)

Example 9 with Match

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);
}
Also used : DriverSelector(org.osgi.service.device.DriverSelector) ServiceReference(org.osgi.framework.ServiceReference) Match(org.osgi.service.device.Match) Test(org.junit.Test)

Example 10 with 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);
}
Also used : DriverSelector(org.osgi.service.device.DriverSelector) ServiceReference(org.osgi.framework.ServiceReference) Match(org.osgi.service.device.Match) Test(org.junit.Test)

Aggregations

Match (org.osgi.service.device.Match)13 Test (org.junit.Test)11 ServiceReference (org.osgi.framework.ServiceReference)5 DriverSelector (org.osgi.service.device.DriverSelector)4 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 DriverAttributes (org.apache.felix.das.DriverAttributes)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1