usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject usergrid git commit: Added additional test, and verified that they all throw their kind of exceptions but they get mapped to NotAllowed for whatever reason.
Date Fri, 08 Jan 2016 20:08:33 GMT
Repository: usergrid
Updated Branches:
  refs/heads/USERGRID-767 b15359161 -> 783c58403


Added additional test, and verified that they all throw their kind of exceptions but they
get mapped to NotAllowed for whatever reason.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/783c5840
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/783c5840
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/783c5840

Branch: refs/heads/USERGRID-767
Commit: 783c58403e5ecaf1fd899261746260268018aa33
Parents: b153591
Author: George Reyes <grey@apache.org>
Authored: Fri Jan 8 12:08:30 2016 -0800
Committer: George Reyes <grey@apache.org>
Committed: Fri Jan 8 12:08:30 2016 -0800

----------------------------------------------------------------------
 .../exceptions/AbstractExceptionMapper.java     |  3 ---
 .../AwsPropertiesNotFoundExceptionMapper.java   |  3 ++-
 .../exceptions/NotAllowedExceptionMapper.java   | 21 ++++++++++++++++
 .../UnsupportedOperationExceptionMapper.java    | 20 ++++++++++++++++
 ...upportedServiceOperationExceptionMapper.java | 21 ++++++++++++++++
 .../usergrid/rest/ExceptionResourceIT.java      | 25 +++++++++++++-------
 6 files changed, 81 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/783c5840/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
