From 004b298e388562907ffbadc297e7a3721b0c4190 Mon Sep 17 00:00:00 2001 From: Abraham Fine Date: Mon, 7 Mar 2016 17:06:57 -0800 Subject: [PATCH] SQOOP-2870: Sqoop2: RESTiliency: Add tests for DriverHandler (Jarek Jarcec Cecho via Abraham Fine) --- .../sqoop/handler/DriverRequestHandler.java | 5 -- .../server/rest/DriverRestTest.java | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 test/src/test/java/org/apache/sqoop/integration/server/rest/DriverRestTest.java diff --git a/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java index 95a32916..7b82ce54 100644 --- a/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java +++ b/server/src/main/java/org/apache/sqoop/handler/DriverRequestHandler.java @@ -40,11 +40,6 @@ public DriverRequestHandler() { @Override public JsonBean handleEvent(RequestContext ctx) { - // driver only support GET requests - if (ctx.getMethod() != Method.GET) { - throw new SqoopException(ServerError.SERVER_0002, "Unsupported HTTP method for driver:" - + ctx.getMethod()); - } AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(), "get", "driver", ""); diff --git a/test/src/test/java/org/apache/sqoop/integration/server/rest/DriverRestTest.java b/test/src/test/java/org/apache/sqoop/integration/server/rest/DriverRestTest.java new file mode 100644 index 00000000..438e074f --- /dev/null +++ b/test/src/test/java/org/apache/sqoop/integration/server/rest/DriverRestTest.java @@ -0,0 +1,53 @@ +/** + * 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 DriverRestTest extends RestTest { + + public static TestDescription[] PROVIDER_DATA = new TestDescription[]{ + new TestDescription("Get driver", "v1/driver", "GET", null, new Validator() { + @Override + void validate() throws Exception { + assertResponseCode(200); + assertContains("job-config"); + assertContains("all-config-resources"); + }}), + new TestDescription("Invalid post request", "v1/driver", "POST", "Random data", new Validator() { + @Override + void validate() throws Exception { + assertResponseCode(405); + assertServerException("Unsupported HTTP method", "SERVER_0002"); + }}), + }; + + @DataProvider(name="driver-rest-test") + public static Iterator data() { + return ParametrizedUtils.toArrayOfArrays(PROVIDER_DATA).iterator(); + } + + @Factory(dataProvider = "driver-rest-test") + public DriverRestTest(TestDescription desc) { + super(desc); + } +}