]> git.basschouten.com Git - openhab-addons.git/blob
22460fcd76f4f1d157c67dd9fa6ec68b04776112
[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 java.time.ZonedDateTime;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.junit.jupiter.api.BeforeAll;
20 import org.openhab.core.library.items.DateTimeItem;
21 import org.openhab.core.library.types.DateTimeType;
22 import org.openhab.core.types.State;
23
24 /**
25  *
26  * @author Sami Salonen - Initial contribution
27  *
28  */
29 @NonNullByDefault
30 public class DateTimeItemIntegrationTest extends AbstractTwoItemIntegrationTest {
31
32     private static final String NAME = "datetime";
33     private static final ZonedDateTime ZDT1 = ZonedDateTime.parse("2016-06-15T10:00:00Z");
34     private static final ZonedDateTime ZDT2 = ZonedDateTime.parse("2016-06-15T16:00:00.123Z");
35     private static final ZonedDateTime ZDT_BETWEEN = ZonedDateTime.parse("2016-06-15T14:00:00Z");
36
37     private static final DateTimeType STATE1 = new DateTimeType(ZDT1);
38     private static final DateTimeType STATE2 = new DateTimeType(ZDT2);
39     private static final DateTimeType STATE_BETWEEN = new DateTimeType(ZDT_BETWEEN);
40
41     @BeforeAll
42     public static void storeData() throws InterruptedException {
43         DateTimeItem item = (DateTimeItem) ITEMS.get(NAME);
44
45         item.setState(STATE1);
46
47         beforeStore = ZonedDateTime.now();
48         Thread.sleep(10);
49         service.store(item);
50         afterStore1 = ZonedDateTime.now();
51         Thread.sleep(10);
52         item.setState(STATE2);
53         service.store(item);
54         Thread.sleep(10);
55         afterStore2 = ZonedDateTime.now();
56
57         LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
58                 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
59     }
60
61     @Override
62     protected String getItemName() {
63         return NAME;
64     }
65
66     @Override
67     protected State getFirstItemState() {
68         return STATE1;
69     }
70
71     @Override
72     protected State getSecondItemState() {
73         return STATE2;
74     }
75
76     @Override
77     protected @Nullable State getQueryItemStateBetween() {
78         return STATE_BETWEEN;
79     }
80 }