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.persistence.dynamodb.internal;
15 import static org.junit.jupiter.api.Assertions.assertTrue;
17 import java.math.BigDecimal;
18 import java.time.ZonedDateTime;
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;
30 * @author Sami Salonen - Initial contribution
34 public class RollershutterItemIntegrationTest extends AbstractTwoItemIntegrationTest {
36 public static final boolean LEGACY_MODE = false;
37 private static final String NAME = "rollershutter";
38 private static final PercentType STATE1 = PercentType.ZERO;
39 private static final PercentType STATE2 = new PercentType("72.938289428989489389329834898929892439842399483498");
40 private static final PercentType STATE_BETWEEN = new PercentType(66); // no such that exists
42 @SuppressWarnings("null")
44 public static void storeData() throws InterruptedException {
45 RollershutterItem item = (RollershutterItem) ITEMS.get(NAME);
46 item.setState(STATE1);
47 beforeStore = ZonedDateTime.now();
50 afterStore1 = ZonedDateTime.now();
52 item.setState(STATE2);
55 afterStore2 = ZonedDateTime.now();
57 LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
58 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
62 protected String getItemName() {
67 protected State getFirstItemState() {
72 protected State getSecondItemState() {
77 protected @Nullable State getQueryItemStateBetween() {
82 * Use relaxed state comparison due to numerical rounding. See also DynamoDBBigDecimalItem.loseDigits
85 protected void assertStateEquals(State expected, State actual) {
86 BigDecimal expectedDecimal = ((DecimalType) expected).toBigDecimal();
87 BigDecimal actualDecimal = ((DecimalType) actual).toBigDecimal();
88 assertTrue(DynamoDBBigDecimalItem.loseDigits(expectedDecimal).compareTo(actualDecimal) == 0);