Review Board 1.7.22


Unit test for common module

Review Request #8974 - Created Jan. 16, 2013 and updated

Vasanth kumar RJ
SQOOP-831
Reviewers
Sqoop
sqoop-sqoop2
Unit test cases for Sqoop2 Common module
Executed test cases
common/src/test/java/org/apache/sqoop/common/TestMapContext.java
New File

    
   
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.common;

    
   
19

   

    
   
20
import java.util.HashMap;

    
   
21
import java.util.Map;

    
   
22

   

    
   
23
import junit.framework.Assert;

    
   
24

   

    
   
25
import org.junit.Test;

    
   
26

   

    
   
27
/**

    
   
28
 * Test class for org.apache.sqoop.common.MapContext

    
   
29
 */

    
   
30
public class TestMapContext {

    
   
31

   

    
   
32
  /**

    
   
33
   * Test method for Initialization

    
   
34
   */

    
   
35
  @Test

    
   
36
  public void testInitalization() {

    
   
37
    Map<String, String> options = new HashMap<String, String>();

    
   
38
    options.put("testkey", "testvalue");

    
   
39
    MapContext mc = new MapContext(options);

    
   
40
    Assert.assertEquals("testvalue", mc.getString("testkey"));

    
   
41
  }

    
   
42

   

    
   
43
  /**

    
   
44
   * Test method for getString

    
   
45
   */

    
   
46
  @Test

    
   
47
  public void testGetString() {

    
   
48
    Map<String, String> options = new HashMap<String, String>();

    
   
49
    options.put("testkey", "testvalue");

    
   
50
    MapContext mc = new MapContext(options);

    
   
51
    Assert.assertEquals("testvalue", mc.getString("testkey", "defaultValue"));

    
   
52
    Assert.assertEquals("defaultValue",

    
   
53
        mc.getString("wrongKey", "defaultValue"));

    
   
54
  }

    
   
55

   

    
   
56
  /**

    
   
57
   * Test method for getString with default value

    
   
58
   */

    
   
59
  @Test

    
   
60
  public void testGetBoolean() {

    
   
61
    Map<String, String> options = new HashMap<String, String>();

    
   
62
    options.put("testkey", "true");

    
   
63
    MapContext mc = new MapContext(options);

    
   
64
    Assert.assertEquals(true, mc.getBoolean("testkey", false));

    
   
65
    Assert.assertEquals(false, mc.getBoolean("wrongKey", false));

    
   
66
  }

    
   
67

   

    
   
68
  /**

    
   
69
   * Test method for getInt with default value

    
   
70
   */

    
   
71
  @Test

    
   
72
  public void testGetInt() {

    
   
73
    Map<String, String> options = new HashMap<String, String>();

    
   
74
    options.put("testkey", "123");

    
   
75
    MapContext mc = new MapContext(options);

    
   
76
    Assert.assertEquals(123, mc.getInt("testkey", 456));

    
   
77
    Assert.assertEquals(456, mc.getInt("wrongKey", 456));

    
   
78
  }

    
   
79

   

    
   
80
  /**

    
   
81
   * Test method for getLong with default value

    
   
82
   */

    
   
83
  @Test

    
   
84
  public void testGetLong() {

    
   
85
    Map<String, String> options = new HashMap<String, String>();

    
   
86
    options.put("testkey", "123");

    
   
87
    MapContext mc = new MapContext(options);

    
   
88
    Assert.assertEquals(123l, mc.getLong("testkey", 456l));

    
   
89
    Assert.assertEquals(456l, mc.getLong("wrongKey", 456l));

    
   
90
  }

    
   
91

   

    
   
92
  /**

    
   
93
   * Test method for getNestedProperties()

    
   
94
   */

    
   
95
  @Test

    
   
96
  public void testGetNestedProperties() {

    
   
97
    Map<String, String> options = new HashMap<String, String>();

    
   
98
    options.put("sqooptest1", "value");

    
   
99
    options.put("sqooptest2", "value");

    
   
100
    options.put("testsqoop1", "value");

    
   
101
    options.put("testsqoop1", "value");

    
   
102
    MapContext mc = new MapContext(options);

    
   
103
    Map<String, String> result = mc.getNestedProperties("sqoop");

    
   
104
    Assert.assertEquals(2, result.size());

    
   
105
    Assert.assertTrue(result.containsKey("test1"));

    
   
106
    Assert.assertTrue(result.containsKey("test2"));

    
   
107
    Assert.assertFalse(result.containsKey("testsqoop1"));

    
   
108
    Assert.assertFalse(result.containsKey("testsqoop2"));

    
   
109
  }

    
   
110
}
common/src/test/java/org/apache/sqoop/common/TestSqoopResponseCode.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMConnection.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMConnectionForms.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMConnector.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMEnumInput.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMForm.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMIntegerInput.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMJob.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMJobForms.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMMapInput.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMNamedElement.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMStringInput.java
New File
 
common/src/test/java/org/apache/sqoop/model/TestMValidatedElement.java
New File
 
common/src/test/java/org/apache/sqoop/submission/TestSubmissionStatus.java
New File
 
common/src/test/java/org/apache/sqoop/submission/counter/TestCounter.java
New File
 
common/src/test/java/org/apache/sqoop/submission/counter/TestCounterGroup.java
New File
 
common/src/test/java/org/apache/sqoop/submission/counter/TestCounters.java
New File
 
common/src/test/java/org/apache/sqoop/validation/TestValidation.java
New File
 
  1. common/src/test/java/org/apache/sqoop/common/TestMapContext.java: Loading...
  2. common/src/test/java/org/apache/sqoop/common/TestSqoopResponseCode.java: Loading...
  3. common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java: Loading...
  4. common/src/test/java/org/apache/sqoop/model/TestMConnection.java: Loading...
  5. common/src/test/java/org/apache/sqoop/model/TestMConnectionForms.java: Loading...
  6. common/src/test/java/org/apache/sqoop/model/TestMConnector.java: Loading...
  7. common/src/test/java/org/apache/sqoop/model/TestMEnumInput.java: Loading...
  8. common/src/test/java/org/apache/sqoop/model/TestMForm.java: Loading...
  9. common/src/test/java/org/apache/sqoop/model/TestMIntegerInput.java: Loading...
  10. common/src/test/java/org/apache/sqoop/model/TestMJob.java: Loading...
  11. common/src/test/java/org/apache/sqoop/model/TestMJobForms.java: Loading...
  12. common/src/test/java/org/apache/sqoop/model/TestMMapInput.java: Loading...
  13. common/src/test/java/org/apache/sqoop/model/TestMNamedElement.java: Loading...
  14. common/src/test/java/org/apache/sqoop/model/TestMStringInput.java: Loading...
  15. common/src/test/java/org/apache/sqoop/model/TestMValidatedElement.java: Loading...
  16. common/src/test/java/org/apache/sqoop/submission/TestSubmissionStatus.java: Loading...
  17. common/src/test/java/org/apache/sqoop/submission/counter/TestCounter.java: Loading...
  18. common/src/test/java/org/apache/sqoop/submission/counter/TestCounterGroup.java: Loading...
  19. common/src/test/java/org/apache/sqoop/submission/counter/TestCounters.java: Loading...
  20. common/src/test/java/org/apache/sqoop/validation/TestValidation.java: Loading...