]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-245: Stubbed out bare-bones client-side tests of a generic HTTP service, which...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 26 Jun 2009 19:27:44 +0000 (19:27 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 26 Jun 2009 19:27:44 +0000 (19:27 +0000)
services/id/service/pom.xml
services/id/service/src/main/java/org/collectionspace/services/IDService.java
services/id/service/src/test/java/org/collectionspace/services/IDServiceTest.java

index e16cf8893d27812edc9f220b88a99c8f410b8def..396cb4b61dbeed6f7c049792f96610bff94fc796 100644 (file)
         <dependency>
             <groupId>org.restlet</groupId>
             <artifactId>org.restlet</artifactId>
-            <version>1.0.7</version>
+            <version>1.1.5</version>
         </dependency>
         <dependency>
             <groupId>com.noelios.restlet</groupId>
             <artifactId>com.noelios.restlet.ext.httpclient</artifactId>
-            <version>1.0.7</version>
+            <version>1.1.5</version>
         </dependency>
         <dependency>
             <groupId>com.noelios.restlet</groupId>
             <artifactId>com.noelios.restlet</artifactId>
-            <version>1.0.7</version>
+            <version>1.1.5</version>
         </dependency>
 
     </dependencies>
index d0b9a60776f88ad4d4be7ec4a3c38fb27b29dc8d..92aa6c13c535af244a2da97efefbe116c61795b7 100644 (file)
  
 package org.collectionspace.services;
 
-import java.io.IOException;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-
 import org.collectionspace.services.id.*;
-import org.collectionspace.services.id.IDServiceNuxeoImpl;
 
 public interface IDService {
 
@@ -55,28 +50,5 @@ public interface IDService {
        // Update
        
        // Delete (possibly not permitted - deactivate instead?)
-       
-
-/*
-       // Create
-       Document postCollectionObject(CollectionObject co)
-                       throws DocumentException, IOException;
-
-       // Read single object
-       Document getCollectionObject(String csid) throws DocumentException,
-                       IOException;
-
-       // Read a list of objects
-       Document getCollectionObjectList() throws DocumentException, IOException;
-
-       // Update
-       Document putCollectionObject(String csid, CollectionObject theUpdate)
-                       throws DocumentException, IOException;
-
-       // Delete
-       Document deleteCollectionObject(String csid) throws DocumentException,
-                       IOException;
-                       
-*/
 
 }
index 9a69a486f4f132d04de00c562cdf990bf5e9a978..20ddaf179557a45e4977079c9bca16295b4f60b1 100644 (file)
@@ -1,3 +1,31 @@
+/*     
+ * IDServiceTest
+ *
+ * Test class for the ID Service.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Use a URL builder in core Java or the Restlet framework,
+// rather than String objects.
+
+// @TODO: Consider using client-side RESTeasy, rather than Restlet,
+// if there is a desire to reduce the number of dependencies.
+//
+// (Note also Sanjay's comment c. June 2009 re RESTEasy's client-side
+// behavior around having to send authentication credentials in
+// advance, rather than via a challenge - if that was understood correctly.)
+
 package org.collectionspace.services.test;
 
 //import org.collectionspace.services.id.Id;
@@ -5,6 +33,80 @@ package org.collectionspace.services.test;
 //import org.collectionspace.services.id.IdPattern;
 //import org.collectionspace.services.id.IdPatternList;
 
-public class IDServiceTest {
-       //empty
+import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
+import org.restlet.Client;
+import org.restlet.data.Method;
+import org.restlet.data.Protocol;
+import org.restlet.data.Request;
+import org.restlet.data.Response;
+import org.restlet.data.Status;
+
+public class IDServiceTest extends TestCase {
+
+       final static String DEFAULT_REFERRER_URL = "http://collectionspace.org";
+       final static String DEFAULT_SUCCESS_URL_STRING = "http://www.example.com/";
+       final static String DEFAULT_FAILURE_URL_STRING = "http://www.example.com/nonexistent";
+
+       // Stub test to verify basic functionality.
+       public void testSuccessfulRequest() {
+               Response response = submitRequest(DEFAULT_SUCCESS_URL_STRING);
+               assertTrue(isSuccessResponse(response));                
+       }
+
+       // Stub test to verify basic functionality.
+       public void testFailureRequest() {
+               Response response = submitRequest(DEFAULT_FAILURE_URL_STRING);
+               assertFalse(isSuccessResponse(response));               
+       }
+
+       // Return a flag indicating whether a response from a
+       // service request represents a successful outcome.
+       public boolean isSuccessResponse(Response response) {
+       
+               if (response == null || response.getStatus() == null) {
+                       return false;
+               }
+
+               // Note: we can also test specifically for a 200 OK response via
+               // 'if (response.getStatus() == Status.SUCCESS_OK) ...'
+               if (response.getStatus().isSuccess()) {
+                       return true;
+               } else {
+                       return false;
+               }
+               
+       }
+
+       // Submit a request to a service.
+       //
+       // @TODO: Remove hard-coding of HTTP protocol requests.
+       public Response submitRequest(String urlStr) {
+
+               // Adapted from the Restlet 1.1 tutorial
+               // http://www.restlet.org/documentation/1.1/tutorial
+               //
+               // Note that if we later migrate to using the Restlet 2.0
+               // framework, it uses a resource model on the client-side,
+               // via the ClientResource class:
+               // http://www.restlet.org/documentation/2.0/tutorial
+
+               // @TODO: Validate the submitted URL here. 
+               
+               // Prepare the request.
+               Request request = new Request(Method.GET, urlStr);
+               request.setReferrerRef(DEFAULT_REFERRER_URL);
+               
+               // Handle it using an HTTP client connector.
+               //
+               // @TODO: We may need to derive the protocol,
+               // such as HTTP v. HTTPS, from the submitted URL.
+               Client client = new Client(Protocol.HTTP);
+               Response response = client.handle(request);
+               
+               return response;
+               
+       }
+       
 }