added migrated 2.x add-ons

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer
2020-09-21 01:58:32 +02:00
parent bbf1a7fd29
commit 6df6783b60
11662 changed files with 1302875 additions and 11 deletions

View File

@@ -0,0 +1,27 @@
<?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 kind="output" path="target/classes"/>
</classpath>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.astro.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>

View 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

View File

@@ -0,0 +1,49 @@
-include: ../itest-common.bndrun
Bundle-SymbolicName: ${project.artifactId}
Fragment-Host: org.openhab.binding.astro
-runrequires: bnd.identity;id='org.openhab.binding.astro.tests'
#
# done
#
-runbundles: \
javax.measure.unit-api;version='[1.0.0,1.0.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.scr;version='[2.1.10,2.1.11)',\
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
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)',\
org.openhab.core;version='[2.5.0,2.5.1)',\
org.openhab.core.config.core;version='[2.5.0,2.5.1)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
org.objenesis;version='[2.6.0,2.6.1)',\
org.openhab.core.config.discovery;version='[2.5.0,2.5.1)',\
org.openhab.core.io.console;version='[2.5.0,2.5.1)',\
org.openhab.core.thing;version='[2.5.0,2.5.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
com.google.gson;version='[2.8.2,2.8.3)',\
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)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
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)',\
net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\
net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\
org.mockito.mockito-core;version='[3.1.0,3.1.1)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
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.openhab.core.test;version='[2.5.0,2.5.1)',\
org.openhab.binding.astro;version='[2.5.9,2.5.10)',\
org.openhab.binding.astro.tests;version='[2.5.9,2.5.10)'

View File

@@ -0,0 +1,25 @@
<?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.astro.tests</artifactId>
<name>openHAB Add-ons :: Integration Tests :: Astro Binding Tests</name>
<dependencies>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.astro</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,25 @@
<?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.astro.tests</artifactId>
<name>openHAB Add-ons :: Integration Tests :: Astro Binding Tests</name>
<dependencies>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.astro</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,78 @@
/**
* 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.astro.handler.test;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.openhab.binding.astro.internal.AstroBindingConstants.THING_TYPE_SUN;
import static org.openhab.binding.astro.test.cases.AstroBindingTestsData.*;
import java.time.ZoneId;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.scheduler.CronScheduler;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.junit.Test;
import org.openhab.binding.astro.internal.handler.AstroThingHandler;
import org.openhab.binding.astro.internal.handler.SunHandler;
import org.openhab.binding.astro.internal.model.Sun;
/**
* OSGi test for the {@link AstroThingHandler}
* <p>
* This class tests the commands for the astro thing.
*
* @author Petar Valchev - Initial implementation
* @author Svilen Valkanov - Reworked to plain unit tests
* @author Christoph Weitkamp - Migrated tests to pure Java
*/
public class AstroCommandTest {
@Test
public void testRefreshCommandUpdatesTheStateOfTheChannels() {
ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID);
ChannelUID channelUID = new ChannelUID(thingUID, DEFAULT_TEST_CHANNEL_ID);
Channel channel = ChannelBuilder.create(channelUID, DEFAULT_IMEM_TYPE).build();
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, INTERVAL_DEFAULT_VALUE);
Thing thing = mock(Thing.class);
when(thing.getConfiguration()).thenReturn(thingConfiguration);
when(thing.getUID()).thenReturn(thingUID);
when(thing.getChannel(DEFAULT_TEST_CHANNEL_ID)).thenReturn(channel);
ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
CronScheduler cronScheduler = mock(CronScheduler.class);
TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
AstroThingHandler sunHandler = spy(new SunHandler(thing, cronScheduler, timeZoneProvider));
// Required from the AstroThingHandler to send the status update
doReturn(true).when(callback).isChannelLinked(eq(channelUID));
doReturn(new Sun()).when(sunHandler).getPlanet();
sunHandler.setCallback(callback);
sunHandler.handleCommand(channelUID, RefreshType.REFRESH);
verify(callback, times(1)).stateUpdated(eq(channelUID), any(State.class));
}
}

View File

