]> git.basschouten.com Git - openhab-addons.git/blob
ec62616afcea6181cb191140f4bafa337835a082
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.NonNull;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.junit.jupiter.api.BeforeAll;
21 import org.junit.jupiter.api.TestInfo;
22 import org.openhab.core.library.items.PlayerItem;
23 import org.openhab.core.library.types.RewindFastforwardType;
24 import org.openhab.core.types.State;
25
26 /**
27  *
28  * @author Sami Salonen - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class PlayerItemRewindFastForwardIntegrationTest extends AbstractTwoItemIntegrationTest {
33
34     public static final boolean LEGACY_MODE = false;
35     private static final String NAME = "player_rewindfastforward";
36
37     private static @Nullable RewindFastforwardType STATE1, STATE2;
38     private static final @Nullable RewindFastforwardType STATE_BETWEEN = null;
39
40     @SuppressWarnings("null")
41     @BeforeAll
42     public static void storeData(TestInfo testInfo) throws InterruptedException {
43         @NonNull
44         RewindFastforwardType localState1, localState2;
45         if (isLegacyTest(testInfo)) {
46             // In legacy, FASTFORWARD < REWIND
47             STATE1 = RewindFastforwardType.FASTFORWARD;
48             STATE2 = RewindFastforwardType.REWIND;
49         } else {
50             // In non-legacy, FASTFORWARD (serialized as 1) > REWIND (-1)
51             STATE1 = RewindFastforwardType.REWIND;
52             STATE2 = RewindFastforwardType.FASTFORWARD;
53         }
54         localState1 = (@NonNull RewindFastforwardType) STATE1;
55         localState2 = (@NonNull RewindFastforwardType) STATE2;
56         assert localState1 != null;
57         assert localState2 != null;
58
59         PlayerItem item = (PlayerItem) ITEMS.get(NAME);
60
61         item.setState(localState1);
62
63         beforeStore = ZonedDateTime.now();
64         Thread.sleep(10);
65         service.store(item);
66         afterStore1 = ZonedDateTime.now();
67         Thread.sleep(10);
68         item.setState(localState2);
69         service.store(item);
70         Thread.sleep(10);
71         afterStore2 = ZonedDateTime.now();
72
73         LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore),
74                 AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
75     }
76
77     @Override
78     protected String getItemName() {
79         return NAME;
80     }
81
82     @Override
83     protected State getFirstItemState() {
84         return (@NonNull RewindFastforwardType) STATE1;
85     }
86
87     @Override
88     protected State getSecondItemState() {
89         return (@NonNull RewindFastforwardType) STATE2;
90     }
91
92     @Override
93     protected @Nullable State getQueryItemStateBetween() {
94         return STATE_BETWEEN;
95     }
96 }