Merge "Include owner in createLockRef"
[music.git] / music-core / src / test / java / org / onap / music / datastore / jsonobjects / JsonTableTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  *  Modifications Copyright (c) 2019 IBM.
8  * ===================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  * 
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  * 
21  * ============LICENSE_END=============================================
22  * ====================================================================
23  */
24
25 package org.onap.music.datastore.jsonobjects;
26
27 import static org.junit.Assert.*;
28 import java.util.HashMap;
29 import java.util.Map;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.music.exceptions.MusicQueryException;
33
34 public class JsonTableTest {
35
36     JsonTable jt = null;
37     
38     @Before
39     public void init() {
40         jt = new JsonTable();
41     }
42     
43     @Test
44     public void testGetConsistencyInfo() {
45         Map<String, String> mapSs = new HashMap<>();
46         mapSs.put("k1", "one");
47         jt.setConsistencyInfo(mapSs);
48         assertEquals("one",jt.getConsistencyInfo().get("k1"));
49     }
50
51     @Test
52     public void testGetProperties() {
53         Map<String, Object> properties = new HashMap<>();
54         properties.put("k1", "one");
55         jt.setProperties(properties);
56         assertEquals(properties.size(), jt.getProperties().size());
57     }
58
59     @Test
60     public void testGetFields() {
61         Map<String, String> fields = new HashMap<>();
62         fields.put("k1", "one");
63         jt.setFields(fields);
64         assertEquals("one",jt.getFields().get("k1"));
65     }
66
67     @Test
68     public void testGetKeyspaceName() {
69         String keyspace = "keyspace";
70         jt.setKeyspaceName(keyspace);
71         assertEquals(keyspace,jt.getKeyspaceName());
72     }
73
74     @Test
75     public void testGetTableName() {
76         String table = "table";
77         jt.setTableName(table);
78         assertEquals(table,jt.getTableName());
79    }
80
81     @Test
82     public void testGetClusteringOrder() {
83         String clusteringOrder = "clusteringOrder";
84         jt.setClusteringOrder(clusteringOrder);
85         assertEquals(clusteringOrder,jt.getClusteringOrder());
86     }
87     
88     @Test
89     public void testGetClusterKey() {
90         String clusterKey = "clusterKey";
91         jt.setClusteringKey(clusterKey);
92         assertEquals(clusterKey, jt.getClusteringKey());
93     }
94
95     @Test
96     public void testGetPrimaryKey() {
97         String primaryKey = "primaryKey";
98         jt.setPrimaryKey(primaryKey);
99         assertEquals(primaryKey,jt.getPrimaryKey());        
100     }
101     
102     @Test
103     public void testFilteringKey() {
104         jt.setFilteringKey("FilteringKey");
105         assertEquals("FilteringKey",jt.getFilteringKey());        
106     }
107     
108     @Test
109     public void testPartitionKey() {
110         jt.setPartitionKey("ParitionKey");
111         assertEquals("ParitionKey",jt.getPartitionKey());
112     }
113
114     @Test
115     public void genCreateTableQuery() throws MusicQueryException {
116         JsonTable jt2 = new JsonTable();
117         jt2.setKeyspaceName("keyspace");
118         jt2.setTableName("table");
119         Map<String, String> fields = new HashMap<>();
120         fields.put("k1", "one");
121         jt2.setFields(fields);
122         jt2.setPrimaryKey("k1");
123         Map<String, String> mapSs = new HashMap<>();
124         mapSs.put("k1", "one");
125         jt2.setConsistencyInfo(mapSs);
126         String clusteringOrder = "clusteringOrder";
127         jt.setClusteringOrder(clusteringOrder);
128         String clusterKey = "clusterKey";
129         jt.setClusteringKey(clusterKey);
130         
131         System.out.println(jt2.genCreateTableQuery().getQuery());
132         assertEquals("CREATE TABLE keyspace.table (vector_ts text,k1 one, PRIMARY KEY ( (k1) ));",
133                 jt2.genCreateTableQuery().getQuery());
134     }
135     
136     @Test
137     public void genDropTableQuery() throws MusicQueryException {
138         JsonTable jt2 = new JsonTable();
139         jt2.setKeyspaceName("keyspace");
140         jt2.setTableName("table");
141         Map<String, String> fields = new HashMap<>();
142         fields.put("k1", "one");
143         jt2.setFields(fields);
144         jt2.setPrimaryKey("k1");
145         Map<String, String> mapSs = new HashMap<>();
146         mapSs.put("k1", "one");
147         jt.setConsistencyInfo(mapSs);
148         
149         System.out.println(jt2.genDropTableQuery().getQuery());
150         assertEquals("DROP TABLE  keyspace.table;",
151                 jt2.genDropTableQuery().getQuery());
152     }
153 }