added migrated 2.x add-ons
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
32
itests/org.openhab.binding.feed.tests/.classpath
Normal file
32
itests/org.openhab.binding.feed.tests/.classpath
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
23
itests/org.openhab.binding.feed.tests/.project
Normal file
23
itests/org.openhab.binding.feed.tests/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.openhab.binding.feed.tests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
13
itests/org.openhab.binding.feed.tests/NOTICE
Normal file
13
itests/org.openhab.binding.feed.tests/NOTICE
Normal file
@@ -0,0 +1,13 @@
|
||||
This content is produced and maintained by the openHAB project.
|
||||
|
||||
* Project home: https://www.openhab.org
|
||||
|
||||
== Declared Project Licenses
|
||||
|
||||
This program and the accompanying materials are made available under the terms
|
||||
of the Eclipse Public License 2.0 which is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/.
|
||||
|
||||
== Source Code
|
||||
|
||||
https://github.com/openhab/openhab-addons
|
||||
66
itests/org.openhab.binding.feed.tests/itest.bndrun
Normal file
66
itests/org.openhab.binding.feed.tests/itest.bndrun
Normal file
@@ -0,0 +1,66 @@
|
||||
-include: ../itest-common.bndrun
|
||||
|
||||
Bundle-SymbolicName: ${project.artifactId}
|
||||
Fragment-Host: org.openhab.binding.feed
|
||||
|
||||
-runrequires: \
|
||||
bnd.identity;id='org.openhab.binding.feed.tests',\
|
||||
bnd.identity;id='org.openhab.core.binding.xml',\
|
||||
bnd.identity;id='org.openhab.core.thing.xml',\
|
||||
bnd.identity;id='org.apache.felix.configadmin',\
|
||||
osgi.identity;filter:='(&(osgi.identity=org.ops4j.pax.web.pax-web-runtime)(version>=7.2.3))'
|
||||
|
||||
-runvm: -Dorg.osgi.service.http.port=${org.osgi.service.http.port}
|
||||
|
||||
#
|
||||
# done
|
||||
#
|
||||
-runbundles: \
|
||||
org.apache.servicemix.specs.activation-api-1.1;version='[2.9.0,2.9.1)',\
|
||||
org.apache.servicemix.specs.jaxb-api-2.2;version='[2.9.0,2.9.1)',\
|
||||
org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\
|
||||
com.google.gson;version='[2.8.2,2.8.3)',\
|
||||
javax.measure.unit-api;version='[1.0.0,1.0.1)',\
|
||||
org.apache.commons.lang;version='[2.6.0,2.6.1)',\
|
||||
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
|
||||
org.apache.servicemix.bundles.xstream;version='[1.4.7,1.4.8)',\
|
||||
org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\
|
||||
org.apache.xbean.finder;version='[4.12.0,4.12.1)',\
|
||||
org.openhab.core;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.binding.xml;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.config.core;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.config.xml;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.io.console;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.test;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.thing;version='[2.5.0,2.5.1)',\
|
||||
org.openhab.core.thing.xml;version='[2.5.0,2.5.1)',\
|
||||
org.osgi.service.event;version='[1.4.0,1.4.1)',\
|
||||
osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\
|
||||
osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\
|
||||
slf4j.api;version='[1.7.25,1.7.26)',\
|
||||
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
|
||||
org.apache.commons.io;version='[2.2.0,2.2.1)',\
|
||||
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
|
||||
org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\
|
||||
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
|
||||
tec.uom.se;version='[1.0.10,1.0.11)',\
|
||||
org.apache.servicemix.bundles.jaxb-impl;version='[2.2.11,2.2.12)',\
|
||||
org.objectweb.asm;version='[7.1.0,7.1.1)',\
|
||||
org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\
|
||||
org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\
|
||||
org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.server;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.servlet;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\
|
||||
org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\
|
||||
org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\
|
||||
org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\
|
||||
org.ops4j.pax.web.pax-web-jetty;version='[7.2.11,7.2.12)',\
|
||||
org.ops4j.pax.web.pax-web-runtime;version='[7.2.11,7.2.12)',\
|
||||
org.ops4j.pax.web.pax-web-spi;version='[7.2.11,7.2.12)',\
|
||||
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
|
||||
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
|
||||
org.openhab.binding.feed;version='[2.5.9,2.5.10)',\
|
||||
org.openhab.binding.feed.tests;version='[2.5.9,2.5.10)',\
|
||||
68
itests/org.openhab.binding.feed.tests/pom.xml
Normal file
68
itests/org.openhab.binding.feed.tests/pom.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.addons.itests</groupId>
|
||||
<artifactId>org.openhab.addons.reactor.itests</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.binding.feed.tests</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Integration Tests :: Feed Binding Tests</name>
|
||||
|
||||
<properties>
|
||||
<org.osgi.service.http.port>9090</org.osgi.service.http.port>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.binding.feed</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rometools</groupId>
|
||||
<artifactId>rome</artifactId>
|
||||
<version>1.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.servicemix.bundles</groupId>
|
||||
<artifactId>org.apache.servicemix.bundles.jdom</artifactId>
|
||||
<version>2.0.6_1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>reserve-network-port</id>
|
||||
<goals>
|
||||
<goal>reserve-network-port</goal>
|
||||
</goals>
|
||||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<portNames>
|
||||
<portName>org.osgi.service.http.port</portName>
|
||||
</portNames>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
68
itests/org.openhab.binding.feed.tests/pom.xml.versionsBackup
Normal file
68
itests/org.openhab.binding.feed.tests/pom.xml.versionsBackup
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.openhab.addons.itests</groupId>
|
||||
<artifactId>org.openhab.addons.reactor.itests</artifactId>
|
||||
<version>2.5.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.binding.feed.tests</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Integration Tests :: Feed Binding Tests</name>
|
||||
|
||||
<properties>
|
||||
<org.osgi.service.http.port>9090</org.osgi.service.http.port>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.binding.feed</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rometools</groupId>
|
||||
<artifactId>rome</artifactId>
|
||||
<version>1.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.servicemix.bundles</groupId>
|
||||
<artifactId>org.apache.servicemix.bundles.jdom</artifactId>
|
||||
<version>2.0.6_1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>reserve-network-port</id>
|
||||
<goals>
|
||||
<goal>reserve-network-port</goal>
|
||||
</goals>
|
||||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<portNames>
|
||||
<portName>org.osgi.service.http.port</portName>
|
||||
</portNames>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,419 @@
|
||||
/**
|
||||
* 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 static java.lang.Thread.sleep;
|
||||
import static org.openhab.core.thing.ThingStatus.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.items.Item;
|
||||
import org.openhab.core.items.ItemRegistry;
|
||||
import org.openhab.core.items.StateChangeListener;
|
||||
import org.openhab.core.library.items.StringItem;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.thing.Channel;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.thing.ManagedThingProvider;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingProvider;
|
||||
import org.openhab.core.thing.ThingRegistry;
|
||||
import org.openhab.core.thing.ThingStatusDetail;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
import org.openhab.core.thing.link.ItemChannelLink;
|
||||
import org.openhab.core.thing.link.ManagedItemChannelLinkProvider;
|
||||
import org.openhab.core.types.RefreshType;
|
||||
import org.openhab.core.types.State;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
import org.openhab.core.test.storage.VolatileStorageService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.openhab.binding.feed.internal.FeedBindingConstants;
|
||||
import org.openhab.binding.feed.internal.handler.FeedHandler;
|
||||
import org.osgi.service.http.HttpService;
|
||||
import org.osgi.service.http.NamespaceException;
|
||||
|
||||
/**
|
||||
* Tests for {@link FeedHandler}
|
||||
*
|
||||
* @author Svilen Valkanov - Initial contribution
|
||||
* @author Wouter Born - Migrate Groovy to Java tests
|
||||
*/
|
||||
public class FeedHandlerTest extends JavaOSGiTest {
|
||||
|
||||
// Servlet URL configuration
|
||||
private static final String MOCK_SERVLET_PROTOCOL = "http";
|
||||
private static final String MOCK_SERVLET_HOSTNAME = "localhost";
|
||||
private static final int MOCK_SERVLET_PORT = Integer.getInteger("org.osgi.service.http.port", 8080);
|
||||
private static final String MOCK_SERVLET_PATH = "/test/feed";
|
||||
|
||||
// Files used for the test as input. They are located in /src/test/resources directory
|
||||
/**
|
||||
* The default mock content in the test is RSS 2.0 format, as this is the most popular format
|
||||
*/
|
||||
private static final String DEFAULT_MOCK_CONTENT = "rss_2.0.xml";
|
||||
|
||||
/**
|
||||
* One new entry is added to {@link #DEFAULT_MOCK_CONTENT}
|
||||
*/
|
||||
private static final String MOCK_CONTENT_CHANGED = "rss_2.0_changed.xml";
|
||||
|
||||
private static final String ITEM_NAME = "testItem";
|
||||
private static final String THING_NAME = "testFeedThing";
|
||||
|
||||
/**
|
||||
* Default auto refresh interval for the test is 1 Minute.
|
||||
*/
|
||||
private static final int DEFAULT_TEST_AUTOREFRESH_TIME = 1;
|
||||
|
||||
/**
|
||||
* It is updated from mocked {@link StateChangeListener#stateUpdated() }
|
||||
*/
|
||||
private StringType currentItemState = null;
|
||||
|
||||
// Required services for the test
|
||||
private ManagedThingProvider managedThingProvider;
|
||||
private VolatileStorageService volatileStorageService;
|
||||
private ThingRegistry thingRegistry;
|
||||
|
||||
private FeedServiceMock servlet;
|
||||
private Thing feedThing;
|
||||
private FeedHandler feedHandler;
|
||||
private ChannelUID channelUID;
|
||||
|
||||
/**
|
||||
* This class is used as a mock for HTTP web server, serving XML feed content.
|
||||
*/
|
||||
class FeedServiceMock extends HttpServlet {
|
||||
private static final long serialVersionUID = -7810045624309790473L;
|
||||
|
||||
String feedContent;
|
||||
int httpStatus;
|
||||
|
||||
public FeedServiceMock(String feedContentFile) {
|
||||
super();
|
||||
try {
|
||||
setFeedContent(feedContentFile);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Error loading feed content from: " + feedContentFile);
|
||||
}
|
||||
// By default the servlet returns HTTP Status code 200 OK
|
||||
this.httpStatus = HttpStatus.OK_200;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
response.getOutputStream().println(feedContent);
|
||||
// Recommended RSS MIME type - http://www.rssboard.org/rss-mime-type-application.txt
|
||||
// Atom MIME type is - application/atom+xml
|
||||
// Other MIME types - text/plan, text/xml, text/html are tested and accepted as well
|
||||
response.setContentType("application/rss+xml");
|
||||
response.setStatus(httpStatus);
|
||||
}
|
||||
|
||||
public void setFeedContent(String feedContentFile) throws IOException {
|
||||
String path = "input/" + feedContentFile;
|
||||
feedContent = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream(path));
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
volatileStorageService = new VolatileStorageService();
|
||||
registerService(volatileStorageService);
|
||||
|
||||
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
|
||||
assertThat(managedThingProvider, is(notNullValue()));
|
||||
|
||||
thingRegistry = getService(ThingRegistry.class);
|
||||
assertThat(thingRegistry, is(notNullValue()));
|
||||
|
||||
registerFeedTestServlet();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
currentItemState = null;
|
||||
if (feedThing != null) {
|
||||
// Remove the feed thing. The handler will be also disposed automatically
|
||||
Thing removedThing = thingRegistry.forceRemove(feedThing.getUID());
|
||||
assertThat("The feed thing cannot be deleted", removedThing, is(notNullValue()));
|
||||
}
|
||||
|
||||
unregisterFeedTestServlet();
|
||||
|
||||
// Wait for FeedHandler to be unregistered
|
||||
waitForAssert(() -> {
|
||||
feedHandler = (FeedHandler) feedThing.getHandler();
|
||||
assertThat(feedHandler, is(nullValue()));
|
||||
});
|
||||
}
|
||||
|
||||
private void registerFeedTestServlet() {
|
||||
HttpService httpService = getService(HttpService.class);
|
||||
assertThat(httpService, is(notNullValue()));
|
||||
servlet = new FeedServiceMock(DEFAULT_MOCK_CONTENT);
|
||||
try {
|
||||
httpService.registerServlet(MOCK_SERVLET_PATH, servlet, null, null);
|
||||
} catch (ServletException | NamespaceException e) {
|
||||
throw new IllegalStateException("Failed to register feed test servlet", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterFeedTestServlet() {
|
||||
HttpService httpService = getService(HttpService.class);
|
||||
assertThat(httpService, is(notNullValue()));
|
||||
httpService.unregister(MOCK_SERVLET_PATH);
|
||||
servlet = null;
|
||||
}
|
||||
|
||||
private String generateURLString(String protocol, String hostname, int port, String path) {
|
||||
return protocol + "://" + hostname + ":" + port + path;
|
||||
}
|
||||
|
||||
private void initializeDefaultFeedHandler() {
|
||||
String mockServletURL = generateURLString(MOCK_SERVLET_PROTOCOL, MOCK_SERVLET_HOSTNAME, MOCK_SERVLET_PORT,
|
||||
MOCK_SERVLET_PATH);
|
||||
// One minute update time is used for the tests
|
||||
BigDecimal defaultTestRefreshInterval = new BigDecimal(DEFAULT_TEST_AUTOREFRESH_TIME);
|
||||
initializeFeedHandler(mockServletURL, defaultTestRefreshInterval);
|
||||
}
|
||||
|
||||
private void initializeFeedHandler(String url) {
|
||||
initializeFeedHandler(url, null);
|
||||
}
|
||||
|
||||
private void initializeFeedHandler(String url, BigDecimal refreshTime) {
|
||||
// Set up configuration
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.put((FeedBindingConstants.URL), url);
|
||||
configuration.put((FeedBindingConstants.REFRESH_TIME), refreshTime);
|
||||
|
||||
// Create Feed Thing
|
||||
ThingUID feedUID = new ThingUID(FeedBindingConstants.FEED_THING_TYPE_UID, THING_NAME);
|
||||
channelUID = new ChannelUID(feedUID, FeedBindingConstants.CHANNEL_LATEST_DESCRIPTION);
|
||||
Channel channel = ChannelBuilder.create(channelUID, "String").build();
|
||||
feedThing = ThingBuilder.create(FeedBindingConstants.FEED_THING_TYPE_UID, feedUID)
|
||||
.withConfiguration(configuration).withChannel(channel).build();
|
||||
|
||||
managedThingProvider.add(feedThing);
|
||||
|
||||
// Wait for FeedHandler to be registered
|
||||
waitForAssert(() -> {
|
||||
feedHandler = (FeedHandler) feedThing.getHandler();
|
||||
assertThat("FeedHandler is not registered", feedHandler, is(notNullValue()));
|
||||
});
|
||||
|
||||
// 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)));
|
||||
}, 60000, DFL_SLEEP_TIME);
|
||||
initializeItem(channelUID);
|
||||
}
|
||||
|
||||
private void initializeItem(ChannelUID channelUID) {
|
||||
// Create new item
|
||||
ItemRegistry itemRegistry = getService(ItemRegistry.class);
|
||||
assertThat(itemRegistry, is(notNullValue()));
|
||||
|
||||
StringItem newItem = new StringItem(ITEM_NAME);
|
||||
|
||||
// Add item state change listener
|
||||
StateChangeListener updateListener = new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(Item item, State oldState, State newState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateUpdated(Item item, State state) {
|
||||
currentItemState = (StringType) state;
|
||||
}
|
||||
};
|
||||
|
||||
newItem.addStateChangeListener(updateListener);
|
||||
itemRegistry.add(newItem);
|
||||
|
||||
// Add item channel link
|
||||
ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
|
||||
assertThat(itemChannelLinkProvider, is(notNullValue()));
|
||||
itemChannelLinkProvider.add(new ItemChannelLink(ITEM_NAME, channelUID));
|
||||
}
|
||||
|
||||
private void testIfItemStateIsUpdated(boolean commandReceived, boolean contentChanged)
|
||||
throws IOException, InterruptedException {
|
||||
initializeDefaultFeedHandler();
|
||||
|
||||
waitForAssert(() -> {
|
||||
assertThat("Feed Thing can not be initialized", feedThing.getStatus(), is(equalTo(ONLINE)));
|
||||
assertThat("Item's state is not updated on initialize", currentItemState, is(notNullValue()));
|
||||
});
|
||||
|
||||
assertThat(currentItemState, is(instanceOf(StringType.class)));
|
||||
StringType firstItemState = currentItemState;
|
||||
|
||||
if (contentChanged) {
|
||||
// The content on the mocked server should be changed
|
||||
servlet.setFeedContent(MOCK_CONTENT_CHANGED);
|
||||
}
|
||||
|
||||
if (commandReceived) {
|
||||
// Before this time has expired, the refresh command will no trigger a request to the server
|
||||
sleep(FeedBindingConstants.MINIMUM_REFRESH_TIME);
|
||||
|
||||
feedHandler.handleCommand(channelUID, RefreshType.REFRESH);
|
||||
} else {
|
||||
// The auto refresh task will handle the update after the default wait time
|
||||
sleep(DEFAULT_TEST_AUTOREFRESH_TIME * 60 * 1000);
|
||||
}
|
||||
|
||||
waitForAssert(() -> {
|
||||
assertThat("Error occurred while trying to connect to server. Content is not downloaded!",
|
||||
feedThing.getStatus(), is(equalTo(ONLINE)));
|
||||
});
|
||||
|
||||
waitForAssert(() -> {
|
||||
if (contentChanged) {
|
||||
assertThat("Content is not updated!", currentItemState, not(equalTo(firstItemState)));
|
||||
} else {
|
||||
assertThat(currentItemState, is(equalTo(firstItemState)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatInvalidConfigurationFallsBackToDefaultValues() {
|
||||
String mockServletURL = generateURLString(MOCK_SERVLET_PROTOCOL, MOCK_SERVLET_HOSTNAME, MOCK_SERVLET_PORT,
|
||||
MOCK_SERVLET_PATH);
|
||||
BigDecimal defaultTestRefreshInterval = new BigDecimal(-10);
|
||||
initializeFeedHandler(mockServletURL, defaultTestRefreshInterval);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(SlowTests.class)
|
||||
public void assertThatItemsStateIsNotUpdatedOnAutoRefreshIfContentIsNotChanged()
|
||||
throws IOException, InterruptedException {
|
||||
boolean commandReceived = false;
|
||||
boolean contentChanged = false;
|
||||
testIfItemStateIsUpdated(commandReceived, contentChanged);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(SlowTests.class)
|
||||
public void assertThatItemsStateIsUpdatedOnAutoRefreshIfContentChanged() throws IOException, InterruptedException {
|
||||
boolean commandReceived = false;
|
||||
boolean contentChanged = true;
|
||||
testIfItemStateIsUpdated(commandReceived, contentChanged);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatThingsStatusIsUpdatedWhenHTTP500ErrorCodeIsReceived() throws InterruptedException {
|
||||
testIfThingStatusIsUpdated(HttpStatus.INTERNAL_SERVER_ERROR_500);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatThingsStatusIsUpdatedWhenHTTP401ErrorCodeIsReceived() throws InterruptedException {
|
||||
testIfThingStatusIsUpdated(HttpStatus.UNAUTHORIZED_401);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatThingsStatusIsUpdatedWhenHTTP403ErrorCodeIsReceived() throws InterruptedException {
|
||||
testIfThingStatusIsUpdated(HttpStatus.FORBIDDEN_403);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatThingsStatusIsUpdatedWhenHTTP404ErrorCodeIsReceived() throws InterruptedException {
|
||||
testIfThingStatusIsUpdated(HttpStatus.NOT_FOUND_404);
|
||||
}
|
||||
|
||||
private void testIfThingStatusIsUpdated(Integer serverStatus) throws InterruptedException {
|
||||
initializeDefaultFeedHandler();
|
||||
|
||||
servlet.httpStatus = serverStatus;
|
||||
|
||||
// Before this time has expired, the refresh command will no trigger a request to the server
|
||||
sleep(FeedBindingConstants.MINIMUM_REFRESH_TIME);
|
||||
|
||||
// Invalid channel UID is used for the test, because otherwise
|
||||
feedHandler.handleCommand(channelUID, RefreshType.REFRESH);
|
||||
|
||||
waitForAssert(() -> {
|
||||
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
|
||||
});
|
||||
|
||||
servlet.httpStatus = HttpStatus.OK_200;
|
||||
|
||||
// Before this time has expired, the refresh command will no trigger a request to the server
|
||||
sleep(FeedBindingConstants.MINIMUM_REFRESH_TIME);
|
||||
|
||||
feedHandler.handleCommand(channelUID, RefreshType.REFRESH);
|
||||
|
||||
waitForAssert(() -> {
|
||||
assertThat(feedThing.getStatus(), is(equalTo(ONLINE)));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createThingWithInvalidUrlProtocol() {
|
||||
String invalidProtocol = "gdfs";
|
||||
String invalidURL = generateURLString(invalidProtocol, MOCK_SERVLET_HOSTNAME, MOCK_SERVLET_PORT,
|
||||
MOCK_SERVLET_PATH);
|
||||
|
||||
initializeFeedHandler(invalidURL);
|
||||
waitForAssert(() -> {
|
||||
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
|
||||
assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.CONFIGURATION_ERROR)));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createThingWithInvalidUrlHostname() {
|
||||
String invalidHostname = "invalidhost";
|
||||
String invalidURL = generateURLString(MOCK_SERVLET_PROTOCOL, invalidHostname, MOCK_SERVLET_PORT,
|
||||
MOCK_SERVLET_PATH);
|
||||
|
||||
initializeFeedHandler(invalidURL);
|
||||
waitForAssert(() -> {
|
||||
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
|
||||
assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.COMMUNICATION_ERROR)));
|
||||
}, 30000, DFL_SLEEP_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createThingWithInvalidUrlPath() {
|
||||
String invalidPath = "/invalid/path";
|
||||
String invalidURL = generateURLString(MOCK_SERVLET_PROTOCOL, MOCK_SERVLET_HOSTNAME, MOCK_SERVLET_PORT,
|
||||
invalidPath);
|
||||
|
||||
initializeFeedHandler(invalidURL);
|
||||
waitForAssert(() -> {
|
||||
assertThat(feedThing.getStatus(), is(equalTo(OFFLINE)));
|
||||
assertThat(feedThing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.COMMUNICATION_ERROR)));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* This interface is used to mark tests that take too much time
|
||||
*
|
||||
* @author Svilen Valkanov
|
||||
*/
|
||||
public interface SlowTests {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="windows-1252"?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>Sample Feed - Favorite RSS Related Software & Resources</title>
|
||||
<description>Take a look at some of FeedForAll's favorite software and resources for learning more about RSS.</description>
|
||||
<link>http://www.feedforall.com</link>
|
||||
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
|
||||
<copyright>Copyright 2004 NotePage, Inc.</copyright>
|
||||
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
|
||||
<language>en-us</language>
|
||||
<lastBuildDate>Mon, 1 Nov 2004 13:17:17 -0500</lastBuildDate>
|
||||
<managingEditor>marketing@feedforall.com</managingEditor>
|
||||
<pubDate>Tue, 26 Oct 2004 14:06:44 -0500</pubDate>
|
||||
<webMaster>webmaster@feedforall.com</webMaster>
|
||||
<generator>FeedForAll Beta1 (0.0.1.8)</generator>
|
||||
<image>
|
||||
<url>http://www.feedforall.com/feedforall-temp.gif</url>
|
||||
<title>FeedForAll Sample Feed</title>
|
||||
<link>http://www.feedforall.com/industry-solutions.htm</link>
|
||||
<description>FeedForAll Sample Feed</description>
|
||||
<width>144</width>
|
||||
<height>117</height>
|
||||
</image>
|
||||
<item>
|
||||
<title>RSS Resources</title>
|
||||
<description>Be sure to take a look at some of our favorite RSS Resources<br>
|
||||
<a href="http://www.rss-specifications.com">RSS Specifications</a><br>
|
||||
<a href="http://www.blog-connection.com">Blog Connection</a><br>
|
||||
<br></description>
|
||||
<link>http://www.feedforall.com</link>
|
||||
<pubDate>Tue, 26 Oct 2004 14:01:01 -0500</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title>Recommended Desktop Feed Reader Software</title>
|
||||
<description><b>FeedDemon</b> enables you to quickly read and gather information from hundreds of web sites - without having to visit them. Don't waste any more time checking your favorite web sites for updates. Instead, use FeedDemon and make them come to you. <br>
|
||||
More <a href="http://store.esellerate.net/a.asp?c=1_SKU5139890208_AFL403073819">FeedDemon Information</a></description>
|
||||
<link>http://www.feedforall.com/feedforall-partners.htm</link>
|
||||
<pubDate>Tue, 26 Oct 2004 14:03:25 -0500</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title>Recommended Web Based Feed Reader Software</title>
|
||||
<description><b>FeedScout</b> enables you to view RSS/ATOM/RDF feeds from different sites directly in Internet Explorer. You can even set your Home Page to show favorite feeds. Feed Scout is a plug-in for Internet Explorer, so you won't have to learn anything except for how to press 2 new buttons on Internet Explorer toolbar. <br>
|
||||
More <a href="http://www.bytescout.com/feedscout.html">Information on FeedScout</a><br>
|
||||
</description>
|
||||
<link>http://www.feedforall.com/feedforall-partners.htm</link>
|
||||
<pubDate>Tue, 26 Oct 2004 14:06:44 -0500</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="windows-1252"?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>Sample Feed - Favorite RSS Related Software & Resources</title>
|
||||
<description>Take a look at some of FeedForAll's favorite software and resources for learning more about RSS.</description>
|
||||
<link>http://www.feedforall.com</link>
|
||||
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
|
||||
<copyright>Copyright 2004 NotePage, Inc.</copyright>
|
||||
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
|
||||
<language>en-us</language>
|
||||
<lastBuildDate>Mon, 1 Nov 2004 13:17:17 -0500</lastBuildDate>
|
||||
<managingEditor>marketing@feedforall.com</managingEditor>
|
||||
<pubDate>Tue, 26 Oct 2004 14:06:44 -0500</pubDate>
|
||||
<webMaster>webmaster@feedforall.com</webMaster>
|
||||
<generator>FeedForAll Beta1 (0.0.1.8)</generator>
|
||||
<image>
|
||||
<url>http://www.feedforall.com/feedforall-temp.gif</url>
|
||||
<title>FeedForAll Sample Feed</title>
|
||||
<link>http://www.feedforall.com/industry-solutions.htm</link>
|
||||
<description>FeedForAll Sample Feed</description>
|
||||
<width>144</width>
|
||||
<height>117</height>
|
||||
</image>
|
||||
<item>
|
||||
<title>RSS Resources</title>
|
||||
<description>New Description. Be sure to take a look at some of our favorite RSS Resources<br>
|
||||
<a href="http://www.rss-specifications.com">RSS Specifications</a><br>
|
||||
<a href="http://www.blog-connection.com">Blog Connection</a><br>
|
||||
<br></description>
|
||||
<link>http://www.feedforall.com</link>
|
||||
<pubDate>Tue, 26 Oct 2004 14:01:01 -0500</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title>Recommended Desktop Feed Reader Software</title>
|
||||
<description><b>FeedDemon</b> enables you to quickly read and gather information from hundreds of web sites - without having to visit them. Don't waste any more time checking your favorite web sites for updates. Instead, use FeedDemon and make them come to you. <br>
|
||||
More <a href="http://store.esellerate.net/a.asp?c=1_SKU5139890208_AFL403073819">FeedDemon Information</a></description>
|
||||
<link>http://www.feedforall.com/feedforall-partners.htm</link>
|
||||
<pubDate>Tue, 26 Oct 2004 14:03:25 -0500</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title>Recommended Web Based Feed Reader Software</title>
|
||||
<description><b>FeedScout</b> enables you to view RSS/ATOM/RDF feeds from different sites directly in Internet Explorer. You can even set your Home Page to show favorite feeds. Feed Scout is a plug-in for Internet Explorer, so you won't have to learn anything except for how to press 2 new buttons on Internet Explorer toolbar. <br>
|
||||
More <a href="http://www.bytescout.com/feedscout.html">Information on FeedScout</a><br>
|
||||
</description>
|
||||
<link>http://www.feedforall.com/feedforall-partners.htm</link>
|
||||
<pubDate>Tue, 26 Oct 2004 14:06:44 -0500</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title>Some new item</title>
|
||||
<description><b>FeedScout</b> enables you to view RSS/ATOM/RDF feeds from different sites directly in Internet Explorer. You can even set your Home Page to show favorite feeds. Feed Scout is a plug-in for Internet Explorer, so you won't have to learn anything except for how to press 2 new buttons on Internet Explorer toolbar. <br>
|
||||
More <a href="http://www.bytescout.com/feedscout.html">Information on FeedScout</a><br>
|
||||
</description>
|
||||
<link>http://www.feedforall.com/</link>
|
||||
<pubDate>Tue, 26 Oct 2004 18:06:44 -0500</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
Reference in New Issue
Block a user