Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

JsonDB storage service #1868

Merged
merged 2 commits into from
Nov 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/groovy"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="output" path="target/test-classes"/>
</classpath>
34 changes: 34 additions & 0 deletions bundles/storage/org.eclipse.smarthome.storage.json.test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.smarthome.storage.json.test</name>
<comment>This is JSON Storage Test component of Eclipse SmartHome</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Fri Feb 19 22:30:18 CET 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests for the openHAB Json Storage
Bundle-SymbolicName: org.eclipse.smarthome.storage.json.test
Bundle-Version: 0.9.0.qualifier
Bundle-Vendor: Eclipse.org/SmartHome
Fragment-Host: org.eclipse.smarthome.storage.json
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: groovy.lang,
org.codehaus.groovy.reflection,
org.codehaus.groovy.runtime,
org.codehaus.groovy.runtime.callsite,
org.codehaus.groovy.runtime.typehandling,
org.eclipse.smarthome.core.items,
org.eclipse.smarthome.core.library.items,
org.eclipse.smarthome.test,
org.hamcrest;core=split,
org.junit;version="4.0.0",
org.junit.matchers;version="4.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
<booleanAttribute key="append.args" value="true"/>
<stringAttribute key="application" value="org.eclipse.pde.junit.runtime.coretestapplication"/>
<booleanAttribute key="askclear" value="false"/>
<booleanAttribute key="automaticAdd" value="false"/>
<booleanAttribute key="automaticValidate" value="false"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="true"/>
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
<booleanAttribute key="default" value="false"/>
<booleanAttribute key="default_auto_start" value="true"/>
<booleanAttribute key="includeOptional" value="false"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.eclipse.smarthome.storage.mapdb.test"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.smarthome.storage.mapdb.test"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.smarthome.storage.mapdb.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dsmarthome.userdata=runtime/etc"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.platform.ide"/>
<booleanAttribute key="run_in_ui_thread" value="true"/>
<stringAttribute key="selected_target_plugins" value="ch.qos.logback.classic@default:default,ch.qos.logback.core@default:default,ch.qos.logback.slf4j@default:false,com.google.gson@default:default,com.google.guava@default:default,javax.transaction@default:false,javax.xml@default:default,org.apache.ant@default:default,org.apache.commons.io@default:default,org.apache.commons.lang@default:default,org.apache.felix.gogo.command@default:true,org.apache.felix.gogo.runtime@default:true,org.apache.felix.gogo.shell@default:true,org.codehaus.groovy*2.1.8.xx-201407142235-e44-RELEASE@default:default,org.codehaus.groovy*2.3.4.xx-201407142235-e44-RELEASE@default:default,org.codehaus.jackson.core@default:true,org.codehaus.jackson.mapper@default:true,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.runtime.compatibility.registry@default:false,org.eclipse.core.runtime@default:true,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.console@default:true,org.eclipse.equinox.ds@1:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.transforms.hook@default:false,org.eclipse.equinox.util@default:default,org.eclipse.equinox.weaving.hook@default:false,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true,org.hamcrest.core@default:default,org.junit*4.11.0.v201303080030@default:default,org.slf4j.api@default:default"/>
<stringAttribute key="selected_workspace_plugins" value="org.eclipse.smarthome.config.core@default:default,org.eclipse.smarthome.core.library@default:true,org.eclipse.smarthome.core@default:true,org.eclipse.smarthome.storage.mapdb.test@default:false,org.eclipse.smarthome.storage.mapdb@default:true,org.eclipse.smarthome.test@default:default"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="false"/>
<booleanAttribute key="useProduct" value="false"/>
</launchConfiguration>
28 changes: 28 additions & 0 deletions bundles/storage/org.eclipse.smarthome.storage.json.test/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>

<p>June 5, 2006</p>
<h3>License</h3>

<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>

<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source.. = src/main/groovy/
output.. = target/test-classes/
bin.includes = META-INF/,\
.,\
about.html

57 changes: 57 additions & 0 deletions bundles/storage/org.eclipse.smarthome.storage.json.test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.eclipse.smarthome.bundles</groupId>
<artifactId>storage</artifactId>
<version>0.9.0-SNAPSHOT</version>
</parent>

<properties>
<bundle.symbolicName>org.eclipse.smarthome.storage.json.test</bundle.symbolicName>
<bundle.namespace>org.eclipse.smarthome.storage.json.test</bundle.namespace>
</properties>

