mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
remove io.rest.sitemap itests (already moved) (#563)
The io.rest.sitemap integration test has already been moved to a pure JUnit test of the respective bundle. Related to: https://github.com/openhab/openhab-core/pull/499 Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
This commit is contained in:
parent
0197896f5f
commit
396cbe67b8
@ -1,27 +0,0 @@
|
|||||||
<?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-1.8">
|
|
||||||
<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 kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>org.openhab.core.io.rest.sitemap.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>
|
|
@ -1,3 +0,0 @@
|
|||||||
eclipse.preferences.version=1
|
|
||||||
encoding//src/main/java=UTF-8
|
|
||||||
encoding/<project>=UTF-8
|
|
@ -1,4 +0,0 @@
|
|||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
version=1
|
|
@ -1,19 +0,0 @@
|
|||||||
This content is produced and maintained by the Eclipse SmartHome project.
|
|
||||||
|
|
||||||
* Project home: https://eclipse.org/smarthome/
|
|
||||||
|
|
||||||
== 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/eclipse/smarthome
|
|
||||||
|
|
||||||
== Copyright Holders
|
|
||||||
|
|
||||||
See the NOTICE file distributed with the source code at
|
|
||||||
https://github.com/eclipse/smarthome/blob/master/NOTICE
|
|
||||||
for detailed information regarding copyright ownership.
|
|
@ -1,95 +0,0 @@
|
|||||||
-include: ../itest-common.bndrun
|
|
||||||
|
|
||||||
Bundle-SymbolicName: ${project.artifactId}
|
|
||||||
Fragment-Host: org.openhab.core.io.rest.sitemap
|
|
||||||
|
|
||||||
-runrequires: bnd.identity;id='org.openhab.core.io.rest.sitemap.tests'
|
|
||||||
|
|
||||||
#
|
|
||||||
# done
|
|
||||||
#
|
|
||||||
-runbundles: \
|
|
||||||
ch.qos.logback.classic;version='[1.2.0,1.2.1)',\
|
|
||||||
ch.qos.logback.core;version='[1.2.0,1.2.1)',\
|
|
||||||
com.google.gson;version='[2.7.0,2.7.1)',\
|
|
||||||
com.google.guava;version='[15.0.0,15.0.1)',\
|
|
||||||
com.google.inject;version='[3.0.0,3.0.1)',\
|
|
||||||
javax.measure.unit-api;version='[1.0.0,1.0.1)',\
|
|
||||||
joda-time;version='[2.9.2,2.9.3)',\
|
|
||||||
log4j;version='[1.2.17,1.2.18)',\
|
|
||||||
org.antlr.runtime;version='[3.2.0,3.2.1)',\
|
|
||||||
org.apache.commons.collections;version='[3.2.1,3.2.2)',\
|
|
||||||
org.apache.commons.exec;version='[1.1.0,1.1.1)',\
|
|
||||||
org.apache.commons.io;version='[2.2.0,2.2.1)',\
|
|
||||||
org.apache.commons.lang;version='[2.6.0,2.6.1)',\
|
|
||||||
org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\
|
|
||||||
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
|
|
||||||
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
|
|
||||||
org.apache.servicemix.bundles.commons-codec;version='[1.3.0,1.3.1)',\
|
|
||||||
org.apache.servicemix.bundles.commons-httpclient;version='[3.1.0,3.1.1)',\
|
|
||||||
org.apache.xbean.bundleutils;version='[4.6.0,4.6.1)',\
|
|
||||||
org.apache.xbean.finder;version='[4.6.0,4.6.1)',\
|
|
||||||
org.eclipse.emf.common;version='[2.12.0,2.12.1)',\
|
|
||||||
org.eclipse.emf.ecore;version='[2.12.0,2.12.1)',\
|
|
||||||
org.eclipse.emf.ecore.xmi;version='[2.12.0,2.12.1)',\
|
|
||||||
org.eclipse.equinox.common;version='[3.8.0,3.8.1)',\
|
|
||||||
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
|
|
||||||
org.eclipse.jetty.client;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.http;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.io;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.proxy;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.security;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.server;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.servlet;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.util;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.websocket.api;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.websocket.client;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.websocket.common;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.jetty.xml;version='[9.4.11,9.4.12)',\
|
|
||||||
org.eclipse.xtend.lib;version='[2.14.0,2.14.1)',\
|
|
||||||
org.eclipse.xtend.lib.macro;version='[2.14.0,2.14.1)',\
|
|
||||||
org.eclipse.xtext;version='[2.14.0,2.14.1)',\
|
|
||||||
org.eclipse.xtext.common.types;version='[2.14.0,2.14.1)',\
|
|
||||||
org.eclipse.xtext.util;version='[2.14.0,2.14.1)',\
|
|
||||||
org.eclipse.xtext.xbase;version='[2.14.0,2.14.1)',\
|
|
||||||
org.eclipse.xtext.xbase.lib;version='[2.14.0,2.14.1)',\
|
|
||||||
org.glassfish.hk2.external.aopalliance-repackaged;version='[2.4.0,2.4.1)',\
|
|
||||||
org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\
|
|
||||||
org.objectweb.asm;version='[6.1.1,6.1.2)',\
|
|
||||||
org.objectweb.asm.commons;version='[6.1.1,6.1.2)',\
|
|
||||||
org.objectweb.asm.tree;version='[6.1.1,6.1.2)',\
|
|
||||||
org.openhab.core.compat1x;version='[2.5.0,2.5.1)',\
|
|
||||||
org.ops4j.pax.swissbox.optional.jcl;version='[1.8.2,1.8.3)',\
|
|
||||||
org.ops4j.pax.web.pax-web-api;version='[7.2.3,7.2.4)',\
|
|
||||||
org.ops4j.pax.web.pax-web-jetty;version='[7.2.3,7.2.4)',\
|
|
||||||
org.ops4j.pax.web.pax-web-runtime;version='[7.2.3,7.2.4)',\
|
|
||||||
org.ops4j.pax.web.pax-web-spi;version='[7.2.3,7.2.4)',\
|
|
||||||
org.osgi.service.event;version='[1.4.0,1.4.1)',\
|
|
||||||
slf4j.api;version='[1.7.21,1.7.22)',\
|
|
||||||
tec.uom.lib.uom-lib-common;version='[1.0.2,1.0.3)',\
|
|
||||||
tec.uom.se;version='[1.0.8,1.0.9)',\
|
|
||||||
osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\
|
|
||||||
osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\
|
|
||||||
org.openhab.core;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.audio;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.compat1x.tests;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.config.core;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.io.console;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.io.http;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.io.net;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.core;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.item;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.persistence;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.script;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.script.runtime;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.sitemap;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.persistence;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.scheduler;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.thing;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.transform;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.ui;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.voice;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.persistence.runtime;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.rule;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.model.thing;version='[2.5.0,2.5.1)',\
|
|
||||||
org.openhab.core.storage.json;version='[2.5.0,2.5.1)'
|
|
@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<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.core.itests</groupId>
|
|
||||||
<artifactId>org.openhab.core.reactor.itests</artifactId>
|
|
||||||
<version>2.5.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>org.openhab.core.io.rest.sitemap.tests</artifactId>
|
|
||||||
|
|
||||||
<name>openHAB Core :: Integration Tests :: I/O :: REST :: Sitemap Tests</name>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,389 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014,2019 Contributors to the Eclipse Foundation
|
|
||||||
*
|
|
||||||
* See the NOTICE file(s) distributed with this work for additional
|
|
||||||
* information regarding copyright ownership.
|
|
||||||
*
|
|
||||||
* 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.eclipse.smarthome.io.rest.sitemap.internal;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
|
||||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
|
||||||
import static org.hamcrest.collection.IsEmptyCollection.empty;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
import static org.mockito.MockitoAnnotations.initMocks;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
import javax.ws.rs.core.UriInfo;
|
|
||||||
|
|
||||||
import org.eclipse.emf.common.util.BasicEList;
|
|
||||||
import org.eclipse.emf.common.util.EList;
|
|
||||||
import org.eclipse.emf.ecore.EClass;
|
|
||||||
import org.eclipse.smarthome.core.items.GenericItem;
|
|
||||||
import org.eclipse.smarthome.core.items.ItemNotFoundException;
|
|
||||||
import org.eclipse.smarthome.core.library.types.DecimalType;
|
|
||||||
import org.eclipse.smarthome.core.library.types.OnOffType;
|
|
||||||
import org.eclipse.smarthome.core.library.types.PercentType;
|
|
||||||
import org.eclipse.smarthome.core.types.Command;
|
|
||||||
import org.eclipse.smarthome.core.types.State;
|
|
||||||
import org.eclipse.smarthome.io.rest.LocaleService;
|
|
||||||
import org.eclipse.smarthome.model.sitemap.ColorArray;
|
|
||||||
import org.eclipse.smarthome.model.sitemap.Sitemap;
|
|
||||||
import org.eclipse.smarthome.model.sitemap.SitemapProvider;
|
|
||||||
import org.eclipse.smarthome.model.sitemap.VisibilityRule;
|
|
||||||
import org.eclipse.smarthome.model.sitemap.Widget;
|
|
||||||
import org.eclipse.smarthome.test.java.JavaTest;
|
|
||||||
import org.eclipse.smarthome.ui.items.ItemUIRegistry;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test aspects of the {@link SitemapResource}.
|
|
||||||
*
|
|
||||||
* @author Henning Treu - initial contribution
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SitemapResourceTest extends JavaTest {
|
|
||||||
|
|
||||||
private static final int STATE_UPDATE_WAIT_TIME = 100;
|
|
||||||
|
|
||||||
private static final String HTTP_HEADER_X_ATMOSPHERE_TRANSPORT = "X-Atmosphere-Transport";
|
|
||||||
private static final String ITEM_NAME = "itemName";
|
|
||||||
private static final String SITEMAP_PATH = "/sitemaps";
|
|
||||||
private static final String SITEMAP_MODEL_NAME = "sitemapModel";
|
|
||||||
private static final String SITEMAP_NAME = "defaultSitemap";
|
|
||||||
private static final String SITEMAP_TITLE = "Default Sitemap";
|
|
||||||
private static final String VISIBILITY_RULE_ITEM_NAME = "visibilityRuleItem";
|
|
||||||
private static final String LABEL_COLOR_ITEM_NAME = "labelColorItemName";
|
|
||||||
private static final String VALUE_COLOR_ITEM_NAME = "valueColorItemName";
|
|
||||||
private static final String WIDGET1_LABEL = "widget 1";
|
|
||||||
private static final String WIDGET2_LABEL = "widget 2";
|
|
||||||
private static final String WIDGET1_ID = "00";
|
|
||||||
private static final String WIDGET2_ID = "01";
|
|
||||||
private static final String CLIENT_IP = "127.0.0.1";
|
|
||||||
|
|
||||||
private SitemapResource sitemapResource;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private UriInfo uriInfo;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private HttpServletRequest request;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private SitemapProvider sitemapProvider;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Sitemap defaultSitemap;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ItemUIRegistry itemUIRegistry;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private HttpHeaders headers;
|
|
||||||
|
|
||||||
private GenericItem item;
|
|
||||||
private GenericItem visibilityRuleItem;
|
|
||||||
private GenericItem labelColorItem;
|
|
||||||
private GenericItem valueColorItem;
|
|
||||||
|
|
||||||
private EList<Widget> widgets;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() throws Exception {
|
|
||||||
initMocks(this);
|
|
||||||
sitemapResource = new SitemapResource();
|
|
||||||
|
|
||||||
when(uriInfo.getAbsolutePathBuilder()).thenReturn(UriBuilder.fromPath(SITEMAP_PATH));
|
|
||||||
when(uriInfo.getBaseUriBuilder()).thenReturn(UriBuilder.fromPath(SITEMAP_PATH));
|
|
||||||
sitemapResource.uriInfo = uriInfo;
|
|
||||||
|
|
||||||
when(request.getRemoteAddr()).thenReturn(CLIENT_IP);
|
|
||||||
sitemapResource.request = request;
|
|
||||||
|
|
||||||
item = new TestItem(ITEM_NAME);
|
|
||||||
visibilityRuleItem = new TestItem(VISIBILITY_RULE_ITEM_NAME);
|
|
||||||
labelColorItem = new TestItem(LABEL_COLOR_ITEM_NAME);
|
|
||||||
valueColorItem = new TestItem(VALUE_COLOR_ITEM_NAME);
|
|
||||||
|
|
||||||
LocaleService localeService = mock(LocaleService.class);
|
|
||||||
when(localeService.getLocale(null)).thenReturn(Locale.US);
|
|
||||||
sitemapResource.setLocaleService(localeService);
|
|
||||||
|
|
||||||
configureSitemapProviderMock();
|
|
||||||
configureSitemapMock();
|
|
||||||
sitemapResource.addSitemapProvider(sitemapProvider);
|
|
||||||
|
|
||||||
widgets = initSitemapWidgets();
|
|
||||||
configureItemUIRegistry(PercentType.HUNDRED, OnOffType.ON);
|
|
||||||
sitemapResource.setItemUIRegistry(itemUIRegistry);
|
|
||||||
|
|
||||||
// Disable long polling
|
|
||||||
when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenNoSitemapProvidersAreSet_ShouldReturnEmptyList() {
|
|
||||||
sitemapResource.removeSitemapProvider(sitemapProvider);
|
|
||||||
Response sitemaps = sitemapResource.getSitemaps();
|
|
||||||
|
|
||||||
assertThat(sitemaps.getEntity(), instanceOf(Collection.class));
|
|
||||||
assertThat((Collection<?>) sitemaps.getEntity(), is(empty()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenSitemapsAreProvided_ShouldReturnSitemapBeans() {
|
|
||||||
Response sitemaps = sitemapResource.getSitemaps();
|
|
||||||
|
|
||||||
assertThat((Collection<?>) sitemaps.getEntity(), hasSize(1));
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
SitemapDTO dto = ((Collection<SitemapDTO>) sitemaps.getEntity()).iterator().next();
|
|
||||||
assertThat(dto.name, is(SITEMAP_MODEL_NAME));
|
|
||||||
assertThat(dto.link, is(SITEMAP_PATH + "/" + SITEMAP_MODEL_NAME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenLongPolling_ShouldObserveItems() {
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Thread.sleep(STATE_UPDATE_WAIT_TIME); // wait for the #getPageData call and listeners to attach to the
|
|
||||||
// item
|
|
||||||
item.setState(PercentType.ZERO);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
// non-null is sufficient here.
|
|
||||||
when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(Collections.emptyList());
|
|
||||||
|
|
||||||
Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
|
|
||||||
|
|
||||||
PageDTO pageDTO = (PageDTO) response.getEntity();
|
|
||||||
assertThat(pageDTO.timeout, is(false)); // assert that the item state change did trigger the blocking method to
|
|
||||||
// return
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenLongPolling_ShouldObserveItemsFromVisibilityRules() {
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Thread.sleep(STATE_UPDATE_WAIT_TIME); // wait for the #getPageData call and listeners to attach to the
|
|
||||||
// item
|
|
||||||
visibilityRuleItem.setState(new DecimalType(BigDecimal.ONE));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
// non-null is sufficient here.
|
|
||||||
when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(Collections.emptyList());
|
|
||||||
|
|
||||||
Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
|
|
||||||
|
|
||||||
PageDTO pageDTO = (PageDTO) response.getEntity();
|
|
||||||
assertThat(pageDTO.timeout, is(false)); // assert that the item state change did trigger the blocking method to
|
|
||||||
// return
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenLongPolling_ShouldObserveItemsFromLabelColorConditions() {
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Thread.sleep(STATE_UPDATE_WAIT_TIME); // wait for the #getPageData call and listeners to attach to the
|
|
||||||
// item
|
|
||||||
labelColorItem.setState(new DecimalType(BigDecimal.ONE));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
// non-null is sufficient here.
|
|
||||||
when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(Collections.emptyList());
|
|
||||||
|
|
||||||
Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
|
|
||||||
|
|
||||||
PageDTO pageDTO = (PageDTO) response.getEntity();
|
|
||||||
assertThat(pageDTO.timeout, is(false)); // assert that the item state change did trigger the blocking method to
|
|
||||||
// return
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenLongPolling_ShouldObserveItemsFromValueColorConditions() {
|
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Thread.sleep(STATE_UPDATE_WAIT_TIME); // wait for the #getPageData call and listeners to attach to the
|
|
||||||
// item
|
|
||||||
valueColorItem.setState(new DecimalType(BigDecimal.ONE));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
// non-null is sufficient here.
|
|
||||||
when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(Collections.emptyList());
|
|
||||||
|
|
||||||
Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
|
|
||||||
|
|
||||||
PageDTO pageDTO = (PageDTO) response.getEntity();
|
|
||||||
assertThat(pageDTO.timeout, is(false)); // assert that the item state change did trigger the blocking method to
|
|
||||||
// return
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenGetPageData_ShouldReturnPageBean() throws ItemNotFoundException {
|
|
||||||
item.setState(new PercentType(50));
|
|
||||||
configureItemUIRegistry(item.getState(), OnOffType.ON);
|
|
||||||
|
|
||||||
// Disable long polling
|
|
||||||
when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(null);
|
|
||||||
|
|
||||||
Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
|
|
||||||
|
|
||||||
PageDTO pageDTO = (PageDTO) response.getEntity();
|
|
||||||
assertThat(pageDTO.id, is(SITEMAP_NAME));
|
|
||||||
assertThat(pageDTO.title, is(SITEMAP_TITLE));
|
|
||||||
assertThat(pageDTO.leaf, is(true));
|
|
||||||
assertThat(pageDTO.timeout, is(false));
|
|
||||||
|
|
||||||
assertThat(pageDTO.widgets, notNullValue());
|
|
||||||
assertThat((Collection<?>) pageDTO.widgets, hasSize(2));
|
|
||||||
|
|
||||||
assertThat(pageDTO.widgets.get(0).widgetId, is(WIDGET1_ID));
|
|
||||||
assertThat(pageDTO.widgets.get(0).label, is(WIDGET1_LABEL));
|
|
||||||
assertThat(pageDTO.widgets.get(0).labelcolor, is("GREEN"));
|
|
||||||
assertThat(pageDTO.widgets.get(0).valuecolor, is("BLUE"));
|
|
||||||
assertThat(pageDTO.widgets.get(0).state, nullValue());
|
|
||||||
assertThat(pageDTO.widgets.get(0).item, notNullValue());
|
|
||||||
assertThat(pageDTO.widgets.get(0).item.name, is(ITEM_NAME));
|
|
||||||
assertThat(pageDTO.widgets.get(0).item.state, is("50"));
|
|
||||||
|
|
||||||
assertThat(pageDTO.widgets.get(1).widgetId, is(WIDGET2_ID));
|
|
||||||
assertThat(pageDTO.widgets.get(1).label, is(WIDGET2_LABEL));
|
|
||||||
assertThat(pageDTO.widgets.get(1).labelcolor, nullValue());
|
|
||||||
assertThat(pageDTO.widgets.get(1).valuecolor, nullValue());
|
|
||||||
assertThat(pageDTO.widgets.get(1).state, is("ON"));
|
|
||||||
assertThat(pageDTO.widgets.get(1).item, notNullValue());
|
|
||||||
assertThat(pageDTO.widgets.get(1).item.name, is(ITEM_NAME));
|
|
||||||
assertThat(pageDTO.widgets.get(1).item.state, is("50"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configureItemUIRegistry(State state1, State state2) throws ItemNotFoundException {
|
|
||||||
when(itemUIRegistry.getChildren(defaultSitemap)).thenReturn(widgets);
|
|
||||||
when(itemUIRegistry.getItem(ITEM_NAME)).thenReturn(item);
|
|
||||||
when(itemUIRegistry.getItem(VISIBILITY_RULE_ITEM_NAME)).thenReturn(visibilityRuleItem);
|
|
||||||
when(itemUIRegistry.getItem(LABEL_COLOR_ITEM_NAME)).thenReturn(labelColorItem);
|
|
||||||
when(itemUIRegistry.getItem(VALUE_COLOR_ITEM_NAME)).thenReturn(valueColorItem);
|
|
||||||
|
|
||||||
when(itemUIRegistry.getWidgetId(widgets.get(0))).thenReturn(WIDGET1_ID);
|
|
||||||
when(itemUIRegistry.getCategory(widgets.get(0))).thenReturn("");
|
|
||||||
when(itemUIRegistry.getLabel(widgets.get(0))).thenReturn(WIDGET1_LABEL);
|
|
||||||
when(itemUIRegistry.getVisiblity(widgets.get(0))).thenReturn(true);
|
|
||||||
when(itemUIRegistry.getLabelColor(widgets.get(0))).thenReturn("GREEN");
|
|
||||||
when(itemUIRegistry.getValueColor(widgets.get(0))).thenReturn("BLUE");
|
|
||||||
when(itemUIRegistry.getState(widgets.get(0))).thenReturn(state1);
|
|
||||||
|
|
||||||
when(itemUIRegistry.getWidgetId(widgets.get(1))).thenReturn(WIDGET2_ID);
|
|
||||||
when(itemUIRegistry.getCategory(widgets.get(1))).thenReturn("");
|
|
||||||
when(itemUIRegistry.getLabel(widgets.get(1))).thenReturn(WIDGET2_LABEL);
|
|
||||||
when(itemUIRegistry.getVisiblity(widgets.get(1))).thenReturn(true);
|
|
||||||
when(itemUIRegistry.getLabelColor(widgets.get(1))).thenReturn(null);
|
|
||||||
when(itemUIRegistry.getValueColor(widgets.get(1))).thenReturn(null);
|
|
||||||
when(itemUIRegistry.getState(widgets.get(1))).thenReturn(state2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private EList<Widget> initSitemapWidgets() {
|
|
||||||
// Initialize a sitemap containing 2 widgets linked to the same number item,
|
|
||||||
// one slider and one switch
|
|
||||||
|
|
||||||
Widget w1 = mock(Widget.class);
|
|
||||||
EClass sliderEClass = mock(EClass.class);
|
|
||||||
when(sliderEClass.getName()).thenReturn("slider");
|
|
||||||
when(sliderEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Slider");
|
|
||||||
when(w1.eClass()).thenReturn(sliderEClass);
|
|
||||||
when(w1.getLabel()).thenReturn(WIDGET1_LABEL);
|
|
||||||
when(w1.getItem()).thenReturn(ITEM_NAME);
|
|
||||||
|
|
||||||
// add visibility rules to the mock widget:
|
|
||||||
VisibilityRule visibilityRule = mock(VisibilityRule.class);
|
|
||||||
when(visibilityRule.getItem()).thenReturn(VISIBILITY_RULE_ITEM_NAME);
|
|
||||||
BasicEList<VisibilityRule> visibilityRules = new BasicEList<>(1);
|
|
||||||
visibilityRules.add(visibilityRule);
|
|
||||||
when(w1.getVisibility()).thenReturn(visibilityRules);
|
|
||||||
|
|
||||||
// add label color conditions to the item:
|
|
||||||
ColorArray labelColor = mock(ColorArray.class);
|
|
||||||
when(labelColor.getItem()).thenReturn(LABEL_COLOR_ITEM_NAME);
|
|
||||||
EList<ColorArray> labelColors = new BasicEList<>();
|
|
||||||
labelColors.add(labelColor);
|
|
||||||
when(w1.getLabelColor()).thenReturn(labelColors);
|
|
||||||
|
|
||||||
// add value color conditions to the item:
|
|
||||||
ColorArray valueColor = mock(ColorArray.class);
|
|
||||||
when(valueColor.getItem()).thenReturn(VALUE_COLOR_ITEM_NAME);
|
|
||||||
EList<ColorArray> valueColors = new BasicEList<>();
|
|
||||||
valueColors.add(valueColor);
|
|
||||||
when(w1.getValueColor()).thenReturn(valueColors);
|
|
||||||
|
|
||||||
visibilityRules = new BasicEList<>();
|
|
||||||
labelColors = new BasicEList<>();
|
|
||||||
valueColors = new BasicEList<>();
|
|
||||||
|
|
||||||
Widget w2 = mock(Widget.class);
|
|
||||||
EClass switchEClass = mock(EClass.class);
|
|
||||||
when(switchEClass.getName()).thenReturn("switch");
|
|
||||||
when(switchEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Switch");
|
|
||||||
when(w2.eClass()).thenReturn(switchEClass);
|
|
||||||
when(w2.getLabel()).thenReturn(WIDGET2_LABEL);
|
|
||||||
when(w2.getItem()).thenReturn(ITEM_NAME);
|
|
||||||
when(w2.getVisibility()).thenReturn(visibilityRules);
|
|
||||||
when(w2.getLabelColor()).thenReturn(labelColors);
|
|
||||||
when(w2.getValueColor()).thenReturn(valueColors);
|
|
||||||
|
|
||||||
BasicEList<Widget> widgets = new BasicEList<>(2);
|
|
||||||
widgets.add(w1);
|
|
||||||
widgets.add(w2);
|
|
||||||
return widgets;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configureSitemapMock() {
|
|
||||||
when(defaultSitemap.getName()).thenReturn(SITEMAP_NAME);
|
|
||||||
when(defaultSitemap.getLabel()).thenReturn(SITEMAP_TITLE);
|
|
||||||
when(defaultSitemap.getIcon()).thenReturn("");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configureSitemapProviderMock() {
|
|
||||||
when(sitemapProvider.getSitemapNames()).thenReturn(Collections.singleton(SITEMAP_MODEL_NAME));
|
|
||||||
when(sitemapProvider.getSitemap(SITEMAP_MODEL_NAME)).thenReturn(defaultSitemap);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestItem extends GenericItem {
|
|
||||||
|
|
||||||
public TestItem(String name) {
|
|
||||||
super("Number", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Class<? extends State>> getAcceptedDataTypes() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Class<? extends Command>> getAcceptedCommandTypes() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -39,7 +39,6 @@
|
|||||||
<!-- <module>org.openhab.core.io.rest.tests</module> -->
|
<!-- <module>org.openhab.core.io.rest.tests</module> -->
|
||||||
<module>org.openhab.core.io.rest.core.tests</module>
|
<module>org.openhab.core.io.rest.core.tests</module>
|
||||||
<!-- <module>org.openhab.core.io.rest.sse.tests</module> -->
|
<!-- <module>org.openhab.core.io.rest.sse.tests</module> -->
|
||||||
<!-- <module>org.openhab.core.io.rest.sitemap.tests</module> -->
|
|
||||||
<!-- <module>org.openhab.core.io.transport.mqtt.tests</module> -->
|
<!-- <module>org.openhab.core.io.transport.mqtt.tests</module> -->
|
||||||
<!-- <module>org.openhab.core.io.transport.upnp.tests</module> -->
|
<!-- <module>org.openhab.core.io.transport.upnp.tests</module> -->
|
||||||
<!-- <module>org.openhab.core.magic.tests</module> -->
|
<!-- <module>org.openhab.core.magic.tests</module> -->
|
||||||
|
Loading…
Reference in New Issue
Block a user