ItemEventFactory extends AbstractEventFactory { private String getItemName(String topic) { String[] topicElements = getTopicElements(topic); if (topicElements.length < 4) { throw new IllegalArgumentException("Event creation failed, invalid topic: " + topic); } return topicElements[2]; } ItemEventFactory(); static ItemCommandEvent createCommandEvent(String itemName, Command command, String source); static ItemCommandEvent createCommandEvent(String itemName, Command command); static ItemStateEvent createStateEvent(String itemName, State state, String source); static ItemStateEvent createStateEvent(String itemName, State state); static ItemStatePredictedEvent createStatePredictedEvent(String itemName, State state,
            boolean isConfirmation); static ItemStateChangedEvent createStateChangedEvent(String itemName, State newState, State oldState); static GroupItemStateChangedEvent createGroupStateChangedEvent(String itemName, String memberName,
            State newState, State oldState); static ItemAddedEvent createAddedEvent(Item item); static ItemRemovedEvent createRemovedEvent(Item item); static ItemUpdatedEvent createUpdateEvent(Item item, Item oldItem);  }
@Test public void testCreateEventItemCommandEventOnOffType() throws Exception { Event event = factory.createEvent(ITEM_COMMAND_EVENT_TYPE, ITEM_COMMAND_EVENT_TOPIC, ITEM_COMMAND_EVENT_PAYLOAD, SOURCE); assertEquals(ItemCommandEvent.class, event.getClass()); ItemCommandEvent itemCommandEvent = (ItemCommandEvent) event; assertEquals(ITEM_COMMAND_EVENT_TYPE, itemCommandEvent.getType()); assertEquals(ITEM_COMMAND_EVENT_TOPIC, itemCommandEvent.getTopic()); assertEquals(ITEM_COMMAND_EVENT_PAYLOAD, itemCommandEvent.getPayload()); assertEquals(ITEM_NAME, itemCommandEvent.getItemName()); assertEquals(SOURCE, itemCommandEvent.getSource()); assertEquals(OnOffType.class, itemCommandEvent.getItemCommand().getClass()); assertEquals(ITEM_COMMAND, itemCommandEvent.getItemCommand()); }
@Test public void testCreateEventItemCommandEventRefreshType() throws Exception { Event event = factory.createEvent(ITEM_COMMAND_EVENT_TYPE, ITEM_COMMAND_EVENT_TOPIC, ITEM_REFRESH_COMMAND_EVENT_PAYLOAD, SOURCE); assertEquals(ItemCommandEvent.class, event.getClass()); ItemCommandEvent itemCommandEvent = (ItemCommandEvent) event; assertEquals(ITEM_COMMAND_EVENT_TYPE, itemCommandEvent.getType()); assertEquals(ITEM_COMMAND_EVENT_TOPIC, itemCommandEvent.getTopic()); assertEquals(ITEM_REFRESH_COMMAND_EVENT_PAYLOAD, itemCommandEvent.getPayload()); assertEquals(ITEM_NAME, itemCommandEvent.getItemName()); assertEquals(SOURCE, itemCommandEvent.getSource()); assertEquals(RefreshType.REFRESH, itemCommandEvent.getItemCommand()); }
@Test public void testCreateEventItemStateEventUnDefType() throws Exception { Event event = factory.createEvent(ITEM_STATE_EVENT_TYPE, ITEM_STATE_EVENT_TOPIC, ITEM_UNDEF_STATE_EVENT_PAYLOAD, SOURCE); assertEquals(ItemStateEvent.class, event.getClass()); ItemStateEvent itemStateEvent = (ItemStateEvent) event; assertEquals(ITEM_STATE_EVENT_TYPE, itemStateEvent.getType()); assertEquals(ITEM_STATE_EVENT_TOPIC, itemStateEvent.getTopic()); assertEquals(ITEM_UNDEF_STATE_EVENT_PAYLOAD, itemStateEvent.getPayload()); assertEquals(ITEM_NAME, itemStateEvent.getItemName()); assertEquals(SOURCE, itemStateEvent.getSource()); assertEquals(UnDefType.UNDEF, itemStateEvent.getItemState()); }
@Test public void testCreateEventItemStateEventOnOffType() throws Exception { Event event = factory.createEvent(ITEM_STATE_EVENT_TYPE, ITEM_STATE_EVENT_TOPIC, ITEM_STATE_EVENT_PAYLOAD, SOURCE); assertEquals(ItemStateEvent.class, event.getClass()); ItemStateEvent itemStateEvent = (ItemStateEvent) event; assertEquals(ITEM_STATE_EVENT_TYPE, itemStateEvent.getType()); assertEquals(ITEM_STATE_EVENT_TOPIC, itemStateEvent.getTopic()); assertEquals(ITEM_STATE_EVENT_PAYLOAD, itemStateEvent.getPayload()); assertEquals(ITEM_NAME, itemStateEvent.getItemName()); assertEquals(SOURCE, itemStateEvent.getSource()); assertEquals(OnOffType.class, itemStateEvent.getItemState().getClass()); assertEquals(ITEM_STATE, itemStateEvent.getItemState()); }
@Test public void testCreateEventItemStatePredictedEventOnOffType() throws Exception { Event event = factory.createEvent(ITEM_STATE_PREDICTED_EVENT_TYPE, ITEM_STATE_PREDICTED_EVENT_TOPIC, ITEM_STATE_PREDICTED_EVENT_PAYLOAD, SOURCE); assertEquals(ItemStatePredictedEvent.class, event.getClass()); ItemStatePredictedEvent itemStatePredictedEvent = (ItemStatePredictedEvent) event; assertEquals(ITEM_STATE_PREDICTED_EVENT_TYPE, itemStatePredictedEvent.getType()); assertEquals(ITEM_STATE_PREDICTED_EVENT_TOPIC, itemStatePredictedEvent.getTopic()); assertEquals(ITEM_STATE_PREDICTED_EVENT_PAYLOAD, itemStatePredictedEvent.getPayload()); assertEquals(ITEM_NAME, itemStatePredictedEvent.getItemName()); assertEquals(OnOffType.class, itemStatePredictedEvent.getPredictedState().getClass()); assertEquals(ITEM_STATE, itemStatePredictedEvent.getPredictedState()); }