Commit ba45ef06 authored by Gwenael Cattez's avatar Gwenael Cattez
Browse files

new feature : Generic test for BindingProcessor

Remove propagation for binding on collection interface (to refactor)
Generic tests for SCA, JSONRPC, UPnP
parent fbc619de
......@@ -217,17 +217,16 @@ public interface FractalUtilItf
public Interface findInterfaceById(Component owner, String itfId) throws NoSuchInterfaceException;
//TODO doc
public Interface getServerInterface(Interface itf);
/**
*
* @param itf
* @return
*/
public Object getServerInterface(Interface itf);
//TODO doc
public List<Interface> getClientInterfaces(Interface itf);
//TODO doc
public Interface getDeepestClient(Interface itf);
public List<Object> getClientInterfaces(Interface itf);
//TODO doc
public Interface getHighestServer(Interface itf);
/**
* Get the name of the last interface bound to a collection Reference define by collectionName
......
......@@ -159,6 +159,33 @@
<!-- <classifier>frascati-contribution</classifier> -->
<!-- <overWrite>true</overWrite> -->
<!-- <destFileName>helloworld-jms.zip</destFileName> -->
<!-- </artifactItem> -->
<!-- <artifactItem> -->
<!-- <groupId>org.ow2.frascati.examples</groupId> -->
<!-- <artifactId>helloworld-jsonrpc-contribution</artifactId> -->
<!-- <version>1.5-SNAPSHOT</version> -->
<!-- <type>zip</type> -->
<!-- <classifier>frascati-contribution</classifier> -->
<!-- <overWrite>true</overWrite> -->
<!-- <destFileName>helloworld-jsonrpc.zip</destFileName> -->
<!-- </artifactItem> -->
<!-- <artifactItem> -->
<!-- <groupId>org.ow2.frascati.examples</groupId> -->
<!-- <artifactId>helloworld-upnp-contribution</artifactId> -->
<!-- <version>1.5-SNAPSHOT</version> -->
<!-- <type>zip</type> -->
<!-- <classifier>frascati-contribution</classifier> -->
<!-- <overWrite>true</overWrite> -->
<!-- <destFileName>helloworld-upnp.zip</destFileName> -->
<!-- </artifactItem> -->
<!-- <artifactItem> -->
<!-- <groupId>org.ow2.frascati.examples</groupId> -->
<!-- <artifactId>helloworld-binding-sca</artifactId> -->
<!-- <version>1.5-SNAPSHOT</version> -->
<!-- <type>zip</type> -->
<!-- <classifier>frascati-contribution</classifier> -->
<!-- <overWrite>true</overWrite> -->
<!-- <destFileName>helloworld-binding-sca.zip</destFileName> -->
<!-- </artifactItem> -->
</artifactItems>
</configuration>
......
......@@ -489,28 +489,28 @@ public class BindingManagerImpl implements BindingManagerItf
private Interface propagateUnbind(Interface itf) throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException
{
InterfaceType interfaceType=(InterfaceType) itf.getFcItfType();
if(interfaceType.isFcCollectionItf())
{
Interface deepestClientInterface=this.fractalUtil.getDeepestClient(itf);
Interface deepestClientServerInterface=this.fractalUtil.getServerInterface(deepestClientInterface);
org.objectweb.fractal.api.Component deepestClientOwner;
BindingController deepestOwnerBindingController;
while(deepestClientServerInterface!=null)
{
deepestClientOwner=deepestClientInterface.getFcItfOwner();
deepestOwnerBindingController=Fractal.getBindingController(deepestClientOwner);
fractalUtil.stopComponent(deepestClientOwner);
deepestOwnerBindingController.unbindFc(deepestClientInterface.getFcItfName());
logger.info("unbind "+deepestClientInterface.getFcItfName()+" from "+fractalUtil.getComponentName(deepestClientOwner));
fractalUtil.startComponent(deepestClientOwner);
deepestClientInterface=deepestClientServerInterface;
deepestClientServerInterface=fractalUtil.getServerInterface(deepestClientInterface);
}
logger.info(deepestClientInterface.getFcItfName());
return deepestClientInterface;
}
// InterfaceType interfaceType=(InterfaceType) itf.getFcItfType();
// if(interfaceType.isFcCollectionItf())
// {
// Interface deepestClientInterface=this.fractalUtil.getDeepestClient(itf);
// Interface deepestClientServerInterface=(Interface) this.fractalUtil.getServerInterface(deepestClientInterface);
// org.objectweb.fractal.api.Component deepestClientOwner;
// BindingController deepestOwnerBindingController;
//
// while(deepestClientServerInterface!=null)
// {
// deepestClientOwner=deepestClientInterface.getFcItfOwner();
// deepestOwnerBindingController=Fractal.getBindingController(deepestClientOwner);
// fractalUtil.stopComponent(deepestClientOwner);
// deepestOwnerBindingController.unbindFc(deepestClientInterface.getFcItfName());
// logger.info("unbind "+deepestClientInterface.getFcItfName()+" from "+fractalUtil.getComponentName(deepestClientOwner));
// fractalUtil.startComponent(deepestClientOwner);
// deepestClientInterface=deepestClientServerInterface;
// deepestClientServerInterface=(Interface) fractalUtil.getServerInterface(deepestClientInterface);
// }
// logger.info(deepestClientInterface.getFcItfName());
// return deepestClientInterface;
// }
return itf;
}
......
......@@ -538,14 +538,14 @@ public class FractalUtilImpl implements FractalUtilItf
/**
* @see org.ow2.frascati.remote.introspection.util.FractalUtilItf#getClientInterfaces(org.objectweb.fractal.api.Interface)
*/
public List<Interface> getClientInterfaces(Interface itf)
public List<Object> getClientInterfaces(Interface itf)
{
String interfaceName=itf.getFcItfName();
Component owner=itf.getFcItfOwner();
String ownerName=this.getComponentName(owner);
logger.finest("getPromotedInterface owner : "+ownerName+" interface : "+interfaceName);
List<Interface> clientInterfaces=new ArrayList<Interface>();
List<Object> clientInterfaces=new ArrayList<Object>();
List<org.objectweb.fractal.api.Component> children=null;
try
{
......@@ -607,65 +607,37 @@ public class FractalUtilImpl implements FractalUtilItf
/**
* @see org.ow2.frascati.remote.introspection.util.FractalUtilItf#getServerInterface(org.objectweb.fractal.api.Interface)
*/
public Interface getServerInterface(Interface itf)
public Object getServerInterface(Interface itf)
{
logger.fine("getServerInterface " + itf.getFcItfName());
Component owner = itf.getFcItfOwner();
BindingController ownerBindingController = null;
try
{
logger.fine("getServerInterface " + itf.getFcItfName());
Component owner = itf.getFcItfOwner();
BindingController ownerBindingController = Fractal.getBindingController(owner);
Object promoter = ownerBindingController.lookupFc(itf.getFcItfName());
ownerBindingController = Fractal.getBindingController(owner);
if(promoter!=null && promoter instanceof Interface)
{
logger.fine(promoter.getClass().getName()+" instanceof Interface");
Interface promoterInterface=(Interface) promoter;
Component promoterInterfaceOwner=promoterInterface.getFcItfOwner();
logger.fine("owner "+this.getComponentName(promoterInterfaceOwner));
String promoterInterfaceOwnerName=this.getComponentName(promoterInterfaceOwner);
if(promoterInterfaceOwnerName.endsWith("-stub") || promoterInterfaceOwnerName.endsWith("-skeleton") || promoterInterfaceOwnerName.endsWith("-connector"))
{
logger.fine("promoter : "+promoterInterface.getFcItfName());
return promoterInterface;
}
}
}
catch (NoSuchInterfaceException noSuchInterfaceException)
{
logger.fine("Can't get BindingController for owner of interface : "+itf.getFcItfName());
return null;
}
return null;
}
public Interface getDeepestClient(Interface itf)
{
Interface tmpClient=itf;
List<Interface> clientInterfaces=this.getClientInterfaces(tmpClient);
while(!clientInterfaces.isEmpty())
try
{
tmpClient=clientInterfaces.get(0);
clientInterfaces=this.getClientInterfaces(tmpClient);
return ownerBindingController.lookupFc(itf.getFcItfName());
}
return tmpClient;
}
public Interface getHighestServer(Interface itf)
{
Interface server,serverTmp;
server=null;
serverTmp=itf;
while(serverTmp!=null)
catch (NoSuchInterfaceException noSuchInterfaceException)
{
server=serverTmp;
serverTmp=this.getServerInterface(server);
logger.fine("No object bound to interface "+itf.getFcItfName());
return null;
}
return server;
}
/**
* Get the name of the last interface bound to a collection Reference define
* by collectionName i.e collectionName-(highest index found)
......
......@@ -168,7 +168,7 @@ public class IntrospectionTestSuite
/** Helper methods */
public static void deployContribution(String contributionName)
public static StringList deployContribution(String contributionName)
{
String contributionPath=getResourcePath(contributionName+".zip");
......@@ -183,9 +183,10 @@ public class IntrospectionTestSuite
StringList deployedComponents=IntrospectionTestSuite.deployment.deployContribution(contrib);
assertTrue(deployedComponents.getStringList().size()>0);
return deployedComponents;
}
public static void deployComposite(String compositeFinaleName, String compositeName)
public static String deployComposite(String compositeFinaleName, String compositeName)
{
String compositePath=getResourcePath(compositeFinaleName+".jar");
System.out.println(compositePath);
......@@ -201,6 +202,7 @@ public class IntrospectionTestSuite
String deployedComponent=IntrospectionTestSuite.deployment.deployComposite(compositeName,compositeFile);
assertEquals(deployedComponent, compositeName);
return deployedComponent;
}
public static void undeployComposite(String compositePath)
......
......@@ -33,6 +33,7 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.WebApplicationException;
......@@ -89,11 +90,12 @@ public class DeploymentTest
String entriesString=deployment.getCompositeEntriesFromJar(compositeString);
String[] entries=entriesString.split(FileUtil.JAR_ENTRIES_SEPARATOR);
assertEquals(5, entries.length);
assertEquals("RunnerMultipleContainer", entries[0]);
assertEquals("RunnerMultipleLevel1", entries[1]);
assertEquals("RunnerMultipleLevel2", entries[2]);
assertEquals("RunnerMultipleTopLevel", entries[3]);
assertEquals("RunnerSimple", entries[4]);
List<String> entriesList=Arrays.asList(entries);
assertEquals(true, entriesList.contains("RunnerMultipleContainer"));
assertEquals(true, entriesList.contains("RunnerMultipleLevel1"));
assertEquals(true, entriesList.contains("RunnerMultipleLevel2"));
assertEquals(true, entriesList.contains("RunnerMultipleTopLevel"));
assertEquals(true, entriesList.contains("RunnerSimple"));
/** Test with invalid parameter*/
try
......
......@@ -33,6 +33,7 @@ import static org.junit.Assert.fail;
import java.util.List;
import org.eclipse.stp.sca.JMSBinding;
import org.junit.BeforeClass;
import org.junit.Test;
import org.objectweb.fractal.api.Interface;
......@@ -41,6 +42,13 @@ import org.ow2.frascati.remote.IntrospectionTestSuite;
import org.ow2.frascati.remote.introspection.binding.exception.UnsupportedBindingComponentException;
import org.ow2.frascati.remote.introspection.binding.exception.UnsupportedBindingException;
import org.ow2.frascati.remote.introspection.binding.processor.BindingProcessorItf;
import org.ow2.frascati.remote.introspection.binding.processor.BindingProcessorTest;
import org.ow2.frascati.remote.introspection.binding.processor.JMSBindingProcessorTest;
import org.ow2.frascati.remote.introspection.binding.processor.JSONRPCBindingProcessor;
import org.ow2.frascati.remote.introspection.binding.processor.JSONRPCBindingProcessorTest;
import org.ow2.frascati.remote.introspection.binding.processor.RESTBindingProcessorTest;
import org.ow2.frascati.remote.introspection.binding.processor.SCABindingProcessorTest;
import org.ow2.frascati.remote.introspection.binding.processor.UPnPBindingProcessorTest;
import org.ow2.frascati.remote.introspection.resources.BindingKind;
import org.ow2.frascati.remote.introspection.util.FractalUtilItf;
......@@ -84,57 +92,126 @@ public class BindingManagerTest
{
assertEquals("The binding null is not currently supported", unsupportedBindingException.getMessage());
}
}
public void getBindinProcessor(BindingProcessorTest bindingProcessorTest) throws UnsupportedBindingComponentException, UnsupportedBindingException
{
BindingProcessorItf processor=bindingManager.getBindingProcessor(bindingProcessorTest.getBindingKind());
assertEquals(bindingProcessorTest.getBindingKind(), processor.getBindingKind());
Object stubInterfaceFc=bindingProcessorTest.getStubInterfaceFc();
if(stubInterfaceFc!=null)
{
Object boundedObject=stubInterfaceFc;
if(stubInterfaceFc instanceof Interface)
{
boundedObject=((Interface) stubInterfaceFc).getFcItfOwner();
}
processor=bindingManager.getBindingProcessor(boundedObject);
assertEquals(bindingProcessorTest.getBindingKind(), processor.getBindingKind());
}
/**we just check if the processor is found, specific binding tests are done here*/
BindingProcessorItf processor=bindingManager.getBindingProcessor("JMS");
assertEquals(BindingKind.JMS, processor.getBindingKind());
processor=bindingManager.getBindingProcessor("JMS");
assertEquals(BindingKind.JMS, processor.getBindingKind());
processor=bindingManager.getBindingProcessor("JSON_RPC");
assertEquals(BindingKind.JSON_RPC, processor.getBindingKind());
processor=bindingManager.getBindingProcessor("REST");
assertEquals(BindingKind.REST, processor.getBindingKind());
processor=bindingManager.getBindingProcessor("RMI");
assertEquals(BindingKind.RMI, processor.getBindingKind());
processor=bindingManager.getBindingProcessor("SCA");
assertEquals(BindingKind.SCA, processor.getBindingKind());
processor=bindingManager.getBindingProcessor("UPNP");
assertEquals(BindingKind.UPNP, processor.getBindingKind());
processor=bindingManager.getBindingProcessor("WS");
assertEquals(BindingKind.WS, processor.getBindingKind());
Object skeltonInterfaceFc=bindingProcessorTest.getSkeltonInterfaceFc();
if(skeltonInterfaceFc!=null)
{
Object boundedObject=skeltonInterfaceFc;
if(skeltonInterfaceFc instanceof Interface)
{
boundedObject=((Interface) skeltonInterfaceFc).getFcItfOwner();
}
processor=bindingManager.getBindingProcessor(boundedObject);
assertEquals(bindingProcessorTest.getBindingKind(), processor.getBindingKind());
}
}
public void getClientBindingBundle(BindingProcessorTest bindingProcessorTest) throws NoSuchInterfaceException
{
Interface clientInterfacefc = bindingProcessorTest.getClientInterfaceFc();
BindingBundle clientBindingBundle = bindingManager.getBindingBundle(clientInterfacefc);
assertNotNull(clientBindingBundle);
assertEquals(true, clientBindingBundle.isReferenceBinding());
assertEquals(1, clientBindingBundle.getProcessors().size());
assertEquals(bindingProcessorTest.getBindingKind(), clientBindingBundle.getProcessors().get(0).getBindingKind());
assertEquals(1, clientBindingBundle.getBoundedObjects().size());
Object stubInterfaceFc=bindingProcessorTest.getStubInterfaceFc();
Object boundedObject=stubInterfaceFc;
if(stubInterfaceFc instanceof Interface)
{
boundedObject=((Interface) stubInterfaceFc).getFcItfOwner();
}
assertEquals(boundedObject.getClass(), clientBindingBundle.getBoundedObjects().get(0).getClass());
}
public void getServerBindingBundle(BindingProcessorTest bindingProcessorTest) throws NoSuchInterfaceException
{
Interface serverInterfaceFc = bindingProcessorTest.getServerInterfaceFc();
BindingBundle serverBindingBundle = bindingManager.getBindingBundle(serverInterfaceFc);
assertNotNull(serverBindingBundle);
assertEquals(false, serverBindingBundle.isReferenceBinding());
assertEquals(1, serverBindingBundle.getProcessors().size());
assertEquals(bindingProcessorTest.getBindingKind(), serverBindingBundle.getProcessors().get(0).getBindingKind());
assertEquals(1, serverBindingBundle.getBoundedObjects().size());
Object skeltonInterfaceFc=bindingProcessorTest.getSkeltonInterfaceFc();
Object boundedObject=skeltonInterfaceFc;
if(skeltonInterfaceFc instanceof Interface)
{
boundedObject=((Interface) skeltonInterfaceFc).getFcItfOwner();
}
assertEquals(boundedObject.getClass(), serverBindingBundle.getBoundedObjects().get(0).getClass());
}
@Test
public void getJMSBindingProcessor() throws UnsupportedBindingException, NoSuchInterfaceException, UnsupportedBindingComponentException
public void jmsBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
{
IntrospectionTestSuite.deployContribution("helloworld-jms");
IntrospectionTestSuite.assertComponentExist("Publisher");
IntrospectionTestSuite.assertComponentExist("Subscriber");
Interface jmsWireItf=fractalUtil.getInterface("Publisher/pub/jmsWire");
Interface jmsWireStub=fractalUtil.getServerInterface(jmsWireItf);
assertNotNull(jmsWireStub);
BindingProcessorItf processor=bindingManager.getBindingProcessor(jmsWireStub.getFcItfOwner());
assertEquals(BindingKind.JMS, processor.getBindingKind());
Interface messageInItf=fractalUtil.getInterface("Subscriber/sub/messageIn");
List<Interface> clientInterfaces=fractalUtil.getClientInterfaces(messageInItf);
assertEquals(1, clientInterfaces.size());
Interface messageInSkelton=clientInterfaces.get(0);
assertNotNull(messageInSkelton);
processor=bindingManager.getBindingProcessor(messageInSkelton.getFcItfOwner());
assertEquals(BindingKind.JMS, processor.getBindingKind());
IntrospectionTestSuite.undeployComposite("Publisher");
IntrospectionTestSuite.undeployComposite("Subscriber");
JMSBindingProcessorTest jmsBindingProcessorTest=new JMSBindingProcessorTest();
jmsBindingProcessorTest.initTest(fractalUtil);
this.getBindinProcessor(jmsBindingProcessorTest);
this.getClientBindingBundle(jmsBindingProcessorTest);
this.getServerBindingBundle(jmsBindingProcessorTest);
jmsBindingProcessorTest.finishTest();
}
@Test
public void jsonrpcBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
{
JSONRPCBindingProcessorTest jsonrpcBindingProcessorTest=new JSONRPCBindingProcessorTest();
jsonrpcBindingProcessorTest.initTest(fractalUtil);
this.getBindinProcessor(jsonrpcBindingProcessorTest);
this.getClientBindingBundle(jsonrpcBindingProcessorTest);
this.getServerBindingBundle(jsonrpcBindingProcessorTest);
jsonrpcBindingProcessorTest.finishTest();
}
@Test
public void restBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
{
RESTBindingProcessorTest restBindingProcessorTest=new RESTBindingProcessorTest();
restBindingProcessorTest.initTest(fractalUtil);
this.getBindinProcessor(restBindingProcessorTest);
this.getClientBindingBundle(restBindingProcessorTest);
this.getServerBindingBundle(restBindingProcessorTest);
restBindingProcessorTest.finishTest();
}
@Test
public void upnpBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
{
UPnPBindingProcessorTest upnpBindingProcessorTest=new UPnPBindingProcessorTest();
upnpBindingProcessorTest.initTest(fractalUtil);
this.getBindinProcessor(upnpBindingProcessorTest);
this.getClientBindingBundle(upnpBindingProcessorTest);
this.getServerBindingBundle(upnpBindingProcessorTest);
upnpBindingProcessorTest.finishTest();
}
@Test
public void scaBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
{
SCABindingProcessorTest scaBindingProcessorTest=new SCABindingProcessorTest();
scaBindingProcessorTest.initTest(fractalUtil);
this.getBindinProcessor(scaBindingProcessorTest);
this.getClientBindingBundle(scaBindingProcessorTest);
scaBindingProcessorTest.finishTest();
}
}
/**
* OW2 FraSCAti
* Copyright (C) 2013 Inria, University of Lille 1
*
* 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: Gwenael Cattez
*
* Contributor(s):
*
*/
package org.ow2.frascati.remote.introspection.binding.processor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import junit.framework.TestCase;
import org.junit.Test;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.ow2.frascati.remote.IntrospectionTestSuite;
import org.ow2.frascati.remote.introspection.resources.BindingKind;
import org.ow2.frascati.remote.introspection.stringlist.StringList;
import org.ow2.frascati.remote.introspection.util.FractalUtilItf;
/**
*
*/
public abstract class BindingProcessorTest
{
protected Logger logger=Logger.getLogger(BindingProcessorTest.class.getName());
protected List<String> deployedComposites;
protected BindingKind bindingKind;
protected String serverInterfacePath;
protected String clientInterfacePath;
protected Interface serverInterfaceFc;