Commit 0d6edb87 authored by Gwenael Cattez's avatar Gwenael Cattez
Browse files

Split tests into test suites

Add not working binding tests
parent 569d781c
......@@ -162,7 +162,7 @@ public class RemoteScaDomainImpl implements RemoteScaDomain, Deployment
if (stringTokenizer.hasMoreTokens())
{
String parentName = nextToken(stringTokenizer);
LOG.info("Trying to get a reference to the '" + parentName + "' component");
// LOG.info("Trying to get a reference to the '" + parentName + "' component");
try
{
current = compositeManager.getComposite(parentName);
......@@ -769,8 +769,8 @@ public class RemoteScaDomainImpl implements RemoteScaDomain, Deployment
{
throw new MyWebApplicationException(nsie, "Error when trying to instrospect interface : " + itf.getFcItfName());
}
throw new MyWebApplicationException("No binding found for interface : " + itf.getFcItfName() + " at position " + position);
return null;
// throw new MyWebApplicationException("No binding found for interface : " + itf.getFcItfName() + " at position " + position);
}
/**
......@@ -795,8 +795,8 @@ public class RemoteScaDomainImpl implements RemoteScaDomain, Deployment
{
throw new MyWebApplicationException(nsie, "Error when trying to instrospect interface : " + itf.getFcItfName());
}
throw new MyWebApplicationException("No binding found for interface : " + itf.getFcItfName());
return null;
// throw new MyWebApplicationException("No binding found for interface : " + itf.getFcItfName());
}
/**
......
......@@ -163,7 +163,7 @@ public class ResourceUtil
// No sub-components
if (componentNameController != null)
{
log.info("no sub-component found for component " + componentNameController.getFcName());
// log.info("no sub-component found for component " + componentNameController.getFcName());
}
}
......@@ -431,10 +431,10 @@ public class ResourceUtil
}
} catch (Exception exception)
{
if (ownerNameController != null)
{
log.info("no binding found for fractal component : " + ownerNameController.getFcName());
}
// if (ownerNameController != null)
// {
// log.info("no binding found for fractal component : " + ownerNameController.getFcName());
// }
}
try
......
......@@ -18,7 +18,7 @@
*
* Contact: frascati@ow2.org
*
* Author: Gwnal Cattez
* Author: Gwnal Cattez
*
* Contributor(s):
*
......@@ -33,13 +33,11 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.ow2.frascati.remote.introspection.Deployment;
import org.ow2.frascati.remote.introspection.FileUtil;
import org.ow2.frascati.remote.introspection.IntrospectionAllTest;
import org.ow2.frascati.remote.introspection.deployementTests.DeployTestSuite;
......
......@@ -83,13 +83,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- Apache Commons FileUpload. -->
<dependency>
<groupId>commons-fileupload</groupId>
......@@ -103,13 +96,6 @@
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.ow2.frascati.demo</groupId>
<artifactId>common-onoffdevice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -33,6 +33,9 @@ import org.jdom.JDOMException;
import org.json.JSONException;
import org.json.JSONObject;
import org.ow2.frascati.remote.introspection.Deployment;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.ComponentTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.CompositeTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.domain.DomainTreeNode;
import org.ow2.frascati.webexplorer.tree.root.RootTreeNode;
......@@ -92,4 +95,30 @@ public class UploadServiceImpl implements UploadServiceItf
return "";
}
}
public String undeployComposite(String treeId) throws JDOMException, IOException, JSONException
{
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()==ComponentTreeNode.COMPONENT_TYPE || node.getType()==CompositeTreeNode.COMPOSITE_TYPE)
{
try
{
String domainURI=node.getDomainURI();
DomainTreeNode domain=root.getDomainByURI(domainURI);
Deployment deployment=domain.getdeploymentClient();
String nodePath=node.getFrascatiPath();
deployment.undeployComposite(nodePath);
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
catch(Exception exception)
{
return "";
}
}
return "";
}
}
......@@ -29,6 +29,7 @@ package org.ow2.frascati.webexplorer.service.upload;
import java.io.IOException;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
......@@ -58,4 +59,9 @@ public interface UploadServiceItf
@Path("/composite")
@Produces("application/json")
public String deployComposite(@FormParam("domainId") String domainId, @FormParam("compositeName") String compositeName, @FormParam("jar") String encodedComposite) throws JSONException, JDOMException, IOException;
@DELETE
@Path("/composite")
@Produces("application/json")
public String undeployComposite(@FormParam("treeId") String treeId) throws JDOMException, IOException, JSONException;
}
/**
* OW2 FraSCAti Web Explorer
*
* Copyright (c) 2011-2012 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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import javax.ws.rs.core.MultivaluedMap;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.jdom.JDOMException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.ow2.frascati.remote.introspection.FileUtil;
import org.ow2.frascati.util.FrascatiException;
import org.ow2.frascati.webexplorer.service.WebExplorerItf;
import org.ow2.frascati.webexplorer.service.upload.UploadServiceItf;
/**
*
*/
public class WebExplorerTestCase //extends FraSCAtiTestCase
{
protected FraSCAti frascati;
@Before
public void init() throws FrascatiException
{
System.setProperty("org.ow2.frascati.bootstrap", "org.ow2.frascati.bootstrap.FraSCAtiWebExplorer");
this.frascati=FraSCAti.newFraSCAti();
}
@Test
public void test() throws FrascatiException, URISyntaxException, IOException, JSONException, JDOMException, InterruptedException
{
org.objectweb.fractal.api.Component frascatiComponent=this.frascati.getComposite("org.ow2.frascati.FraSCAti");
WebExplorerItf webExplorer=this.frascati.getService(frascatiComponent, "webexplorer", WebExplorerItf.class);
assertNotNull(webExplorer);
/*getTree*/
String treeString=webExplorer.getTree();
JSONObject tree=new JSONObject(treeString);
assertNotNull(tree);
JSONObject rootDomain=getItem(tree,"text","Root");
assertNotNull(rootDomain);
/*only one default domain*/
JSONArray domains=rootDomain.getJSONArray("item");
assertEquals(domains.length(),1);
JSONObject defaultDomain=domains.getJSONObject(0);
UploadServiceItf uploader=this.frascati.getService(frascatiComponent, "webexplorerUpload", UploadServiceItf.class);
assertNotNull(uploader);
/*addDomain*/
String defaultDomainURI=defaultDomain.getString("domainURI");
String testDomainString=webExplorer.addDomain("test", defaultDomainURI, "FF0000");
JSONObject testDomain=new JSONObject(testDomainString);
assertNotNull(testDomain);
treeString=webExplorer.getTree();
tree=new JSONObject(treeString);
rootDomain=getItem(tree,"text","Root");
domains=rootDomain.getJSONArray("item");
assertEquals(domains.length(),2);
/*remove domain*/
String testDomainId=testDomain.getString("id");
treeString=webExplorer.removeDomain(testDomainId);
tree=new JSONObject(treeString);
rootDomain=getItem(tree,"text","Root");
domains=rootDomain.getJSONArray("item");
assertEquals(domains.length(),1);
/*deployContribution*/
URL url=this.getClass().getClassLoader().getResource("alarm.zip");
File contributionFile=new File(url.toURI());
String encodedContribution=FileUtil.getStringFromFile(contributionFile);
String defaultDomainId=defaultDomain.getString("id");
String domainString=uploader.deployContribution(defaultDomainId, encodedContribution);
JSONObject domain=new JSONObject(domainString);
JSONObject alarmComposite=getItem(domain, "text", "alarm");
assertNotNull(alarmComposite);
/*refreshTreeNode*/
alarmComposite=getItem(defaultDomain, "text", "alarm");
assertNull(alarmComposite);
String defaultDomainString=webExplorer.refreshTreeNode(defaultDomainId);
defaultDomain=new JSONObject(defaultDomainString);
alarmComposite=getItem(defaultDomain, "text", "alarm");
assertNotNull(alarmComposite);
/*stopComponent*/
String alarmStatus=alarmComposite.getString("status");
assertEquals(alarmStatus, "STARTED");
String alarmId=alarmComposite.getString("id");
webExplorer.stopComponent(alarmId);
String alarmCompositeString=webExplorer.refreshTreeNode(alarmId);
alarmComposite=new JSONObject(alarmCompositeString);
alarmStatus=alarmComposite.getString("status");
assertEquals(alarmStatus, "STOPPED");
/*startComponent*/
webExplorer.startComponent(alarmId);
alarmCompositeString=webExplorer.refreshTreeNode(alarmId);
alarmComposite=new JSONObject(alarmCompositeString);
alarmStatus=alarmComposite.getString("status");
assertEquals(alarmStatus, "STARTED");
/*invokeMethod*/
JSONObject alarmControl=getItem(alarmComposite, "text", "alarmControl");
assertNotNull(alarmControl);
JSONObject alarmControlInterface=getItem(alarmControl, "type", "interface");
assertNotNull(alarmControlInterface);
JSONObject getStatusMethod=getItem(alarmControlInterface, "value", "getStatus");
assertNotNull(getStatusMethod);
JSONObject onMethod=getItem(alarmControlInterface, "value", "on");
assertNotNull(onMethod);
JSONObject offMethod=getItem(alarmControlInterface, "value", "off");
assertNotNull(offMethod);
MultivaluedMap<String, String> params=new MetadataMap<String, String>();
String methodId=getStatusMethod.getString("id");
params.add("treeId", methodId);
String methodReturn=webExplorer.invokeMethod(params);
assertEquals("false", methodReturn);
params.clear();
methodId=onMethod.getString("id");
params.add("treeId", methodId);
methodReturn=webExplorer.invokeMethod(params);
assertEquals("true", methodReturn);
params.clear();
methodId=getStatusMethod.getString("id");
params.add("treeId", methodId);
methodReturn=webExplorer.invokeMethod(params);
assertEquals("true", methodReturn);
params.clear();
methodId=offMethod.getString("id");
params.add("treeId", methodId);
methodReturn=webExplorer.invokeMethod(params);
assertEquals("true", methodReturn);
params.clear();
methodId=getStatusMethod.getString("id");
params.add("treeId", methodId);
methodReturn=webExplorer.invokeMethod(params);
assertEquals("false", methodReturn);
/*setProperty*/
JSONObject alarmComponent=getItem(alarmComposite, "text", "alarm");
assertNotNull(alarmComponent);
JSONObject frameTitleProperty=getItem(alarmComponent, "text", "frameTitle");
assertNotNull(frameTitleProperty);
String frameTitlePropertyId=frameTitleProperty.getString("id");
String isSet=webExplorer.setProperty(frameTitlePropertyId, "testValue");
assertEquals(isSet, "true");
String frameTitlePropertyString=webExplorer.refreshTreeNode(frameTitlePropertyId);
frameTitleProperty=new JSONObject(frameTitlePropertyString);
String frameTitlePropertyValue=frameTitleProperty.getString("value");
assertEquals(frameTitlePropertyValue, "testValue");
/*addBinding*/
params.clear();
String alarmControlId=alarmControl.getString("id");
params.add("treeId", alarmControlId);
params.add("kind", "WS");
params.add("uri", "http://localhost:9000/AlarmControl");
// webExplorer.addBinding(params);
}
private JSONObject getItem(JSONObject parent, String searchedKey, Object searchValue) throws JSONException
{
JSONArray items=parent.getJSONArray("item");
JSONObject tmpItem,item=null;
Object tmpValue;
if(items!=null)
{
for(int i=0; i<items.length();i++)
{
tmpItem=items.getJSONObject(i);
tmpValue=tmpItem.get(searchedKey);
if(searchValue.equals(tmpValue))
{
item=tmpItem;
}
}
}
return item;
}
}
/**
* OW2 FraSCAti Web Explorer
*
* Copyright (c) 2011-2012 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.webexplorer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.julia.Julia;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.util.FrascatiException;
import org.ow2.frascati.webexplorer.binding.BindingTestSuite;
import org.ow2.frascati.webexplorer.domain.DomainTestSuite;
import org.ow2.frascati.webexplorer.node.NodeTestSuite;
import org.ow2.frascati.webexplorer.service.WebExplorerItf;
import org.ow2.frascati.webexplorer.service.upload.UploadServiceItf;
import org.ow2.frascati.webexplorer.upload.UploadTestSuite;
import static org.junit.Assert.assertNotNull;
/**
*
*/
@RunWith(Suite.class)
@SuiteClasses({DomainTestSuite.class,UploadTestSuite.class,NodeTestSuite.class,BindingTestSuite.class})
public class WebExplorerAllTest
{
public static WebExplorerItf webExplorer;
public static UploadServiceItf uploader;
/**
* Create a new FraSCAti platform and initialize the domain
*
* @throws FrascatiException
*/
@BeforeClass
public static void init() throws FrascatiException
{
System.setProperty("fractal.provider", Julia.class.getCanonicalName());
System.setProperty("org.ow2.frascati.bootstrap", "org.ow2.frascati.bootstrap.FraSCAtiWebExplorer");
FraSCAti frascati=FraSCAti.newFraSCAti();
Component frascatiComponent=frascati.getComposite("org.ow2.frascati.FraSCAti");
webExplorer=frascati.getService(frascatiComponent, "webexplorer", WebExplorerItf.class);
assertNotNull(webExplorer);
uploader=frascati.getService(frascatiComponent, "webexplorerUpload", UploadServiceItf.class);
assertNotNull(uploader);
}
public static JSONObject getItem(JSONObject parent, String searchedKey, Object searchValue) throws JSONException
{
JSONArray items=parent.getJSONArray("item");
JSONObject tmpItem,item=null;
Object tmpValue;
if(items!=null)
{
for(int i=0; i<items.length();i++)
{
tmpItem=items.getJSONObject(i);
tmpValue=tmpItem.get(searchedKey);
if(searchValue.equals(tmpValue))
{
item=tmpItem;
}
}
}
return item;
}
public static JSONObject getObject(JSONObject parent,String arrayKey, String searchedKey, Object searchValue) throws JSONException
{
JSONArray objects=parent.getJSONArray(arrayKey);
JSONObject tmpObject;
String tmpValue;
if(objects!=null)
{
for(int i=0;i<objects.length();i++)
{
tmpObject=objects.getJSONObject(i);
tmpValue=tmpObject.getString(searchedKey);
if(searchValue.equals(tmpValue))
{
return tmpObject;
}
}
}
return null;
}
}
/**
* OW2 FraSCAti Web Explorer
*
* Copyright (c) 2011-2012 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.webexplorer.binding;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.IOException;