2 * ============LICENSE_START==========================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=============================================
22 * ====================================================================
25 package org.onap.music.datastore.jsonobjects;
27 import static org.junit.Assert.*;
28 import java.util.HashMap;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.music.exceptions.MusicQueryException;
34 public class JsonTableTest {
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"));
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());
60 public void testGetFields() {
61 Map<String, String> fields = new HashMap<>();
62 fields.put("k1", "one");
64 assertEquals("one",jt.getFields().get("k1"));
68 public void testGetKeyspaceName() {
69 String keyspace = "keyspace";
70 jt.setKeyspaceName(keyspace);
71 assertEquals(keyspace,jt.getKeyspaceName());
75 public void testGetTableName() {
76 String table = "table";
77 jt.setTableName(table);
78 assertEquals(table,jt.getTableName());
82 public void testGetClusteringOrder() {
83 String clusteringOrder = "clusteringOrder";
84 jt.setClusteringOrder(clusteringOrder);
85 assertEquals(clusteringOrder,jt.getClusteringOrder());
89 public void testGetClusterKey() {
90 String clusterKey = "clusterKey";
91 jt.setClusteringKey(clusterKey);
92 assertEquals(clusterKey, jt.getClusteringKey());
96 public void testGetPrimaryKey() {
97 String primaryKey = "primaryKey";
98 jt.setPrimaryKey(primaryKey);
99 assertEquals(primaryKey,jt.getPrimaryKey());
103 public void testFilteringKey() {
104 jt.setFilteringKey("FilteringKey");
105 assertEquals("FilteringKey",jt.getFilteringKey());
109 public void testPartitionKey() {
110 jt.setPartitionKey("ParitionKey");
111 assertEquals("ParitionKey",jt.getPartitionKey());
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);
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());
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);
149 System.out.println(jt2.genDropTableQuery().getQuery());
150 assertEquals("DROP TABLE keyspace.table;",
151 jt2.genDropTableQuery().getQuery());