5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-11 22:41:50 +08:00

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

(Jarek Jarcec Cecho via Abraham Fine)
This commit is contained in:
Abraham Fine 2016-03-04 12:05:30 -08:00
parent 9e34dd3b85
commit b024e8cae5
5 changed files with 78 additions and 9 deletions

View File

@ -44,12 +44,6 @@ public SubmissionRequestHandler() {
@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) {

View File

@ -140,7 +140,14 @@ private void sendErrorResponse(RequestContext ctx, Exception ex)
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);

View File

@ -45,7 +45,7 @@ void validate() throws Exception {
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");
}}),
};

View File

@ -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);
}
}

View File

@ -34,7 +34,7 @@ void validate() throws Exception {
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");
}}),
};