SQOOP-2822: Sqoop2: RESTiliency: Provide tests for Link POST action
[sqoop.git] / test / src / test / java / org / apache / sqoop / integration / server / rest / LinkRestTest.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.sqoop.integration.server.rest;
19
20 import org.apache.sqoop.test.utils.ParametrizedUtils;
21 import org.testng.annotations.BeforeMethod;
22 import org.testng.annotations.DataProvider;
23 import org.testng.annotations.Factory;
24
25 import java.util.Iterator;
26
27 public class LinkRestTest extends RestTest {
28
29 @BeforeMethod
30 public void setUp() {
31 createFirstLink();
32 }
33
34 public static TestDescription[] PROVIDER_DATA = new TestDescription[]{
35 // Get
36 new TestDescription("Get all links", "v1/link/all", "GET", null, new Validator() {
37 @Override
38 void validate() throws Exception {
39 assertResponseCode(200);
40 assertContains("first-link");
41 }}),
42 new TestDescription("Get link by name", "v1/link/first-link", "GET", null, new Validator() {
43 @Override
44 void validate() throws Exception {
45 assertResponseCode(200);
46 assertContains("first-link");
47 }}),
48 new TestDescription("Get all links for connector", "v1/link/all?cname=hdfs-connector", "GET", null, new Validator() {
49 @Override
50 void validate() throws Exception {
51 assertResponseCode(200);
52 assertContains("first-link");
53 }}),
54 new TestDescription("Get non existing link", "v1/link/i-dont-exists", "GET", null, new Validator() {
55 @Override
56 void validate() throws Exception {
57 assertResponseCode(500);
58 assertServerException("Entity requested doesn't exist", "SERVER_0006");
59 assertContains("Invalid link name: i-dont-exists");
60 }}),
61 new TestDescription("Get links for non existing connector", "v1/link/all?cname=i-dont-exists", "GET", null, new Validator() {
62 @Override
63 void validate() throws Exception {
64 assertResponseCode(500);
65 assertServerException("Entity requested doesn't exist", "SERVER_0006");
66 assertContains("Invalid connector: i-dont-exists");
67 }}),
68
69 // Post
70 new TestDescription("Empty data", "v1/link", "POST", "", new Validator() {
71 @Override
72 void validate() throws Exception {
73 assertResponseCode(500);
74 assertServerException("Invalid JSON", "SERIALIZATION_002");
75 }}),
76 new TestDescription("Corrupted JSON", "v1/link", "POST", "{\"blah\" : {}", new Validator() {
77 @Override
78 void validate() throws Exception {
79 assertResponseCode(500);
80 assertServerException("Invalid JSON", "SERIALIZATION_002");
81 }}),
82 new TestDescription("Empty JSON", "v1/link", "POST", "{}", new Validator() {
83 @Override
84 void validate() throws Exception {
85 assertResponseCode(500);
86 assertServerException("Required key field is missing", "SERIALIZATION_003");
87 }}),
88 };
89
90 @DataProvider(name="link-rest-test", parallel=false)
91 public static Iterator<Object[]> data() {
92 return ParametrizedUtils.toArrayOfArrays(PROVIDER_DATA).iterator();
93 }
94
95 @Factory(dataProvider = "link-rest-test")
96 public LinkRestTest(TestDescription desc) {
97 super(desc);
98 }
99 }