Commit cfde4c37 authored by Nicolas Dolet's avatar Nicolas Dolet
Browse files

- Add a testing module to extend in tests of examples.

- Refine Helloworld WS Server test
- Add an example for testing SCA Properties.
- For the examples that use remote services, perform 3 tries before failing the test.
- + svn:ignore target and Eclipse files
parent 22908e63
......@@ -62,4 +62,20 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -26,29 +26,44 @@ package org.ow2.frascati.examples.dictionary;
import java.io.StringReader;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Assert;
import org.junit.Test;
import org.ow2.frascati.factory.Launcher;
import org.ow2.frascati.examples.dictionary.api.Dictionary;
import org.ow2.frascati.examples.test.FraSCAtiTestCase;
public class DictionaryTestCase {
public class DictionaryTestCase extends FraSCAtiTestCase {
protected Launcher launcher;
@Before
public void init() {
// Load the composite
launcher = new Launcher("dictionary");
@Override
public String getComposite() {
return "dictionary";
}
@Test
public void testService() {
String response;
response = launcher.call("Dictionary", "definition", String.class,
"middleware");
System.out.println(response);
// Try 3 times to reach the service before giving up
int nbTries = 3;
boolean success = false;
String response = null;
while (nbTries > 0 && !success) {
try {
Dictionary dict = getService(Dictionary.class, "Dictionary");
response = dict.definition("middleware");
System.out.println(response);
success = true;
} catch (RuntimeException e) {
System.err.println("Cannot get the service response...");
System.err.println("Number of tries left: " + (nbTries - 1));
// Sleep 15 seconds
try {
Thread.currentThread().sleep(15000);
} catch (InterruptedException ie) {
throw new Error(ie);
}
}
nbTries--;
}
Assert.assertNotSame("Service unavailable after 3 tries", 0, nbTries);
StringReader sr = new StringReader(response);
StringReader srExpected = new StringReader(expected);
int b;
......
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: Testing module
*
* Copyright (c) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Nicolas Dolet
*
* Contributor(s): Philippe Merle
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>1.1-SNAPSHOT</version>
<name>OW2 FraSCAti Examples: Testing module</name>
<description>APIs for running SCA applications with FraSCAti</description>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti Examples: Testing module
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Nicolas Dolet
*
* Contributor(s):
*/
package org.ow2.frascati.examples.test;
import org.junit.After;
import org.junit.Before;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.ow2.frascati.factory.Factory;
import org.ow2.frascati.tinfi.TinfiDomain;
/**
* Abstract class for testing SCA applications with FraSCAti
*
*/
public abstract class FraSCAtiTestCase {
/**
* The SCA composite to test
*/
protected Component scaComposite;
/**
* Load a composite
*
* @param name
* the composite name
*/
@Before
public void loadComposite() {
String compositeName = getComposite();
System.out.println("Loading " + compositeName + " composite...");
scaComposite = new Factory().getComposite(compositeName);
}
/**
* Get a service on the SCA composite
*
* @param <T>
* the class type for the return
* @param serviceName
* the name of the service
* @return the service named <code>serviceName</code> or null
*/
protected <T> T getService(Class<T> cl, String serviceName) {
System.out.println("Getting service " + serviceName + "...");
try {
return TinfiDomain.getService(scaComposite, cl, serviceName);
} catch (NoSuchInterfaceException e) {
System.err.println("No such service: " + serviceName);
return null;
}
}
/**
* Close the SCA domain
*
* @throws IllegalLifeCycleException
* if the domain cannot be closed
* @throws NoSuchInterfaceException
* if the lifecycle controller of the component is not found
*/
@After
public void close() throws IllegalLifeCycleException,
NoSuchInterfaceException {
TinfiDomain.close(scaComposite);
}
// ---------------------------------------------------------------------------
// Abstract methods
// ---------------------------------------------------------------------------
/**
* Return the name of the composite to test
*
* @return name of the composite to test
*/
public abstract String getComposite();
}
......@@ -49,4 +49,20 @@
<method.name>run</method.name>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -24,23 +24,19 @@
*/
package org.ow2.frascati.examples.helloworld;
import org.junit.Before;
import org.junit.Test;
import org.ow2.frascati.factory.Launcher;
import org.ow2.frascati.examples.test.FraSCAtiTestCase;
public class HelloworldTestCase {
public class HelloworldTestCase extends FraSCAtiTestCase {
protected Launcher launcher;
@Before
public void init() {
// Load the composite
launcher = new Launcher("helloworld-wired");
@Override
public String getComposite() {
return "helloworld-wired";
}
@Test
public void testService() {
launcher.call("r", "run", null, null);
getService(Runnable.class, "r").run();
}
}
......@@ -49,4 +49,19 @@
<method.name>run</method.name>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -24,23 +24,19 @@
*/
package org.ow2.frascati.examples.helloworld;
import org.junit.Before;
import org.junit.Test;
import org.ow2.frascati.factory.Launcher;
import org.ow2.frascati.examples.test.FraSCAtiTestCase;
public class HelloworldTestCase {
public class HelloworldTestCase extends FraSCAtiTestCase {
protected Launcher launcher;
@Before
public void init() {
// Load the composite
launcher = new Launcher("helloworld-pojo");
@Override
public String getComposite() {
return "helloworld-pojo";
}
@Test
public void testService() {
launcher.call("r", "run", null, null);
getService(Runnable.class, "r").run();
}
}
============================================================================
OW2 FraSCAti Examples: Helloworld Property
Copyright (C) 2009 INRIA, USTL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: frascati@ow2.org
Author: Nicolas Dolet
Contributor:
============================================================================
HelloWorld Property:
--------------------
This example shows how to configure an SCA component by using an SCA Property.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
mvn -Prun (standalone execution)
Compilation and execution with the FraSCAti script:
---------------------------------------------------
frascati compile src helloworld-property
frascati run helloworld-property -libpath helloworld-property.jar -s r -m run
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld Property
*
* Copyright (c) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Nicolas Dolet
*
* Contributor(s):
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-property</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld Property</name>
<description>Test the initialization of an SCA property with FraSCAti</description>
<parent>
<artifactId>parent</artifactId>
<groupId>org.ow2.frascati.examples</groupId>
<version>1.1-SNAPSHOT</version>
</parent>
<properties>
<composite.file>helloworld-property</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti Examples: HelloWorld Property
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Nicolas Dolet
*
* Contributor(s):
*/
package org.ow2.frascati.examples.helloworld.property;
public interface HelloProperty {
public String getProperty();
}
/***
* OW2 FraSCAti Examples: HelloWorld Property
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Nicolas Dolet
*
* Contributor(s):
*/
package org.ow2.frascati.examples.helloworld.property;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Service;
@Service(interfaces={HelloProperty.class, Runnable.class})
public class PropertyImpl implements HelloProperty, Runnable {
@Property
String prop;
@Init
public void init() {
System.out.println("Initialize component with property: " + prop);
}
// --------------------------------------------------------------------------
// Implementation of the HelloProperty interface
// --------------------------------------------------------------------------
public String getProperty() {
return prop;
}
// --------------------------------------------------------------------------
// Implementation of the Runnable interface
// --------------------------------------------------------------------------
public void run() {
System.out.println("Running component with property: " + prop);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- OW2 FraSCAti Examples : HelloWorld Property -->
<!-- Copyright (C) 2009 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: frascati@ow2.org -->
<!-- -->
<!-- Author: Nicolas Dolet -->
<!-- -->
<!-- Contributor(s): -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
name="hellworld-property">
<service name="helloProp" promote="client/HelloProperty"/>
<service name="r" promote="client/Runnable"/>
<component name="client">
<property name="prop">foo</property>
<implementation.java class="org.ow2.frascati.examples.helloworld.property.PropertyImpl"/>
</component>
</composite>