use of org.eclipse.smarthome.core.events.Event in project smarthome by eclipse.
the class ThingEventFactoryTest method testCreateEvent_ChannelTriggeredEvent.
@Test
public void testCreateEvent_ChannelTriggeredEvent() throws Exception {
Event event = factory.createEvent(ChannelTriggeredEvent.TYPE, CHANNEL_TRIGGERED_EVENT_TOPIC, CHANNEL_TRIGGERED_EVENT_PAYLOAD, null);
assertThat(event, is(instanceOf(ChannelTriggeredEvent.class)));
ChannelTriggeredEvent triggeredEvent = (ChannelTriggeredEvent) event;
assertEquals(ChannelTriggeredEvent.TYPE, triggeredEvent.getType());
assertEquals(CHANNEL_TRIGGERED_EVENT_TOPIC, triggeredEvent.getTopic());
assertEquals(CHANNEL_TRIGGERED_EVENT_PAYLOAD, triggeredEvent.getPayload());
assertNotNull(triggeredEvent.getEvent());
assertEquals(CommonTriggerEvents.PRESSED, triggeredEvent.getEvent());
}
use of org.eclipse.smarthome.core.events.Event in project smarthome by eclipse.
the class ThingEventFactoryTest method testCreateEvent_ThingAddedEvent.
@Test
public void testCreateEvent_ThingAddedEvent() throws Exception {
Event event = factory.createEvent(ThingAddedEvent.TYPE, THING_ADDED_EVENT_TOPIC, THING_ADDED_EVENT_PAYLOAD, null);
assertThat(event, is(instanceOf(ThingAddedEvent.class)));
ThingAddedEvent addedEvent = (ThingAddedEvent) event;
assertEquals(ThingAddedEvent.TYPE, addedEvent.getType());
assertEquals(THING_ADDED_EVENT_TOPIC, addedEvent.getTopic());
assertEquals(THING_ADDED_EVENT_PAYLOAD, addedEvent.getPayload());
assertNotNull(addedEvent.getThing());
assertEquals(THING_UID.getAsString(), addedEvent.getThing().UID);
}
use of org.eclipse.smarthome.core.events.Event in project smarthome by eclipse.
the class FirmwareUpdateServiceTest method testEvents.
@Test
public void testEvents() {
doAnswer(invocation -> {
Firmware firmware = (Firmware) invocation.getArguments()[0];
ProgressCallback progressCallback = (ProgressCallback) invocation.getArguments()[1];
progressCallback.defineSequence(SEQUENCE);
progressCallback.next();
progressCallback.next();
progressCallback.next();
progressCallback.next();
thing1.setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());
return null;
}).when(handler1).updateFirmware(any(Firmware.class), any(ProgressCallback.class));
// getFirmwareStatusInfo() method will internally generate and post one FirmwareStatusInfoEvent event.
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
firmwareUpdateService.updateFirmware(THING1_UID, FW112_EN.getUID(), null);
AtomicReference<List<Event>> events = new AtomicReference<>(new ArrayList<>());
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
waitForAssert(() -> {
// Wait for four FirmwareUpdateProgressInfoEvents plus one FirmwareStatusInfoEvent event.
verify(mockPublisher, atLeast(SEQUENCE.length + 1)).post(eventCaptor.capture());
});
events.get().addAll(eventCaptor.getAllValues());
List<Event> list = events.get().stream().filter(event -> event instanceof FirmwareUpdateProgressInfoEvent).collect(Collectors.toList());
assertTrue(list.size() >= SEQUENCE.length);
for (int i = 0; i < SEQUENCE.length; i++) {
FirmwareUpdateProgressInfoEvent event = (FirmwareUpdateProgressInfoEvent) list.get(i);
assertThat(event.getTopic(), containsString(THING1_UID.getAsString()));
assertThat(event.getThingUID(), is(THING1_UID));
assertThat(event.getProgressInfo().getProgressStep(), is(SEQUENCE[i]));
}
}
use of org.eclipse.smarthome.core.events.Event in project smarthome by eclipse.
the class GroupItemTest method testItemUpdateWithItemRegistry.
@Ignore
@Test
public void testItemUpdateWithItemRegistry() {
GroupItem item = new GroupItem("mySimpleGroupItem");
item.setLabel("firstLabel");
itemRegistry.add(item);
GroupItem updatedItem = (GroupItem) itemRegistry.get("mySimpleGroupItem");
assertNotNull(updatedItem);
events.clear();
updatedItem.setLabel("secondLabel");
itemRegistry.update(updatedItem);
waitForAssert(() -> assertThat(events.size(), is(1)));
List<Event> stateChanges = events.stream().filter(it -> it instanceof ItemUpdatedEvent).collect(Collectors.toList());
assertThat(stateChanges.size(), is(1));
ItemUpdatedEvent change = (ItemUpdatedEvent) stateChanges.get(0);
assertThat(change.getItem().label, is("secondLabel"));
}
use of org.eclipse.smarthome.core.events.Event in project smarthome by eclipse.
the class GroupItemTest method assertThatGroupItemwithDimmeritemAcceptsGetsPercentTypeStateIfMembersHavePercentTypeStates.
@Test
public void assertThatGroupItemwithDimmeritemAcceptsGetsPercentTypeStateIfMembersHavePercentTypeStates() {
events.clear();
GroupItem groupItem = new GroupItem("root", new DimmerItem("myDimmer"), new ArithmeticGroupFunction.Avg());
groupItem.setItemStateConverter(itemStateConverter);
DimmerItem member1 = new DimmerItem("dimmer1");
groupItem.addMember(member1);
DimmerItem member2 = new DimmerItem("dimmer2");
groupItem.addMember(member2);
groupItem.setEventPublisher(publisher);
member1.setState(new PercentType(50));
waitForAssert(() -> assertThat(events.size(), is(1)));
List<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList());
GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0);
assertTrue(change.getItemName().equals(groupItem.getName()));
State newEventState = change.getItemState();
assertTrue(newEventState instanceof PercentType);
assertThat(((PercentType) newEventState).intValue(), is(50));
State newGroupState = groupItem.getState();
assertTrue(newGroupState instanceof PercentType);
assertThat(((PercentType) newGroupState).intValue(), is(50));
events.clear();
member2.setState(new PercentType(10));
waitForAssert(() -> assertThat(events.size(), is(1)));
changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList());
assertThat(changes.size(), is(1));
change = (GroupItemStateChangedEvent) changes.get(0);
assertTrue(change.getItemName().equals(groupItem.getName()));
newEventState = change.getItemState();
assertTrue(newEventState instanceof PercentType);
assertThat(((PercentType) newEventState).intValue(), is(30));
newGroupState = groupItem.getState();
assertTrue(newGroupState instanceof PercentType);
assertThat(((PercentType) newGroupState).intValue(), is(30));
}
Aggregations