Search in sources :

Example 46 with ThingTypeUID

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));
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 47 with ThingTypeUID

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);
}
Also used : ExtendedDiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.ExtendedDiscoveryServiceMock) DiscoveryServiceMockOfBridge(org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMockOfBridge) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Inbox(org.eclipse.smarthome.config.discovery.inbox.Inbox) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ExtendedDiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.ExtendedDiscoveryServiceMock) DiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMock) Before(org.junit.Before)

Example 48 with ThingTypeUID

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);
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 49 with ThingTypeUID

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));
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 50 with ThingTypeUID

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);
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)63 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)27 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)25 Thing (org.eclipse.smarthome.core.thing.Thing)12 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)11 Locale (java.util.Locale)10 HashMap (java.util.HashMap)9 Collection (java.util.Collection)5 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)5 Before (org.junit.Before)5 Configuration (org.eclipse.smarthome.config.core.Configuration)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)3 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)3 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)3 ArrayList (java.util.ArrayList)2