<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.smarthome.storage</groupId>
<artifactId>org.eclipse.smarthome.storage.json.test</artifactId>

<name>Eclipse SmartHome Storage JSON Tests</name>

<packaging>eclipse-test-plugin</packaging>

<build>
<plugins>
<plugin>
<groupId>${tycho-groupid}</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<environments combine.self="override"></environments>
<dependency-resolution>
<extraRequirements>
<requirement>
<type>eclipse-plugin</type>
<id>org.eclipse.equinox.ds</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>
<plugin>
<groupId>${tycho-groupid}</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<bundleStartLevel>
<bundle>
<id>org.eclipse.equinox.ds</id>
<level>1</level>
<autoStart>true</autoStart>
</bundle>
</bundleStartLevel>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please update the license headers to the current version?

* Copyright (c) 2014-2016 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.storage.json

import static org.hamcrest.CoreMatchers.*
import static org.junit.Assert.*
import static org.junit.matchers.JUnitMatchers.*

import org.eclipse.smarthome.core.storage.StorageService
import org.eclipse.smarthome.test.OSGiTest
import org.junit.After
import org.junit.Before
import org.junit.Test

/**
* @author Chris Jackson - Initial contribution
*/
class JsonStorageServiceOSGiTest extends OSGiTest {

JsonStorageService storageService
JsonStorage storage


@Before
void setUp() {
storageService = getService(StorageService)
storage = storageService.getStorage('TestStorage', this.getClass().getClassLoader());
}

@After
void tearDown() {
unregisterService(storageService)

// clean up database files ...
new File('./runtime').deleteDir()
}

@Test
void 'assert elements are serialized and deserialized by the Storage'() {

assertThat storage.getKeys().size(), is(0)

storage.put 'Key1', new PersistedItem('String', ['LIGHT', 'GROUND_FLOOR']);
storage.put 'Key2', new PersistedItem('Number', ['TEMPERATURE', 'OUTSIDE']);
assertThat storage.getKeys().size(), is(2)

PersistedItem pItem = storage.get 'Key1'

storage.remove 'Key1'
storage.remove 'Key2'
assertThat storage.getKeys().size(), is(0)
}

@Test
void 'assert old element gets overwritten when new value is stored under an existing key'() {
PersistedItem pItem = null

assertThat storage.getKeys().size(), is(0)

pItem = storage.put 'Key1', new PersistedItem('String', ['LIGHT', 'GROUND_FLOOR']);
assertThat storage.getKeys().size(), is(1)
assertThat pItem, is(null)

pItem = storage.get 'Key1'
assertThat pItem.itemType, is('String')

pItem = storage.put 'Key1', new PersistedItem('Number', ['TEMPERATURE']);
assertThat storage.getKeys().size(), is(1)
assertThat pItem.itemType, is('String')
assertThat storage.get('Key1').itemType, is('Number')

storage.remove 'Key1'
assertThat storage.getKeys().size(), is(0)
}

@Test
void 'assert storage works without classloader'() {
def storageWithoutClassloader = storageService.getStorage("storageWithoutClassloader")
storageWithoutClassloader.put("Key1", "Value")

assertThat storageWithoutClassloader.get("Key1"), is(equalTo("Value"))
}

@Test
void 'assert store configuration works'() {
def storageWithoutClassloader = storageService.getStorage("storage")

def configuration = new MockConfiguration();
configuration.put("bigDecimal", new BigDecimal(3))

storageWithoutClassloader.put("configuration", configuration)

def bigDecimal = storageWithoutClassloader.get("configuration").get("bigDecimal")
assertThat bigDecimal instanceof BigDecimal, is(true)
}

private class MockConfiguration {
private Map<String, Object> configuration = new HashMap<String, Object>();

public void put(String key, Object value) {
configuration.put(key, value);
}

public Object get(String key) {
return configuration.get(key);
}
}


private class PersistedItem {

public String itemType;
public List<String> groupNames;
public String baseItemType;

public PersistedItem(String itemType, List<String> groupNames) {
this(itemType, groupNames, null);
}

public PersistedItem(String itemType, List<String> groupNames, String baseItemType) {
this.itemType = itemType;
this.groupNames = groupNames;
this.baseItemType = baseItemType;
}

@Override
public String toString() {
return "PersistedItem [itemType=$itemType, groupNames=$groupNames, baseItemType=$baseItemType]";
}
}
}
7 changes: 7 additions & 0 deletions bundles/storage/org.eclipse.smarthome.storage.json/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Loading