[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Apr 12 00:54:16 UTC 2007


gordonp
Wed Apr 11 20:54:16 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/test
In directory dev.open-bio.org:/tmp/cvs-serv30460/src/main/org/biomoby/service/test

Modified Files:
	MobyServletTestCase.java 
Log Message:
Several changes to improve extensibility of tests by subclasses
moby-live/Java/src/main/org/biomoby/service/test MobyServletTestCase.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/test/MobyServletTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/test/MobyServletTestCase.java	2007/03/12 16:57:30	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/test/MobyServletTestCase.java	2007/04/12 00:54:16	1.4
@@ -21,8 +21,10 @@
 
 public class MobyServletTestCase extends TestCase{
     private final static String TEST_MOBY_XML = "org/biomoby/service/test/mobyAASeq.xml";
+    private final static String SERVLET_TEST_WEBXML = "org/biomoby/service/test/web.xml";
     private final static String SERVLET_TEST_URL = "http://moby.ucalgary.ca:8089/MobyServlet";
     private final static String TEST_MAIN_CLASS_NAME = "org.biomoby.service.test.ConvertAAtoFASTA_AA";
+
     /**
      * @param name Test case name.
      */
@@ -94,11 +96,35 @@
     }
 
     public void testRDF(){
-	TestServletConfig config = new TestServletConfig("ConvertAAtoFASTA_AA", new TestServletContext());
-	//config.addInitParameter();
-	MobyServlet servlet = new ConvertAAtoFASTA_AA();
+	String webXMLPath = "WEB-INF/web.xml";
+	java.net.URL webXmlURL = getClass().getClassLoader().getResource(webXMLPath);
+	assertNotNull("No \""+ webXMLPath+"\" in the resource path", webXmlURL);
+	TestServletConfig servletConfig = null;
 	try{
-	    servlet.init(config);
+	    servletConfig = new TestServletConfig(new TestServletContext(), webXmlURL);
+	} catch(Exception e){
+	    e.printStackTrace();
+	    fail("Could not create servlet configuration from " + webXmlURL + ": " + e);
+	}
+
+	MobyServlet servlet = null;
+        try{
+	    // This line can throw many different exception if you didn't get the class right! 
+	    Class servletClass = MobyServlet.class.getClassLoader().loadClass(servletConfig.getServletClassName());
+            if(servletClass == null){
+                throw new ClassNotFoundException("The servlet Class to run (" + 
+						 servletConfig.getServletClassName() + 
+						 ") was not found, please ensure the web.xml is up-to-date.");
+            }
+	    servlet = (MobyServlet) servletClass.newInstance();
+        } catch(Exception e){
+	    e.printStackTrace();
+	    fail("The servlet Class was not specified properly in " + webXmlURL +
+		 " (the servlet-class tag was not useable): " + e);
+        }
+
+	try{
+	    servlet.init(servletConfig);
 	}
 	catch(Exception e){
 	    e.printStackTrace();
@@ -106,9 +132,8 @@
 	}
 
 	TestHttpServletRequest request = new TestHttpServletRequest();
-	request.addHeader("SOAPAction", "MobyServlet");
 	request.setParameter(MobyServlet.MODE_HTTP_PARAM, MobyServlet.RDF_MODE);
-	request.setRequestURL("http://moby.ucalgary.ca:8089/ConvertAAtoFASTA_AA");
+	request.setRequestURL("http://hostname.domain.tld:8089/UnImportantServiceName");
 
 	TestHttpServletResponse response = new TestHttpServletResponse();
 	StringBufferServletOutputStream out = new StringBufferServletOutputStream();
@@ -237,7 +262,17 @@
 
     public void testServletTester(){
 	try{
-	    ServletTester.main(new String[]{getExampleServlet(), getExampleURL().toString()});
+	    // Use the specific, basic servlet test, with the defined web.xml
+	    // because we want to be able to do this test regardless of the
+	    // class environment we find ourselves in (i.e. a WEB-INF/web.xml
+	    // that is for a more specialized service such as ACDService)
+	    ServletTester tester = new ServletTester(SERVLET_TEST_WEBXML);
+
+	    // A useful side effect of an object instance is that it
+	    // can use the classloader that loaded it to find resources
+	    // (there is no class instance get a classloader from in static methods) 
+	    tester.runService(new String[]{SERVLET_TEST_URL, TEST_MOBY_XML});
+
 	} catch(Exception e){
 	    e.printStackTrace();
 	    fail("Could not run servlet tester successfully: " + e);




More information about the MOBY-guts mailing list