@@ -0,0 +1,159 @@
/**
* 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.astro.handler.test;
import static org.mockito.Mockito.*;
import static org.openhab.binding.astro.internal.AstroBindingConstants.THING_TYPE_SUN;
import static org.openhab.binding.astro.test.cases.AstroBindingTestsData.*;
import java.time.ZoneId;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.scheduler.CronScheduler;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.junit.Test;
import org.openhab.binding.astro.internal.handler.AstroThingHandler;
import org.openhab.binding.astro.internal.handler.SunHandler;
/**
* Tests for the {@link AstroThingHandler}
* <p>
* This class tests the required configuration for the astro thing.
*
* @author Petar Valchev - Initial implementation
* @author Svilen Valkanov - Reworked to plain unit tests, removed irrelevant tests
* @author Christoph Weitkamp - Migrated tests to pure Java
*/
public class AstroValidConfigurationTest {
private final String NULL_LONGITUDE = "51.2,null";
private final String NULL_LATITUDE = "null,25.4";
@Test
public void testIfGeolocationIsProvidedForASunThing_theThingStatusBecomesONLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, INTERVAL_DEFAULT_VALUE);
assertThingStatus(thingConfiguration, ThingStatus.ONLINE, ThingStatusDetail.NONE);
}
@Test
public void testIfGeolocationIsProvidedForAMoonThing_theThingStatusBecomesONLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, INTERVAL_DEFAULT_VALUE);
assertThingStatus(thingConfiguration, ThingStatus.ONLINE, ThingStatusDetail.NONE);
}
@Test
public void testIfGeolocationForASunThingIsNull_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, null);
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfGeolocationForAMoonThingIsNull_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, null);
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheLatitudeForASunThingIsNull_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LATITUDE);
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheLatitudeForAMoonThingIsNull_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LATITUDE);
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheLongitudeForASunThingIsNull_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LONGITUDE);
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheLongitudeForAMoonThingIsNull_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, NULL_LONGITUDE);
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheIntervalForASunThingIsLessThan1_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(0));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheIntervalForAMoonThingIsLessThan1_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(0));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheIntervalForASunThingIsGreaterThan86400_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(86401));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
@Test
public void testIfTheIntervalForAMoonThingIsGreaterThan86400_theThingStatusBecomesOFFLINE() {
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, new Integer(86401));
assertThingStatus(thingConfiguration, ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
}
private void assertThingStatus(Configuration configuration, ThingStatus expectedStatus,
ThingStatusDetail expectedStatusDetail) {
ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID);
Thing thing = mock(Thing.class);
when(thing.getConfiguration()).thenReturn(configuration);
when(thing.getUID()).thenReturn(thingUID);
ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
CronScheduler cronScheduler = mock(CronScheduler.class);
TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
ThingHandler sunHandler = new SunHandler(thing, cronScheduler, timeZoneProvider);
sunHandler.setCallback(callback);
sunHandler.initialize();
ThingStatusInfo expectedThingStatus = new ThingStatusInfo(expectedStatus, expectedStatusDetail, null);
verify(callback, times(1)).statusUpdated(thing, expectedThingStatus);
}
}

View File

