]> git.basschouten.com Git - openhab-addons.git/blob
6faf0dce30f99f1936295cbf0221fa9892e8a8eb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.ContactItem;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.library.types.OpenClosedType;
23 import org.openhab.core.types.State;
24
25 /**
26  * @author Sami Salonen - Initial contribution
27  */
28 @NonNullByDefault
29 public class ContactItemIntegrationTest extends AbstractTwoItemIntegrationTest {
30
31     private static final String NAME = "contact";
32     private static final OpenClosedType STATE1 = OpenClosedType.CLOSED;
33     private static final OpenClosedType STATE2 = OpenClosedType.OPEN;
34     // There is no OpenClosedType state value between CLOSED and OPEN.
35     // Omit extended query tests AbstractTwoItemIntegrationTest by setting stateBetween to null.
36     private static final @Nullable OnOffType STATE_BETWEEN = null;
37
38     @BeforeAll
39     public static void storeData() throws InterruptedException {
40         ContactItem item = (ContactItem) ITEMS.get(NAME);
41         item.setState(STATE1);
42         beforeStore = ZonedDateTime.now();
43         Thread.sleep(10);
44         service.store(item);
45         afterStore1 = ZonedDateTime.now();
46         Thread.sleep(10);
47         item.setState(STATE2);
48         service.store(item);
49         Thread.sleep(10);
50         afterStore2 = ZonedDateTime.now();
51
52         LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
53                 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
54     }
55
56     @Override
57     protected String getItemName() {
58         return NAME;
59     }
60
61     @Override
62     protected State getFirstItemState() {
63         return STATE1;
64     }
65
66     @Override
67     protected State getSecondItemState() {
68         return STATE2;
69     }
70
71     @Override
72     protected @Nullable State getQueryItemStateBetween() {
73         return STATE_BETWEEN;
74     }
75 }