Decoupling the testsuite from the stubs, introducing dedicated ant tasks and adding a secure client for resource registration

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@43034 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2011-07-22 02:57:52 +00:00
parent 4babb8014f
commit c2615afce3
8 changed files with 293 additions and 133 deletions

View File

@ -7,6 +7,6 @@
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/GCORELIBS"/>
<classpathentry kind="lib" path="/Dependencies/ISREGISTRY/org.gcube.informationsystem.registry.stubs.jar"/>
<classpathentry kind="lib" path="/Dependencies/ISCollector/org.gcube.informationsystem.collector.stubs.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/GCF.1.1.0"/>
<classpathentry combineaccessrules="false" kind="src" path="/GCF.TRUNK"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -59,6 +59,8 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
<property name="etc.dir.name" value="etc" />
<property name="etc.dir" value="${service.dir}/${etc.dir.name}" />
<property name="source.dir" value="${service.dir}/src" />
<property name="testsuite.dir" value="${service.dir}/test" />
<!-- load input properties -->
@ -73,6 +75,8 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
<property name="garfile" value="${garname}.gar"/>
<property name="jarfile" value="${package}.jar" />
<property name="jarfile.stubs" value="${package}.stubs.jar" />
<property name="jarfile.testsuite" value="${package}.testsuite.jar" />
<if name="etics.build" value="true">
<property name="build.location" location="${service.dir}" />
@ -90,6 +94,7 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
<property name="stubs.package" value="${package}.${stubs.dir.name}"/>
<property name="stubs.dir.name" value="stubs" /> <!-- auxiliary stub classes -->
<property name="stubs.dir" value="${source.dir}/${package.dir}/${stubs.dir.name}" />
<available file="${stubs.dir}" property="stubs.dir.present"/>
<!-- temporary build locations -->
@ -101,6 +106,9 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
<property name="build.stubs.dir" location="${build.dir}/stubs-${package}" />
<property name="build.stubs.src.dir" location="${build.stubs.dir}/src" />
<property name="build.stubs.class.dir" location="${build.stubs.dir}/classes" />
<property name="build.testsuite.dir" location="${build.dir}/testsuite-${package}" />
<property name="build.testsuite.src.dir" location="${build.testsuite.dir}/test" />
<property name="build.testsuite.class.dir" location="${build.testsuite.dir}/classes" />
<!-- misc defaults -->
<property name="java.debug" value="on" />
@ -144,7 +152,11 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
<mkdir dir="${build.stubs.dir}" />
<mkdir dir="${build.stubs.src.dir}" />
<mkdir dir="${build.stubs.class.dir}"/>
<mkdir dir="${build.testsuite.dir}" />
<mkdir dir="${build.testsuite.src.dir}" />
<mkdir dir="${build.testsuite.class.dir}"/>
<!-- Populates schema folder -->
<copy toDir="${build.schema.dir}">
<fileset dir="${container.schema.dir}" casesensitive="yes">
@ -462,10 +474,39 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac
</copy>
</target>
<target name="buildTestsuite" depends="init" description="testsuite">
<copy toDir="${build.testsuite.src.dir}/" overwrite="true">
<fileset dir="${testsuite.dir}" casesensitive="yes">
<exclude name="**/*.class" />
</fileset>
</copy>
<javac srcdir="${build.testsuite.src.dir}" destdir="${build.testsuite.class.dir}" debug="${java.debug}" deprecation="${java.deprecation}" description="compile testsuite classes">
<include name="**/*.java" />
<classpath>
<fileset dir="${container.dir}/lib">
<include name="*.jar" />
<exclude name="${jarfile.testsuite}" />
<exclude name="${jarfile}" />
</fileset>
<fileset dir="${lib.location}">
<include name="**/*.jar" />
<exclude name="**/${jarfile.testsuite}" />
<exclude name="**/${jarfile}" />
</fileset>
</classpath>
</javac>
</target>
<target name="jarStubs" depends="buildStubs" description="jar stub classes">
<jar destfile="${build.lib.dir}/${jarfile.stubs}" basedir="${build.stubs.class.dir}" />
</target>
<target name="jarTestSuite" depends="buildTestsuite" description="jar testsuite classes">
<jar destfile="${build.lib.dir}/${jarfile.testsuite}" basedir="${build.testsuite.class.dir}" />
</target>
<target name="testsuite" depends="jarTestSuite" description="generates and jars testsuite"/>
<target name="deployStubs" depends="jarStubs" description="deploy stub jar">
<copy file="${build.lib.dir}/${jarfile.stubs}" toDir="${lib.location}"/>
<if name="etics.build" value="false">

