]> git.basschouten.com Git - openhab-addons.git/blob
d6a73caab37ab52d1a534f3759c095680cae2e0d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.nanoleaf.internal;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.junit.Assert.assertThat;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.openhab.binding.nanoleaf.internal.model.Layout;
23
24 import com.google.gson.Gson;
25
26 /**
27  * Test for the Layout
28  *
29  * @author Stefan Höhn - Initial contribution
30  */
31
32 @NonNullByDefault
33 public class LayoutTest {
34
35     private final Gson gson = new Gson();
36     String layout1Json = "";
37     String layoutInconsistentPanelNoJson = "";
38
39     @Before
40     public void setup() {
41         layout1Json = "{\"numPanels\":14,\"sideLength\":100,\"positionData\":[{\"panelId\":41451,\"x\":350,\"y\":0,\"o\":0,\"shapeType\":3},{\"panelId\":8134,\"x\":350,\"y\":150,\"o\":0,\"shapeType\":2},{\"panelId\":58086,\"x\":200,\"y\":100,\"o\":270,\"shapeType\":2},{\"panelId\":38724,\"x\":300,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":48111,\"x\":200,\"y\":200,\"o\":270,\"shapeType\":2},{\"panelId\":56093,\"x\":100,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":55836,\"x\":0,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":31413,\"x\":100,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":9162,\"x\":300,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":13276,\"x\":400,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":17870,\"x\":400,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":5164,\"x\":500,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":64279,\"x\":600,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":39755,\"x\":500,\"y\":100,\"o\":90,\"shapeType\":2}]}";
42         // panel number is not consistent to returned panels in array but it should still work
43         layoutInconsistentPanelNoJson = "{\"numPanels\":15,\"sideLength\":100,\"positionData\":[{\"panelId\":41451,\"x\":350,\"y\":0,\"o\":0,\"shapeType\":3},{\"panelId\":8134,\"x\":350,\"y\":150,\"o\":0,\"shapeType\":2},{\"panelId\":58086,\"x\":200,\"y\":100,\"o\":270,\"shapeType\":2},{\"panelId\":38724,\"x\":300,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":48111,\"x\":200,\"y\":200,\"o\":270,\"shapeType\":2},{\"panelId\":56093,\"x\":100,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":55836,\"x\":0,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":31413,\"x\":100,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":9162,\"x\":300,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":13276,\"x\":400,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":17870,\"x\":400,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":5164,\"x\":500,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":64279,\"x\":600,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":39755,\"x\":500,\"y\":100,\"o\":90,\"shapeType\":2}]}";
44     }
45
46     @Test
47     public void testTheRightLayoutView() {
48         @Nullable
49         Layout layout = gson.fromJson(layout1Json, Layout.class);
50         String layoutView = layout.getLayoutView();
51         assertThat(layoutView,
52                 is(equalTo("            31413                    9162       13276                         \n"
53                         + "                                                                              \n"
54                         + "55836       56093       48111       38724       17870        5164       64279 \n"
55                         + "                                           8134                               \n"
56                         + "                        58086                               39755             \n"
57                         + "                                                                              \n"
58                         + "                                          41451                               \n")));
59     }
60
61     @Test
62     public void testTheInconsistentLayoutView() {
63         @Nullable
64         Layout layout = gson.fromJson(layoutInconsistentPanelNoJson, Layout.class);
65         String layoutView = layout.getLayoutView();
66         assertThat(layoutView,
67                 is(equalTo("            31413                    9162       13276                         \n"
68                         + "                                                                              \n"
69                         + "55836       56093       48111       38724       17870        5164       64279 \n"
70                         + "                                           8134                               \n"
71                         + "                        58086                               39755             \n"
72                         + "                                                                              \n"
73                         + "                                          41451                               \n")));
74     }
75 }