[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Thu Feb 14 03:04:44 UTC 2008
gordonp
Wed Feb 13 22:04:44 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/test
In directory dev.open-bio.org:/tmp/cvs-serv19467/src/main/ca/ucalgary/services/test
Modified Files:
ACDServiceTestCase.java
Added Files:
CGIServiceTestCase.java LegacyServiceTestCase.java
Log Message:
Initial commit of CGIService, including ACDServlet refactor causing LegacyService addition
moby-live/Java/src/main/ca/ucalgary/services/test CGIServiceTestCase.java,NONE,1.1 LegacyServiceTestCase.java,NONE,1.1 ACDServiceTestCase.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/test/ACDServiceTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/test/ACDServiceTestCase.java 2007/08/01 18:22:44 1.4
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/test/ACDServiceTestCase.java 2008/02/14 03:04:44 1.5
@@ -20,17 +20,19 @@
import java.net.URL;
import java.util.*;
+/**
+ * For the testMain cases to be actually successful, the WEB-INF/web.xml
+ * file must be one with all the ACD parameters...
+ */
public class ACDServiceTestCase extends MobyServletTestCase{
private final static String ACDTEST_CLASS_NAME = "ca.ucalgary.services.ACDService";
private final static String ACDTEST_MOBY_XML = "ca/ucalgary/services/test/mobyDNASeq.xml";
- private final static String ACDTEST_BINARY_DATA1 = "ca/ucalgary/services/test/mobyTest1.png";
- private final static String ACDTEST_BINARY_DATA2 = "ca/ucalgary/services/test/mobyTest2.png";
- private final static String MOBY_PNG_DATATYPE = "PNGFormatImage";
public ACDServiceTestCase(String name){
super(name);
}
+ // these are called by testMain in MobyServlet
protected URL getExampleURL(){
URL testDataURL = getClass().getClassLoader().getResource(ACDTEST_MOBY_XML);
if(testDataURL == null){
@@ -45,122 +47,22 @@
}
/**
- * Loads a binary file, then tests it against a regex, creates a MOBY object, and
- * then the new object is compared to the original file data (they should be
- * identical byte arrays.
- */
- public void testBinaryRegex(){
- System.setProperty(MobyClient.RESOURCE_SYSTEM_PROPERTY, ACDService.ACD_RULES_DEFAULT_RESOURCE);
- MobyClient mobyClient = null;
- try{
- mobyClient = new MobyClient();
- } catch(Exception e){
- e.printStackTrace();
- fail("Could not initialize MobyClient, got exception: " + e);
- }
-
- URL u1 = getClass().getClassLoader().getResource(ACDTEST_BINARY_DATA1);
- assertNotNull("Cannot find the binary test data resource " + ACDTEST_BINARY_DATA1 +
- "), please make sure your class path is specified correctly", u1);
- URL u2 = getClass().getClassLoader().getResource(ACDTEST_BINARY_DATA2);
- assertNotNull("Cannot find the binary test data resource " + ACDTEST_BINARY_DATA2 +
- "), please make sure your class path is specified correctly", u2);
-
- Map<String, byte[]> binaryDataParts = new HashMap<String, byte[]>();
- try{
- binaryDataParts.put(u1.toString(), getURLData(u1));
- } catch(Exception e){
- e.printStackTrace();
- fail("Could not read data from URL (" + u1 + "), got exception: " + e);
- }
- assertNotNull("The binary test data resource " + u1.toString() + " could not be loaded",
- binaryDataParts.get(u1.toString()));
-
- try{
- binaryDataParts.put(u2.toString(), getURLData(u2));
- } catch(Exception e){
- e.printStackTrace();
- fail("Could not read data from URL (" + u2 + "), got exception: " + e);
- }
- assertNotNull("The binary test data resource " + u2.toString() + " could not be loaded",
- binaryDataParts.get(u2.toString()));
- // Check that the byte holder class works okay
- MobyDataBytes byteObject = null;
- try{
- byteObject = new MobyDataBytes("foo", binaryDataParts.get(u2.toString()));
- } catch(Exception e){
- e.printStackTrace();
- fail("Could not build a MobyDataBytes object from a byte array: "+ e);
- }
- assertTrue("The MobyDataBytes object does not return the same byte array " +
- "as given in its constructor (data corruption occured)",
- Arrays.equals(byteObject.getBytes(), binaryDataParts.get(u2.toString())));
-
- MobyDataObjectSet pngCollectionTemplate = new MobyDataObjectSet("test",
- new MobyDataObject[]{new MobyDataComposite(MOBY_PNG_DATATYPE)});
- MobyDataInstance mdi = null;
- try{
- mdi = mobyClient.getMobyObject(binaryDataParts, pngCollectionTemplate);
- } catch(Exception e){
- e.printStackTrace();
- fail("Could not create Moby Object Collection from binary data map, got exception: " +e);
- }
-
- assertTrue("The two PNG images loaded should have been returned as a " +
- "MobyDataObjectSet, but were not ("+mdi.getClass().getName()+")",
- mdi instanceof MobyDataObjectSet);
- MobyDataObjectSet objSet = (MobyDataObjectSet) mdi;
- assertTrue("The MobyDataObjectSet returned from processing the two PNG files " +
- "did not have the expected size of 2 (was " +objSet.size()+")",
- objSet.size() == 2);
- assertTrue("The MobyDataObjectSet returned from processing the two PNG files" +
- " did not return a datatype (was null)",
- objSet.getDataType() != null);
- assertTrue("The MobyDataObjectSet returned from processing the two PNG files" +
- "did not have the expected data type " + MOBY_PNG_DATATYPE + ", found " +
- objSet.getDataType().getName(),
- objSet.getDataType().inheritsFrom(pngCollectionTemplate.getDataType()));
-
- // Check to make sure neither the name nor the contents have been corrupted
- for(MobyDataObject mobyObject: objSet){
- assertTrue("A returned MobyDataObject was not of the expected type MobyDataBytes " +
- "(found "+mobyObject.getClass().getName()+")", mobyObject instanceof MobyDataBytes);
-
- byte[] origBytes = binaryDataParts.get(mobyObject.getName());
- assertNotNull("A member of the returned MobyDataObjectSet did not have a name" +
- "corresponding to a name in the input map (the offending name is " +
- mobyObject.getName()+")", origBytes);
- byte[] objBytes = ((MobyDataBytes) mobyObject).getBytes();
- assertTrue("The original binary data and the MOBY representation have different " +
- "lengths ("+origBytes.length+" and " +objBytes.length+" respectively)",
- origBytes.length == objBytes.length);
- //TODO: Check each byte...
- }
- }
-
- private byte[] getURLData(URL u) throws Exception{
- InputStream urlStream = u.openStream();
- byte[] byteBufferChunk = new byte[1024];
- ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
- for(int r = urlStream.read(byteBufferChunk, 0, 1024);
- r != -1;
- r = urlStream.read(byteBufferChunk, 0, 1024)){
- byteBuffer.write(byteBufferChunk, 0, r);
- }
- return byteBuffer.toByteArray();
- }
-
- /**
* @return a test suite for all the test methods of this test case.
+ *
+ * We do a bunch of tests, not just of this class, but ones it depends on, so that
+ * we can use Minnow create a self-contained WAR of only the classes
+ * required to run ACD services.
*/
public static Test suite() {
TestSuite suite = new TestSuite();
- suite.addTest(new ACDServiceTestCase("testBinaryRegex"));
- suite.addTest(new MobyServletTestCase("testRDF"));
- suite.addTest(new MobyServletTestCase("testRequestChain"));
suite.addTest(new ACDServiceTestCase("testMain"));
+
+ suite.addTest(new LegacyServiceTestCase("testBinaryRegex"));
suite.addTest(new MobyClientTestCase("testMemberInheritance"));
+
+ suite.addTest(new MobyServletTestCase("testRDF"));
+ suite.addTest(new MobyServletTestCase("testRequestChain"));
suite.addTest(new MobyServletTestCase("testSecondaryParams"));
suite.addTest(new MobyServletTestCase("testServletTester"));
return suite;
More information about the MOBY-guts
mailing list