Author: glen
Date: Thu Feb  7 23:35:28 2008
New Revision: 13432

Log:

Make sure we throw ResourceNotFoundExceptions appropriately, which means we'll 
get back 404s appropriately.  Basically we should always check if something 
exists before checking authorization, because authorization on non-existent 
resources is always false.

Don't catch exceptions in RatingTest. 

Also a little format cleanup.

Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/RatingTest.java

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java   
(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java   
Thu Feb  7 23:35:28 2008
@@ -45,8 +45,8 @@
 
     /**
      * Move or rename a resource in the registry.  This is equivalent to 1) 
delete the resource,
-     * then 2) add the resource to the new location.  The operation is atomic, 
so if it fails
-     * the old resource will still be there.
+     * then 2) add the resource to the new location.  The operation is atomic, 
so if it fails the
+     * old resource will still be there.
      *
      * @param currentPath current path of the resource
      * @param newPath     where we'd like to move the reosurce
@@ -56,8 +56,8 @@
     String rename(String currentPath, String newPath) throws RegistryException;
 
     /**
-     * Get a list of all versions of the resource located at the given path. 
Version paths
-     * are returned in the form /projects/myresource?v=12
+     * Get a list of all versions of the resource located at the given path. 
Version paths are
+     * returned in the form /projects/myresource?v=12
      *
      * @param path path of a current version of a resource
      * @return a String array containing the individual paths of versions
@@ -135,11 +135,10 @@
      * Change the text of an existing comment.
      *
      * @param commentPath path to comment resource ("..foo/r1;comment:1")
-     *
-     * @param text new text for the comment.
-     *
-     * @throws RegistryException Registry implementations may handle 
exceptions and thorw
-     * RegistryException if the exception has to be propagated to the client.
+     * @param text        new text for the comment.
+     * @throws RegistryException Registry implementations may handle 
exceptions and throw
+     *                           RegistryException if the exception has to be 
propagated to the
+     *                           client.
      */
     void editComment(String commentPath, String text) throws RegistryException;
 
@@ -147,11 +146,10 @@
      * Get all comments for the given resource.
      *
      * @param resourcePath path of the resource.
-     *
      * @return an array of Comment objects.
-     *
-     * @throws RegistryException Registry implementations may handle 
exceptions and thorw
-     * RegistryException if the exception has to be propagated to the client.
+     * @throws RegistryException Registry implementations may handle 
exceptions and throw
+     *                           RegistryException if the exception has to be 
propagated to the
+     *                           client.
      */
     Comment[] getComments(String resourcePath) throws RegistryException;
 
@@ -163,11 +161,10 @@
      * Rate the given resource.
      *
      * @param resourcePath Path of the resource.
-     *
-     * @param rating Rating value between 1 and 5.
-     *
-     * @throws RegistryException Registry implementations may handle 
exceptions and thorw
-     * RegistryException if the exception has to be propagated to the client.
+     * @param rating       Rating value between 1 and 5.
+     * @throws RegistryException Registry implementations may handle 
exceptions and throw
+     *                           RegistryException if the exception has to be 
propagated to the
+     *                           client.
      */
     void rateResource(String resourcePath, int rating) throws 
RegistryException;
 

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
   (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
   Thu Feb  7 23:35:28 2008
@@ -318,7 +318,7 @@
         String entry_id = getRealPath(request);
         if ("/tags".equals(entry_id)) {
             entry_id = "/;tags";
-        } else if ("/comments".equals(entry_id)){
+        } else if ("/comments".equals(entry_id)) {
             entry_id = "/;comments";
         }
         int idx = entry_id.indexOf(RegistryConstants.URL_SEPARATOR);
@@ -378,8 +378,8 @@
                     feed = getFeedForTags(abdera, resourcePath, baseURI, 
request);
                 } else {
                     try {
-                        if (parts.length == 2){
-                            feed = 
getFeedForTagPaths(abdera,parameter,baseURI,request);
+                        if (parts.length == 2) {
+                            feed = getFeedForTagPaths(abdera, parameter, 
baseURI, request);
                         } else {
                             resource = 
getSecureRegistry(request).get(entry_id);
                             feed = populateFeed(abdera, baseURI, entry_id, 
resource, false);
@@ -399,6 +399,8 @@
                         feed.addSimpleExtension(QNAME_AVGRATING,
                                                 "" + 
jdbcregistry.getAverageRating(resourcePath));
                     }
+                } catch (ResourceNotFoundException e) {
+                    return new EmptyResponseContext(404);
                 } catch (RegistryException e) {
                     return new StringResponseContext(abdera, e, 500);
                 }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
 (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
 Thu Feb  7 23:35:28 2008
@@ -613,6 +613,12 @@
                                                      
RegistryConstants.URL_SEPARATOR +
                                                      PARAMETER_RATINGS),
                                  getAuthorization());
+
+// TODO!!!  Otherwise we get a ClassCastException below...
+//        if (clientResponse.getStatus() != 200) {
+//            // throw RegistryException
+//        }
+
         Document introspection = clientResponse.getDocument();
         Feed feed = (Feed)introspection.getRoot();
         String floatvalue = feed.getSimpleExtension(QNAME_AVGRATING);

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
      (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
      Thu Feb  7 23:35:28 2008
@@ -142,7 +142,9 @@
 
     public Resource get(String path) throws RegistryException {
 
-//        if (!registry.resourceExists(path)) {
+//        if (!path.contains(RegistryConstants.URL_SEPARATOR) &&
+//            !path.contains("?") &&
+//            !registry.resourceExists(path)) {
 //            throw new ResourceNotFoundException(path);
 //        }
 

Modified: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java
==============================================================================
--- 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java
        (original)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java
        Thu Feb  7 23:35:28 2008
@@ -22,12 +22,15 @@
 
 public class AbstractAPPTest extends TestCase {
     public static final String PORT = "8081";
-    public static final String BASEURL = "http://localhost:"; + PORT + 
"/wso2registry/atom/";
 
     RegistryServer server;
     Registry registry;
+    
+    int clientPort = 8081; // Default client port.  Change prior to setUp() to 
debug with tcpmon.
+    String BASEURL;
 
     protected void setUp() throws Exception {
+        BASEURL = "http://localhost:"; + clientPort + "/wso2registry/atom/";
         if (server == null) {
             server = new RegistryServer(Integer.parseInt(PORT));
             server.setPort(Integer.parseInt(PORT));

Modified: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/RatingTest.java
==============================================================================
--- 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/RatingTest.java 
    (original)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/RatingTest.java 
    Thu Feb  7 23:35:28 2008
@@ -1,38 +1,26 @@
 package org.wso2.registry.app;
 
-import org.wso2.registry.RegistryException;
 import org.wso2.registry.Resource;
 
 
 public class RatingTest extends AbstractAPPTest {
 
-    public void testAddResourceRating() {
-        try {
-            Resource r1 = new Resource();
-            r1.setAuthorUserName("Author R1");
-            byte[] r1content = "R1 content".getBytes();
-            r1.setContent(r1content);
-
-            registry.put("/d16/d17/r1", r1);
-
-        } catch (
-                RegistryException e) {
-            fail("Failed to put test resources.");
-        }
+    protected void setUp() throws Exception {
+        clientPort = 8081;
+        super.setUp();
+    }
 
-        try {
-            registry.rateResource("/d16/d17/r1", 5);
-        } catch (RegistryException e) {
-            fail("Couldn't rate the resource /d16/d17/r1");
-        }
+    public void testAddResourceRating() throws Exception {
+        Resource r1 = new Resource();
+        r1.setAuthorUserName("Author R1");
+        byte[] r1content = "R1 content".getBytes();
+        r1.setContent(r1content);
 
-        float rating = 0;
-        try {
-            rating = registry.getAverageRating("/d16/d17/r1");
+        registry.put("/d16/d17/r1", r1);
 
-        } catch (RegistryException e) {
-            fail("Couldn't get the rating of the resource /d16/d17/r1");
-        }
+        registry.rateResource("/d16/d17/r1", 5);
+
+        float rating = registry.getAverageRating("/d16/d17/r1");
 
         //System.out.println("Start rating:" + rating);
         assertEquals("Rating of the resource /d16/d17/r1 should be 5.", 
rating, (float)5.0,
@@ -45,34 +33,16 @@
        } */
     }
 
-    public void testAddCollectionRating() {
+    public void testAddCollectionRating() throws Exception {
+        Resource r1 = new Resource();
+        r1.setAuthorUserName("Author R2");
+        byte[] r1content = "R2 content".getBytes();
+        r1.setContent(r1content);
 
-        try {
-            Resource r1 = new Resource();
-            r1.setAuthorUserName("Author R2");
-            byte[] r1content = "R2 content".getBytes();
-            r1.setContent(r1content);
-
-            registry.put("/d16/d18", r1);
-
-        } catch (
-                RegistryException e) {
-            fail("Failed to put test resources.");
-        }
+        registry.put("/d16/d18", r1);
+        registry.rateResource("/d16/d18", 4);
 
-        try {
-            registry.rateResource("/d16/d18", 4);
-        } catch (RegistryException e) {
-            fail("Couldn't rate the resource /d16/d18");
-        }
-
-        float rating = 0;
-        try {
-            rating = registry.getAverageRating("/d16/d18");
-
-        } catch (RegistryException e) {
-            fail("Couldn't get the rating of the resource /d16/d18");
-        }
+        float rating = registry.getAverageRating("/d16/d18");
 
         //System.out.println("Start rating:" + rating);
         assertEquals("Rating of the resource /d16/d18 should be 5.", rating, 
(float)4.0,
@@ -85,59 +55,31 @@
        } */
     }
 
-    public void testEditResourceRating() {
-
-        try {
-            Resource r1 = new Resource();
-            r1.setAuthorUserName("Author R1");
-            byte[] r1content = "R1 content".getBytes();
-            r1.setContent(r1content);
-
-            registry.put("/d61/d17/d18/r1", r1);
-
-        } catch (
-                RegistryException e) {
-            fail("Failed to put test resources.");
-        }
-
-        try {
-            registry.rateResource("/d61/d17/d18/r1", 5);
-        } catch (RegistryException e) {
-            fail("Couldn't rate the resource /d61/d17/d18/r1");
-        }
+    public void testEditResourceRating() throws Exception {
+        Resource r1 = new Resource();
+        r1.setAuthorUserName("Author R1");
+        byte[] r1content = "R1 content".getBytes();
+        r1.setContent(r1content);
 
-        float rating = 0;
-        try {
-            rating = registry.getAverageRating("/d61/d17/d18/r1");
+        registry.put("/d61/d17/d18/r1", r1);
+        registry.rateResource("/d61/d17/d18/r1", 5);
 
-        } catch (RegistryException e) {
-            fail("Couldn't get the rating of the resource /d61/d17/d18/r1");
-        }
+        float rating = registry.getAverageRating("/d61/d17/d18/r1");
 
         //System.out.println("Start rating:" + rating);
 
-        assertEquals("Rating of the resource /d61/d17/d18/r1 should be 5.", 
rating, (float)5.0,
+        assertEquals("Rating of the resource /d61/d17/d18/r1 should be 5.", 
(float)5.0, rating,
                      (float)0.01);
 
         /*rate the same resource again*/
 
-        try {
-            registry.rateResource("/d61/d17/d18/r1", 3);
-        } catch (RegistryException e) {
-            fail("Couldn't rate the resource /d61/d17/d18/r1");
-        }
+        registry.rateResource("/d61/d17/d18/r1", 3);
 
-        float rating_edit = 0;
-        try {
-            rating_edit = registry.getAverageRating("/d61/d17/d18/r1");
-
-        } catch (RegistryException e) {
-            fail("Couldn't get the rating of the resource /d61/d17/d18/r1");
-        }
+        float rating_edit = registry.getAverageRating("/d61/d17/d18/r1");
 
         //System.out.println("Start rating:" + rating_edit);
 
-        assertEquals("Rating of the resource /d61/d17/d18/r1 should be 5.", 
rating_edit, (float)3.0,
+        assertEquals("Rating of the resource /d61/d17/d18/r1 should be 3.", 
(float)3.0, rating_edit,
                      (float)0.01);
         /* try {
            registry.delete("/d16/d17/r1");
@@ -146,52 +88,32 @@
        } */
     }
 
-    public void testRatingsPath() {
+    public void testRatingsPath() throws Exception {
         Resource r5 = new Resource();
         String r5Content = "this is r5 content";
         r5.setContent(r5Content.getBytes());
         r5.setDescription("production ready.");
         String r5Path = "/c1/r5";
 
-        try {
-            registry.put(r5Path, r5);
-        } catch (RegistryException e) {
-            fail("Valid put scenario failed.");
-        }
+        registry.put(r5Path, r5);
 
-        try {
-            registry.rateResource("/c1/r5", 3);
-        } catch (RegistryException e) {
-            fail("Valid tagging scenario failed.");
-        }
-
-        Resource ratings = null;
-        try {
-            ratings = registry.get("/c1/r5;ratings");
-        } catch (RegistryException e) {
-            fail("Failed to get ratings using URL.");
-        }
+        registry.rateResource("/c1/r5", 3);
 
+        Resource ratings = registry.get("/c1/r5;ratings");
         String[] ratingPaths = (String[])ratings.getContent();
 
         int rating = 0;
-        try {
-            Resource c1 = registry.get(ratingPaths[0]);
-
-            Object o = c1.getContent();
-            if (o instanceof Integer) {
-                rating = (Integer)o;
-            } else {
-                rating = Integer.parseInt(o.toString());
-            }
+        Resource c1 = registry.get(ratingPaths[0]);
 
-        } catch (RegistryException e) {
-            fail("Failed to get rating using a path.");
+        Object o = c1.getContent();
+        if (o instanceof Integer) {
+            rating = (Integer)o;
+        } else {
+            rating = Integer.parseInt(o.toString());
         }
 
         assertEquals("Ratings are not retrieved properly as resources.", 
rating, 3);
     }
-
-
 }
 
+

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to