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))));
}
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")));
}
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")));
}
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();
}
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);
}
Aggregations