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.NumberItem;
24 import org.openhab.core.library.types.DecimalType;
25 import org.openhab.core.types.State;
29 * @author Sami Salonen - Initial contribution
33 public class NumberItemIntegrationTest extends AbstractTwoItemIntegrationTest {
35 public static final boolean LEGACY_MODE = false;
36 private static final String NAME = "number";
37 // On purpose we have super accurate number here (testing limits of aws)
38 private static final DecimalType STATE1 = new DecimalType(new BigDecimal(
39 "-32343243.193490838904389298049802398048923849032809483209483209482309840239840932840932849083094809483"));
40 private static final DecimalType STATE2 = new DecimalType(600.9123);
41 private static final DecimalType STATE_BETWEEN = new DecimalType(500);
43 @SuppressWarnings("null")
45 public static void storeData() throws InterruptedException {
46 NumberItem item = (NumberItem) ITEMS.get(NAME);
48 item.setState(STATE1);
50 beforeStore = ZonedDateTime.now();
53 afterStore1 = ZonedDateTime.now();
55 item.setState(STATE2);
58 afterStore2 = ZonedDateTime.now();
60 LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
61 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
65 protected String getItemName() {
70 protected State getFirstItemState() {
75 protected State getSecondItemState() {
80 protected @Nullable State getQueryItemStateBetween() {
85 * Use relaxed state comparison due to numerical rounding. See also DynamoDBBigDecimalItem.loseDigits
88 protected void assertStateEquals(State expected, State actual) {
89 BigDecimal expectedDecimal = ((DecimalType) expected).toBigDecimal();
90 BigDecimal actualDecimal = ((DecimalType) actual).toBigDecimal();
91 assertTrue(DynamoDBBigDecimalItem.loseDigits(expectedDecimal).compareTo(actualDecimal) == 0);