Search in sources :

Example 31 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-core by openhab.

the class GenericItemChannelLinkProviderJavaTest method testNoAmnesia.

@SuppressWarnings("unchecked")
@Test
public void testNoAmnesia() throws Exception {
    GenericItemChannelLinkProvider provider = new GenericItemChannelLinkProvider();
    ProviderChangeListener<ItemChannelLink> localListenerMock = listenerMock;
    if (localListenerMock != null) {
        provider.addProviderChangeListener(localListenerMock);
    } else {
        throw new IllegalStateException("listenerMock is null");
    }
    provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, CoreItemFactory.NUMBER, ITEM, CHANNEL, new Configuration());
    provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    assertThat(provider.getAll().size(), is(1));
    assertThat(provider.getAll().iterator().next().toString(), is(LINK));
    verify(localListenerMock, only()).added(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
    reset(localListenerMock);
    provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, CoreItemFactory.NUMBER, ITEM, CHANNEL, new Configuration());
    provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    assertThat(provider.getAll().size(), is(1));
    assertThat(provider.getAll().iterator().next().toString(), is(LINK));
    verify(localListenerMock, only()).updated(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
    reset(localListenerMock);
    provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    assertThat(provider.getAll().size(), is(0));
    verify(localListenerMock, only()).removed(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
}
Also used : Configuration(org.openhab.core.config.core.Configuration) ChannelUID(org.openhab.core.thing.ChannelUID) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) GenericItemChannelLinkProvider(org.openhab.core.model.thing.internal.GenericItemChannelLinkProvider) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 32 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-core by openhab.

the class GenericItemChannelLinkProviderTest method testThatAnItemChannelLinkWasCreatedForAthingAndAnItem.

@Test
public void testThatAnItemChannelLinkWasCreatedForAthingAndAnItem() {
    Collection<Thing> things = thingRegistry.getAll();
    assertThat(things.size(), is(0));
    String thingsModel = "Bridge hue:bridge:huebridge [ ipAddress = \"192.168.3.84\", userName = \"19fc3fa6fc870a4280a55f21315631f\" ] {" + // 
    "    LCT001 bulb3 [ lightId = \"3\" ]" + // 
    "    LCT001 bulb4 [ lightId = \"3\" ]" + // 
    "}";
    modelRepository.addOrRefreshModel(THINGS_TESTMODEL_NAME, new ByteArrayInputStream(thingsModel.getBytes()));
    Collection<Thing> actualThings = thingRegistry.getAll();
    assertThat(actualThings.size(), is(3));
    Collection<Item> items = itemRegistry.getItems();
    assertThat(items.size(), is(0));
    Collection<ItemChannelLink> itemChannelLinks = itemChannelLinkRegistry.getAll();
    assertThat(itemChannelLinks.size(), is(0));
    String itemsModel = "Color Light3Color \"Light3 Color\" { channel=\"hue:LCT001:huebridge:bulb3:color\" }";
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    Collection<Item> actualItems = itemRegistry.getItems();
    assertThat(actualItems.size(), is(1));
    List<ItemChannelLink> actualItemChannelLinks = new ArrayList<>(itemChannelLinkRegistry.getAll());
    assertThat(actualItemChannelLinks.size(), is(1));
    assertThat(actualItemChannelLinks.get(0).toString(), is(equalTo("Light3Color -> hue:LCT001:huebridge:bulb3:color")));
}
Also used : Item(org.openhab.core.items.Item) ByteArrayInputStream(java.io.ByteArrayInputStream) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ArrayList(java.util.ArrayList) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 33 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-core by openhab.

the class GenericItemChannelLinkProviderTest method testThatMultipleLinksAreCreated.

