added migrated 2.x add-ons
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* 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.millheat.internal;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.openhab.binding.millheat.internal.config.MillheatAccountConfiguration;
|
||||
import org.openhab.binding.millheat.internal.handler.MillheatAccountHandler;
|
||||
import org.openhab.binding.millheat.internal.model.MillheatModel;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
|
||||
/**
|
||||
* @author Arne Seime - Initial contribution
|
||||
*/
|
||||
public class MillHeatAccountHandlerTest {
|
||||
@Rule
|
||||
public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.options().dynamicPort());
|
||||
|
||||
@Mock
|
||||
private Bridge millheatAccountMock;
|
||||
|
||||
private HttpClient httpClient;
|
||||
@Mock
|
||||
private Configuration configuration;
|
||||
|
||||
@Mock
|
||||
private BundleContext bundleContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
httpClient = new HttpClient();
|
||||
httpClient.start();
|
||||
MillheatAccountHandler.authEndpoint = "http://localhost:" + wireMockRule.port() + "/zc-account/v1/";
|
||||
MillheatAccountHandler.serviceEndpoint = "http://localhost:" + wireMockRule.port() + "/millService/v1/";
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() throws Exception {
|
||||
httpClient.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateModel() throws InterruptedException, IOException, MillheatCommunicationException {
|
||||
final String getHomesResponse = IOUtils.toString(getClass().getResourceAsStream("/select_home_list_ok.json"));
|
||||
final String getRoomsByHomeResponse = IOUtils
|
||||
.toString(getClass().getResourceAsStream("/get_rooms_by_home_ok.json"));
|
||||
final String getDeviceByRoomResponse = IOUtils
|
||||
.toString(getClass().getResourceAsStream("/get_device_by_room_ok.json"));
|
||||
final String getIndependentDevicesResponse = IOUtils
|
||||
.toString(getClass().getResourceAsStream("/get_independent_devices_ok.json"));
|
||||
|
||||
stubFor(post(urlEqualTo("/millService/v1/selectHomeList"))
|
||||
.willReturn(aResponse().withStatus(200).withBody(getHomesResponse)));
|
||||
stubFor(post(urlEqualTo("/millService/v1/selectRoombyHome"))
|
||||
.willReturn(aResponse().withStatus(200).withBody(getRoomsByHomeResponse)));
|
||||
stubFor(post(urlEqualTo("/millService/v1/selectDevicebyRoom"))
|
||||
.willReturn(aResponse().withStatus(200).withBody(getDeviceByRoomResponse)));
|
||||
stubFor(post(urlEqualTo("/millService/v1/getIndependentDevices"))
|
||||
.willReturn(aResponse().withStatus(200).withBody(getIndependentDevicesResponse)));
|
||||
|
||||
when(millheatAccountMock.getConfiguration()).thenReturn(configuration);
|
||||
when(millheatAccountMock.getUID()).thenReturn(new ThingUID("millheat:account:thinguid"));
|
||||
|
||||
final MillheatAccountConfiguration accountConfig = new MillheatAccountConfiguration();
|
||||
accountConfig.username = "username";
|
||||
accountConfig.password = "password";
|
||||
when(configuration.as(eq(MillheatAccountConfiguration.class))).thenReturn(accountConfig);
|
||||
|
||||
final MillheatAccountHandler subject = new MillheatAccountHandler(millheatAccountMock, httpClient,
|
||||
bundleContext);
|
||||
MillheatModel model = subject.refreshModel();
|
||||
Assert.assertEquals(1, model.getHomes().size());
|
||||
|
||||
verify(postRequestedFor(urlMatching("/millService/v1/selectHomeList")));
|
||||
verify(postRequestedFor(urlMatching("/millService/v1/selectRoombyHome")));
|
||||
verify(postRequestedFor(urlMatching("/millService/v1/selectDevicebyRoom")));
|
||||
verify(postRequestedFor(urlMatching("/millService/v1/getIndependentDevices")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"always": 0,
|
||||
"backMinute": 0,
|
||||
"roomProgramId": 3242342342324,
|
||||
"controlSource": "0,0,0",
|
||||
"comfortTemp": 20,
|
||||
"roomProgram": "Kontor",
|
||||
"awayTemp": 10,
|
||||
"holidayTemp": 10,
|
||||
"avgTemp": 15.0,
|
||||
"roomId": 23423423423423,
|
||||
"roomName": "Kontor",
|
||||
"deviceInfo": [
|
||||
{
|
||||
"heaterFlag": 0,
|
||||
"subDomainId": 242424,
|
||||
"controlType": 0,
|
||||
"currentTemp": 15.0,
|
||||
"canChangeTemp": 0,
|
||||
"deviceId": 12334,
|
||||
"deviceName": "Kontor",
|
||||
"mac": "F0XXXXXXXXX",
|
||||
"deviceStatus": 0
|
||||
}
|
||||
],
|
||||
"backHour": 0,
|
||||
"currentMode": 4,
|
||||
"heatStatus": 0,
|
||||
"offLineDeviceNum": 0,
|
||||
"total": 1,
|
||||
"independentCount": 0,
|
||||
"sleepTemp": 13,
|
||||
"onlineDeviceNum": 1,
|
||||
"isOffline": 1,
|
||||
"programMode": 0
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deviceInfo": []
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"backMinute": 0,
|
||||
"offLineDeviceNum": 0,
|
||||
"mode": 0,
|
||||
"homeAlways": 0,
|
||||
"homeName": "Hjemme",
|
||||
"isHoliday": 0,
|
||||
"onlineDeviceNum": 3,
|
||||
"programList": [
|
||||
{
|
||||
"programName": "Standard Program",
|
||||
"homeId": 20190260000,
|
||||
"programId": 20190260000
|
||||
},
|
||||
{
|
||||
"programName": "Barnerom",
|
||||
"homeId": 20190260000,
|
||||
"programId": 20171231209984
|
||||
},
|
||||
{
|
||||
"programName": "Kontor",
|
||||
"homeId": 20190260000,
|
||||
"programId": 2019129984
|
||||
}
|
||||
],
|
||||
"homeType": 0,
|
||||
"backHour": 0,
|
||||
"roomInfo": [
|
||||
{
|
||||
"controlSource": "0,0,0",
|
||||
"comfortTemp": 20,
|
||||
"roomProgram": "Barnerom",
|
||||
"awayTemp": 10,
|
||||
"avgTemp": 19.0,
|
||||
"roomId": 201900000,
|
||||
"roomName": "Bedroom1",
|
||||
"currentMode": 2,
|
||||
"heatStatus": 0,
|
||||
"offLineDeviceNum": 0,
|
||||
"total": 1,
|
||||
"independentCount": 0,
|
||||
"sleepTemp": 18,
|
||||
"onlineDeviceNum": 1,
|
||||
"isOffline": 1
|
||||
},
|
||||
{
|
||||
"controlSource": "0,0,0",
|
||||
"comfortTemp": 20,
|
||||
"roomProgram": "Barnerom",
|
||||
"awayTemp": 10,
|
||||
"avgTemp": 19.0,
|
||||
"roomId": 20190207000,
|
||||
"roomName": "Bedroom2",
|
||||
"currentMode": 2,
|
||||
"heatStatus": 0,
|
||||
"offLineDeviceNum": 0,
|
||||
"total": 1,
|
||||
"independentCount": 0,
|
||||
"sleepTemp": 17,
|
||||
"onlineDeviceNum": 1,
|
||||
"isOffline": 1
|
||||
},
|
||||
{
|
||||
"controlSource": "0,0,0",
|
||||
"comfortTemp": 20,
|
||||
"roomProgram": "Kontor",
|
||||
"awayTemp": 10,
|
||||
"avgTemp": 16.0,
|
||||
"roomId": 20190000,
|
||||
"roomName": "Kontor",
|
||||
"currentMode": 5,
|
||||
"heatStatus": 0,
|
||||
"offLineDeviceNum": 0,
|
||||
"total": 1,
|
||||
"independentCount": 0,
|
||||
"sleepTemp": 13,
|
||||
"onlineDeviceNum": 1,
|
||||
"isOffline": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"description": "password is not set",
|
||||
"error": "invalid param",
|
||||
"errorCode": 3002
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"email": "email@gmail.com",
|
||||
"nickName": "Nikky",
|
||||
"phone": "",
|
||||
"refreshToken": "refreshToken",
|
||||
"refreshTokenExpire": "2019-03-20 18:13:30",
|
||||
"token": "token",
|
||||
"tokenExpire": "2019-02-18 20:13:30",
|
||||
"userId": 234324,
|
||||
"userProfile": {
|
||||
"nick_name": "Nikky",
|
||||
"privacyPolicy": 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"hourSystem": 1,
|
||||
"homeList": [
|
||||
{
|
||||
"homeAlways": 0,
|
||||
"homeName": "Hjemme",
|
||||
"isHoliday": 0,
|
||||
"holidayStartTime": 1549145440,
|
||||
"timeZone": "+01:00",
|
||||
"modeMinute": 0,
|
||||
"modeStartTime": 0,
|
||||
"holidayTemp": 10,
|
||||
"modeHour": 0,
|
||||
"currentMode": 0,
|
||||
"holidayEndTime": 1549875200,
|
||||
"homeType": 0,
|
||||
"homeId": 2019000,
|
||||
"programId": 201960000
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user