SQOOP-931: Integrate HCatalog with Sqoop
[sqoop.git] / src / test / org / apache / sqoop / hcat / TestHCatalogBasic.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
19 package org.apache.sqoop.hcat;
20
21 import junit.framework.TestCase;
22
23 import org.junit.Before;
24
25 import com.cloudera.sqoop.SqoopOptions;
26 import com.cloudera.sqoop.tool.ExportTool;
27 import com.cloudera.sqoop.tool.ImportTool;
28
29 /**
30 * Test basic HCatalog related features.
31 */
32 public class TestHCatalogBasic extends TestCase {
33 private static ImportTool importTool;
34 private static ExportTool exportTool;
35
36 @Before
37 @Override
38 public void setUp() {
39 importTool = new ImportTool();
40 exportTool = new ExportTool();
41 }
42 private SqoopOptions parseImportArgs(String[] argv) throws Exception {
43 SqoopOptions opts = importTool.parseArguments(argv, null, null, false);
44 return opts;
45 }
46
47 private SqoopOptions parseExportArgs(String[] argv) throws Exception {
48 SqoopOptions opts = exportTool.parseArguments(argv, null, null, false);
49 return opts;
50 }
51
52 public void testHCatalogHomeWithImport() throws Exception {
53 String[] args = {
54 "--hcatalog-home",
55 "/usr/lib/hcatalog",
56 };
57
58 SqoopOptions opts = parseImportArgs(args);
59 }
60
61 public void testHCatalogHomeWithExport() throws Exception {
62 String[] args = {
63 "--hcatalog-home",
64 "/usr/lib/hcatalog",
65 };
66
67 SqoopOptions opts = parseExportArgs(args);
68 }
69
70 public void testHCatalogImport() throws Exception {
71 String[] args = {
72 "--hcatalog-table",
73 "table",
74 };
75
76 SqoopOptions opts = parseImportArgs(args);
77 }
78
79 public void testHCatalogExport() throws Exception {
80 String[] args = {
81 "--hcatalog-table",
82 "table",
83 };
84
85 SqoopOptions opts = parseExportArgs(args);
86 }
87
88 public void testHCatImportWithTargetDir() throws Exception {
89 String[] args = {
90 "--connect",
91 "jdbc:db:url",
92 "--table",
93 "dbtable",
94 "--hcatalog-table",
95 "table",
96 "--target-dir",
97 "/target/dir",
98 };
99 try {
100 SqoopOptions opts = parseImportArgs(args);
101 importTool.validateOptions(opts);
102 fail("Expected InvalidOptionsException");
103 } catch (SqoopOptions.InvalidOptionsException ioe) {
104 // expected.
105 }
106 }
107
108 public void testHCatImportWithWarehouseDir() throws Exception {
109 String[] args = {
110 "--connect",
111 "jdbc:db:url",
112 "--table",
113 "dbtable",
114 "--hcatalog-table",
115 "table",
116 "--warehouse-dir",
117 "/target/dir",
118 };
119 try {
120 SqoopOptions opts = parseImportArgs(args);
121 importTool.validateOptions(opts);
122 fail("Expected InvalidOptionsException");
123 } catch (SqoopOptions.InvalidOptionsException ioe) {
124 // expected.
125 }
126 }
127
128 public void testHCatImportWithHiveImport() throws Exception {
129 String[] args = {
130 "--connect",
131 "jdbc:db:url",
132 "--table",
133 "dbtable",
134 "--hcatalog-table",
135 "table",
136 "--hive-import",
137 };
138 try {
139 SqoopOptions opts = parseImportArgs(args);
140 importTool.validateOptions(opts);
141 fail("Expected InvalidOptionsException");
142 } catch (SqoopOptions.InvalidOptionsException ioe) {
143 // expected.
144 }
145 }
146
147 public void testHCatExportWithExportDir() throws Exception {
148 String[] args = {
149 "--connect",
150 "jdbc:db:url",
151 "--table",
152 "dbtable",
153 "--hcatalog-table",
154 "table",
155 "--export-dir",
156 "/export/dir",
157 };
158 try {
159 SqoopOptions opts = parseExportArgs(args);
160 exportTool.validateOptions(opts);
161 fail("Expected InvalidOptionsException");
162 } catch (SqoopOptions.InvalidOptionsException ioe) {
163 // expected.
164 }
165 }
166
167 public void testHCatImportWithDirect() throws Exception {
168 String[] args = {
169 "--connect",
170 "jdbc:db:url",
171 "--table",
172 "dbtable",
173 "--hcatalog-table",
174 "table",
175 "--direct",
176 };
177 try {
178 SqoopOptions opts = parseImportArgs(args);
179 importTool.validateOptions(opts);
180 fail("Expected InvalidOptionsException");
181 } catch (SqoopOptions.InvalidOptionsException ioe) {
182 // expected.
183 }
184 }
185
186 public void testHCatImportWithSequenceFile() throws Exception {
187 String[] args = {
188 "--connect",
189 "jdbc:db:url",
190 "--table",
191 "dbtable",
192 "--hcatalog-table",
193 "table",
194 "--as-sequencefile"
195 };
196 try {
197 SqoopOptions opts = parseImportArgs(args);
198 importTool.validateOptions(opts);
199 fail("Expected InvalidOptionsException");
200 } catch (SqoopOptions.InvalidOptionsException ioe) {
201 // expected.
202 }
203 }
204
205 public void testHCatImportWithAvroFile() throws Exception {
206 String[] args = {
207 "--connect",
208 "jdbc:db:url",
209 "--table",
210 "dbtable",
211 "--hcatalog-table",
212 "table",
213 "--as-avrofile"
214 };
215 try {
216 SqoopOptions opts = parseImportArgs(args);
217 importTool.validateOptions(opts);
218 fail("Expected InvalidOptionsException");
219 } catch (SqoopOptions.InvalidOptionsException ioe) {
220 // expected.
221 }
222 }
223 public void testHCatImportWithCreateTable() throws Exception {
224 String[] args = {
225 "--hcatalog-table",
226 "table",
227 "--create-hcatalog-table",
228 };
229 SqoopOptions opts = parseImportArgs(args);
230 }
231
232 public void testHCatImportWithStorageStanza() throws Exception {
233 String[] args = {
234 "--hcatalog-table",
235 "table",
236 "--hcatalog-storage-stanza",
237 "stored as textfile",
238 };
239 SqoopOptions opts = parseImportArgs(args);
240 }
241
242 public void testHCatImportWithDatabase() throws Exception {
243 String[] args = {
244 "--hcatalog-table",
245 "table",
246 "--hcatalog-database",
247 "default",
248 };
249 SqoopOptions opts = parseImportArgs(args);
250 }
251 }