From 1e89b792a0b39fb072097b731877e2084a12dc9f Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Fri, 30 Oct 2020 20:27:09 +0100 Subject: [PATCH] [feed] Added Channel for link to feed item; Updated rome library to version 1.15 (#8893) * Added Channel for link to latest feed; update rome deoendency to version 1.15 * Removed unsed interface * Run spotless Signed-off-by: Christoph Weitkamp --- bundles/org.openhab.binding.feed/README.md | 8 ++++--- bundles/org.openhab.binding.feed/pom.xml | 6 +++-- .../feed/internal/FeedBindingConstants.java | 7 +++++- .../feed/internal/handler/FeedHandler.java | 7 ++++++ .../resources/OH-INF/thing/thing-types.xml | 10 +++++++- itests/org.openhab.binding.feed.tests/pom.xml | 4 +++- .../binding/feed/test/FeedHandlerTest.java | 18 +++++++------- .../openhab/binding/feed/test/SlowTests.java | 24 ------------------- 8 files changed, 43 insertions(+), 41 deletions(-) delete mode 100644 itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/SlowTests.java diff --git a/bundles/org.openhab.binding.feed/README.md b/bundles/org.openhab.binding.feed/README.md index cec19d5472dc5..5803423729311 100644 --- a/bundles/org.openhab.binding.feed/README.md +++ b/bundles/org.openhab.binding.feed/README.md @@ -35,8 +35,9 @@ The binding supports following channels | Channel Type ID | Item Type | Description | |--------------------|-----------|-----------------------------------------------------| | latest-title | String | Contains the title of the last feed entry. | -| latest-description | String | Contains the description of last feed entry. | +| latest-description | String | Contains the description of the last feed entry. | | latest-date | DateTime | Contains the published date of the last feed entry. | +| latest-link | String | Contains the link of the last feed entry. | | author | String | The name of the feed author, if author is present. | | title | String | The title of the feed. | | description | String | Description of the feed. | @@ -48,8 +49,8 @@ The binding supports following channels Things: ```java -feed:feed:bbc [ URL="http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml?edition=uk"] -feed:feed:techCrunch [ URL="http://feeds.feedburner.com/TechCrunch/", refresh=60] +feed:feed:bbc [URL="http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml?edition=uk"] +feed:feed:techCrunch [URL="http://feeds.feedburner.com/TechCrunch/", refresh=60] ``` Items: @@ -58,6 +59,7 @@ Items: String latest_title {channel="feed:feed:bbc:latest-title"} String latest_description {channel="feed:feed:bbc:latest-description"} DateTime latest_date {channel="feed:feed:bbc:latest-date"} +String latest_link {channel="feed:feed:bbc:latest-link"} Number number_of_entries {channel="feed:feed:bbc:number-of-entries"} String description {channel="feed:feed:bbc:description"} String author {channel="feed:feed:bbc:author"} diff --git a/bundles/org.openhab.binding.feed/pom.xml b/bundles/org.openhab.binding.feed/pom.xml index 5d7d6e0e48636..db7b4211170af 100644 --- a/bundles/org.openhab.binding.feed/pom.xml +++ b/bundles/org.openhab.binding.feed/pom.xml @@ -16,13 +16,15 @@ org.jaxen.*;resolution:=optional + + 1.15.0 com.rometools rome - 1.12.0 + ${rome.version} compile @@ -34,7 +36,7 @@ com.rometools rome-utils - 1.12.0 + ${rome.version} compile diff --git a/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/FeedBindingConstants.java b/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/FeedBindingConstants.java index 366f131a7f820..ec908b0633817 100644 --- a/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/FeedBindingConstants.java +++ b/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/FeedBindingConstants.java @@ -41,10 +41,15 @@ public class FeedBindingConstants { public static final String CHANNEL_LATEST_TITLE = "latest-title"; /** - * Contains the description of last feed entry. + * Contains the description of the last feed entry. */ public static final String CHANNEL_LATEST_DESCRIPTION = "latest-description"; + /** + * Contains the link to the last feed entry. + */ + public static final String CHANNEL_LATEST_LINK = "latest-link"; + /** * Description of the feed. */ diff --git a/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/handler/FeedHandler.java b/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/handler/FeedHandler.java index 874654c09fd75..488c847aed229 100644 --- a/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/handler/FeedHandler.java +++ b/bundles/org.openhab.binding.feed/src/main/java/org/openhab/binding/feed/internal/handler/FeedHandler.java @@ -162,6 +162,13 @@ private void publishChannelIfLinked(ChannelUID channelUID) { state = new StringType(getValueSafely(description)); } break; + case CHANNEL_LATEST_LINK: + if (latestEntry == null || latestEntry.getLink() == null) { + state = UnDefType.UNDEF; + } else { + state = new StringType(getValueSafely(latestEntry.getLink())); + } + break; case CHANNEL_LATEST_PUBLISHED_DATE: case CHANNEL_LAST_UPDATE: if (latestEntry == null || latestEntry.getPublishedDate() == null) { diff --git a/bundles/org.openhab.binding.feed/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.feed/src/main/resources/OH-INF/thing/thing-types.xml index 25834727440f6..f1c8259e340f9 100644 --- a/bundles/org.openhab.binding.feed/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.feed/src/main/resources/OH-INF/thing/thing-types.xml @@ -19,6 +19,7 @@ + @@ -52,7 +53,7 @@ String - Contains the description of last feed entry. + Contains the description of the last feed entry. @@ -63,6 +64,13 @@ + + String + + Contains the link of the last feed entry. + + + String diff --git a/itests/org.openhab.binding.feed.tests/pom.xml b/itests/org.openhab.binding.feed.tests/pom.xml index 30453c1c43fcb..c849485291fc7 100644 --- a/itests/org.openhab.binding.feed.tests/pom.xml +++ b/itests/org.openhab.binding.feed.tests/pom.xml @@ -16,6 +16,8 @@ 9090 + + 1.15.0 @@ -27,7 +29,7 @@ com.rometools rome - 1.12.0 + ${rome.version} org.apache.servicemix.bundles diff --git a/itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/FeedHandlerTest.java b/itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/FeedHandlerTest.java index fea0dba789ef8..258393dc86b51 100644 --- a/itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/FeedHandlerTest.java +++ b/itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/FeedHandlerTest.java @@ -15,7 +15,6 @@ import static java.lang.Thread.sleep; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.openhab.core.thing.ThingStatus.*; import java.io.IOException; import java.math.BigDecimal; @@ -46,6 +45,7 @@ import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingProvider; import org.openhab.core.thing.ThingRegistry; +import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingUID; import org.openhab.core.thing.binding.builder.ChannelBuilder; @@ -232,7 +232,7 @@ private void initializeFeedHandler(String url, BigDecimal refreshTime) { // This will ensure that the configuration is read before the channelLinked() method in FeedHandler is called ! waitForAssert(() -> { - assertThat(feedThing.getStatus(), anyOf(is(ONLINE), is(OFFLINE))); + assertThat(feedThing.getStatus(), anyOf(is(ThingStatus.ONLINE), is(ThingStatus.OFFLINE))); }, 60000, DFL_SLEEP_TIME); initializeItem(channelUID); } @@ -270,7 +270,7 @@ private void testIfItemStateIsUpdated(boolean commandReceived, boolean contentCh initializeDefaultFeedHandler(); waitForAssert(() -> { - assertThat("Feed Thing can not be initialized", feedThing.getStatus(), is(equalTo(ONLINE))); + assertThat("Feed Thing can not be initialized", feedThing.getStatus(), is(equalTo(ThingStatus.ONLINE))); assertThat("Item's state is not updated on initialize", currentItemState, is(notNullValue())); }); @@ -294,7 +294,7 @@ private void testIfItemStateIsUpdated(boolean commandReceived, boolean contentCh waitForAssert(() -> { assertThat("Error occurred while trying to connect to server. Content is not downloaded!", - feedThing.getStatus(), is(equalTo(ONLINE))); + feedThing.getStatus(), is(equalTo(ThingStatus.ONLINE))); }); waitForAssert(() -> { @@ -361,7 +361,7 @@ private void testIfThingStatusIsUpdated(Integer serverStatus) throws Interrupted feedHandler.handleCommand(channelUID, RefreshType.REFRESH); waitForAssert(() -> { - assertThat(feedThing.getStatus(), is(equalTo(OFFLINE))); + assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE))); }); servlet.httpStatus = HttpStatus.OK_200; @@ -372,7 +372,7 @@ private void testIfThingStatusIsUpdated(Integer serverStatus) throws Interrupted feedHandler.handleCommand(channelUID, RefreshType.REFRESH); waitForAssert(() -> { - assertThat(feedThing.getStatus(), is(equalTo(ONLINE))); + assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.ONLINE))); }); } @@ -384,7 +384,7 @@ public void createThingWithInvalidUrlProtocol() { initializeFeedHandler(invalidURL); waitForAssert(() -> { - assertThat(feedThing.getStatus(), is(equalTo(OFFLINE))); + assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE))); assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.CONFIGURATION_ERROR))); }); } @@ -397,7 +397,7 @@ public void createThingWithInvalidUrlHostname() { initializeFeedHandler(invalidURL); waitForAssert(() -> { - assertThat(feedThing.getStatus(), is(equalTo(OFFLINE))); + assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE))); assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.COMMUNICATION_ERROR))); }, 30000, DFL_SLEEP_TIME); } @@ -410,7 +410,7 @@ public void createThingWithInvalidUrlPath() { initializeFeedHandler(invalidURL); waitForAssert(() -> { - assertThat(feedThing.getStatus(), is(equalTo(OFFLINE))); + assertThat(feedThing.getStatus(), is(equalTo(ThingStatus.OFFLINE))); assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.COMMUNICATION_ERROR))); }); } diff --git a/itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/SlowTests.java b/itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/SlowTests.java deleted file mode 100644 index 4e858916df35c..0000000000000 --- a/itests/org.openhab.binding.feed.tests/src/main/java/org/openhab/binding/feed/test/SlowTests.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2010-2020 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.feed.test; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * This interface is used to mark tests that take too much time - * - * @author Svilen Valkanov - Initial contribution - */ -@NonNullByDefault -public interface SlowTests { -}