AQute Inside OSGi By Peter Kriens CEO aQute OSGi Technology Officer and OSGi Fellow.
Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel
-
Upload
mfrancis -
Category
Technology
-
view
832 -
download
3
description
Transcript of Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel
![Page 1: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/1.jpg)
EclipseCon Europe 2013
TESTING�OSGI�THE�GROOVY�W?Y
Lars Pfannenschmidt & Dennis Nobel
![Page 2: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/2.jpg)
Lars PfannenschmidtSenior Software Engineer at Level Up Analytics IntuitFounder of
ÔÔ @mobilecgn
![Page 3: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/3.jpg)
Dennis NobelIT Consultant at itemis AG Java, Web and OSGi Developer
Ô @itemisÔ
![Page 4: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/4.jpg)
IM?GINEwriting tests would make fun...
![Page 5: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/5.jpg)
QUESTION�1:Do you test your OSGi
components?
![Page 6: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/6.jpg)
QUESTION�2:Are you using Groovy?
![Page 7: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/7.jpg)
Our Testing StoryEmbedded Device with CVM (~Java 1.4)OSGi framework (Prosyst mBS)Development with EclipseCI Build with Maven and Tycho
ÔÔÔÔ
![Page 8: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/8.jpg)
How to write our tests?
![Page 9: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/9.jpg)
Test RequirementsEasy to writeModern languageType-safe access to Java classesEasy mockingExecutable in Eclipse and Maven CI buildGood IDE supportNo side effects for production code
ÔÔÔÔÔÔÔ
![Page 10: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/10.jpg)
J?V?�Modern language?
Not really...
![Page 11: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/11.jpg)
![Page 12: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/12.jpg)
What? Why Groovy?
![Page 13: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/13.jpg)
Because we can!
![Page 14: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/14.jpg)
GROOVYJVM LanguageSyntax SugarClosuresLess "Chatty"
ÔÔÔÔ
![Page 15: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/15.jpg)
Groovy JUnit TestType inference, readable asserts, syntax sugar and more:
@Testvoid 'Build pizza with BBQ sauce only'() { def pizza = PizzaBuilder.newPizza() .withSauce(BBQ) .build()
assertThat pizza.sauce, is(BBQ) }
![Page 16: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/16.jpg)
How to test our OSGi Services?
![Page 17: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/17.jpg)
Pizza Service SampleServices: PizzaService → PaymentService
public class PizzaServiceImpl implements PizzaService {
@Override public void placeOrder(final Order order) { ... creditCardPaymentService.handleTransaction(...); ... } }
![Page 18: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/18.jpg)
UNIT�TESTS+ Executed fast+ Focussed on the component No OSGi Runtime features Dependencies must be mocked No testing of declarative OSGi parts
![Page 19: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/19.jpg)
SYSTEM�TESTS+ Cover complete system+ Real target environment+ No mocking or special configuration Embedded device is needed (high execution effort) Slow execution Not focussed
![Page 20: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/20.jpg)
IN�CONT?INER�TESTSExecuted in OSGi environmentFocussed on the componentTesting of declarative OSGi partsOnly partial mocking
ÔÔÔÔ
![Page 21: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/21.jpg)
...we can not run Groovy in CVM
![Page 22: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/22.jpg)
Why not use
EQUINOXwith a modern JVM?
![Page 23: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/23.jpg)
GROOVYIn-Container Testing with
equinox
![Page 24: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/24.jpg)
MockingSimply transform a map to a proxy:
def paymentService = [ handleTransaction: { String companyId, long creditCardNumber -> assertThat companyId, is(equalTo('LUIGIS_PIZZA_SERVICE')) transactionCalled = true }] as CreditCardPaymentService
![Page 25: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/25.jpg)
Register OSGi service mocks (1)
class PizzaServiceTest extends OSGiTest {
@Override protected BundleContext getBundleContext() { Activator.context } ...}
![Page 26: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/26.jpg)
Register OSGi service mocks (2)
@Testvoid 'Assert that the handleTransaction method is called'() { ... registerMock(paymentService)
PizzaService pizzaService = getService(PizzaService)
def pizza = PizzaBuilder.newPizza().withSauce(Sauce.BBQ).build() def customerInfo = new CustomerInfo("Max Mustermann", new Address(), 4242) pizzaService.placeOrder(new Order(pizza, customerInfo))
assertThat transactionCalled, is(true)}
![Page 27: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/27.jpg)
OSGiTest.groovy
def registeredServices = [:]protected abstract BundleContext getBundleContext()
def <T> T getService(Class<T> clazz){ def serviceReference = bundleContext.getServiceReference(clazz.name) assertThat serviceReference, is(notNullValue()) bundleContext.getService(serviceReference)}
def registerMock(def mock, Hashtable properties = [:]) { def interfaceName = mock.class.interfaces?.find({it})?.name assertThat interfaceName, is(notNullValue()) registeredServices.put(interfaceName, bundleContext.registerService(interfaceName, mock, properties))} ...
![Page 28: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/28.jpg)
?UTOM?TIONwith Maven and Tycho
![Page 29: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/29.jpg)
Tycho Groovy configuration (1)Groovy & Maven
http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven
Groovy Repository
<repositories> ... <repository> <id>groovy-eclipse</id> <layout>p2</layout> <url>http://dist.springsource.org/release/GRECLIPSE/e4.3/</url> </repository></repositories>
![Page 30: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/30.jpg)
Tycho Groovy configuration (2)Tycho, Groovy & Surefire
...<plugin> <groupid>org.eclipse.tycho</groupid> <artifactid>tycho-surefire-plugin</artifactid> <version>${tycho.version}</version> <configuration> <includes> <include>**/*</include> </includes> ... </configuration></plugin>...
![Page 31: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/31.jpg)
CONCLUSIONAdd integrative Tests to your OSGi projectsEasy to add groovy support in equinox and tychoGroovy makes developing tests more easierPowerful tests which run as fast as unit tests (>300 Tests in ~3minutes)Fun!
ÔÔÔÔ
Ô
![Page 32: Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel](https://reader033.fdocuments.net/reader033/viewer/2022042714/55660822d8b42a06318b4603/html5/thumbnails/32.jpg)
1/32
TH?NK�YOU�Checkout "groovy" OSGi testing at github:
$ git clone https://github.com/groovyosgi/testing.git$ cd testing$ mvn clean install
Lars Pfannenschmidt (Intuit, Inc.)
Dennis Nobel (itemis AG)