[MOBY-guts] biomoby commit

senger@ebi.ac.uk senger at pub.open-bio.org
Thu Jun 12 10:00:22 UTC 2003


senger
Thu Jun 12 06:00:22 EDT 2003
Update of /home/repository/moby/moby-live/Java/Clients
In directory pub.open-bio.org:/tmp/cvs-serv9158/Clients

Modified Files:
	TestingCentral.java 
Log Message:


moby-live/Java/Clients TestingCentral.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/Clients/TestingCentral.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/Clients/TestingCentral.java	2003/03/02 20:48:24	1.4
+++ /home/repository/moby/moby-live/Java/Clients/TestingCentral.java	2003/06/12 10:00:22	1.5
@@ -1,25 +1,18 @@
 // TestingCentral.java
-//    A sample client accessing a Moby Central service.
+//    A client testing methods of a Moby Central.
 //
 //    senger at ebi.ac.uk
 //    November 2002
 //
 
-import org.biomoby.shared.Utils;
+import org.biomoby.shared.*;
+import org.biomoby.client.*;
 
-import org.apache.axis.client.*;
-import org.apache.axis.*;
-import javax.xml.namespace.QName;
 import java.net.*;
 import java.util.*;
 
 /**
- * An example how to call Moby registry directly.
- * It is written using <a href="http://xml.apache.org/axis/" target="_top">Apache Axis</a>
- * (tested with Axis version 1.0).
- *<p>
- *
- * This is a testing client that calls as many Moby method as possible
+ * This is a testing client that calls as many Moby methods as possible
  * in order to test whether they return an error or not. Many pieces are
  * there hard-coded - so there is no much sense to use it for anything
  * else than just testing.
@@ -27,228 +20,56 @@
  *
  * The command-line arguments for this client are:
  * <pre>
- *    -e &lt;endpoint&gt;
- *    -u &lt;uri&gt;
+ *    Usage: java TestingCentral [-e <endpoint>] [-u <uri>] [-debug]
  * </pre>
- * where <em>endpoint</em> is a URL of a Moby Central service
- * and <em>uri</em> is a namespace used by that service (some default
+ * where <em>endpoint</em> is a URL of a Moby Central registry
+ * (default value is <tt>http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY-Central.pl</tt>,
+ * or whatever is defined in <tt>org.biomoby.client.CentralImpl.DEFAULT_ENDPOINT)
+ * and <em>uri</em> is a namespace used by that service
+ * (default value is <tt>http://mobycentral.cbr.nrc.ca/MOBY/Central</tt>
  * values applied if not given on the command-line).
+ * or whatever is defined in <tt>org.biomoby.client.CentralImpl.DEFAULT_NAMESPACE).
+ * With <em>-debug</em> the whole XML input that is being sent to the Moby Central 
+ * registry is printed.
  *<p>
  *
- * By default it does all tests. But you can signal not to do any tests
- * by the command-line option <tt>-na</tt>, or by one or more specific
- * command-line options:
- *<pre>
- *  -no   ... do not test object type
- *  -nt   ... do not test service type
- *  -ns   ... do not test service
- *  -ms   ... do not test namespace
- *  -nl   ... do not do retrieval tests
- *</pre>
- * Of course, this makes sense only if you specify what tests you really
- * want to do using one or more other command-line options:
- *<pre>
- *  -o    ... do object test
- *  -t    ... do service type test
- *  -m    ... do namespace test
- *  -s    ... do service test
- *  -l    ... do all retrieval tests
- *  -ls   ... do service names retrieval
- *  -lt   ... do service types retrieval
- *  -lp   ... do providers retrieval
- *  -ln   ... do namespaces retrieval
- *  -lo   ... do object retrieval
- *</pre>
- *
  * @author <A HREF="mailto:senger at ebi.ac.uk">Martin Senger</A>
  * @version $Id$ */
 public class TestingCentral {
 
-    private URL target;
-    private String uri;
-
-    /*************************************************************************
-     * Constructor
-     *************************************************************************/
-    public TestingCentral (String endpoint, String uri)
-	throws MalformedURLException {
-	target = new java.net.URL (endpoint);
-	this.uri = uri;
-    }
+    private String emailContact = "mail at mail.com";
 
     /*************************************************************************
-     * Call 'method' with 'parameters' and return its result. Exit on error...
+     * Create a ServiceType object.
      *************************************************************************/
-    protected Object doCall (String method, Object[] parameters) {
-	Call call = null;
-	try {
-	    Service service = new Service();
-	    AxisEngine engine = service.getEngine();
-	    engine.setOption (AxisEngine.PROP_DOMULTIREFS, new Boolean (false));
-	    call = (Call) service.createCall();
-	    call.setTargetEndpointAddress (target);
-	    return call.invoke (uri, method, parameters);
-
-	} catch (AxisFault e) {
-	    System.err.println (Utils.formatFault (e, target.toString(),
-						   (call == null ? null : call.getOperationName())));
-	    System.exit (1);
-	} catch (Exception e) {
-	    System.err.println (e.toString());
-	    e.printStackTrace();
-	    System.exit (1);
- 	}
-	return null;
-    }
-
-    /*************************************************************************
-     * Extract 'id' from an XML... (as paintlessly as possible :-) ).
-     * Return an empty string if no 'id' found.
-     *************************************************************************/
-    protected String extractId (String xml) {
-	String id = "";
-	int pos = xml.indexOf ("<id>");
-	if (pos > -1) {
-	    int pos2 = xml.indexOf ("</id>");
-	    if (pos2 > pos)
-		id = xml.substring (pos + 4, pos2);
-	}
-	return id;
+    protected MobyServiceType createServiceType (String serviceTypeName) {
+	MobyServiceType stype = new MobyServiceType (serviceTypeName);
+	stype.setDescription ("description for " + serviceTypeName);
+	stype.setAuthority ("testing.org");
+	stype.setEmailContact (emailContact);
+	return stype;
     }
 
     /*************************************************************************
-     * Register service type; return resulting xml
+     * Create a Namespace object.
      *************************************************************************/
-    protected String registerServiceType (String serviceTypeName) {
-	//
-	System.out.println ("METHOD: registerServiceType '" + serviceTypeName + "\'");
-	String result =
-	    (String)doCall ("registerServiceType",
-			    new Object[] {
-				"<registerServiceType>" +
-				  "<serviceType>" + serviceTypeName + "</serviceType>" +
-				  "<Description>" +
-				    "<![CDATA[ This is ONLY A TESTING service type. ]]>" +
-				  "</Description>" +
-				  "<ISA>" +
-				    "<serviceType>Service</serviceType>" +
-				  "</ISA>" +
-				"</registerServiceType>"
-			    });
-	System.out.println ("----------------------------\n" + result);
-	return result;
+    protected MobyNamespace createNamespace (String namespaceName) {
+	MobyNamespace namespace = new MobyNamespace (namespaceName);
+	namespace.setDescription ("description for " + namespaceName);
+	namespace.setAuthority ("testing.org");
+	namespace.setEmailContact (emailContact);
+	return namespace;
     }
 
     /*************************************************************************
-     * Deregister service type; return resulting xml
+     * Create a DataType object
      *************************************************************************/
-    protected String deregisterServiceType (String serviceTypeId) {
-	System.out.println ("METHOD: deregisterServiceType \"" + serviceTypeId + "\"");
-	String result =
-	    (String)doCall ("deregisterServiceType",
-			    new Object[] {
-				"<deregisterServiceType>" +
-				  "<serviceTypeAcc>" + serviceTypeId + "</serviceTypeAcc>" +
-				"</deregisterServiceType>"
-			    });
-	System.out.println ("---------------------------\n" + result);
-	return result;
-    }
-
-    /*************************************************************************
-     * Register namespace; return resulting xml
-     *************************************************************************/
-    protected String registerNamespace (String namespaceName) {
-	System.out.println ("METHOD: registerNamespace \"" + namespaceName + "\"");
-	String result =
-	    (String)doCall ("registerNamespace",
-			    new Object[] {
-				"<registerNamespace>" +
-				  "<namespaceType>" + namespaceName + "</namespaceType>" +
-				  "<authURI>org.embl.ebi.senger</authURI>" +
-				  "<Description>" +
-				    "<![CDATA[ This is ONLY A TESTING namespace. ]]>" +
-				  "</Description>" +
-				  "<Clobber>0</Clobber>" +
-				"</registerNamespace>"
-			    });
-	System.out.println ("----------------------------\n" + result);
-	return result;
-    }
-
-    /*************************************************************************
-     * Deregister namespace; return resulting xml
-     *************************************************************************/
-    protected String deregisterNamespace (String namespaceId) {
-	System.out.println ("METHOD: deregisterNamespace \"" + namespaceId + "\"");
-	String result =
-	    (String)doCall ("deregisterNamespace",
-			    new Object[] {
-				"<deregisterNamespace>" +
-				  "<namespaceAcc>" + namespaceId + "</namespaceAcc>" +
-				"</deregisterNamespace>"
-			    });
-	System.out.println ("---------------------------\n" + result);
-	return result;
-    }
-
-    /*************************************************************************
-     * Register object; return resulting xml
-     *************************************************************************/
-    protected String registerObject (String objectType, String xsd) {
-	System.out.println ("METHOD: registerObject \"" + objectType + "\"");
-	String result =
-	    (String)doCall ("registerObject",
-			    new Object[] {
-				"<registerObject>" +
-				  "<objectType>" + objectType + "</objectType>" +
-				  "<Description><![CDATA[" +
-				    "This is a biologically completely useless object." +
-				    "Its only purpose is to test MOBY central method calls." +
-				    "]]>" +
-				  "</Description>" +
-				  "<ISA>" +
-				    "<objectType>Object</objectType>" +
-				  "</ISA>" +
-				  "<authURI>org.embl.ebi.senger</authURI>" +
-				  "<Clobber>2</Clobber>" +
-				  "<xsd>" + xsd + "</xsd>" +
-				"</registerObject>"
-			    });
-	System.out.println ("----------------------------\n" + result);
-	return result;
-    }
-
-    /*************************************************************************
-     * Deregister object; return resulting xml
-     *************************************************************************/
-    protected String deregisterObject (String objectId) {
-	System.out.println ("METHOD: deregisterObject \"" + objectId + "\"");
-	String result =
-	    (String)doCall ("deregisterObject",
-			    new Object[] {
-				"<deregisterObject>" +
-				  "<objectAcc>" + objectId + "</objectAcc>" +
-				"</deregisterObject>"
-			    });
-	System.out.println ("---------------------------\n" + result);
-	return result;
-    }
-
-    /*************************************************************************
-     * Retrieve object; return resulting xml
-     *************************************************************************/
-    protected String retrieveObject (String objectType) {
-	System.out.println ("METHOD: retrieveObject '" + objectType + "'");
-	String result =
-	    (String)doCall ("retrieveObject",
-			    new Object[] {
-				"<retrieveObject>" +
-				  "<objectType>" + objectType + "</objectType>" +
-				"</retrieveObject>"
-			    });
-	System.out.println ("---------------------------\n" + result);
-	return result;
+    protected MobyDataType createDataType (String objectType) {
+	MobyDataType data = new MobyDataType (objectType);
+	data.setDescription ("description for " + objectType);
+	data.setAuthority ("testing.org");
+	data.setEmailContact (emailContact);
+	return data;
     }
 
     /*************************************************************************
@@ -260,27 +81,16 @@
 	try {
 
 	    // default values
- 	    String endpoint = "http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY-Central.pl";
-//   	    String endpoint = "http://198.166.4.151/cgi-bin/MOBY-Central.pl";
-	    String uri      = "http://mobycentral.cbr.nrc.ca/MOBY/Central";
-
-	    boolean testLists = true;
-	    boolean testListServiceNames = true;
-	    boolean testListServiceTypes = true;
-	    boolean testListProviders = true;
-	    boolean testListNamespaces = true;
-	    boolean testListObjects = true;
-	    boolean testObject = true;
-	    boolean testServiceType = true;
-	    boolean testNamespace = true;
-	    boolean testService = true;
+ 	    String endpoint = CentralImpl.DEFAULT_ENDPOINT;
+	    String uri      = CentralImpl.DEFAULT_NAMESPACE;
+            boolean debug = false;
 
 	    // command-line parameters
 	    int i = 0;
 	    while (i < args.length) {
 		if (args[i].equals ("-help") || args[i].equals ("-")) {
 		    System.out.println
-			("Usage: java TestingCentral [-e <endpoint>] [-u <uri>]");
+			("Usage: java TestingCentral [-e <endpoint>] [-u <uri>] [-debug]");
 		    System.exit (0);
 		}
 		if (args[i].equals ("-e") && i < args.length-1) {
@@ -293,237 +103,272 @@
 		    i += 2;
 		    continue;
 		}
-		if (args[i].equals ("-na")) {
-		    testObject      = false;
-		    testLists       = false;
-		    testServiceType = false;
-		    testNamespace   = false;
-		    testService     = false;
-		    testListServiceNames = testListServiceTypes = testListProviders =
-			testListNamespaces = testListObjects = false;
+		if (args[i].equals ("-debug")) {
+		    debug = true;
+		    i += 1;
+		    continue;
 		}
-		if (args[i].equals ("-o"))  testObject = true;
-		if (args[i].equals ("-no")) testObject = false;
-		if (args[i].equals ("-t"))  testServiceType = true;
-		if (args[i].equals ("-nt")) testServiceType = false;
-		if (args[i].equals ("-m"))  testNamespace = true;
-		if (args[i].equals ("-ms")) testNamespace = false;
-		if (args[i].equals ("-s"))  testService = true;
-		if (args[i].equals ("-ns")) testService = false;
-
-		if (args[i].equals ("-l"))  testLists = true;
-		if (args[i].equals ("-nl")) testLists = false;
-		if (args[i].equals ("-ls")) testListServiceNames = true;
-		if (args[i].equals ("-lt")) testListServiceTypes = true;
-		if (args[i].equals ("-lp")) testListProviders = true;
-		if (args[i].equals ("-ln")) testListNamespaces = true;
-		if (args[i].equals ("-lo")) testListObjects = true;
-
 		i++;
 	    }
 
 	    // create service proxy...
-	    TestingCentral client = new TestingCentral (endpoint, uri);
+ 	    TestingCentral helper = new TestingCentral();
+	    Central worker = new CentralImpl (endpoint, uri);
 
 	    // ...and call other methods:
 	    String result;
 
-	    if (testObject) {
-		String objectType = "TestingObjectType";
-		result = client.registerObject (objectType, "<blank/>");
-		String objectId = client.extractId (result);
-		client.retrieveObject (objectType);
-		client.deregisterObject (objectId);
-		client.retrieveObject (objectType);  // not-existing
-	    }
-
-	    if (testLists || testListServiceNames) {
-		System.out.println ("METHOD: retrieveServiceNames");
-		result = (String)client.doCall ("retrieveServiceNames",
-						new Object[] {});
-		System.out.println ("----------------------------\n" + result);
-	    }
-	    if (testLists || testListProviders) {
-		System.out.println ("METHOD: retrieveServiceProviders");
-		result = (String)client.doCall ("retrieveServiceProviders",
-						new Object[] {});
-		System.out.println ("--------------------------------\n" + result);
-	    }
-
-	    if (testLists || testListServiceTypes) {
-		System.out.println ("METHOD: retrieveServiceTypes");
-		result = (String)client.doCall ("retrieveServiceTypes",
-						new Object[] {});
-		System.out.println ("----------------------------\n" + result);
-	    }
-
-	    if (testLists || testListNamespaces) {
-		System.out.println ("METHOD: retrieveNamespaces");
-		result = (String)client.doCall ("retrieveNamespaces",
-						new Object[] {});
-		System.out.println ("--------------------------\n" + result);
-	    }
-		
-	    if (testLists || testListObjects) {
-		System.out.println ("METHOD: retrieveObjectNames");
-		result = (String)client.doCall ("retrieveObjectNames",
-						new Object[] {});
-		System.out.println ("---------------------------\n" + result);
-	    }
-
-	    if (testServiceType) {
-		String uniqueName = "TestingServiceType_" + new Date().getTime();
-		result = client.registerServiceType (uniqueName);
-		String serviceTypeId = client.extractId (result);
-		result = client.deregisterServiceType (serviceTypeId);
-	    }
-
-	    if (testNamespace) {
-		String uniqueName = "TestingNamespace_" + new Date().getTime();
-		result = client.registerNamespace (uniqueName);
-		String namespaceId = client.extractId (result);
-		result = client.deregisterNamespace (namespaceId);
-	    }
 
-	    if (testService) {
-		String serviceName = "TestingService_" + new Date().getTime();
-		String serviceType = "TestingServiceType_" + new Date().getTime();
-		String objectType1 = "TestingObjectType1_" + new Date().getTime();
-		String namespace1  = "TestingNamespace1_" + new Date().getTime();
-		String objectType2 = "TestingObjectType2_" + new Date().getTime();
-		String namespace2  = "TestingNamespace2_" + new Date().getTime();
-		String objectType3 = "TestingObjectType3_" + new Date().getTime();
-		String objectType4 = "TestingObjectType4_" + new Date().getTime();
-		String authURI = "org.embl.ebi.senger";
-
-		result = client.registerServiceType (serviceType);
-		String serviceTypeId = client.extractId (result);
-		result = client.registerNamespace (namespace1);
-		String namespaceId1 = client.extractId (result);
-		result = client.registerNamespace (namespace2);
-		String namespaceId2 = client.extractId (result);
-		result = client.registerObject (objectType1, "<blank/>");
-		String objectId1 = client.extractId (result);
-		result = client.registerObject (objectType2, "<blank/>");
-		String objectId2 = client.extractId (result);
-		result = client.registerObject (objectType3, "<blank/>");
-		String objectId3 = client.extractId (result);
-		result = client.registerObject (objectType4, "<blank/>");
-		String objectId4 = client.extractId (result);
-
-		// 1. register a service
-		System.out.println ("METHOD: registerService '" + serviceName + "'");
-		result = (String)client.doCall ("registerService",
-						new Object[] {
-						    "<registerService>" +
-						      "<Category>moby</Category>" +
-						      "<serviceName>" + serviceName + "</serviceName>" +
-						      "<serviceType>" + serviceType + "</serviceType>" +
-						      "<authURI>" + authURI + "</authURI>" +
-						      "<inputObjects>" +
-						        "<Input>" +
-						          "<objectType>" + objectType1 + "</objectType>" +
-						           "<namespaceType>" + namespace1 + "</namespaceType>" +
-						        "</Input>" +
-						        "<Input>" +
-						          "<objectType>" + objectType2 + "</objectType>" +
-						          "<namespaceType>" + namespace2 + "</namespaceType>" +
-						        "</Input>" +
-						      "</inputObjects>" +
-						      "<outputObjects>" +
-						        "<objectType>" + objectType3 + "</objectType>" +
-						        "<objectType>" + objectType4 + "</objectType>" +
-						      "</outputObjects>" +
-						      "<URL>http://not.existing.server/not.existing.service</URL>" +
-						      "<Description><![CDATA[" +
-						        "This is ONLY A TESTING service." +
-						        "]]>" +
-						      "</Description>" +
-						    "</registerService>"
-						});
-		System.out.println ("----------------------------\n" + result);
-		String serviceId = client.extractId (result);
-
-		// 2. locate service byte service type
-		System.out.println ("METHOD: locateServiceByType '" + serviceType + "'");
-		result = (String)client.doCall ("locateServiceByType",
-						new Object[] {
-						    "<locateServiceByType>" +
-						      "<serviceType>" + serviceType + "</serviceType>" +
-						      "<fullServices>1</fullServices>" +
-						    "</locateServiceByType>"
-						});
-		System.out.println ("---------------------------\n" + result);
-
-		// 3. locate service by input type
-		System.out.println ("METHOD: locateServiceByInput");
-		result = (String)client.doCall ("locateServiceByInput",
-						new Object[] { 
-						    "<locateServiceByInput>" +
-						      "<inputObjects>" +
-						        "<Input>" +
-						          "<objectType>" + objectType1 + "</objectType>" +
-						          "<namespaceType>" + namespace1 + "</namespaceType>" +
-						        "</Input>" +
-						        "<Input>" +
-						          "<objectType>" + objectType2 + "</objectType>" +
-						          "<namespaceType>" + namespace2 + "</namespaceType>" +
-						        "</Input>" +
-						      "</inputObjects>" +
-						      "<serviceType>" + serviceType + "</serviceType>" +
-						      "<authURI>" + authURI + "</authURI>" +
-						      "<fullObjects>1</fullObjects>" +
-						      "<fullServices>1</fullServices>" +
-						    "</locateServiceByInput>"
-						});
- 		System.out.println ("--------------------------------\n" + result);
-
-		// 4. locate service by output type
-		System.out.println ("METHOD: locateServiceByOutput");
-		result = (String)client.doCall ("locateServiceByOutput",
-						new Object[] { 
-						    "<locateServiceByOutput>" +
-						      "<objectType>" + objectType4 + "</objectType>" +
-						      "<serviceType>" + serviceType + "</serviceType>" +
-						      "<authURI>" + authURI + "</authURI>" +
-						      "<fullObjects>1</fullObjects>" +
-						      "<fullServices>1</fullServices>" +
-						    "</locateServiceByOutput>"
-						});
-		System.out.println ("---------------------------------\n" + result);
-
-		// 5. retrieve service (by service name)
-		System.out.println ("METHOD: retrieveService");
-		result = (String)client.doCall ("retrieveService",
-						new Object[] {
-						    "<retrieveService>" +
-						      "<authURI>" + authURI + "</authURI>" +
-						      "<serviceName>" + serviceName + "</serviceName>" +
-						    "</retrieveService>"
-						});
-		System.out.println ("-----------------------\n" + result);
-
-		// 6. deregister service
-		System.out.println ("METHOD: deregisterService \"" + serviceTypeId + "\"");
-		result = (String)client.doCall ("deregisterService",
-						new Object[] {
-						    "<deregisterService>" +
-						      "<serviceID>" + serviceId + "</serviceID>" +
-						    "</deregisterService>"
-
-						});
-		System.out.println ("---------------------------\n" + result);
-
-		// 7. deregister the rest
-		result = client.deregisterServiceType (serviceTypeId);
-		result = client.deregisterObject (objectId1);
-		result = client.deregisterObject (objectId2);
-		result = client.deregisterObject (objectId3);
-		result = client.deregisterObject (objectId4);
-		result = client.deregisterNamespace (namespaceId1);
-		result = client.deregisterNamespace (namespaceId2);
+	    try {
+		start ("retrieveServiceNames");
+		Map serviceNames = worker.getServiceNames();
+		ok();
+	    } catch (MobyException e) { error (e); }
+
+	    try {
+		start ("retrieveServiceProviders");
+		String[] providers = worker.getProviders();
+		ok();
+	    } catch (MobyException e) {	error (e); }
+
+	    try {
+		start ("retrieveServiceTypes");
+		Map serviceTypes = worker.getServiceNames();
+		ok();
+	    } catch (MobyException e) {	error (e); }
+
+	    try {
+		start ("retrieveNamespaces");
+		Map namespaces = worker.getNamespaces();
+		ok();
+	    } catch (MobyException e) {	error (e); }
+
+ 	    try {
+		start ("retrieveObjectNames");
+		Map typeNames = worker.getDataTypeNames();
+		ok();
+	    } catch (MobyException e) {	error (e); }
+
+	    String uniqueName = "MyTestingServiceType_" + new Date().getTime();
+	    MobyServiceType stype = helper.createServiceType (uniqueName);
+ 	    try {
+		start ("registerServiceType");
+		worker.registerServiceType (stype);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+
+ 	    try {
+		start ("deregisterServiceType");
+		worker.unregisterServiceType (stype);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+
+	    uniqueName = "MyTestingNamespace_" + new Date().getTime();
+	    MobyNamespace namespace = helper.createNamespace (uniqueName);
+ 	    try {
+		start ("registerNamespace");
+		worker.registerNamespace (namespace);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+
+ 	    try {
+		start ("deregisterNamespace");
+		worker.unregisterNamespace (namespace);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+
+	    String name1 = "MyTestingDataType_" + new Date().getTime() + 1;
+	    String name2 = "MyTestingDataType_" + new Date().getTime() + 2;
+	    String name3 = "MyTestingDataType_" + new Date().getTime() + 3;
+	    MobyDataType data1 = helper.createDataType (name1);
+	    MobyDataType data2 = helper.createDataType (name2);
+	    MobyDataType data3 = helper.createDataType (name3);
+ 	    try {
+		start ("registerDataType - 1");
+		worker.registerDataType (data1);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+ 	    try {
+		start ("registerDataType - 3");
+		worker.registerDataType (data3);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+ 	    try {
+		start ("registerDataType - 2");
+		data2.addParentName (data1.getName());
+		data2.addChild ("len", "Integer");
+		data2.addChild ("sub", "String");
+		data2.addChild ("real_type", data3.getName());
+		worker.registerDataType (data2);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+
+ 	    try {
+		start ("deregisterDataType - 3");
+		worker.unregisterDataType (data3);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+ 	    try {
+		start ("deregisterDataType - 2");
+		worker.unregisterDataType (data2);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+ 	    try {
+		start ("deregisterDataType - 1");
+		worker.unregisterDataType (data1);
+		ok();
+	    } catch (MobyException e)      { error (e);
+	    } catch (NoSuccessException e) { error (e); }
+
+
+// 	    if (testService) {
+// 		String serviceName = "TestingService_" + new Date().getTime();
+// 		String serviceType = "TestingServiceType_" + new Date().getTime();
+// 		String objectType1 = "TestingObjectType1_" + new Date().getTime();
+// 		String namespace1  = "TestingNamespace1_" + new Date().getTime();
+// 		String objectType2 = "TestingObjectType2_" + new Date().getTime();
+// 		String namespace2  = "TestingNamespace2_" + new Date().getTime();
+// 		String objectType3 = "TestingObjectType3_" + new Date().getTime();
+// 		String objectType4 = "TestingObjectType4_" + new Date().getTime();
+// 		String authURI = "org.embl.ebi.senger";
+
+// 		result = client.registerServiceType (serviceType);
+// 		String serviceTypeId = client.extractId (result);
+// 		result = client.registerNamespace (namespace1);
+// 		String namespaceId1 = client.extractId (result);
+// 		result = client.registerNamespace (namespace2);
+// 		String namespaceId2 = client.extractId (result);
+// 		result = client.registerObject (objectType1, "<blank/>");
+// 		String objectId1 = client.extractId (result);
+// 		result = client.registerObject (objectType2, "<blank/>");
+// 		String objectId2 = client.extractId (result);
+// 		result = client.registerObject (objectType3, "<blank/>");
+// 		String objectId3 = client.extractId (result);
+// 		result = client.registerObject (objectType4, "<blank/>");
+// 		String objectId4 = client.extractId (result);
+
+// 		// 1. register a service
+// 		System.out.println ("METHOD: registerService '" + serviceName + "'");
+// 		result = (String)client.doCall ("registerService",
+// 						new Object[] {
+// 						    "<registerService>" +
+// 						      "<Category>moby</Category>" +
+// 						      "<serviceName>" + serviceName + "</serviceName>" +
+// 						      "<serviceType>" + serviceType + "</serviceType>" +
+// 						      "<authURI>" + authURI + "</authURI>" +
+// 						      "<inputObjects>" +
+// 						        "<Input>" +
+// 						          "<objectType>" + objectType1 + "</objectType>" +
+// 						           "<namespaceType>" + namespace1 + "</namespaceType>" +
+// 						        "</Input>" +
+// 						        "<Input>" +
+// 						          "<objectType>" + objectType2 + "</objectType>" +
+// 						          "<namespaceType>" + namespace2 + "</namespaceType>" +
+// 						        "</Input>" +
+// 						      "</inputObjects>" +
+// 						      "<outputObjects>" +
+// 						        "<objectType>" + objectType3 + "</objectType>" +
+// 						        "<objectType>" + objectType4 + "</objectType>" +
+// 						      "</outputObjects>" +
+// 						      "<URL>http://not.existing.server/not.existing.service</URL>" +
+// 						      "<Description><![CDATA[" +
+// 						        "This is ONLY A TESTING service." +
+// 						        "]]>" +
+// 						      "</Description>" +
+// 						    "</registerService>"
+// 						});
+// 		System.out.println ("----------------------------\n" + result);
+// 		String serviceId = client.extractId (result);
+
+// 		// 2. locate service byte service type
+// 		System.out.println ("METHOD: locateServiceByType '" + serviceType + "'");
+// 		result = (String)client.doCall ("locateServiceByType",
+// 						new Object[] {
+// 						    "<locateServiceByType>" +
+// 						      "<serviceType>" + serviceType + "</serviceType>" +
+// 						      "<fullServices>1</fullServices>" +
+// 						    "</locateServiceByType>"
+// 						});
+// 		System.out.println ("---------------------------\n" + result);
+
+// 		// 3. locate service by input type
+// 		System.out.println ("METHOD: locateServiceByInput");
+// 		result = (String)client.doCall ("locateServiceByInput",
+// 						new Object[] { 
+// 						    "<locateServiceByInput>" +
+// 						      "<inputObjects>" +
+// 						        "<Input>" +
+// 						          "<objectType>" + objectType1 + "</objectType>" +
+// 						          "<namespaceType>" + namespace1 + "</namespaceType>" +
+// 						        "</Input>" +
+// 						        "<Input>" +
+// 						          "<objectType>" + objectType2 + "</objectType>" +
+// 						          "<namespaceType>" + namespace2 + "</namespaceType>" +
+// 						        "</Input>" +
+// 						      "</inputObjects>" +
+// 						      "<serviceType>" + serviceType + "</serviceType>" +
+// 						      "<authURI>" + authURI + "</authURI>" +
+// 						      "<fullObjects>1</fullObjects>" +
+// 						      "<fullServices>1</fullServices>" +
+// 						    "</locateServiceByInput>"
+// 						});
+//  		System.out.println ("--------------------------------\n" + result);
+
+// 		// 4. locate service by output type
+// 		System.out.println ("METHOD: locateServiceByOutput");
+// 		result = (String)client.doCall ("locateServiceByOutput",
+// 						new Object[] { 
+// 						    "<locateServiceByOutput>" +
+// 						      "<objectType>" + objectType4 + "</objectType>" +
+// 						      "<serviceType>" + serviceType + "</serviceType>" +
+// 						      "<authURI>" + authURI + "</authURI>" +
+// 						      "<fullObjects>1</fullObjects>" +
+// 						      "<fullServices>1</fullServices>" +
+// 						    "</locateServiceByOutput>"
+// 						});
+// 		System.out.println ("---------------------------------\n" + result);
+
+// 		// 5. retrieve service (by service name)
+// 		System.out.println ("METHOD: retrieveService");
+// 		result = (String)client.doCall ("retrieveService",
+// 						new Object[] {
+// 						    "<retrieveService>" +
+// 						      "<authURI>" + authURI + "</authURI>" +
+// 						      "<serviceName>" + serviceName + "</serviceName>" +
+// 						    "</retrieveService>"
+// 						});
+// 		System.out.println ("-----------------------\n" + result);
+
+// 		// 6. deregister service
+// 		System.out.println ("METHOD: deregisterService \"" + serviceTypeId + "\"");
+// 		result = (String)client.doCall ("deregisterService",
+// 						new Object[] {
+// 						    "<deregisterService>" +
+// 						      "<serviceID>" + serviceId + "</serviceID>" +
+// 						    "</deregisterService>"
+
+// 						});
+// 		System.out.println ("---------------------------\n" + result);
+
+// 		// 7. deregister the rest
+// 		result = client.deregisterServiceType (serviceTypeId);
+// 		result = client.deregisterObject (objectId1);
+// 		result = client.deregisterObject (objectId2);
+// 		result = client.deregisterObject (objectId3);
+// 		result = client.deregisterObject (objectId4);
+// 		result = client.deregisterNamespace (namespaceId1);
+// 		result = client.deregisterNamespace (namespaceId2);
 
-	    }
+// 	    }
 
 	} catch (Exception e) {
 	    System.err.println ("===ERROR===");
@@ -531,4 +376,20 @@
 	    System.err.println ("===========");
 	}
     }
+
+    static final int MAX_MSG_LEN = 35;
+    static void start (String msg) {
+	System.out.print (msg);
+	for (int i = MAX_MSG_LEN; i > msg.length(); i--)
+	    System.out.print (" ");
+    }
+
+    static void ok() {
+	System.out.println ("OK");
+    }
+
+    static void error (Exception e) {
+	System.out.println ("FAILED");
+	System.err.println (e.toString() + "\n");
+    }
 }




More information about the MOBY-guts mailing list