Commit 26586c7a authored by Christophe Demarey's avatar Christophe Demarey
Browse files

Add a client to simply run the scenario. Add a jUnit test.

parent 32d36fe2
/***
* OW2 FraSCAti Examples : Fscript reconfiguration
* Copyright (C) 2008-2010 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
*
* Authors: Christophe Demarey
*/
package org.ow2.frascati.examples.test;
import org.junit.Before;
import org.ow2.frascati.fscript.FrascatiScriptFactory;
import org.ow2.frascati.factory.FactoryException;
import org.ow2.frascati.factory.FactoryInstantiationException;
/**
* An utility class used to run tests on FraSCAti runtime with FScript enable.
*
* @author Christophe Demarey
*/
public abstract class FraSCAtiScriptTestCase extends FraSCAtiTestCase {
/**
* Load a composite
*
* @param name
* the composite name
* @throws FactoryException, FactoryInstantiationException
*/
@Before
@Override
public void loadComposite() throws FactoryException, FactoryInstantiationException {
String compositeName = getComposite();
System.out.println("Loading " + compositeName + " composite...");
scaComposite = new FrascatiScriptFactory().getComposite(compositeName);
}
}
......@@ -45,6 +45,8 @@
<properties>
<logging.conf.file>../../distribution/standalone/src/main/conf/logging.properties</logging.conf.file>
<composite.file>reconfig</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
</properties>
<dependencies>
......@@ -79,6 +81,24 @@
<!-- ========= -->
<profiles>
<!-- To execute an SCA composite type 'mvn -Prun'. -->
<profile>
<id>run</id>
<build>
<plugins>
<plugin>
<groupId>org.ow2.frascati.factory</groupId>
<artifactId>frascati-factory-plugin</artifactId>
<configuration>
<useFscript>true</useFscript>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- To execute an SCA composite with FraSCAti Explorer type 'mvn -Pexplorer'. -->
<profile>
<id>explorer</id>
<build>
......
/***
* OW2 FraSCAti Examples : Fscript reconfiguration
* Copyright (C) 2008-2010 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
*
* Author: Christophe Demarey
*/
package org.ow2.frascati.examples.reconfig;
import org.objectweb.fractal.fscript.FScriptException;
import org.osoa.sca.annotations.Reference;
import org.ow2.frascati.examples.reconfig.converter.CurrencyConverter;
import org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdater;
/**
* A simple client providing a Runnable interface to easily run the whole demo.
*
* @author Christophe Demarey
*/
public class Client implements Runnable {
@Reference
protected CurrencyConverter converter;
@Reference
protected ExchangeRateUpdater updater;
private final static double newRate = 0.823;
/** Default constructor. */
public Client() { }
/** Run the client. */
public void run() {
double result;
result = converter.dollarToEuro(100);
System.out.println("100$ are worth about "+result+"€.");
System.out.print("Updating exchange rate to 0.823 ...");
try {
updater.updateExchangeRate(newRate);
} catch (FScriptException e) {
System.out.println("Reconfiguration failed!");
e.printStackTrace();
}
System.out.println(" Done!");
result = converter.dollarToEuro(100);
System.out.println("100$ are now worth about "+result+"€.");
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ import org.osoa.sca.annotations.Scope;
/**
* The Currency converter service implementation.
*/
@Scope(value="COMPOSITE")
//@Scope(value="COMPOSITE")
public class CurrencyConverterImpl implements CurrencyConverter {
private double exchangeRate;
......
......@@ -23,7 +23,7 @@
<!-- Contributor(s): -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="reconfig">
<service name="r" promote="currency-converter/currencyConverter"/>
<service name="r" promote="client/run"/>
<component name="currency-converter">
<implementation.java class="org.ow2.frascati.examples.reconfig.converter.CurrencyConverterImpl"/>
......@@ -42,4 +42,16 @@
<interface.java interface="org.ow2.frascati.examples.reconfig.converter.fscript.ExchangeRateUpdater"/>
</service>
</component>
<component name="client">
<implementation.java class="org.ow2.frascati.examples.reconfig.Client"/>
<service name="run">
<interface.java interface="java.lang.Runnable"/>
</service>
</component>
<wire source="client/converter" target="currency-converter/currencyConverter"/>
<wire source="client/updater" target="exchange-rate-updater/exchangeRateUpdater"/>
</composite>
......@@ -25,10 +25,10 @@
package org.ow2.frascati.examples.reconfig;
import org.junit.Test;
import org.ow2.frascati.examples.test.FraSCAtiTestCase;
import org.ow2.frascati.examples.test.FraSCAtiScriptTestCase;
public class ReconfigTestCase extends FraSCAtiTestCase {
public class ReconfigTestCase extends FraSCAtiScriptTestCase {
@Override
public String getComposite() {
......@@ -37,6 +37,6 @@ public class ReconfigTestCase extends FraSCAtiTestCase {
@Test
public void testService() {
// getService(Runnable.class, "r").run();
getService(Runnable.class, "r").run();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment