Commit 7cc83554 authored by Gwenael Cattez's avatar Gwenael Cattez

New generic Test for BindingProcessor, allow testing CRUD operation on both service and reference

Add Generic test for WSBindingProcessor
parent f1d0e70e
......@@ -37,6 +37,12 @@ public class BindingAttribute
private String clazz;
private String value;
public BindingAttribute(String name, String value)
{
this.name=name;
this.value=value;
}
public BindingAttribute(String name, Class<?> clazz, Object value)
{
this.name=name;
......@@ -65,6 +71,19 @@ public class BindingAttribute
{
return value;
}
@Override
public boolean equals(Object obj)
{
if(obj==null || !(obj instanceof BindingAttribute))
{
return false;
}
BindingAttribute bindingAttribte=(BindingAttribute) obj;
boolean isNameEquals= this.name.equals(bindingAttribte.getName());
boolean isValueEquals=this.value.equals(bindingAttribte.getValue());
return isNameEquals && isValueEquals;
}
}
......@@ -142,12 +142,12 @@ public class BindingManagerImpl implements BindingManagerItf
/**
* @see org.ow2.frascati.remote.introspection.binding.BindingManagerItf#getBindingProcessor(java.lang.Object)
*/
public BindingProcessorItf getBindingProcessor(Object component) throws UnsupportedBindingComponentException
public BindingProcessorItf getBindingProcessor(Object boundedObject) throws UnsupportedBindingComponentException
{
BindingProcessorItf bindingProcessor;
try
{
bindingProcessor=this.getReferenceBindingProcessor(component);
bindingProcessor=this.getReferenceBindingProcessor(boundedObject);
return bindingProcessor;
}
catch (UnsupportedBindingComponentException unsupportedBindingComponentException)
......@@ -155,7 +155,7 @@ public class BindingManagerImpl implements BindingManagerItf
//nothing to do try to find a serviceBindingProcessor
}
bindingProcessor=this.getServiceBindingProcessor(component);
bindingProcessor=this.getServiceBindingProcessor(boundedObject);
return bindingProcessor;
}
......
......@@ -77,8 +77,10 @@ public class ResourceUtilImpl implements ResourceUtilItf
@Reference(name = "bindingManager")
private BindingManagerItf bindingManager;
@Reference(name= "scaModelUtil")
private SCAModelUtilItf scaModelUtil;
/**
* @see org.ow2.frascati.remote.introspection.util.ResourceUtilItf#getComponentResource(org.objectweb.fractal.api.Component)
*/
......@@ -95,6 +97,7 @@ public class ResourceUtilImpl implements ResourceUtilItf
{
compResource.setStatus(ComponentStatus.STOPPED);
}
return compResource;
}
......
......@@ -111,6 +111,7 @@
</service>
<reference name="fractalUtil" target="fractalUtil/util"/>
<reference name="bindingManager" target="bindingManager/manager"/>
<reference name="scaModelUtil" target="scaModelUtil/util"/>
</component>
<component name="scaModelUtil">
......
......@@ -170,8 +170,9 @@ public class IntrospectionTestSuite
public static StringList deployContribution(String contributionName)
{
String contributionPath=getResourcePath(contributionName+".zip");
//TODO remove comment when contribution file will be imported from maven repo
// String contributionPath=getResourcePath(contributionName+".zip");
String contributionPath="src/test/resources/"+contributionName+".zip";
String contrib = null;
try
{
......
......@@ -38,16 +38,17 @@ import org.objectweb.fractal.api.NoSuchInterfaceException;
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.BindingProcessorException;
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.JSONRPCBindingProcessorTest;
import org.ow2.frascati.remote.introspection.binding.processor.RMIBindingProcessorTest;
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.binding.processor.WSBindingProcessorTest;
import org.ow2.frascati.remote.introspection.resources.BindingKind;
import org.ow2.frascati.remote.introspection.util.FractalUtilItf;
/**
......@@ -57,14 +58,11 @@ public class BindingManagerTest
{
private static BindingManagerItf bindingManager;
private static FractalUtilItf fractalUtil;
@BeforeClass
public static void initTest()
public static void startTest()
{
System.out.println("-- BindingManagerTest");
bindingManager=IntrospectionTestSuite.getBindingManager();
fractalUtil=IntrospectionTestSuite.getFractalUtil();
}
@Test
......@@ -96,30 +94,19 @@ public class BindingManagerTest
BindingProcessorItf processor=bindingManager.getBindingProcessor(bindingProcessorTest.getBindingKind());
assertEquals(bindingProcessorTest.getBindingKind(), processor.getBindingKind());
Object stubInterfaceFc=bindingProcessorTest.getStubInterfaceFc();
if(stubInterfaceFc!=null)
Object stubObject=bindingProcessorTest.getStubObject();
if(stubObject!=null)
{
Object boundedObject=stubInterfaceFc;
if(stubInterfaceFc instanceof Interface)
{
boundedObject=((Interface) stubInterfaceFc).getFcItfOwner();
}
processor=bindingManager.getBindingProcessor(boundedObject);
processor=bindingManager.getBindingProcessor(stubObject);
assertEquals(bindingProcessorTest.getBindingKind(), processor.getBindingKind());
}
Object skeltonInterfaceFc=bindingProcessorTest.getSkeltonInterfaceFc();
if(skeltonInterfaceFc!=null)
Object skeltonObject=bindingProcessorTest.getSkeltonObject();
if(skeltonObject!=null)
{
Object boundedObject=skeltonInterfaceFc;
if(skeltonInterfaceFc instanceof Interface)
{
boundedObject=((Interface) skeltonInterfaceFc).getFcItfOwner();
}
processor=bindingManager.getBindingProcessor(boundedObject);
processor=bindingManager.getBindingProcessor(skeltonObject);
assertEquals(bindingProcessorTest.getBindingKind(), processor.getBindingKind());
}
}
public void getClientBindingBundle(BindingProcessorTest bindingProcessorTest) throws NoSuchInterfaceException
......@@ -131,13 +118,8 @@ public class BindingManagerTest
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());
Object stubObject=bindingProcessorTest.getStubObject();
assertEquals(stubObject.getClass(), clientBindingBundle.getBoundedObjects().get(0).getClass());
}
public void getServerBindingBundle(BindingProcessorTest bindingProcessorTest) throws NoSuchInterfaceException
......@@ -149,90 +131,92 @@ public class BindingManagerTest
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());
Object skeltonObject=bindingProcessorTest.getSkeltonObject();
assertEquals(skeltonObject.getClass(), serverBindingBundle.getBoundedObjects().get(0).getClass());
}
@Test
public void jmsBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
public void jmsBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException, BindingProcessorException
{
JMSBindingProcessorTest jmsBindingProcessorTest=new JMSBindingProcessorTest();
jmsBindingProcessorTest.initTest();
jmsBindingProcessorTest.startTest();
this.getBindinProcessor(jmsBindingProcessorTest);
this.getClientBindingBundle(jmsBindingProcessorTest);
this.getServerBindingBundle(jmsBindingProcessorTest);
jmsBindingProcessorTest.testSuite();
jmsBindingProcessorTest.finishTest();
}
@Test
public void jsonrpcBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
public void jsonrpcBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException, BindingProcessorException
{
JSONRPCBindingProcessorTest jsonrpcBindingProcessorTest=new JSONRPCBindingProcessorTest();
jsonrpcBindingProcessorTest.initTest();
jsonrpcBindingProcessorTest.startTest();
this.getBindinProcessor(jsonrpcBindingProcessorTest);
this.getClientBindingBundle(jsonrpcBindingProcessorTest);
this.getServerBindingBundle(jsonrpcBindingProcessorTest);
jsonrpcBindingProcessorTest.testSuite();
jsonrpcBindingProcessorTest.finishTest();
}
@Test
public void restBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
public void restBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException, BindingProcessorException
{
RestBindingProcessorTest restBindingProcessorTest=new RestBindingProcessorTest();
restBindingProcessorTest.initTest();
restBindingProcessorTest.startTest();
this.getBindinProcessor(restBindingProcessorTest);
this.getClientBindingBundle(restBindingProcessorTest);
this.getServerBindingBundle(restBindingProcessorTest);
restBindingProcessorTest.testSuite();
restBindingProcessorTest.finishTest();
}
@Test
public void rmiBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
{
SCABindingProcessorTest scaBindingProcessorTest=new SCABindingProcessorTest();
scaBindingProcessorTest.initTest();
this.getBindinProcessor(scaBindingProcessorTest);
this.getClientBindingBundle(scaBindingProcessorTest);
//TODO RMI server is not proceed
scaBindingProcessorTest.finishTest();
}
// @Test
// public void rmiBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException, BindingProcessorException
// {
// RMIBindingProcessorTest rmiBindingProcessorTest=new RMIBindingProcessorTest();
// rmiBindingProcessorTest.startTest();
// this.getBindinProcessor(rmiBindingProcessorTest);
// this.getClientBindingBundle(rmiBindingProcessorTest);
// //TODO RMI server is not proceed
// rmiBindingProcessorTest.testSuite();
// rmiBindingProcessorTest.finishTest();
// }
@Test
public void scaBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
public void scaBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException, BindingProcessorException
{
SCABindingProcessorTest scaBindingProcessorTest=new SCABindingProcessorTest();
scaBindingProcessorTest.initTest();
scaBindingProcessorTest.startTest();
this.getBindinProcessor(scaBindingProcessorTest);
this.getClientBindingBundle(scaBindingProcessorTest);
/**SCA binding on a service is a non sense*/
scaBindingProcessorTest.testSuite();
scaBindingProcessorTest.finishTest();
}
@Test
public void upnpBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
public void upnpBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException, BindingProcessorException
{
UPnPBindingProcessorTest upnpBindingProcessorTest=new UPnPBindingProcessorTest();
upnpBindingProcessorTest.initTest();
upnpBindingProcessorTest.startTest();
this.getBindinProcessor(upnpBindingProcessorTest);
this.getClientBindingBundle(upnpBindingProcessorTest);
this.getServerBindingBundle(upnpBindingProcessorTest);
upnpBindingProcessorTest.testSuite();
upnpBindingProcessorTest.finishTest();
}
@Test
public void wsBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException
public void wsBindingProcessor() throws NoSuchInterfaceException, UnsupportedBindingComponentException, UnsupportedBindingException, BindingProcessorException
{
WSBindingProcessorTest upnpBindingProcessorTest=new WSBindingProcessorTest();
upnpBindingProcessorTest.initTest();
this.getBindinProcessor(upnpBindingProcessorTest);
this.getClientBindingBundle(upnpBindingProcessorTest);
this.getServerBindingBundle(upnpBindingProcessorTest);
upnpBindingProcessorTest.finishTest();
WSBindingProcessorTest wsBindingProcessorTest=new WSBindingProcessorTest();
wsBindingProcessorTest.startTest();
this.getBindinProcessor(wsBindingProcessorTest);
this.getClientBindingBundle(wsBindingProcessorTest);
this.getServerBindingBundle(wsBindingProcessorTest);
wsBindingProcessorTest.testSuite();
wsBindingProcessorTest.finishTest();
}
......
......@@ -27,17 +27,26 @@
package org.ow2.frascati.remote.introspection.binding.processor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.ow2.frascati.remote.IntrospectionTestSuite;
import org.ow2.frascati.remote.introspection.binding.BindingAttribute;
import org.ow2.frascati.remote.introspection.binding.BindingManagerItf;
import org.ow2.frascati.remote.introspection.binding.exception.UnsupportedBindingComponentException;
import org.ow2.frascati.remote.introspection.resources.BindingKind;
import org.ow2.frascati.remote.introspection.stringlist.StringList;
import org.ow2.frascati.remote.introspection.util.FractalUtilItf;
......@@ -48,113 +57,313 @@ import org.ow2.frascati.remote.introspection.util.FractalUtilItf;
public abstract class BindingProcessorTest
{
protected Logger logger=Logger.getLogger(BindingProcessorTest.class.getName());
/**
* List of the deployed composites
*/
protected List<String> deployedComposites;
protected FractalUtilItf fractalUtil;
protected BindingKind bindingKind;
private List<String> contributionsToDeploy;
private Map<String,String> compositesToDeploy;
protected String serverInterfacePath;
protected String serverInterfaceName;
protected String clientInterfacePath;
protected String clientInterfaceName;
protected Interface serverInterfaceFc;
protected Object skeltonInterfaceFc;
protected Component serverComponentFc;
protected Object skeltonObject;
protected Interface skeltonInterfaceFc;
protected Interface clientInterfaceFc;
protected Object stubInterfaceFc;
protected Component clientComponentFc;
protected Interface stubInterfaceFc;
protected Object stubObject;
protected BindingProcessorItf bindingProcessor;
public BindingProcessorTest(BindingKind bindingKind, String serverInterfacePath, String clientInterfacePath)
{
this.bindingKind=bindingKind;
this.serverInterfacePath=serverInterfacePath;
this.clientInterfacePath=clientInterfacePath;
this.contributionsToDeploy=new ArrayList<String>();
this.compositesToDeploy=new HashMap<String, String>();
}
protected void addContributionToDeploy(String contributionName)
{
this.contributionsToDeploy.add(contributionName);
}
protected void addCompositeToDeploy(String compositeFileName, String compositeName)
{
this.compositesToDeploy.put(compositeFileName, compositeName);
}
public void initTest() throws NoSuchInterfaceException
/**
* Deployed composites and retrieve fractal server and client interfaces based on
*
* @throws NoSuchInterfaceException if serverInterfaceFc or clientInterfaceFc can't be found serverInterfacePath and clientInterfacePath
*/
public void startTest() throws NoSuchInterfaceException
{
logger.info("Init test "+this.getClass().getName());
this.logEntering("startTest");
this.fractalUtil=IntrospectionTestSuite.getFractalUtil();
this.deployedComposites=new ArrayList<String>();
List<String> contributionsToDeploy=this.getContributionsToDeploy();
if(contributionsToDeploy!=null)
/**deploy contributions*/
StringList deployedContributionStringList;
for(String contributionFileName : contributionsToDeploy)
{
StringList deployedContributionStringList;
for(String contributionFileName : contributionsToDeploy)
{
deployedContributionStringList=IntrospectionTestSuite.deployContribution(contributionFileName);
this.deployedComposites.addAll(deployedContributionStringList.getStringList());
}
deployedContributionStringList=IntrospectionTestSuite.deployContribution(contributionFileName);
this.log(" contribution "+contributionFileName+" deployed");
this.deployedComposites.addAll(deployedContributionStringList.getStringList());
}
Map<String,String> compositesToDeploy=this.getCompositesToDeploy();
if(compositesToDeploy!=null)
/** deploy composites*/
String deployedComposite;
for(String compositeFileName : compositesToDeploy.keySet())
{
String deployedComposite;
for(String compositeFileName : compositesToDeploy.keySet())
{
deployedComposite=IntrospectionTestSuite.deployComposite(compositeFileName, compositesToDeploy.get(compositeFileName));
this.deployedComposites.add(deployedComposite);
}
deployedComposite=IntrospectionTestSuite.deployComposite(compositeFileName, compositesToDeploy.get(compositeFileName));
this.log(" contribution "+deployedComposite+" deployed");
this.deployedComposites.add(deployedComposite);
}
this.serverInterfaceFc=fractalUtil.getInterface(this.serverInterfacePath);
assertNotNull(this.serverInterfaceFc);
List<Object> clientInterfaces=fractalUtil.getClientInterfaces(this.serverInterfaceFc);
if(!clientInterfaces.isEmpty())
/** get the fractal server interface is defined in serverInterfacePath*/
if(this.serverInterfacePath!=null && !"".equals(this.serverInterfacePath))
{
this.skeltonInterfaceFc=clientInterfaces.get(0);
assertNotNull(skeltonInterfaceFc);
this.serverInterfaceFc=fractalUtil.getInterface(this.serverInterfacePath);
assertNotNull(this.serverInterfaceFc);
this.serverComponentFc=this.serverInterfaceFc.getFcItfOwner();
this.serverInterfaceName=fractalUtil.getComponentName(this.serverComponentFc)+"/"+this.serverInterfaceFc.getFcItfName();
this.log("server : "+this.serverInterfaceName);
initServer();
}
/** get the fractal client interface is defined in clientInterfacePath*/
if(this.clientInterfacePath!=null && !"".equals(this.clientInterfacePath))
{
this.clientInterfaceFc=fractalUtil.getInterface(this.clientInterfacePath);
this.clientComponentFc=this.clientInterfaceFc.getFcItfOwner();
this.clientInterfaceName=fractalUtil.getComponentName(this.clientComponentFc)+"/"+this.clientInterfaceFc.getFcItfName();
this.log("client : "+this.clientInterfaceName);
assertNotNull(this.clientInterfaceFc);
initClient();
}
this.clientInterfaceFc=fractalUtil.getInterface(this.clientInterfacePath);
assertNotNull(this.clientInterfaceFc);
this.stubInterfaceFc=fractalUtil.getServerInterface(this.clientInterfaceFc);
assertNotNull(this.stubInterfaceFc);
}
protected List<String> getContributionsToDeploy()
public abstract void testSuite() throws BindingProcessorException;
public void finishTest()
{
return new ArrayList<String>();
this.logEntering("finishTest");
for(String deployedComposite : this.deployedComposites)
{
IntrospectionTestSuite.undeployComposite(deployedComposite);
this.log("composite "+deployedComposite+" undeloyed");
}
}
protected Map<String,String> getCompositesToDeploy()
/**
* Init server side, get skelton objects and check if this skelton is related to the current BindingKind
*/
private void initServer()
{
return new HashMap<String, String>();
logEntering("initServer");
List<Object> clientInterfaces=fractalUtil.getClientInterfaces(this.serverInterfaceFc);
assertEquals(1, clientInterfaces.size());
this.skeltonObject=clientInterfaces.get(0);
assertNotNull(this.skeltonObject);
if(this.skeltonObject instanceof Interface)
{
this.skeltonInterfaceFc=(Interface) this.skeltonObject;
this.skeltonObject=this.skeltonInterfaceFc.getFcItfOwner();
assertNotNull(this.skeltonObject);
}
try
{
BindingManagerItf bindingManager=IntrospectionTestSuite.getBindingManager();
this.bindingProcessor=bindingManager.getBindingProcessor(this.skeltonObject);
StringBuilder inconsistantBindingKing=new StringBuilder("Inconsistent BindingProcessor : ");
inconsistantBindingKing.append("The provided serverInterfacePath "+this.serverInterfacePath);
inconsistantBindingKing.append(" is bound to "+this.bindingProcessor.getBindingKind()+" skelton");
inconsistantBindingKing.append(", but the provided BindingKind is "+this.getBindingKind().name());
assertEquals(inconsistantBindingKing.toString(),this.bindingKind, this.bindingProcessor.getBindingKind());
}
catch (UnsupportedBindingComponentException unsupportedBindingComponentException)
{
logger.warning("BindingProcessorTest initTest"+unsupportedBindingComponentException.getMessage());
}
}
/**
* Init client side, get stub objects and check if this stub is related to the current BindingKind
*/
private void initClient()
{
this.stubObject=fractalUtil.getServerInterface(this.clientInterfaceFc);
assertNotNull(this.stubObject);
if(this.stubObject instanceof Interface)
{
this.stubInterfaceFc=(Interface) this.stubObject;
this.stubObject=this.stubInterfaceFc.getFcItfOwner();
}