]> git.basschouten.com Git - openhab-addons.git/blob
30c7fecd6b2402076d1126f4ed7f0b4dab4f1918
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mielecloud.internal.webservice.api.json;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.mielecloud.internal.util.ResourceUtil.getResourceAsString;
17
18 import java.io.IOException;
19 import java.util.List;
20 import java.util.Optional;
21 import java.util.Set;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
25
26 /**
27  * @author Björn Lange - Initial contribution
28  */
29 @NonNullByDefault
30 public class ActionsCollectionTest {
31     @Test
32     public void canCreateActionsCollection() throws IOException {
33         // given:
34         String json = getResourceAsString(
35                 "/org/openhab/binding/mielecloud/internal/webservice/api/json/actionsCollection.json");
36
37         // when:
38         ActionsCollection collection = ActionsCollection.fromJson(json);
39
40         // then:
41         assertEquals(Set.of("000123456789"), collection.getDeviceIdentifiers());
42         Actions actions = collection.getActions("000123456789");
43
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());
50     }
51
52     @Test
53     public void creatingActionsCollectionFromInvalidJsonThrowsMieleSyntaxException() {
54         // given:
55         String invalidJson = "{\":{}}";
56
57         // when:
58         assertThrows(MieleSyntaxException.class, () -> {
59             ActionsCollection.fromJson(invalidJson);
60         });
61     }
62
63     @Test
64     public void canCreateActionsCollectionWithLargeProgramID() throws IOException {
65         // given:
66         String json = "{\"mac-00124B000AE539D6\": {}}";
67
68         // when:
69         DeviceCollection collection = DeviceCollection.fromJson(json);
70
71         // then:
72         assertEquals(Set.of("mac-00124B000AE539D6"), collection.getDeviceIdentifiers());
73     }
74 }