2 * Copyright (c) 2010-2021 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 private static final String NAME = "number";
36 // On purpose we have super accurate number here (testing limits of aws)
37 private static final DecimalType STATE1 = new DecimalType(new BigDecimal(
38 "-32343243.193490838904389298049802398048923849032809483209483209482309840239840932840932849083094809483"));
39 private static final DecimalType STATE2 = new DecimalType(600.9123);
40 private static final DecimalType STATE_BETWEEN = new DecimalType(500);
43 public static void storeData() throws InterruptedException {
44 NumberItem item = (NumberItem) ITEMS.get(NAME);
46 item.setState(STATE1);
48 beforeStore = ZonedDateTime.now();
51 afterStore1 = ZonedDateTime.now();
53 item.setState(STATE2);
56 afterStore2 = ZonedDateTime.now();
58 LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
59 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
63 protected String getItemName() {
68 protected State getFirstItemState() {
73 protected State getSecondItemState() {
78 protected @Nullable State getQueryItemStateBetween() {
83 * Use relaxed state comparison due to numerical rounding. See also DynamoDBBigDecimalItem.loseDigits
86 protected void assertStateEquals(State expected, State actual) {
87 BigDecimal expectedDecimal = ((DecimalType) expected).toBigDecimal();
88 BigDecimal actualDecimal = ((DecimalType) actual).toBigDecimal();
89 assertTrue(DynamoDBBigDecimalItem.loseDigits(expectedDecimal).compareTo(actualDecimal) == 0);