@@ -0,0 +1,113 @@
/**
* 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.astro.test;
import static org.junit.Assert.assertEquals;
import static org.openhab.binding.astro.internal.AstroBindingConstants.*;
import static org.openhab.binding.astro.test.cases.AstroBindingTestsData.*;
import static org.openhab.binding.astro.test.cases.AstroParametrizedTestCases.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.types.State;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openhab.binding.astro.internal.calc.MoonCalc;
import org.openhab.binding.astro.internal.calc.SunCalc;
import org.openhab.binding.astro.internal.config.AstroChannelConfig;
import org.openhab.binding.astro.internal.model.Planet;
import org.openhab.binding.astro.internal.util.PropertyUtils;
import org.openhab.binding.astro.test.cases.AstroParametrizedTestCases;
/**
* Tests for the Astro Channels state
*
* @See {@link AstroParametrizedTestCases}
* @author Petar Valchev - Initial implementation
* @author Svilen Valkanov - Reworked to plain unit tests
* @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
* @author Christoph Weitkamp - Migrated tests to pure Java
*/
@RunWith(Parameterized.class)
public class AstroStateTest {
private String thingID;
private String channelId;
private State expectedState;
// These test result timestamps are adapted for the +03:00 time zone
private static final ZoneId ZONE_ID = ZoneId.of("+03:00");
public AstroStateTest(String thingID, String channelId, State expectedState) {
this.thingID = thingID;
this.channelId = channelId;
this.expectedState = expectedState;
}
@Parameters
public static List<Object[]> data() {
AstroParametrizedTestCases cases = new AstroParametrizedTestCases();
return cases.getCases();
}
@Test
public void testParametrized() {
try {
assertStateUpdate(thingID, channelId, expectedState);
} catch (Exception e) {
// do nothing
}
}
private void assertStateUpdate(String thingID, String channelId, State expectedState) throws Exception {
ChannelUID testItemChannelUID = new ChannelUID(getThingUID(thingID), channelId);
State state = PropertyUtils.getState(testItemChannelUID, new AstroChannelConfig(), getPlanet(thingID), ZONE_ID);
assertEquals(expectedState, state);
}
private ThingUID getThingUID(String thingID) {
switch (thingID) {
case (TEST_SUN_THING_ID):
return new ThingUID(THING_TYPE_SUN, thingID);
case (TEST_MOON_THING_ID):
return new ThingUID(THING_TYPE_MOON, thingID);
default:
return null;
}
}
private Planet getPlanet(String thingID) {
LocalDateTime time = LocalDateTime.of(TEST_YEAR, TEST_MONTH, TEST_DAY, 0, 0);
ZonedDateTime zonedTime = ZonedDateTime.ofLocal(time, ZONE_ID, null);
Calendar calendar = GregorianCalendar.from(zonedTime);
switch (thingID) {
case (TEST_SUN_THING_ID):
SunCalc sunCalc = new SunCalc();
return sunCalc.getSunInfo(calendar, TEST_LATITUDE, TEST_LONGITUDE, null, false);
case (TEST_MOON_THING_ID):
MoonCalc moonCalc = new MoonCalc();
return moonCalc.getMoonInfo(calendar, TEST_LATITUDE, TEST_LONGITUDE);
default:
return null;
}
}
}

View File

@@ -0,0 +1,35 @@
/**
* 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.astro.test.cases;
import java.math.BigDecimal;
/**
* Contains some test data used across different tests
*
* @author Svilen Valkanov - Initial implementation
* @author Christoph Weitkamp - Migrated tests to pure Java
*/
public final class AstroBindingTestsData {
public static final String TEST_SUN_THING_ID = "testSunThingId";
public static final String TEST_MOON_THING_ID = "testMoonThingId";
public static final String TEST_ITEM_NAME = "testItem";
public static final String DEFAULT_IMEM_TYPE = "DateTime";
public static final String DEFAULT_TEST_CHANNEL_ID = "rise#start";
public static final String GEOLOCATION_PROPERTY = "geolocation";
public static final String GEOLOCATION_VALUE = "51.2,25.4";
public static final String INTERVAL_PROPERTY = "interval";
public static final BigDecimal INTERVAL_DEFAULT_VALUE = new BigDecimal(300);
}

View File

