]> git.basschouten.com Git - openhab-addons.git/blob
88814ea0a0b6b1c549a5a969d78c5c48f2fbabf8
[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.persistence.dynamodb.internal;
14
15 import static org.junit.jupiter.api.Assertions.assertTrue;
16
17 import java.math.BigDecimal;
18 import java.time.ZonedDateTime;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.junit.jupiter.api.BeforeAll;
23 import org.openhab.core.library.items.RollershutterItem;
24 import org.openhab.core.library.types.DecimalType;
25 import org.openhab.core.library.types.PercentType;
26 import org.openhab.core.types.State;
27
28 /**
29  *
30  * @author Sami Salonen - Initial contribution
31  *
32  */
33 @NonNullByDefault
34 public class RollershutterItemIntegrationTest extends AbstractTwoItemIntegrationTest {
35
36     private static final String NAME = "rollershutter";
37     private static final PercentType STATE1 = PercentType.ZERO;
38     private static final PercentType STATE2 = new PercentType("72.938289428989489389329834898929892439842399483498");
39     private static final PercentType STATE_BETWEEN = new PercentType(66); // no such that exists
40
41     @BeforeAll
42     public static void storeData() throws InterruptedException {
43         RollershutterItem item = (RollershutterItem) ITEMS.get(NAME);
44         item.setState(STATE1);
45         beforeStore = ZonedDateTime.now();
46         Thread.sleep(10);
47         service.store(item);
48         afterStore1 = ZonedDateTime.now();
49         Thread.sleep(10);
50         item.setState(STATE2);
51         service.store(item);
52         Thread.sleep(10);
53         afterStore2 = ZonedDateTime.now();
54
55         LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
56                 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
57     }
58
59     @Override
60     protected String getItemName() {
61         return NAME;
62     }
63
64     @Override
65     protected State getFirstItemState() {
66         return STATE1;
67     }
68
69     @Override
70     protected State getSecondItemState() {
71         return STATE2;
72     }
73
74     @Override
75     protected @Nullable State getQueryItemStateBetween() {
76         return STATE_BETWEEN;
77     }
78
79     /**
80      * Use relaxed state comparison due to numerical rounding. See also DynamoDBBigDecimalItem.loseDigits
81      */
82     @Override
83     protected void assertStateEquals(State expected, State actual) {
84         BigDecimal expectedDecimal = ((DecimalType) expected).toBigDecimal();
85         BigDecimal actualDecimal = ((DecimalType) actual).toBigDecimal();
86         assertTrue(DynamoDBBigDecimalItem.loseDigits(expectedDecimal).compareTo(actualDecimal) == 0);
87     }
88 }