@Test
public void testThatMultipleLinksAreCreated() {
    Collection<Thing> things = thingRegistry.getAll();
    assertThat(things.size(), is(0));
    String thingsModel = "Bridge hue:bridge:huebridge [ ipAddress = \"192.168.3.84\", userName = \"19fc3fa6fc870a4280a55f21315631f\" ] {" + // 
    "    LCT001 bulb3 [ lightId = \"3\" ]" + // 
    "    LCT001 bulb4 [ lightId = \"3\" ]" + // 
    "}";
    modelRepository.addOrRefreshModel(THINGS_TESTMODEL_NAME, new ByteArrayInputStream(thingsModel.getBytes()));
    Collection<Thing> actualThings = thingRegistry.getAll();
    assertThat(actualThings.size(), is(3));
    Collection<Item> items = itemRegistry.getItems();
    assertThat(items.size(), is(0));
    Collection<ItemChannelLink> itemChannelLinks = itemChannelLinkRegistry.getAll();
    assertThat(itemChannelLinks.size(), is(0));
    String itemsModel = "Color Light3Color \"Light3 Color\" { channel=\"hue:LCT001:huebridge:bulb3:color, hue:LCT001:huebridge:bulb4:color\" }";
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    Collection<Item> actualItems = itemRegistry.getItems();
    assertThat(actualItems.size(), is(1));
    List<ItemChannelLink> actualItemChannelLinks = new ArrayList<>(itemChannelLinkRegistry.getAll());
    assertThat(actualItemChannelLinks.size(), is(2));
    assertThat(actualItemChannelLinks.get(0).toString(), is(equalTo("Light3Color -> hue:LCT001:huebridge:bulb3:color")));
    assertThat(actualItemChannelLinks.get(1).toString(), is(equalTo("Light3Color -> hue:LCT001:huebridge:bulb4:color")));
}
Also used : Item(org.openhab.core.items.Item) ByteArrayInputStream(java.io.ByteArrayInputStream) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ArrayList(java.util.ArrayList) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 34 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-core by openhab.

the class AutoUpdateManagerTest method testAutoUpdateMultipleErrors.

@Test
public void testAutoUpdateMultipleErrors() {
    links.add(new ItemChannelLink(ITEM_NAME, CHANNEL_UID_ONLINE_GONE));
    links.add(new ItemChannelLink(ITEM_NAME, CHANNEL_UID_ONLINE_GONE));
    setAutoUpdatePolicy(CHANNEL_UID_ONLINE_GONE, AutoUpdatePolicy.DEFAULT);
    aum.receiveCommand(event, item);
    assertKeepCurrentState();
}
Also used : ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) Test(org.junit.jupiter.api.Test)

Example 35 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-core by openhab.

the class AutoUpdateManagerTest method testAutoUpdateSendOptimisticUpdates.

@Test
public void testAutoUpdateSendOptimisticUpdates() {
    links.add(new ItemChannelLink(ITEM_NAME, CHANNEL_UID_ONLINE_1));
    aum.modified(Map.of(AutoUpdateManager.PROPERTY_SEND_OPTIMISTIC_UPDATES, "true"));
    aum.receiveCommand(event, item);
    assertPredictionEvent("AFTER", null);
    // no?
    assertStateEvent("AFTER", AutoUpdateManager.EVENT_SOURCE_OPTIMISTIC);
}
Also used : ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) Test(org.junit.jupiter.api.Test)

Aggregations

ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)49 Test (org.junit.jupiter.api.Test)30 Thing (org.openhab.core.thing.Thing)14 Item (org.openhab.core.items.Item)13 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)13 ChannelUID (org.openhab.core.thing.ChannelUID)11 StringItem (org.openhab.core.library.items.StringItem)8 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)8 Configuration (org.openhab.core.config.core.Configuration)6 NumberItem (org.openhab.core.library.items.NumberItem)6 ThingUID (org.openhab.core.thing.ThingUID)6 Nullable (org.eclipse.jdt.annotation.Nullable)5 Channel (org.openhab.core.thing.Channel)5 ThingRegistry (org.openhab.core.thing.ThingRegistry)5 ThingHandler (org.openhab.core.thing.binding.ThingHandler)5 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)5 ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)5 ArrayList (java.util.ArrayList)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)4