use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class ChannelItemProviderTest method testDisableBeforeDelayedInitialization.
@Test
public void testDisableBeforeDelayedInitialization() throws Exception {
provider = createProvider();
reset(linkRegistry);
// Set the initialization delay to 40ms so we don't have to wait 2000ms to do the assertion
Field field = ChannelItemProvider.class.getDeclaredField("INITIALIZATION_DELAY_NANOS");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(provider, TimeUnit.MILLISECONDS.toNanos(40));
Map<String, Object> props = new HashMap<>();
props.put("enabled", "true");
provider.activate(props);
provider.linkRegistryListener.added(new ItemChannelLink(ITEM_NAME, CHANNEL_UID));
verify(listener, never()).added(same(provider), same(ITEM));
verify(linkRegistry, never()).getAll();
props = new HashMap<>();
props.put("enabled", "false");
provider.modified(props);
Thread.sleep(100);
provider.linkRegistryListener.added(new ItemChannelLink(ITEM_NAME, CHANNEL_UID));
verify(listener, never()).added(same(provider), same(ITEM));
verify(linkRegistry, never()).getAll();
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class ChannelItemProviderTest method testItemRemoval_linkRemoved.
@Test
public void testItemRemoval_linkRemoved() throws Exception {
provider.linkRegistryListener.added(new ItemChannelLink(ITEM_NAME, CHANNEL_UID));
resetAndPrepareListener();
provider.linkRegistryListener.removed(new ItemChannelLink(ITEM_NAME, CHANNEL_UID));
verify(listener, never()).added(same(provider), same(ITEM));
verify(listener, only()).removed(same(provider), same(ITEM));
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class ChannelStateDescriptionProviderOSGiTest method presentItemStateDescription.
/**
* Assert that item's state description is present.
*/
@Test
public void presentItemStateDescription() throws ItemNotFoundException {
ThingRegistry thingRegistry = getService(ThingRegistry.class);
ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class);
Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration());
assertNotNull(thing);
managedThingProvider.add(thing);
ItemChannelLink link = new ItemChannelLink("TestItem", getChannel(thing, "1").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem2", getChannel(thing, "2").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem3", getChannel(thing, "3").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem4", getChannel(thing, "4").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem5", getChannel(thing, "5").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem6", getChannel(thing, "6").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem7_1", getChannel(thing, "7_1").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem7_2", getChannel(thing, "7_2").getUID());
linkRegistry.add(link);
//
final Collection<Item> items = itemRegistry.getItems();
assertEquals(false, items.isEmpty());
Item item = itemRegistry.getItem("TestItem");
assertEquals("Number", item.getType());
StateDescription state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.ZERO, state.getMinimum());
assertEquals(BigDecimal.valueOf(100), state.getMaximum());
assertEquals(BigDecimal.TEN, state.getStep());
assertEquals("%d Peek", state.getPattern());
assertEquals(true, state.isReadOnly());
List<StateOption> opts = state.getOptions();
assertEquals(1, opts.size());
final StateOption opt = opts.get(0);
assertEquals("SOUND", opt.getValue());
assertEquals("My great sound.", opt.getLabel());
item = itemRegistry.getItem("TestItem2");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.ZERO, state.getMinimum());
assertEquals(BigDecimal.valueOf(256), state.getMaximum());
assertEquals(BigDecimal.valueOf(8), state.getStep());
assertEquals("%.0f", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertEquals(0, opts.size());
item = itemRegistry.getItem("TestItem3");
assertEquals("String", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertNull(state.getMinimum());
assertNull(state.getMaximum());
assertNull(state.getStep());
assertEquals("%s", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertEquals(0, opts.size());
item = itemRegistry.getItem("TestItem4");
assertEquals("Color", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem5");
assertEquals("Dimmer", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem6");
assertEquals("Switch", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem7_1");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.valueOf(10), state.getMinimum());
assertEquals(BigDecimal.valueOf(100), state.getMaximum());
assertEquals(BigDecimal.valueOf(5), state.getStep());
assertEquals("VALUE %d", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertNotNull(opts);
assertEquals(2, opts.size());
final StateOption opt0 = opts.get(0);
assertNotNull(opt0);
assertEquals(opt0.getValue(), "value0");
assertEquals(opt0.getLabel(), "label0");
final StateOption opt1 = opts.get(1);
assertNotNull(opt1);
assertEquals(opt1.getValue(), "value1");
assertEquals(opt1.getLabel(), "label1");
item = itemRegistry.getItem("TestItem7_2");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.valueOf(1), state.getMinimum());
assertEquals(BigDecimal.valueOf(101), state.getMaximum());
assertEquals(BigDecimal.valueOf(20), state.getStep());
assertEquals("NEW %d Peek", state.getPattern());
assertEquals(true, state.isReadOnly());
opts = state.getOptions();
assertNotNull(opts);
assertEquals(1, opts.size());
final StateOption opt2 = opts.get(0);
assertEquals("SOUND", opt2.getValue());
assertEquals("My great sound.", opt2.getLabel());
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class CommunicationManagerTest method setup.
@Before
public void setup() {
initMocks(this);
safeCaller = getService(SafeCaller.class);
assertNotNull(safeCaller);
manager = new CommunicationManager();
manager.setEventPublisher(eventPublisher);
manager.setDefaultProfileFactory(new SystemProfileFactory());
manager.setSafeCaller(safeCaller);
doAnswer(invocation -> {
switch(((Channel) invocation.getArguments()[0]).getKind()) {
case STATE:
return new ProfileTypeUID("test:state");
case TRIGGER:
return new ProfileTypeUID("test:trigger");
}
return null;
}).when(mockProfileAdvisor).getSuggestedProfileTypeUID(isA(Channel.class), isA(String.class));
doAnswer(invocation -> {
switch(((ProfileTypeUID) invocation.getArguments()[0]).toString()) {
case "test:state":
return stateProfile;
case "test:trigger":
return triggerProfile;
}
return null;
}).when(mockProfileFactory).createProfile(isA(ProfileTypeUID.class), isA(ProfileCallback.class), isA(ProfileContext.class));
when(mockProfileFactory.getSupportedProfileTypeUIDs()).thenReturn(Stream.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).collect(Collectors.toList()));
manager.addProfileFactory(mockProfileFactory);
manager.addProfileAdvisor(mockProfileAdvisor);
ItemChannelLinkRegistry iclRegistry = new ItemChannelLinkRegistry() {
@Override
public Stream<ItemChannelLink> stream() {
return Arrays.asList(LINK_1_S1, LINK_1_S2, LINK_2_S2, LINK_1_T1, LINK_1_T2, LINK_2_T2).stream();
}
};
manager.setItemChannelLinkRegistry(iclRegistry);
when(itemRegistry.get(eq(ITEM_NAME_1))).thenReturn(ITEM_1);
when(itemRegistry.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
manager.setItemRegistry(itemRegistry);
THING.setHandler(mockHandler);
when(thingRegistry.get(eq(THING_UID))).thenReturn(THING);
manager.setThingRegistry(thingRegistry);
manager.addItemFactory(new CoreItemFactory());
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class GenericItemChannelLinkProviderJavaTest method testNoAmnesia.
@SuppressWarnings("unchecked")
@Test
public void testNoAmnesia() throws Exception {
GenericItemChannelLinkProvider provider = new GenericItemChannelLinkProvider();
provider.addProviderChangeListener(listener);
provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, "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(listener, only()).added(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
reset(listener);
provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, "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(listener, only()).updated(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
reset(listener);
provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
assertThat(provider.getAll().size(), is(0));
verify(listener, only()).removed(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
}
Aggregations