]> git.basschouten.com Git - openhab-addons.git/blob
9fe988d5fa2a5af59263f4bc419b90336c232314
[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.persistence.dynamodb.internal;
14
15 import java.math.BigDecimal;
16 import java.time.ZonedDateTime;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.junit.jupiter.api.BeforeAll;
21 import org.openhab.core.library.items.ColorItem;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.HSBType;
24 import org.openhab.core.library.types.PercentType;
25 import org.openhab.core.types.State;
26
27 /**
28  *
29  * @author Sami Salonen - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class ColorItemIntegrationTest extends AbstractTwoItemIntegrationTest {
34
35     public static final boolean LEGACY_MODE = false;
36
37     private static HSBType color(double hue, int saturation, int brightness) {
38         return new HSBType(new DecimalType(hue), new PercentType(saturation), new PercentType(brightness));
39     }
40
41     private static HSBType color(String hue, int saturation, int brightness) {
42         return new HSBType(new DecimalType(new BigDecimal(hue)), new PercentType(saturation),
43                 new PercentType(brightness));
44     }
45
46     private static final String NAME = "color";
47     // values are encoded as <hue>,<saturation>,<brightness>, ordering goes wrt strings
48     private static final HSBType STATE1 = color("3.1493842988948932984298384892384823984923849238492839483294893", 50,
49             50);
50     private static final HSBType STATE2 = color(75, 100, 90);
51     private static final HSBType STATE_BETWEEN = color(60, 50, 50);
52
53     @SuppressWarnings("null")
54     @BeforeAll
55     public static void storeData() throws InterruptedException {
56         ColorItem item = (ColorItem) ITEMS.get(NAME);
57         item.setState(STATE1);
58         beforeStore = ZonedDateTime.now();
59         Thread.sleep(10);
60         service.store(item);
61         afterStore1 = ZonedDateTime.now();
62         Thread.sleep(10);
63         item.setState(STATE2);
64         service.store(item);
65         Thread.sleep(10);
66         afterStore2 = ZonedDateTime.now();
67
68         LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
69                 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
70     }
71
72     @Override
73     protected String getItemName() {
74         return NAME;
75     }
76
77     @Override
78     protected State getFirstItemState() {
79         return STATE1;
80     }
81
82     @Override
83     protected State getSecondItemState() {
84         return STATE2;
85     }
86
87     @Override
88     protected @Nullable State getQueryItemStateBetween() {
89         return STATE_BETWEEN;
90     }
91 }