2 * Copyright (c) 2010-2020 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 java.util.Collection;
16 import java.util.HashMap;
18 import java.util.Map.Entry;
19 import java.util.stream.Stream;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.junit.jupiter.api.BeforeAll;
24 import org.openhab.core.common.registry.RegistryChangeListener;
25 import org.openhab.core.items.Item;
26 import org.openhab.core.items.ItemNotFoundException;
27 import org.openhab.core.items.ItemNotUniqueException;
28 import org.openhab.core.items.ItemRegistry;
29 import org.openhab.core.items.RegistryHook;
30 import org.openhab.core.library.items.CallItem;
31 import org.openhab.core.library.items.ColorItem;
32 import org.openhab.core.library.items.ContactItem;
33 import org.openhab.core.library.items.DateTimeItem;
34 import org.openhab.core.library.items.DimmerItem;
35 import org.openhab.core.library.items.LocationItem;
36 import org.openhab.core.library.items.NumberItem;
37 import org.openhab.core.library.items.PlayerItem;
38 import org.openhab.core.library.items.RollershutterItem;
39 import org.openhab.core.library.items.StringItem;
40 import org.openhab.core.library.items.SwitchItem;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
44 import com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException;
48 * @author Sami Salonen - Initial contribution
52 public class BaseIntegrationTest {
53 protected static final Logger LOGGER = LoggerFactory.getLogger(DynamoDBPersistenceService.class);
54 protected static @Nullable DynamoDBPersistenceService service;
55 protected static final Map<String, Item> ITEMS = new HashMap<>();
58 System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace");
62 public static void initService() throws InterruptedException {
63 ITEMS.put("dimmer", new DimmerItem("dimmer"));
64 ITEMS.put("number", new NumberItem("number"));
65 ITEMS.put("string", new StringItem("string"));
66 ITEMS.put("switch", new SwitchItem("switch"));
67 ITEMS.put("contact", new ContactItem("contact"));
68 ITEMS.put("color", new ColorItem("color"));
69 ITEMS.put("rollershutter", new RollershutterItem("rollershutter"));
70 ITEMS.put("datetime", new DateTimeItem("datetime"));
71 ITEMS.put("call", new CallItem("call"));
72 ITEMS.put("location", new LocationItem("location"));
73 ITEMS.put("player_playpause", new PlayerItem("player_playpause"));
74 ITEMS.put("player_rewindfastforward", new PlayerItem("player_rewindfastforward"));
76 service = new DynamoDBPersistenceService(new ItemRegistry() {
78 public Collection<Item> getItems(String pattern) {
79 throw new UnsupportedOperationException();
83 public Collection<Item> getItems() {
84 throw new UnsupportedOperationException();
88 public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException {
89 throw new UnsupportedOperationException();
93 public Item getItem(String name) throws ItemNotFoundException {
94 Item item = ITEMS.get(name);
96 throw new ItemNotFoundException(name);
102 public void addRegistryChangeListener(RegistryChangeListener<Item> listener) {
103 throw new UnsupportedOperationException();
107 public Collection<Item> getAll() {
108 throw new UnsupportedOperationException();
112 public Stream<Item> stream() {
113 throw new UnsupportedOperationException();
117 public @Nullable Item get(String key) {
118 throw new UnsupportedOperationException();
122 public void removeRegistryChangeListener(RegistryChangeListener<Item> listener) {
123 throw new UnsupportedOperationException();
127 public Item add(Item element) {
128 throw new UnsupportedOperationException();
132 public @Nullable Item update(Item element) {
133 throw new UnsupportedOperationException();
137 public @Nullable Item remove(String key) {
138 throw new UnsupportedOperationException();
142 public Collection<Item> getItemsOfType(String type) {
143 throw new UnsupportedOperationException();
147 public Collection<Item> getItemsByTag(String... tags) {
148 throw new UnsupportedOperationException();
152 public Collection<Item> getItemsByTagAndType(String type, String... tags) {
153 throw new UnsupportedOperationException();
157 public <T extends Item> Collection<T> getItemsByTag(Class<T> typeFilter, String... tags) {
158 throw new UnsupportedOperationException();
162 public @Nullable Item remove(String itemName, boolean recursive) {
163 throw new UnsupportedOperationException();
167 public void addRegistryHook(RegistryHook<Item> hook) {
168 throw new UnsupportedOperationException();
172 public void removeRegistryHook(RegistryHook<Item> hook) {
173 throw new UnsupportedOperationException();
177 Map<String, Object> config = new HashMap<>();
178 String value = System.getProperty("DYNAMODBTEST_REGION");
179 config.put("region", value != null ? value : "");
180 value = System.getProperty("DYNAMODBTEST_ACCESS");
181 config.put("accessKey", value != null ? value : "");
182 value = System.getProperty("DYNAMODBTEST_SECRET");
183 config.put("secretKey", value != null ? value : "");
184 config.put("tablePrefix", "dynamodb-integration-tests-");
187 config.put("bufferSize", "0");
189 for (Entry<String, Object> entry : config.entrySet()) {
190 if (((String) entry.getValue()).isEmpty()) {
191 LOGGER.warn(String.format(
192 "Expecting %s to have value for integration tests. Integration tests will be skipped",
199 service.activate(null, config);
203 protected static void clearData() {
205 for (String table : new String[] { "dynamodb-integration-tests-bigdecimal",
206 "dynamodb-integration-tests-string" }) {
208 service.getDb().getDynamoClient().deleteTable(table);
209 service.getDb().getDynamoDB().getTable(table).waitForDelete();
210 } catch (ResourceNotFoundException e) {
211 } catch (InterruptedException e) {
212 LOGGER.warn("Interrupted! Table might not have been deleted");