2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.webservice.api.json;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.mielecloud.internal.util.ResourceUtil.getResourceAsString;
18 import java.io.IOException;
19 import java.util.List;
20 import java.util.Optional;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
27 * @author Björn Lange - Initial contribution
30 public class ActionsCollectionTest {
32 public void canCreateActionsCollection() throws IOException {
34 String json = getResourceAsString(
35 "/org/openhab/binding/mielecloud/internal/webservice/api/json/actionsCollection.json");
38 ActionsCollection collection = ActionsCollection.fromJson(json);
41 assertEquals(Set.of("000123456789"), collection.getDeviceIdentifiers());
42 Actions actions = collection.getActions("000123456789");
44 assertEquals(List.of(ProcessAction.START, ProcessAction.STOP), actions.getProcessAction());
45 assertEquals(List.of(Light.DISABLE), actions.getLight());
46 assertEquals(Optional.empty(), actions.getStartTime());
47 assertEquals(List.of(123), actions.getProgramId());
48 assertEquals(Optional.of(true), actions.getPowerOn());
49 assertEquals(Optional.of(false), actions.getPowerOff());
53 public void creatingActionsCollectionFromInvalidJsonThrowsMieleSyntaxException() {
55 String invalidJson = "{\":{}}";
58 assertThrows(MieleSyntaxException.class, () -> {
59 ActionsCollection.fromJson(invalidJson);
64 public void canCreateActionsCollectionWithLargeProgramID() throws IOException {
66 String json = "{\"mac-00124B000AE539D6\": {}}";
69 DeviceCollection collection = DeviceCollection.fromJson(json);
72 assertEquals(Set.of("mac-00124B000AE539D6"), collection.getDeviceIdentifiers());