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