index b428567..5c42224 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AbstractExceptionMapper.java
@@ -60,9 +60,6 @@ public abstract class AbstractExceptionMapper<E extends java.lang.Throwable>
imp
 
     @Override
     public Response toResponse( E e ) {
-        if(e instanceof UnsupportedServiceOperationException || e instanceof  NotAllowedException
|| e instanceof UnsupportedOperationException){
-            return toResponse( METHOD_NOT_ALLOWED,e );
-        }
         // if we don't know what type of error it is then it's a 500
         return toResponse( INTERNAL_SERVER_ERROR, e );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/783c5840/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPropertiesNotFoundExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPropertiesNotFoundExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPropertiesNotFoundExceptionMapper.java
index f0f6e97..33f20b6 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPropertiesNotFoundExceptionMapper.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/AwsPropertiesNotFoundExceptionMapper.java
@@ -22,13 +22,14 @@ import javax.ws.rs.core.Response;
 import org.apache.usergrid.services.exceptions.AwsPropertiesNotFoundException;
 
 import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
-import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import javax.ws.rs.ext.Provider;
 
 
 /**
  * Maps the AwsPropertiesNotFoundExceptionMapper to a 500 error due to having a legit response
  * but there is an error in the properties file.
  */
+@Provider
 public class AwsPropertiesNotFoundExceptionMapper extends AbstractExceptionMapper<AwsPropertiesNotFoundException>
{
     @Override
     public Response toResponse( AwsPropertiesNotFoundException e ) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/783c5840/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotAllowedExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotAllowedExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotAllowedExceptionMapper.java
new file mode 100644
index 0000000..08070aa
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotAllowedExceptionMapper.java
@@ -0,0 +1,21 @@
+package org.apache.usergrid.rest.exceptions;
+
+
+import javax.ws.rs.NotAllowedException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import static javax.ws.rs.core.Response.Status.METHOD_NOT_ALLOWED;
+
+
+/**
+ * Created by ApigeeCorporation on 1/8/16.
+ */
+@Provider
+public class NotAllowedExceptionMapper extends AbstractExceptionMapper<NotAllowedException>
{
+
+    @Override
+    public Response toResponse( NotAllowedException e ) {
+        return toResponse( METHOD_NOT_ALLOWED, e );
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/783c5840/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedOperationExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedOperationExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedOperationExceptionMapper.java
new file mode 100644
index 0000000..f38d152
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedOperationExceptionMapper.java
@@ -0,0 +1,20 @@
+package org.apache.usergrid.rest.exceptions;
+
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import static javax.ws.rs.core.Response.Status.METHOD_NOT_ALLOWED;
+
+
+/**
+ * Created by ApigeeCorporation on 1/8/16.
+ */
+@Provider
+public class UnsupportedOperationExceptionMapper extends AbstractExceptionMapper<UnsupportedOperationException>
{
+
+    @Override
+    public Response toResponse( UnsupportedOperationException e ) {
+        return toResponse( METHOD_NOT_ALLOWED, e );
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/783c5840/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedServiceOperationExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedServiceOperationExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedServiceOperationExceptionMapper.java
new file mode 100644
index 0000000..0b68793
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/UnsupportedServiceOperationExceptionMapper.java
@@ -0,0 +1,21 @@
+package org.apache.usergrid.rest.exceptions;
+
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.usergrid.services.exceptions.UnsupportedServiceOperationException;
+import static javax.ws.rs.core.Response.Status.METHOD_NOT_ALLOWED;
+
+
+/**
+ * Created by ApigeeCorporation on 1/8/16.
+ */
+@Provider
+public class UnsupportedServiceOperationExceptionMapper extends AbstractExceptionMapper<UnsupportedServiceOperationException>
{
+
+    @Override
+    public Response toResponse( UnsupportedServiceOperationException e ) {
+        return toResponse( METHOD_NOT_ALLOWED, e );
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/783c5840/stack/rest/src/test/java/org/apache/usergrid/rest/ExceptionResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ExceptionResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ExceptionResourceIT.java
index b07de4d..c2f1728 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ExceptionResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ExceptionResourceIT.java
@@ -13,9 +13,12 @@ import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.test.resource.AbstractRestIT;
 import org.apache.usergrid.rest.test.resource.model.Organization;
 import org.apache.usergrid.rest.test.resource.model.Token;
+import org.apache.usergrid.services.exceptions.UnsupportedServiceOperationException;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 
 /**
@@ -29,8 +32,9 @@ public class ExceptionResourceIT extends AbstractRestIT{
 
             clientSetup.getRestClient()
                        .pathResource( getOrgAppPath( "non_existant_delete_endpoint" ) ).delete(
);
+            fail("Should have thrown below exception");
+
         }catch(NotAllowedException e){
-           // assertNotNull(e);
             assertEquals( 405,e.getResponse().getStatus());
         }
     }
@@ -41,9 +45,9 @@ public class ExceptionResourceIT extends AbstractRestIT{
         try {
 
             clientSetup.getRestClient().management().orgs().delete( true );
+            fail("Should have thrown below exception");
 
         }catch(NotAllowedException e){
-            // assertNotNull(e);
             assertEquals( 405,e.getResponse().getStatus());
         }
     }
@@ -52,18 +56,23 @@ public class ExceptionResourceIT extends AbstractRestIT{
         try {
             clientSetup.getRestClient()
                        .pathResource( clientSetup.getOrganizationName() + "/" + clientSetup.getAppName()
 ).delete( );
-
+            fail("Should have thrown below exception");
 
         }catch(NotAllowedException e){
-            // assertNotNull(e);
             assertEquals( 405,e.getResponse().getStatus());
         }
     }
 
+    @Test
+    public void testUnsupportedServiceOperation(){
+        try {
+            clientSetup.getRestClient()
+                       .pathResource( getOrgAppPath( "users" ) ).delete( );
+            fail("Should have thrown below exception");
 
-
-    public Organization createOrgPayload(String baseName,Map properties ){
-        String orgName = baseName + UUIDUtils.newTimeUUID();
-        return new Organization( orgName+ UUIDUtils.newTimeUUID(),orgName,orgName+"@usergrid",orgName,orgName,
properties);
+        }catch(NotAllowedException e){
+            assertEquals( 405,e.getResponse().getStatus());
+        }
     }
+
 }


Mime
View raw message