OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UserMappingTest.java
Go to the documentation of this file.
1 package com.mapd.parser.extension.ddl;
2 
3 import static org.junit.Assert.assertEquals;
4 
5 import com.google.gson.JsonObject;
6 
7 import org.junit.Test;
8 
9 import ai.heavy.thrift.calciteserver.InvalidParseRequest;
10 import ai.heavy.thrift.calciteserver.TPlanResult;
11 
12 public class UserMappingTest extends DDLTest {
13  public UserMappingTest() {
14  resourceDirPath = UserMappingTest.class.getClassLoader().getResource("").getPath();
15  jsonTestDir = "usermapping";
16  }
17 
18  @Test
19  public void createUserMapping() throws Exception {
20  final JsonObject expectedJsonObject = getJsonFromFile("create_user_mapping.json");
21  final TPlanResult result = processDdlCommand(
22  "CREATE USER MAPPING FOR test_user SERVER test_server WITH (attribute_1 = 'value_1', attribute_2 = 2);");
23  final JsonObject actualJsonObject =
24  gson.fromJson(result.plan_result, JsonObject.class);
25 
26  assertEquals(expectedJsonObject, actualJsonObject);
27  }
28 
29  @Test
30  public void createUserMappingForCurrentUser() throws Exception {
31  final JsonObject expectedJsonObject =
32  getJsonFromFile("create_user_mapping_w_current_user.json");
33  final TPlanResult result = processDdlCommand(
34  "CREATE USER MAPPING FOR CURRENT_USER SERVER test_server WITH (attribute_1 = 'value_1', attribute_2 = 2);");
35  final JsonObject actualJsonObject =
36  gson.fromJson(result.plan_result, JsonObject.class);
37 
38  assertEquals(expectedJsonObject, actualJsonObject);
39  }
40 
41  @Test
42  public void createUserMappingForPublicUser() throws Exception {
43  final JsonObject expectedJsonObject =
44  getJsonFromFile("create_user_mapping_w_public.json");
45  final TPlanResult result = processDdlCommand(
46  "CREATE USER MAPPING FOR PUBLIC SERVER test_server WITH (attribute_1 = 'value_1', attribute_2 = 2);");
47  final JsonObject actualJsonObject =
48  gson.fromJson(result.plan_result, JsonObject.class);
49 
50  assertEquals(expectedJsonObject, actualJsonObject);
51  }
52 
53  @Test
54  public void createUserMappingWithIfNotExists() throws Exception {
55  final JsonObject expectedJsonObject =
56  getJsonFromFile("create_user_mapping_w_if_not_exists.json");
57  final TPlanResult result = processDdlCommand(
58  "CREATE USER MAPPING IF NOT EXISTS FOR test_user SERVER test_server "
59  + "WITH (attribute_1 = 'value_1', attribute_2 = 2);");
60  final JsonObject actualJsonObject =
61  gson.fromJson(result.plan_result, JsonObject.class);
62 
63  assertEquals(expectedJsonObject, actualJsonObject);
64  }
65 
66  @Test(expected = InvalidParseRequest.class)
67  public void createUserMappingNoWithClause() throws Exception {
68  processDdlCommand("CREATE USER MAPPING FOR test_user SERVER test_server;");
69  }
70 
71  @Test(expected = InvalidParseRequest.class)
72  public void createUserMappingEmptyOptions() throws Exception {
73  processDdlCommand("CREATE USER MAPPING FOR test_user SERVER test_server WITH ();");
74  }
75 
76  @Test
77  public void dropUserMapping() throws Exception {
78  final JsonObject expectedJsonObject = getJsonFromFile("drop_user_mapping.json");
79  final TPlanResult result =
80  processDdlCommand("DROP USER MAPPING FOR test_user SERVER test_server;");
81  final JsonObject actualJsonObject =
82  gson.fromJson(result.plan_result, JsonObject.class);
83 
84  assertEquals(expectedJsonObject, actualJsonObject);
85  }
86 
87  @Test
88  public void dropUserMappingWithIfExists() throws Exception {
89  final JsonObject expectedJsonObject =
90  getJsonFromFile("drop_user_mapping_w_if_exists.json");
91  final TPlanResult result = processDdlCommand(
92  "DROP USER MAPPING IF EXISTS FOR test_user SERVER test_server;");
93  final JsonObject actualJsonObject =
94  gson.fromJson(result.plan_result, JsonObject.class);
95 
96  assertEquals(expectedJsonObject, actualJsonObject);
97  }
98 }
JsonObject getJsonFromFile(final String fileName)
Definition: DDLTest.java:50
TPlanResult processDdlCommand(final String ddlCommand)
Definition: DDLTest.java:35