View File

@ -1,51 +0,0 @@
package org.gcube.informationsystem.registry.stubs.testsuite;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.informationsystem.registry.stubs.RegistryFactoryPortType;
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator;
public class RegistryRemoveTest {
public static void main(String[] args) throws Exception {
RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {
return true;
}
};
EndpointReferenceType factoryEPR = new EndpointReferenceType();
RegistryFactoryPortType registryFactoryPortType = null;
try {
factoryEPR.setAddress(new Address(args[0]));
registryFactoryPortType = registryLocator
.getRegistryFactoryPortTypePort(factoryEPR);
} catch (Exception e) {
e.printStackTrace();
}
RemoveResourceMessage message = new RemoveResourceMessage();
// managerSec.useCredentials(cred);
registryFactoryPortType = GCUBERemotePortTypeContext.getProxy(
registryFactoryPortType, GCUBEScope.getScope(args[2]),
managerSec);
try {
message.setType(args[3]);
message.setUniqueID(args[1]);
registryFactoryPortType.removeResource(message);
System.out.println("Profile with ID " + args[1] + "has been succesfully removed");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,55 +0,0 @@
package org.gcube.informationsystem.registry.stubs.testsuite;
import java.io.FileReader;
import java.io.StringWriter;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.informationsystem.registry.stubs.RegistryFactoryPortType;
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator;
public class RegistryUpdateTest {
public static void main (String[]args ) throws Exception {
RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() { public boolean isSecurityEnabled() {return true;}};
FileReader fis = new FileReader (args[1]);
// load the resource
GCUBEResource resource = RegistryRegistrationTest.getResource(args[3], new FileReader(args[1]));
EndpointReferenceType factoryEPR = new EndpointReferenceType();
resource.load(fis);
RegistryFactoryPortType registryFactoryPortType= null;
try {
factoryEPR.setAddress(new Address(args[0]));
registryFactoryPortType = registryLocator.getRegistryFactoryPortTypePort(factoryEPR);
}catch(Exception e){
e.printStackTrace();
}
UpdateResourceMessage message = new UpdateResourceMessage();
registryFactoryPortType =GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,GCUBEScope.getScope(args[2]),managerSec);
try {
StringWriter writer =new StringWriter();
resource.store(writer);
message.setXmlProfile(writer.toString());
message.setUniqueID(resource.getID());
message.setType(args[3]);
registryFactoryPortType.updateResource(message);
System.out.println("Profile has been updated");
} catch(Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.registry.stubs.testsuite;
package org.gcube.informationsystem.registry.testsuite;
import java.io.FileReader;
import java.io.StringWriter;
@ -14,12 +14,12 @@ import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
import org.gcube.informationsystem.registry.stubs.RegistryFactoryPortType;
import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator;
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
import org.gcube.informationsystem.registry.stubs.resourceregistration.ResourceRegistrationPortType;
import org.gcube.informationsystem.registry.stubs.resourceregistration.service.ResourceRegistrationServiceAddressingLocator;
/**
* {@link GCUBEResource} registration tester
* Tester for Registration.create() operation
*
* @author Manuele Simi (CNR-ISTI)
*
@ -31,11 +31,11 @@ public class RegistryRegistrationTest {
* @param args
* parameters:
* <ul>
* <li>factory URI
* <li>registration portType URI
* <li>resource file
* <li>resource type
* <li>caller scope
*
* </ul>
* @throws Exception
* if the registration fails
*/
@ -49,7 +49,7 @@ public class RegistryRegistrationTest {
for (String param : args) System.out.println("param "+ param);
// get the scope and the factory URI
GCUBEScope scope = GCUBEScope.getScope(args[2]);
GCUBEScope scope = GCUBEScope.getScope(args[3]);
EndpointReferenceType factoryEPR = new EndpointReferenceType();
try {
@ -59,8 +59,7 @@ public class RegistryRegistrationTest {
Runtime.getRuntime().exit(1);
}
RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator();
ResourceRegistrationServiceAddressingLocator locator = new ResourceRegistrationServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {
return false;
@ -68,26 +67,17 @@ public class RegistryRegistrationTest {
};
// load the resource
GCUBEResource resource = getResource(args[3], new FileReader(args[1]));
RegistryFactoryPortType registryFactoryPortType = null;
try {
registryFactoryPortType = registryLocator
.getRegistryFactoryPortTypePort(factoryEPR);
} catch (Exception e) {
e.printStackTrace();
Runtime.getRuntime().exit(1);
}
CreateResourceMessage message = new CreateResourceMessage();
registryFactoryPortType = GCUBERemotePortTypeContext.getProxy(
registryFactoryPortType, scope, managerSec);
GCUBEResource resource = getResource(args[2], new FileReader(args[1]));
try {
ResourceRegistrationPortType registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
CreateMessage message = new CreateMessage();
registration = GCUBERemotePortTypeContext.getProxy(registration, scope, managerSec);
StringWriter writer = new StringWriter();
resource.store(writer);
message.setProfile(writer.toString());
message.setType(resource.getType());
System.out.println(registryFactoryPortType.createResource(message));
System.out.println(registration.create(message));
} catch (Exception e) {
e.printStackTrace();
@ -140,7 +130,7 @@ public class RegistryRegistrationTest {
*/
static void printUsage() {
System.out
.println("RegistryRegistrationTest <factory URI> <resource file> <caller scope> <resource type>");
.println("RegistryRegistrationTest <registration URI> <resource file> <caller scope> <resource type>");
System.out
.println("allowed types are: RunningInstance/Service/GHN/GenericResource");
System.exit(1);

View File

@ -0,0 +1,62 @@
package org.gcube.informationsystem.registry.testsuite;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.informationsystem.registry.stubs.resourceregistration.RemoveMessage;
import org.gcube.informationsystem.registry.stubs.resourceregistration.ResourceRegistrationPortType;
import org.gcube.informationsystem.registry.stubs.resourceregistration.service.ResourceRegistrationServiceAddressingLocator;
/**
*
* Tester for Registration.remove() operation
*
* @author Manuele Simi (ISTI-CNR)
*
*/
public class RegistryRemoveTest {
public static void main(String[] args) throws Exception {
for (String param : args) System.out.println("param "+ param);
// get the scope and the registration URI
GCUBEScope scope = GCUBEScope.getScope(args[2]);
EndpointReferenceType factoryEPR = new EndpointReferenceType();
try {
factoryEPR.setAddress(new Address(args[0]));
} catch (Exception e) {
e.printStackTrace();
Runtime.getRuntime().exit(1);
}
ResourceRegistrationServiceAddressingLocator locator = new ResourceRegistrationServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {
return false;
}
};
// load the resource
try {
ResourceRegistrationPortType registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
RemoveMessage message = new RemoveMessage();
registration = GCUBERemotePortTypeContext.getProxy(registration, scope, managerSec);
message.setType(args[3]);
message.setUniqueID(args[1]);
registration.remove(message);
System.out.println("Profile with ID " + args[1] + "has been succesfully removed");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,131 @@
package org.gcube.informationsystem.registry.testsuite.security;
import java.io.FileReader;
import java.io.StringWriter;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.resources.GCUBEGenericResource;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.security.GCUBESecurityManager;
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
import org.gcube.informationsystem.registry.stubs.resourceregistration.ResourceRegistrationPortType;
import org.gcube.informationsystem.registry.stubs.resourceregistration.service.ResourceRegistrationServiceAddressingLocator;
/**
* Tester for Registration.create() operation
*
* @author Manuele Simi (CNR-ISTI)
*
*/
public class SecureRegistryRegistrationTest {
/**
*
* @param args
* parameters:
* <ul>
* <li>registration portType URI
* <li>resource file
* <li>resource type
* <li>caller scope
* <li>identity
* </ul>
* @throws Exception
* if the registration fails
*/
public static void main(String[] args) throws Exception {
for (String param : args) System.out.println("param "+ param);
final boolean isSecurityEnabled = GHNContext.getContext().isSecurityEnabled();
if (args.length != 5) {
printUsage();
}
String identity = null;
if (isSecurityEnabled) identity = args [4];
GCUBEResource resource = getResource(args[2], new FileReader(args[1]));
EndpointReferenceType factoryEPR = new EndpointReferenceType();
try {
factoryEPR.setAddress(new Address(args[0]));
ResourceRegistrationServiceAddressingLocator locator = new ResourceRegistrationServiceAddressingLocator();
ResourceRegistrationPortType registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
GCUBESecurityManager securityManager = Utils.generateAndConfigureDefaultSecurityManager(identity, isSecurityEnabled);
securityManager.setSecurity(registration, GCUBESecurityManager.AuthMode.PRIVACY, GCUBESecurityManager.DelegationMode.FULL);
registration = GCUBERemotePortTypeContext.getProxy(registration, GCUBEScope.getScope(args[3]), securityManager);
CreateMessage message = new CreateMessage();
StringWriter writer = new StringWriter();
resource.store(writer);
message.setProfile(writer.toString());
message.setType(resource.getType());
System.out.println("Resource successfully registered");
} catch (Exception e) {
e.printStackTrace();
Runtime.getRuntime().exit(1);
}
}
/**
* Loads the specific GCUBEResource class
*
* @param type
* the resource type
* @param file
* the file representation of the profile
* @return the resource class
* @throws Exception
* if the loading fails
*/
static GCUBEResource getResource(String type, FileReader file)
throws Exception {
if (type.compareTo("Service") == 0) {
GCUBEService service = GHNContext
.getImplementation(GCUBEService.class);
service.load(file);
return (GCUBEResource) service;
} else if (type.compareTo("RunningInstance") == 0) {
GCUBERunningInstance instance = GHNContext
.getImplementation(GCUBERunningInstance.class);
instance.load(file);
return (GCUBEResource) instance;
} else if (type.compareTo("GHN") == 0) {
GCUBEHostingNode node = GHNContext
.getImplementation(GCUBEHostingNode.class);
node.load(file);
return (GCUBEResource) node;
} else if (type.compareTo("GenericResource") == 0) {
GCUBEGenericResource generic = GHNContext
.getImplementation(GCUBEGenericResource.class);
generic.load(file);
return (GCUBEResource) generic;
}
throw new Exception(type + " is an invalid resource type");
}
/**
* Prints tester usage syntax
*/
static void printUsage() {
System.out.println("RegistryRegistrationTest <registration URI> <resource file> <resource type> <caller scope> <identity>");
System.out.println("allowed types are: RunningInstance/Service/GHN/GenericResource");
System.exit(1);
}
}

View File

@ -0,0 +1,42 @@
package org.gcube.informationsystem.registry.testsuite.security;
import org.gcube.common.core.security.GCUBEClientSecurityManager;
import org.gcube.common.core.security.GCUBESecurityManager;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.common.core.security.context.SecurityContextFactory;
import org.gcube.common.core.utils.logging.GCUBELog;
public class Utils
{
public static GCUBESecurityManager generateAndConfigureDefaultSecurityManager (String identity, final boolean isSecurityEnabled)
{
GCUBELog logger = new GCUBELog(Utils.class);
GCUBESecurityManager securityManager = null;
if (isSecurityEnabled)
{
try {
securityManager = SecurityContextFactory.getInstance().getSecurityContext().getDefaultSecurityManager();
logger.debug("Identity = "+identity);
((GCUBEClientSecurityManager) securityManager).setDefaultIdentityParameter(identity);
} catch (Exception e) {
logger.error("Unable to generate default security manager: trying without security...",e);
securityManager = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {return isSecurityEnabled;}
};
}
}
else
{
securityManager = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {return isSecurityEnabled;}
};
}
return securityManager;
}
}