sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From af...@apache.org
Subject sqoop git commit: SQOOP-2545: Sqoop2: RESTiliency: Provide tests for non-existing end points
Date Fri, 04 Mar 2016 20:06:44 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 9e34dd3b8 -> b024e8cae


SQOOP-2545: Sqoop2: RESTiliency: Provide tests for non-existing end points

(Jarek Jarcec Cecho via Abraham Fine)


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

Branch: refs/heads/sqoop2
Commit: b024e8cae5209d7b0859b502777b8b914782a58b
Parents: 9e34dd3
Author: Abraham Fine <afine@apache.org>
Authored: Fri Mar 4 12:05:30 2016 -0800
Committer: Abraham Fine <afine@apache.org>
Committed: Fri Mar 4 12:05:30 2016 -0800

----------------------------------------------------------------------
 .../sqoop/handler/SubmissionRequestHandler.java |  6 --
 .../sqoop/server/SqoopProtocolServlet.java      |  9 ++-
 .../server/rest/ConnectorRestTest.java          |  2 +-
 .../server/rest/NonExistingRestTest.java        | 68 ++++++++++++++++++++
 .../server/rest/VersionRestTest.java            |  2 +-
 5 files changed, 78 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/b024e8ca/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
index b894e37..06c4478 100644
--- a/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
@@ -44,12 +44,6 @@ public class SubmissionRequestHandler implements RequestHandler {
 
   @Override
   public JsonBean handleEvent(RequestContext ctx) {
-
-    // submission only support GET requests
-    if (ctx.getMethod() != Method.GET) {
-      throw new SqoopException(ServerError.SERVER_0002, "Unsupported HTTP method for connector:"
-          + ctx.getMethod());
-    }
     // submissions per job are ordered by update time
     // hence the latest submission is on the top
     if (ctx.getParameterValue(JOB_NAME_QUERY_PARAM) != null) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/b024e8ca/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java b/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
index fb4a99f..4db8d41 100644
--- a/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
+++ b/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
@@ -140,7 +140,14 @@ public class SqoopProtocolServlet extends HttpServlet {
 
       ThrowableBean throwableBean = new ThrowableBean(ex);
 
-      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      // We're using SERVER_002 code to denote 405/Method not allowed so propagating as such
+      if (ec == ServerError.SERVER_0002) {
+        response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+      } else {
+        // Default error code is 500 internal server error
+        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      }
+
       response.getWriter().write(throwableBean.extract(true).toJSONString());
     } else {
       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/b024e8ca/test/src/test/java/org/apache/sqoop/integration/server/rest/ConnectorRestTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/server/rest/ConnectorRestTest.java
b/test/src/test/java/org/apache/sqoop/integration/server/rest/ConnectorRestTest.java
index 839a4d0..e670438 100644
--- a/test/src/test/java/org/apache/sqoop/integration/server/rest/ConnectorRestTest.java
+++ b/test/src/test/java/org/apache/sqoop/integration/server/rest/ConnectorRestTest.java
@@ -45,7 +45,7 @@ public class ConnectorRestTest extends RestTest {
     new TestDescription("Invalid post request", "v1/connector", "POST", "Random data", new
Validator() {
       @Override
       void validate() throws Exception {
-        assertResponseCode(500);
+        assertResponseCode(405);
         assertServerException("Unsupported HTTP method", "SERVER_0002");
       }}),
   };

http://git-wip-us.apache.org/repos/asf/sqoop/blob/b024e8ca/test/src/test/java/org/apache/sqoop/integration/server/rest/NonExistingRestTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/server/rest/NonExistingRestTest.java
b/test/src/test/java/org/apache/sqoop/integration/server/rest/NonExistingRestTest.java
new file mode 100644
index 0000000..cb398ef
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/server/rest/NonExistingRestTest.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.integration.server.rest;
+
+import org.apache.sqoop.test.utils.ParametrizedUtils;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Factory;
+
+import java.util.Iterator;
+
+public class NonExistingRestTest extends RestTest {
+
+  // Various HTTP codes
+  private static Validator notFoundValidator = new Validator() {
+    @Override
+    void validate() throws Exception {
+      assertResponseCode(404);
+    }
+  };
+  private static Validator notAllowedValidator = new Validator() {
+    @Override
+    void validate() throws Exception {
+      assertResponseCode(405);
+    }
+  };
+
+  public static TestDescription[] PROVIDER_DATA = new TestDescription[]{
+    // Various non-existing end-points and HTTP methods
+    new TestDescription("Get to nowhere", "my/cool/endpoint", "GET", null, notFoundValidator),
+    new TestDescription("Get to nowhere in v1 space", "v1/my/cool/endpoint", "GET", null,
notFoundValidator),
+    new TestDescription("Delete to nowhere", "my/cool/endpoint", "DELETE", null, notAllowedValidator),
+    new TestDescription("Delete to nowhere in v1 space", "v1/my/cool/endpoint", "DELETE",
null, notAllowedValidator),
+    new TestDescription("Post to nowhere", "my/cool/endpoint", "POST", "{}", notAllowedValidator),
+    new TestDescription("Post to nowhere in v1 space", "v1/my/cool/endpoint", "POST", "{}",
notAllowedValidator),
+    new TestDescription("Put to nowhere", "my/cool/endpoint", "PUT", "{}", notAllowedValidator),
+    new TestDescription("Put to nowhere in v1 space", "v1/my/cool/endpoint", "PUT", "{}",
notAllowedValidator),
+
+    // Content changing requests for read-only resources
+    new TestDescription("Put to version", "version", "PUT", "{}", notAllowedValidator),
+    new TestDescription("POST to connector", "v1/connector", "POST", "{}", notAllowedValidator),
+    new TestDescription("DELETE to submission", "v1/submission", "DELETE", "{}", notAllowedValidator),
+  };
+
+  @DataProvider(name="non-existing-rest-test")
+  public static Iterator<Object[]> data() {
+    return ParametrizedUtils.toArrayOfArrays(PROVIDER_DATA).iterator();
+  }
+
+  @Factory(dataProvider = "non-existing-rest-test")
+  public NonExistingRestTest(TestDescription desc) {
+    super(desc);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/b024e8ca/test/src/test/java/org/apache/sqoop/integration/server/rest/VersionRestTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/server/rest/VersionRestTest.java
b/test/src/test/java/org/apache/sqoop/integration/server/rest/VersionRestTest.java
index e4c89df..72da3c2 100644
--- a/test/src/test/java/org/apache/sqoop/integration/server/rest/VersionRestTest.java
+++ b/test/src/test/java/org/apache/sqoop/integration/server/rest/VersionRestTest.java
@@ -34,7 +34,7 @@ public class VersionRestTest extends RestTest {
     new TestDescription("Invalid post request", "version", "POST", "Random text", new Validator()
{
       @Override
       void validate() throws Exception {
-        assertResponseCode(500);
+        assertResponseCode(405);
         assertServerException("Unsupported HTTP method", "SERVER_0002");
       }}),
   };


Mime
View raw message