use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method testRemoveOlderResults_onlyOfSpecificBridge.
@Test
public void testRemoveOlderResults_onlyOfSpecificBridge() {
mockDiscoveryListener = mock(DiscoveryListener.class);
ScanListener mockScanListener1 = mock(ScanListener.class);
discoveryServiceRegistry.addDiscoveryListener(mockDiscoveryListener);
discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), mockScanListener1);
waitForAssert(() -> verify(mockScanListener1, times(1)).onFinished(), 2000, DFL_SLEEP_TIME);
verify(mockDiscoveryListener, times(2)).thingDiscovered(any(), any());
// 2 discovery services for the same thing type with different bridges - inbox must contain 2 elements
assertThat(inbox.getAll().size(), is(2));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_1.equals(r.getBridgeUID())).count(), is(1L));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_2.equals(r.getBridgeUID())).count(), is(1L));
// should not remove anything
discoveryServiceMockForBinding3Bridge1.removeOlderResults(discoveryServiceMockForBinding3Bridge1.getTimestampOfLastScan(), discoveryServiceMockForBinding3Bridge1.getBridge());
assertThat(inbox.getAll().size(), is(2));
// should not remove anything
discoveryServiceMockForBinding3Bridge2.removeOlderResults(discoveryServiceMockForBinding3Bridge2.getTimestampOfLastScan(), discoveryServiceMockForBinding3Bridge2.getBridge());
assertThat(inbox.getAll().size(), is(2));
// start discovery again
discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), mockScanListener1);
waitForAssert(() -> verify(mockScanListener1, times(1)).onFinished(), 2000, DFL_SLEEP_TIME);
verify(mockDiscoveryListener, times(4)).thingDiscovered(any(), any());
// 2 discovery services for the same thing type with different bridges - inbox must now contain 4 elements
assertThat(inbox.getAll().size(), is(4));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_1.equals(r.getBridgeUID())).count(), is(2L));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_2.equals(r.getBridgeUID())).count(), is(2L));
// should remove only 1 entry (of bridge1)
discoveryServiceMockForBinding3Bridge1.removeOlderResults(discoveryServiceMockForBinding3Bridge1.getTimestampOfLastScan(), discoveryServiceMockForBinding3Bridge1.getBridge());
assertThat(inbox.getAll().size(), is(3));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_1.equals(r.getBridgeUID())).count(), is(1L));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_2.equals(r.getBridgeUID())).count(), is(2L));
// should remove only 1 entry (of bridge2)
discoveryServiceMockForBinding3Bridge2.removeOlderResults(discoveryServiceMockForBinding3Bridge2.getTimestampOfLastScan(), discoveryServiceMockForBinding3Bridge2.getBridge());
assertThat(inbox.getAll().size(), is(2));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_1.equals(r.getBridgeUID())).count(), is(1L));
assertThat(inbox.getAll().stream().filter(r -> BRIDGE_UID_2.equals(r.getBridgeUID())).count(), is(1L));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method setUp.
@Before
public void setUp() {
initMocks(this);
registerVolatileStorageService();
thingRegistry = getService(ThingRegistry.class);
assertNotNull(thingRegistry);
inbox = getService(Inbox.class);
assertNotNull(inbox);
discoveryServiceMockForBinding1 = new DiscoveryServiceMock(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), 1);
discoveryServiceMockForBinding2 = new ExtendedDiscoveryServiceMock(new ThingTypeUID(ANY_BINDING_ID_2, ANY_THING_TYPE_2), 3);
discoveryServiceMockForBinding3Bridge1 = new DiscoveryServiceMockOfBridge(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), 1, BRIDGE_UID_1);
discoveryServiceMockForBinding3Bridge2 = new DiscoveryServiceMockOfBridge(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), 1, BRIDGE_UID_2);
discoveryServiceFaultyMock = new DiscoveryServiceMock(new ThingTypeUID(FAULTY_BINDING_ID, FAULTY_THING_TYPE), 1, true);
extendedDiscoveryServiceMock = new ExtendedDiscoveryServiceMock(new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE), 1, true);
serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding1, null));
serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding2, null));
serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding3Bridge1, null));
serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding3Bridge2, null));
serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceFaultyMock, null));
serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), extendedDiscoveryServiceMock, null));
discoveryServiceRegistry = getService(DiscoveryServiceRegistry.class);
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method testThingDiscovered.
@Test
public void testThingDiscovered() {
ScanListener mockScanListener = mock(ScanListener.class);
discoveryServiceRegistry.addDiscoveryListener(mockDiscoveryListener);
discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), mockScanListener);
waitForAssert(() -> verify(mockScanListener, times(1)).onFinished(), 2000, DFL_SLEEP_TIME);
verify(mockDiscoveryListener, times(1)).thingDiscovered(any(), any());
verifyNoMoreInteractions(mockScanListener);
verifyNoMoreInteractions(mockDiscoveryListener);
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method testRemoveOlderResults_works.
@Test
public void testRemoveOlderResults_works() {
ScanListener mockScanListener1 = mock(ScanListener.class);
ScanListener mockScanListener2 = mock(ScanListener.class);
discoveryServiceRegistry.addDiscoveryListener(mockDiscoveryListener);
discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), mockScanListener1);
discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_2, ANY_THING_TYPE_2), mockScanListener2);
waitForAssert(() -> verify(mockScanListener1, times(1)).onFinished(), 2000, DFL_SLEEP_TIME);
waitForAssert(() -> verify(mockScanListener2, times(1)).onFinished(), 2000, DFL_SLEEP_TIME);
verify(mockDiscoveryListener, times(2)).thingDiscovered(any(), any());
assertThat(inbox.getAll().size(), is(2));
// should not remove anything
discoveryServiceMockForBinding1.removeOlderResults(discoveryServiceMockForBinding1.getTimestampOfLastScan());
assertThat(inbox.getAll().size(), is(2));
// start discovery again
discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), mockScanListener1);
waitForAssert(() -> verify(mockScanListener1, times(2)).onFinished(), 2000, DFL_SLEEP_TIME);
verify(mockDiscoveryListener, times(3)).thingDiscovered(any(), any());
assertThat(inbox.getAll().size(), is(3));
// should remove one entry
discoveryServiceMockForBinding1.removeOlderResults(discoveryServiceMockForBinding1.getTimestampOfLastScan());
assertThat(inbox.getAll().size(), is(2));
}
use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method testThingDiscovered_removedListener.
@Test
public void testThingDiscovered_removedListener() {
ScanListener mockScanListener1 = mock(ScanListener.class);
discoveryServiceRegistry.addDiscoveryListener(mockDiscoveryListener);
discoveryServiceRegistry.removeDiscoveryListener(mockDiscoveryListener);
discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), mockScanListener1);
waitForAssert(() -> verify(mockScanListener1, times(1)).onFinished(), 2000, DFL_SLEEP_TIME);
verifyNoMoreInteractions(mockDiscoveryListener);
}
Aggregations