migrate tests for storage.json (#624)

Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
This commit is contained in:
Markus Rathgeb 2019-03-05 11:53:02 +01:00 committed by Wouter Born
parent 4c9a5aa291
commit bf4eac7d78
6 changed files with 30 additions and 9 deletions

View File

@ -19,6 +19,12 @@
<artifactId>org.openhab.core.config.core</artifactId> <artifactId>org.openhab.core.config.core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Chris Jackson - Initial Contribution * @author Chris Jackson - Initial Contribution
*/ */
@Component(name = "org.eclipse.smarthome.storage.json", immediate = true, property = { // @Component(name = "org.eclipse.smarthome.storage.json", property = { //
"service.pid=org.eclipse.smarthome.storage.json", // "service.pid=org.eclipse.smarthome.storage.json", //
"service.config.description.uri=system:json_storage", // "service.config.description.uri=system:json_storage", //
"service.config.label=Json Storage", // "service.config.label=Json Storage", //

View File

@ -9,8 +9,6 @@ Fragment-Host: org.openhab.core.storage.json
# done # done
# #
-runbundles: \ -runbundles: \
ch.qos.logback.classic;version='[1.2.0,1.2.1)',\
ch.qos.logback.core;version='[1.2.0,1.2.1)',\
com.google.gson;version='[2.7.0,2.7.1)',\ com.google.gson;version='[2.7.0,2.7.1)',\
javax.measure.unit-api;version='[1.0.0,1.0.1)',\ javax.measure.unit-api;version='[1.0.0,1.0.1)',\
org.apache.commons.io;version='[2.2.0,2.2.1)',\ org.apache.commons.io;version='[2.2.0,2.2.1)',\
@ -32,6 +30,8 @@ Fragment-Host: org.openhab.core.storage.json
org.osgi.service.event;version='[1.4.0,1.4.1)',\ org.osgi.service.event;version='[1.4.0,1.4.1)',\
osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\ osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\
osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\ osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\
slf4j.api;version='[1.7.21,1.7.22)',\
tec.uom.lib.uom-lib-common;version='[1.0.2,1.0.3)',\ tec.uom.lib.uom-lib-common;version='[1.0.2,1.0.3)',\
tec.uom.se;version='[1.0.8,1.0.9)' tec.uom.se;version='[1.0.8,1.0.9)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
slf4j.api;version='[1.7.25,1.7.26)'

View File

@ -21,13 +21,16 @@ import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.eclipse.smarthome.config.core.ConfigConstants;
import org.eclipse.smarthome.config.core.Configuration; import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.storage.Storage; import org.eclipse.smarthome.core.storage.Storage;
import org.eclipse.smarthome.core.storage.StorageService; import org.eclipse.smarthome.core.storage.StorageService;
import org.eclipse.smarthome.test.java.JavaOSGiTest; import org.eclipse.smarthome.test.java.JavaOSGiTest;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -44,15 +47,19 @@ public class JsonStorageServiceOSGiTest extends JavaOSGiTest {
@Before @Before
public void setUp() { public void setUp() {
storageService = getService(StorageService.class); storageService = getService(StorageService.class);
storage = storageService.getStorage("TestStorage", this.getClass().getClassLoader()); storage = storageService.getStorage(UUID.randomUUID().toString(), this.getClass().getClassLoader());
} }
@After @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
unregisterService(storageService); unregisterService(storageService);
}
@AfterClass
public static void afterClass() throws IOException {
// clean up database files ... // clean up database files ...
FileUtils.deleteDirectory(new File("./runtime")); FileUtils.deleteDirectory(new File(ConfigConstants.getUserDataFolder()));
FileUtils.deleteDirectory(new File(ConfigConstants.getConfigFolder()));
} }
@Test @Test
@ -98,7 +105,7 @@ public class JsonStorageServiceOSGiTest extends JavaOSGiTest {
assertThat(pItem, is(nullValue())); assertThat(pItem, is(nullValue()));
pItem = storage.get("Key1"); pItem = storage.get("Key1");
Assert.assertNotNull(pItem); assertThat(pItem, is(notNullValue()));
assertThat(pItem.itemType, is("String")); assertThat(pItem.itemType, is("String"));
pItem = storage.put("Key1", new PersistedItem("Number", Arrays.asList("TEMPERATURE"))); pItem = storage.put("Key1", new PersistedItem("Number", Arrays.asList("TEMPERATURE")));
@ -142,6 +149,14 @@ public class JsonStorageServiceOSGiTest extends JavaOSGiTest {
public List<String> groupNames; public List<String> groupNames;
public String baseItemType; public String baseItemType;
/**
* Package protected default constructor to allow reflective instantiation.
*
* !!! DO NOT REMOVE - Gson needs it !!!
*/
PersistedItem() {
}
public PersistedItem(String itemType, List<String> groupNames) { public PersistedItem(String itemType, List<String> groupNames) {
this(itemType, groupNames, null); this(itemType, groupNames, null);
} }

View File

@ -51,7 +51,7 @@
<module>org.openhab.core.model.thing.testsupport</module> <module>org.openhab.core.model.thing.testsupport</module>
<module>org.openhab.core.model.thing.tests</module> <module>org.openhab.core.model.thing.tests</module>
<!-- <module>org.openhab.core.semantics.tests</module> --> <!-- <module>org.openhab.core.semantics.tests</module> -->
<!-- <module>org.openhab.core.storage.json.tests</module> --> <module>org.openhab.core.storage.json.tests</module>
<module>org.openhab.core.thing.tests</module> <module>org.openhab.core.thing.tests</module>
<module>org.openhab.core.thing.xml.tests</module> <module>org.openhab.core.thing.xml.tests</module>
<module>org.openhab.core.transform.tests</module> <module>org.openhab.core.transform.tests</module>