use of org.openhab.core.items.RegistryHook in project openhab-addons by openhab.
the class BaseIntegrationTest method newService.
/**
* Create new persistence service. Either pointing to real DynamoDB (given credentials as java properties) or local
* in-memory server
*
* @param legacy whether to create config that implies legacy or new schema. Use null for MAYBE_LEGACY
* @param cleanLocal when creating local DB, whether to create new DB
* @param overrideLocalURI URI to use when using local DB
* @param table
* @param tablePrefix
* @return new persistence service
*/
protected static synchronized DynamoDBPersistenceService newService(@Nullable Boolean legacy, boolean cleanLocal, @Nullable URI overrideLocalURI, @Nullable String table, @Nullable String tablePrefix) {
final DynamoDBPersistenceService service;
Map<String, Object> config = getConfig(legacy, table, tablePrefix);
if (cleanLocal && overrideLocalURI != null) {
throw new IllegalArgumentException("cannot specify both cleanLocal=true and overrideLocalURI");
}
if (legacy == null && (table != null || tablePrefix != null)) {
throw new IllegalArgumentException("cannot specify both legacy=null and unambiguous table configuration");
}
URI localEndpointOverride = overrideLocalURI == null ? endpointOverride : overrideLocalURI;
if (overrideLocalURI == null && !credentialsSet() && (cleanLocal || endpointOverride == null)) {
// Local server not started yet, start it
// endpointOverride static field has the URI
LOGGER.info("Since credentials have not been defined, using embedded local AWS DynamoDB server");
System.setProperty("sqlite4java.library.path", "src/test/resources/native-libs");
int port = findFreeTCPPort();
String endpoint = String.format("http://127.0.0.1:%d", port);
try {
localEndpointOverride = new URI(endpoint);
DynamoDBProxyServer localEmbeddedServer = ServerRunner.createServerFromCommandLineArgs(new String[] { "-inMemory", "-port", String.valueOf(port) });
localEmbeddedServer.start();
embeddedServer = localEmbeddedServer;
} catch (Exception e) {
fail("Error with embedded DynamoDB server", e);
throw new IllegalStateException();
}
}
if (endpointOverride == null) {
endpointOverride = localEndpointOverride;
}
service = new DynamoDBPersistenceService(new ItemRegistry() {
@Override
public Collection<Item> getItems(String pattern) {
throw new UnsupportedOperationException();
}
@Override
public Collection<Item> getItems() {
throw new UnsupportedOperationException();
}
@Override
public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException {
throw new UnsupportedOperationException();
}
@Override
public Item getItem(String name) throws ItemNotFoundException {
Item item = ITEMS.get(name);
if (item == null) {
throw new ItemNotFoundException(name);
}
injectItemServices(item);
return item;
}
@Override
public void addRegistryChangeListener(RegistryChangeListener<Item> listener) {
throw new UnsupportedOperationException();
}
@Override
public Collection<Item> getAll() {
throw new UnsupportedOperationException();
}
@Override
public Stream<Item> stream() {
throw new UnsupportedOperationException();
}
@Override
@Nullable
public Item get(String key) {
throw new UnsupportedOperationException();
}
@Override
public void removeRegistryChangeListener(RegistryChangeListener<Item> listener) {
throw new UnsupportedOperationException();
}
@Override
public Item add(Item element) {
throw new UnsupportedOperationException();
}
@Override
@Nullable
public Item update(Item element) {
throw new UnsupportedOperationException();
}
@Override
@Nullable
public Item remove(String key) {
throw new UnsupportedOperationException();
}
@Override
public Collection<Item> getItemsOfType(String type) {
throw new UnsupportedOperationException();
}
@Override
public Collection<Item> getItemsByTag(String... tags) {
throw new UnsupportedOperationException();
}
@Override
public Collection<Item> getItemsByTagAndType(String type, String... tags) {
throw new UnsupportedOperationException();
}
@Override
public <T extends Item> Collection<T> getItemsByTag(Class<T> typeFilter, String... tags) {
throw new UnsupportedOperationException();
}
@Override
@Nullable
public Item remove(String itemName, boolean recursive) {
throw new UnsupportedOperationException();
}
@Override
public void addRegistryHook(RegistryHook<Item> hook) {
throw new UnsupportedOperationException();
}
@Override
public void removeRegistryHook(RegistryHook<Item> hook) {
throw new UnsupportedOperationException();
}
}, localEndpointOverride);
service.activate(null, config);
return service;
}
Aggregations