зеркало из https://github.com/mozilla/smarthome.git
Merge pull request #15 from qivicon/groovytests
Added Groovy OSGi test case infrastructure and sample test
This commit is contained in:
Коммит
686f655fb5
|
@ -3,5 +3,7 @@
|
|||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="src" path="src/test/groovy"/>
|
||||
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
|
||||
<classpathentry kind="output" path="target/test-classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
groovy.compiler.level=21
|
|
@ -12,6 +12,7 @@
|
|||
<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">
|
||||
|
@ -24,6 +25,7 @@
|
|||
<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"/>
|
||||
<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.core.test"/>
|
||||
|
@ -31,8 +33,8 @@
|
|||
<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.guava@default:default,javax.transaction@default:false,org.apache.commons.codec@default:default,org.apache.commons.collections@default:default,org.apache.commons.httpclient@default:default,org.apache.commons.io@default:default,org.apache.commons.lang@default:default,org.apache.commons.logging@default:default,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.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.servletbridge.extensionbundle@default:false,org.eclipse.equinox.transforms.hook@default:false,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.10.0.v4_10_0_v20120426-0900@default:default,org.junit4@default:default,org.slf4j.api@default:default,org.slf4j.jul@default:default"/>
|
||||
<stringAttribute key="selected_workspace_plugins" value="org.eclipse.smarthome.core.test@default:false,org.eclipse.smarthome.core@default:default"/>
|
||||
<stringAttribute key="selected_target_plugins" value="ch.qos.logback.classic*1.0.7.v20121108-1250@default:default,ch.qos.logback.core*1.0.7.v20121108-1250@default:default,ch.qos.logback.slf4j*1.0.7.v20121108-1250@default:false,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.codehaus.groovy@default:default,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.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*1.7.2.v20121108-1250@default:default"/>
|
||||
<stringAttribute key="selected_workspace_plugins" value="org.eclipse.smarthome.core.library.test@default:false,org.eclipse.smarthome.core.library@default:default,org.eclipse.smarthome.core.test@default:false,org.eclipse.smarthome.core@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"/>
|
||||
|
|
|
@ -6,4 +6,15 @@ Bundle-Version: 0.7.0.qualifier
|
|||
Bundle-Vendor: Eclipse.org/SmartHome
|
||||
Fragment-Host: org.eclipse.smarthome.core
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Require-Bundle: org.junit
|
||||
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.library.items,
|
||||
org.eclipse.smarthome.test,
|
||||
org.hamcrest;core=split,
|
||||
org.junit;version="4.0.0",
|
||||
org.junit.matchers;version="4.0.0"
|
||||
Require-Bundle: org.junit;bundle-version="4.0.0"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
source.. = src/test/java/
|
||||
source.. = src/test/java/,\
|
||||
src/test/groovy
|
||||
output.. = target/test-classes/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
|
|
|
@ -1,33 +1,49 @@
|
|||
<?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>core</artifactId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>org.eclipse.smarthome.bundles</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<bundle.symbolicName>org.eclipse.smarthome.core.test</bundle.symbolicName>
|
||||
<bundle.namespace>org.eclipse.smarthome.core.test</bundle.namespace>
|
||||
</properties>
|
||||
<properties>
|
||||
<bundle.symbolicName>org.eclipse.smarthome.core.test</bundle.symbolicName>
|
||||
<bundle.namespace>org.eclipse.smarthome.core.test</bundle.namespace>
|
||||
</properties>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.smarthome.core</groupId>
|
||||
<artifactId>org.eclipse.smarthome.core.test</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.smarthome.core</groupId>
|
||||
<artifactId>org.eclipse.smarthome.core.test</artifactId>
|
||||
|
||||
<name>Eclipse SmartHome Core Tests</name>
|
||||
<name>Eclipse SmartHome Core Tests</name>
|
||||
|
||||
<packaging>eclipse-test-plugin</packaging>
|
||||
<packaging>eclipse-test-plugin</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-surefire-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-surefire-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<type>eclipse-plugin</type>
|
||||
<artifactId>org.eclipse.equinox.ds</artifactId>
|
||||
<version>0.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<bundleStartLevel>
|
||||
<bundle>
|
||||
<id>org.eclipse.equinox.ds</id>
|
||||
<level>1</level>
|
||||
<autoStart>true</autoStart>
|
||||
</bundle>
|
||||
</bundleStartLevel>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Copyright (c) 2014 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.core.internal
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*
|
||||
import static org.junit.Assert.*
|
||||
import static org.junit.matchers.JUnitMatchers.*
|
||||
|
||||
import org.eclipse.smarthome.core.items.ItemProvider
|
||||
import org.eclipse.smarthome.core.items.ItemRegistry
|
||||
import org.eclipse.smarthome.core.library.items.SwitchItem
|
||||
import org.eclipse.smarthome.test.OSGiTest
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.osgi.framework.BundleContext
|
||||
import org.osgi.framework.FrameworkUtil
|
||||
|
||||
/**
|
||||
* The {@link ItemRegistryOSGiTest} runs inside an OSGi container and tests the {@link ItemRegistry}.
|
||||
*
|
||||
* @author Dennis Nobel - Initial contribution
|
||||
*/
|
||||
class ItemRegistryOSGiTest extends OSGiTest {
|
||||
|
||||
ItemRegistry itemRegistry
|
||||
ItemProvider itemProvider
|
||||
def ITEM_NAME = "switchItem"
|
||||
|
||||
@Before
|
||||
void setUp() {
|
||||
itemRegistry = getService(ItemRegistry)
|
||||
itemProvider = [
|
||||
getItems: {[new SwitchItem(ITEM_NAME)]},
|
||||
addItemChangeListener: {def itemCHangeListener -> },
|
||||
removeItemChangeListener: {def itemCHangeListener -> }] as ItemProvider
|
||||
}
|
||||
|
||||
@Test
|
||||
void 'assert getItems returns item from registered ItemProvider'() {
|
||||
|
||||
assertThat itemRegistry.getItems().size, is(0)
|
||||
|
||||
registerService itemProvider
|
||||
|
||||
def items = itemRegistry.getItems()
|
||||
assertThat items.size, is(1)
|
||||
assertThat items.first().name, is(equalTo(ITEM_NAME))
|
||||
|
||||
unregisterService itemProvider
|
||||
|
||||
assertThat itemRegistry.getItems().size, is(0)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) 2014 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.core.events;
|
||||
|
||||
import static org.eclipse.smarthome.core.events.EventConstants.TOPIC_PREFIX;
|
||||
|
@ -6,11 +13,10 @@ import static org.eclipse.smarthome.core.events.EventConstants.TOPIC_SEPERATOR;
|
|||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.smarthome.core.types.Command;
|
||||
import org.eclipse.smarthome.core.types.EventType;
|
||||
import org.eclipse.smarthome.core.types.State;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.osgi.service.event.Event;
|
||||
|
||||
|
|
|
@ -11,12 +11,11 @@ import static org.junit.Assert.fail;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.eclipse.smarthome.core.types.Command;
|
||||
import org.eclipse.smarthome.core.types.State;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>test</module>
|
||||
<module>config</module>
|
||||
<module>core</module>
|
||||
<module>designer</module>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/groovy"/>
|
||||
<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
|
||||
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.eclipse.smarthome.test</name>
|
||||
<comment>This is the test component of Eclipse Smart Home</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>
|
|
@ -0,0 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
groovy.compiler.level=21
|
|
@ -0,0 +1,9 @@
|
|||
#Fri Feb 19 21:35:42 CET 2010
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
|
@ -0,0 +1,18 @@
|
|||
Manifest-Version: 1.0
|
||||
Export-Package: org.eclipse.smarthome.test;uses:="groovy.lang,org.osgi.framework"
|
||||
Bundle-Name: Eclipse SmartHome Test
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-Vendor: Eclipse.org/SmartHome
|
||||
Bundle-Version: 0.7.0.qualifier
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-License: http://www.eclipse.org/legal/epl-v10.html
|
||||
Bundle-SymbolicName: org.eclipse.smarthome.test
|
||||
Import-Package: groovy.lang,
|
||||
org.codehaus.groovy.reflection,
|
||||
org.codehaus.groovy.runtime,
|
||||
org.codehaus.groovy.runtime.callsite,
|
||||
org.codehaus.groovy.runtime.typehandling,
|
||||
org.hamcrest;core=split,
|
||||
org.junit;version="4.0.0",
|
||||
org.junit.matchers;version="4.0.0",
|
||||
org.osgi.framework
|
|
@ -0,0 +1,5 @@
|
|||
output.. = target/classes/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
source.. = src/main/java/,\
|
||||
src/main/groovy/
|
|
@ -0,0 +1,23 @@
|
|||
<?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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.eclipse.smarthome.bundles</groupId>
|
||||
<artifactId>test</artifactId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<bundle.symbolicName>org.eclipse.smarthome.test</bundle.symbolicName>
|
||||
<bundle.namespace>org.eclipse.smarthome.test</bundle.namespace>
|
||||
</properties>
|
||||
|
||||
<groupId>org.eclipse.smarthome.test</groupId>
|
||||
<artifactId>org.eclipse.smarthome.test</artifactId>
|
||||
|
||||
<name>Eclipse SmartHome Test</name>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,165 @@
|
|||
/**
|
||||
* Copyright (c) 2014 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.test
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*
|
||||
import static org.junit.Assert.*
|
||||
import static org.junit.matchers.JUnitMatchers.*
|
||||
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.osgi.framework.BundleContext
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
||||
/**
|
||||
* {@link OSGiTest} is an abstract base class for OSGi based tests. It provides
|
||||
* convenience methods to register and unregister mocks as OSGi services. All services, which
|
||||
* are registered through the {@link OSGiTest#registerService} methods, are unregistered
|
||||
* automatically in the tear down of the test.
|
||||
*
|
||||
* @author Dennis Nobel - Initial contribution
|
||||
*/
|
||||
abstract class OSGiTest {
|
||||
|
||||
BundleContext bundleContext
|
||||
Map<String, ServiceRegistration<?>> registeredServices = [:]
|
||||
|
||||
@Before
|
||||
public void bindBundleContext() {
|
||||
bundleContext = getBundleContext()
|
||||
assertThat bundleContext, is(notNullValue())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link BundleContext}, which is used for registration and unregistration of OSGi
|
||||
* services. By default it uses the bundle context of the test class itself. This method can be overridden
|
||||
* by concrete implementations to provide another bundle context.
|
||||
*
|
||||
* @return bundle context
|
||||
*/
|
||||
protected BundleContext getBundleContext() {
|
||||
def bundle = FrameworkUtil.getBundle(this.getClass())
|
||||
return bundle?.getBundleContext()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an OSGi service for the given class.
|
||||
*
|
||||
* @param clazz class under which the OSGi service is registered
|
||||
* @return OSGi service or null if no service can be found for the given class
|
||||
*/
|
||||
protected <T> T getService(Class<T> clazz){
|
||||
def serviceReference = bundleContext.getServiceReference(clazz.name)
|
||||
return serviceReference ? bundleContext.getService(serviceReference) : null
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given object as OSGi service. The first interface is used as OSGi service
|
||||
* interface name.
|
||||
*
|
||||
* @param service service to be registered
|
||||
* @param properties OSGi service properties
|
||||
* @return service registration object
|
||||
*/
|
||||
protected registerService(def service, Hashtable properties = [:]) {
|
||||
def interfaceName = getInterfaceName(service)
|
||||
assertThat interfaceName, is(notNullValue())
|
||||
registeredServices.put(interfaceName, bundleContext.registerService(interfaceName, service, properties))
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given object as OSGi service. The given interface name as String is used as OSGi service
|
||||
* interface name.
|
||||
*
|
||||
* @param service service to be registered
|
||||
* @param interfaceName interface name of the OSGi service
|
||||
* @param properties OSGi service properties
|
||||
* @return service registration object
|
||||
*/
|
||||
protected registerService(def service, String interfaceName, Hashtable properties = [:]) {
|
||||
assertThat interfaceName, is(notNullValue())
|
||||
registeredServices.put(interfaceName, bundleContext.registerService(interfaceName, service, properties))
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters an OSGi service by the given object, that was registered before. If the object is
|
||||
* a String the service is unregistered by the interface name. If the given service parameter is
|
||||
* the service itself the interface name is taken from the first interface of the service object.
|
||||
*
|
||||
* @param service service or service interface name
|
||||
* @return the service registration that was unregistered or null if no service could be found
|
||||
*/
|
||||
protected unregisterService(def service) {
|
||||
def interfaceName = service instanceof String ?: getInterfaceName(service)
|
||||
registeredServices.get(interfaceName)?.unregister()
|
||||
registeredServices.remove(interfaceName)
|
||||
}
|
||||
|
||||
/**
|
||||
* When this method is called it waits until the condition is fulfilled or the timeout is reached.
|
||||
* The condition is specified by a closure, that must return a boolean object. When the condition is
|
||||
* not fulfilled Thread.sleep is called at the current Thread for a specified time. After this time
|
||||
* the condition is checked again. By a default the specified sleep time is 50 ms. The default timeout
|
||||
* is 1000 ms.
|
||||
*
|
||||
* @param condition closure that must not have an argument and must return a boolean value
|
||||
* @param timeout timeout, default is 1000ms
|
||||
* @param sleepTime interval for checking the condition, default is 50ms
|
||||
*/
|
||||
protected void waitFor(Closure<?> condition, int timeout = 1000, int sleepTime = 50) {
|
||||
def waitingTime = 0
|
||||
while(!condition() && waitingTime < timeout) {
|
||||
waitingTime += sleepTime
|
||||
sleep sleepTime
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When this method is called it waits until the assertion is fulfilled or the timeout is reached.
|
||||
* The assertion is specified by a closure, that must throw an Exception, if the assertion is not fulfilled.
|
||||
* When the assertion is not fulfilled Thread.sleep is called at the current Thread for a specified time.
|
||||
* After this time the condition is checked again. By a default the specified sleep time is 50 ms.
|
||||
* The default timeout is 1000 ms.
|
||||
*
|
||||
* @param condition closure that must not have an argument
|
||||
* @param timeout timeout, default is 1000ms
|
||||
* @param sleepTime interval for checking the condition, default is 50ms
|
||||
*/
|
||||
protected void waitForAssert(Closure<?> assertion, int timeout = 1000, int sleepTime = 50) {
|
||||
def waitingTime = 0
|
||||
while(waitingTime < timeout) {
|
||||
try {
|
||||
assertion()
|
||||
return
|
||||
} catch(Error error) {
|
||||
waitingTime += sleepTime
|
||||
sleep sleepTime
|
||||
}
|
||||
}
|
||||
assertion()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the interface name for a given service object by choosing the first interface.
|
||||
*
|
||||
* @param service service object
|
||||
* @return name of the first interface or null if the object has no interfaces
|
||||
*/
|
||||
protected getInterfaceName(def service) {
|
||||
service.class.interfaces?.find({it})?.name
|
||||
}
|
||||
|
||||
@After
|
||||
public void unregisterMocks() {
|
||||
registeredServices.each() { interfaceName, service ->
|
||||
service.unregister()
|
||||
}
|
||||
registeredServices.clear()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="MACROMAN"?>
|
||||
<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</groupId>
|
||||
<artifactId>bundles</artifactId>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.smarthome.bundles</groupId>
|
||||
<artifactId>test</artifactId>
|
||||
|
||||
<name>Eclipse SmartHome Test Components</name>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>org.eclipse.smarthome.test</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
54
pom.xml
54
pom.xml
|
@ -33,6 +33,10 @@
|
|||
<tycho-version>0.20.0</tycho-version>
|
||||
<tycho-groupid>org.eclipse.tycho</tycho-groupid>
|
||||
<xtext-version>2.5.3</xtext-version>
|
||||
<build.helper.maven.plugin.version>1.8</build.helper.maven.plugin.version>
|
||||
<maven.compiler.version>3.1</maven.compiler.version>
|
||||
<groovy.eclipse.compiler.version>2.8.0-01</groovy.eclipse.compiler.version>
|
||||
<groovy.eclipse.batch.version>2.1.5-03</groovy.eclipse.batch.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
@ -105,6 +109,10 @@
|
|||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<failIfNoTests>false</failIfNoTests>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
<include>**/*.groovy</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -138,6 +146,51 @@
|
|||
<groupId>org.eclipse.xtend</groupId>
|
||||
<artifactId>xtend-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>${build.helper.maven.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/main/groovy</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven.compiler.version}</version>
|
||||
<configuration>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>${groovy.eclipse.compiler.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-batch</artifactId>
|
||||
<version>${groovy.eclipse.batch.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<pluginManagement>
|
||||
|
@ -165,6 +218,7 @@
|
|||
<aggregate>true</aggregate>
|
||||
<includes>
|
||||
<include>**/org/eclipse/smarthome/**/*.java</include>
|
||||
<include>**/org/eclipse/smarthome/**/*.groovy</include>
|
||||
<include>**/feature.xml</include>
|
||||
<include>**/OSGI-INF/*.xml</include>
|
||||
</includes>
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?pde version="3.8"?><target name="SmartHome" sequenceNumber="56">
|
||||
<?pde version="3.8"?><target name="SmartHome" sequenceNumber="58">
|
||||
<locations>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.eclipse.platform.sdk" version="4.3.2.M20140221-1700"/>
|
||||
<repository location="http://download.eclipse.org/eclipse/updates/4.3"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="com.ibm.icu.base" version="50.1.1.v201304230130"/>
|
||||
<unit id="com.ibm.icu.base.source" version="50.1.1.v201304230130"/>
|
||||
<unit id="com.sun.jersey" version="1.17.0.v20130314-2020"/>
|
||||
|
@ -89,5 +85,14 @@
|
|||
<unit id="org.eclipse.jetty.sdk.feature.group" version="8.1.3.201206060641"/>
|
||||
<repository location="http://download.eclipse.org/releases/juno/"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.codehaus.groovy21.feature.feature.group" version="2.8.0.xx-20130703-1600-e43-RELEASE"/>
|
||||
<repository location="http://dist.springsource.org/release/GRECLIPSE/e4.3/"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.eclipse.sdk.ide" version="4.3.2.M20140221-1700"/>
|
||||
<unit id="org.eclipse.pde.feature.group" version="3.9.1.v20140221-1700"/>
|
||||
<repository location="http://download.eclipse.org/eclipse/updates/4.3"/>
|
||||
</location>
|
||||
</locations>
|
||||
</target>
|
||||
|
|
Загрузка…
Ссылка в новой задаче