2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * ===================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.unittests;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.FixMethodOrder;
31 import org.junit.Test;
32 import org.junit.runners.MethodSorters;
33 import org.mockito.Mock;
34 import org.onap.music.exceptions.MusicQueryException;
35 import org.onap.music.exceptions.MusicServiceException;
37 import org.onap.music.datastore.MusicDataStore;
38 import org.onap.music.datastore.PreparedQueryObject;
40 import com.datastax.driver.core.DataType;
41 import com.datastax.driver.core.ResultSet;
42 import com.datastax.driver.core.Row;
43 import com.datastax.driver.core.TableMetadata;
45 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
46 public class MusicDataStoreTest {
48 static MusicDataStore dataStore;
49 static PreparedQueryObject testObject;
52 public static void init() {
53 dataStore = CassandraCQL.connectToEmbeddedCassandra();
58 public static void close() throws MusicServiceException, MusicQueryException {
60 testObject = new PreparedQueryObject();
61 testObject.appendQueryString(CassandraCQL.dropKeyspace);
62 dataStore.executePut(testObject, "eventual");
68 public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
69 boolean result = false;
70 testObject = new PreparedQueryObject();
71 testObject.appendQueryString(CassandraCQL.createKeySpace);
72 result = dataStore.executePut(testObject, "eventual");;
73 testObject = new PreparedQueryObject();
74 testObject.appendQueryString(CassandraCQL.createTableEmployees);
75 result = dataStore.executePut(testObject, "eventual");
76 assertEquals(true, result);
81 public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
82 testObject = CassandraCQL.setPreparedInsertQueryObject1();
83 boolean result = dataStore.executePut(testObject, "eventual");
84 assertEquals(true, result);
88 public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
89 testObject = CassandraCQL.setPreparedInsertQueryObject2();
90 boolean result = dataStore.executePut(testObject, "Critical");
91 assertEquals(true, result);
95 public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
96 testObject = CassandraCQL.setPreparedUpdateQueryObject();
97 boolean result = false;
98 result = dataStore.executePut(testObject, "eventual");
99 assertEquals(true, result);
103 public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
104 testObject = new PreparedQueryObject();
105 testObject.appendQueryString(CassandraCQL.selectALL);
106 boolean result = false;
108 ResultSet output = null;
109 output = dataStore.executeEventualGet(testObject);
110 System.out.println(output);
112 for (Row row : output) {
114 System.out.println(row.toString());
119 assertEquals(true, result);
123 public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
124 testObject = CassandraCQL.setPreparedGetQuery();
125 boolean result = false;
127 ResultSet output = null;
128 output = dataStore.executeCriticalGet(testObject);
129 System.out.println(output);
131 for (Row row : output) {
133 System.out.println(row.toString());
138 assertEquals(true, result);
141 @Test(expected = NullPointerException.class)
142 public void Test7_exception() {
143 PreparedQueryObject queryObject = null;
145 dataStore.executePut(queryObject, "critical");
146 } catch (MusicQueryException | MusicServiceException e) {
147 System.out.println(e.getMessage());
152 public void Test8_columnDataType() {
153 DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
154 String datatype = data.toString();
155 assertEquals("text",datatype);
159 public void Test8_columnMetdaData() {
160 TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");