@@ -0,0 +1,218 @@
/**
* 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.astro.test.cases;
import static org.openhab.binding.astro.test.cases.AstroBindingTestsData.*;
import java.util.Arrays;
import java.util.List;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.binding.astro.test.AstroStateTest;
/**
* Test cases used in the {@link AstroStateTest}
*
* @author Petar Valchev - Initial contribution
* @author Svilen Valakanov - Added test data from
* <a href="http://www.suncalc.net">http://www.suncalc.net</a> and
* <a href="http://www.mooncalc.org">http://www.mooncalc.org</a>
* @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
* @author Christoph Weitkamp - Introduced UoM and migrated tests to pure Java
*/
public final class AstroParametrizedTestCases {
public static final double TEST_LATITUDE = 22.4343;
public static final double TEST_LONGITUDE = 54.3225;
public static final int TEST_YEAR = 2016;
public static final int TEST_MONTH = 2;
public static final int TEST_DAY = 29;
public Object[][] cases = new Object[42][3];
public AstroParametrizedTestCases() {
cases[0][0] = TEST_SUN_THING_ID;
cases[0][1] = "rise#start";
cases[0][2] = new DateTimeType("2016-02-29T05:46:00+03:00");
cases[1][0] = TEST_SUN_THING_ID;
cases[1][1] = "rise#end";
cases[1][2] = new DateTimeType("2016-02-29T05:48:00+03:00");
cases[2][0] = TEST_SUN_THING_ID;
cases[2][1] = "rise#duration";
cases[2][2] = new QuantityType<>(2, SmartHomeUnits.MINUTE);
cases[3][0] = TEST_SUN_THING_ID;
cases[3][1] = "set#start";
cases[3][2] = new DateTimeType("2016-02-29T17:25:00+03:00");
cases[4][0] = TEST_SUN_THING_ID;
cases[4][1] = "set#end";
cases[4][2] = new DateTimeType("2016-02-29T17:27:00+03:00");
cases[5][0] = TEST_SUN_THING_ID;
cases[5][1] = "set#duration";
cases[5][2] = new QuantityType<>(2, SmartHomeUnits.MINUTE);
cases[6][0] = TEST_SUN_THING_ID;
cases[6][1] = "noon#start";
cases[6][2] = new DateTimeType("2016-02-29T11:37:00+03:00");
cases[7][0] = TEST_SUN_THING_ID;
cases[7][1] = "noon#end";
cases[7][2] = new DateTimeType("2016-02-29T11:38:00+03:00");
cases[8][0] = TEST_SUN_THING_ID;
cases[8][1] = "noon#duration";
cases[8][2] = new QuantityType<>(1, SmartHomeUnits.MINUTE);
cases[9][0] = TEST_SUN_THING_ID;
cases[9][1] = "night#start";
cases[9][2] = new DateTimeType("2016-02-29T18:42:00+03:00");
cases[10][0] = TEST_SUN_THING_ID;
cases[10][1] = "night#end";
cases[10][2] = new DateTimeType("2016-03-01T04:31:00+03:00");
cases[11][0] = TEST_SUN_THING_ID;
cases[11][1] = "night#duration";
cases[11][2] = new QuantityType<>(589, SmartHomeUnits.MINUTE);
cases[12][0] = TEST_SUN_THING_ID;
cases[12][1] = "morningNight#start";
cases[12][2] = new DateTimeType("2016-02-29T00:00:00+03:00");
cases[13][0] = TEST_SUN_THING_ID;
cases[13][1] = "morningNight#end";
cases[13][2] = new DateTimeType("2016-02-29T04:32:00+03:00");
cases[14][0] = TEST_SUN_THING_ID;
cases[14][1] = "morningNight#duration";
cases[14][2] = new QuantityType<>(272, SmartHomeUnits.MINUTE);
cases[15][0] = TEST_SUN_THING_ID;
cases[15][1] = "astroDawn#start";
cases[15][2] = new DateTimeType("2016-02-29T04:32:00+03:00");
cases[16][0] = TEST_SUN_THING_ID;
cases[16][1] = "astroDawn#end";
cases[16][2] = new DateTimeType("2016-02-29T04:58:00+03:00");
cases[17][0] = TEST_SUN_THING_ID;
cases[17][1] = "astroDawn#duration";
cases[17][2] = new QuantityType<>(26, SmartHomeUnits.MINUTE);
cases[18][0] = TEST_SUN_THING_ID;
cases[18][1] = "nauticDawn#start";
cases[18][2] = new DateTimeType("2016-02-29T04:58:00+03:00");
cases[19][0] = TEST_SUN_THING_ID;
cases[19][1] = "nauticDawn#end";
cases[19][2] = new DateTimeType("2016-02-29T05:24:00+03:00");
cases[20][0] = TEST_SUN_THING_ID;
cases[20][1] = "nauticDawn#duration";
cases[20][2] = new QuantityType<>(26, SmartHomeUnits.MINUTE);
cases[21][0] = TEST_SUN_THING_ID;
cases[21][1] = "civilDawn#start";
cases[21][2] = new DateTimeType("2016-02-29T05:24:00+03:00");
cases[22][0] = TEST_SUN_THING_ID;
cases[22][1] = "civilDawn#end";
cases[22][2] = new DateTimeType("2016-02-29T05:46:00+03:00");
cases[23][0] = TEST_SUN_THING_ID;
cases[23][1] = "civilDawn#duration";
cases[23][2] = new QuantityType<>(22, SmartHomeUnits.MINUTE);
cases[24][0] = TEST_SUN_THING_ID;
cases[24][1] = "astroDusk#start";
cases[24][2] = new DateTimeType("2016-02-29T18:16:00+03:00");
cases[25][0] = TEST_SUN_THING_ID;
cases[25][1] = "astroDusk#end";
cases[25][2] = new DateTimeType("2016-02-29T18:42:00+03:00");
cases[26][0] = TEST_SUN_THING_ID;
cases[26][1] = "astroDusk#duration";
cases[26][2] = new QuantityType<>(26, SmartHomeUnits.MINUTE);
cases[27][0] = TEST_SUN_THING_ID;
cases[27][1] = "nauticDusk#start";
cases[27][2] = new DateTimeType("2016-02-29T17:50:00+03:00");
cases[28][0] = TEST_SUN_THING_ID;
cases[28][1] = "nauticDusk#end";
cases[28][2] = new DateTimeType("2016-02-29T18:16:00+03:00");
cases[29][0] = TEST_SUN_THING_ID;
cases[29][1] = "nauticDusk#duration";
cases[29][2] = new QuantityType<>(26, SmartHomeUnits.MINUTE);
cases[30][0] = TEST_SUN_THING_ID;
cases[30][1] = "civilDusk#start";
cases[30][2] = new DateTimeType("2016-02-29T17:27:00+03:00");
cases[31][0] = TEST_SUN_THING_ID;
cases[31][1] = "civilDusk#end";
cases[31][2] = new DateTimeType("2016-02-29T17:50:00+03:00");
cases[32][0] = TEST_SUN_THING_ID;
cases[32][1] = "civilDusk#duration";
cases[32][2] = new QuantityType<>(23, SmartHomeUnits.MINUTE);
cases[33][0] = TEST_SUN_THING_ID;
cases[33][1] = "eveningNight#start";
cases[33][2] = new DateTimeType("2016-02-29T18:42:00+03:00");
cases[34][0] = TEST_SUN_THING_ID;
cases[34][1] = "eveningNight#end";
cases[34][2] = new DateTimeType("2016-03-01T00:00:00+03:00");
cases[35][0] = TEST_SUN_THING_ID;
cases[35][1] = "eveningNight#duration";
cases[35][2] = new QuantityType<>(318, SmartHomeUnits.MINUTE);
cases[36][0] = TEST_SUN_THING_ID;
cases[36][1] = "daylight#start";
cases[36][2] = new DateTimeType("2016-02-29T05:48:00+03:00");
cases[37][0] = TEST_SUN_THING_ID;
cases[37][1] = "daylight#end";
cases[37][2] = new DateTimeType("2016-02-29T17:25:00+03:00");
cases[38][0] = TEST_SUN_THING_ID;
cases[38][1] = "daylight#duration";
cases[38][2] = new QuantityType<>(697, SmartHomeUnits.MINUTE);
cases[39][0] = TEST_MOON_THING_ID;
cases[39][1] = "rise#start";
cases[39][2] = new DateTimeType("2016-02-29T23:00:00+03:00");
cases[40][0] = TEST_MOON_THING_ID;
cases[40][1] = "rise#end";
cases[40][2] = new DateTimeType("2016-02-29T23:00:00+03:00");
cases[41][0] = TEST_MOON_THING_ID;
cases[41][1] = "rise#duration";
cases[41][2] = new QuantityType<>(0, SmartHomeUnits.MINUTE);
}
public List<Object[]> getCases() {
return Arrays.asList(cases);
}
}