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 * ====================================================================
22 package org.onap.music.unittests;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.FixMethodOrder;
30 import org.junit.Test;
31 import org.junit.runners.MethodSorters;
32 import org.mockito.Mock;
33 import org.onap.music.exceptions.MusicQueryException;
34 import org.onap.music.exceptions.MusicServiceException;
36 import org.onap.music.datastore.MusicDataStore;
37 import org.onap.music.datastore.PreparedQueryObject;
39 import com.datastax.driver.core.DataType;
40 import com.datastax.driver.core.ResultSet;
41 import com.datastax.driver.core.Row;
42 import com.datastax.driver.core.TableMetadata;
44 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
45 public class MusicDataStoreTest {
47 static MusicDataStore dataStore;
48 static PreparedQueryObject testObject;
51 public static void init() {
52 dataStore = CassandraCQL.connectToEmbeddedCassandra();
57 public static void close() throws MusicServiceException, MusicQueryException {
59 testObject = new PreparedQueryObject();
60 testObject.appendQueryString(CassandraCQL.dropKeyspace);
61 dataStore.executePut(testObject, "eventual");
67 public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
68 boolean result = false;
69 testObject = new PreparedQueryObject();
70 testObject.appendQueryString(CassandraCQL.createKeySpace);
71 result = dataStore.executePut(testObject, "eventual");;
72 testObject = new PreparedQueryObject();
73 testObject.appendQueryString(CassandraCQL.createTableEmployees);
74 result = dataStore.executePut(testObject, "eventual");
75 assertEquals(true, result);
80 public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
81 testObject = CassandraCQL.setPreparedInsertQueryObject1();
82 boolean result = dataStore.executePut(testObject, "eventual");
83 assertEquals(true, result);
87 public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
88 testObject = CassandraCQL.setPreparedInsertQueryObject2();
89 boolean result = dataStore.executePut(testObject, "Critical");
90 assertEquals(true, result);
94 public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
95 testObject = CassandraCQL.setPreparedUpdateQueryObject();
96 boolean result = false;
97 result = dataStore.executePut(testObject, "eventual");
98 assertEquals(true, result);
102 public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
103 testObject = new PreparedQueryObject();
104 testObject.appendQueryString(CassandraCQL.selectALL);
105 boolean result = false;
107 ResultSet output = null;
108 output = dataStore.executeEventualGet(testObject);
109 System.out.println(output);
111 for (Row row : output) {
113 System.out.println(row.toString());
118 assertEquals(true, result);
122 public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
123 testObject = CassandraCQL.setPreparedGetQuery();
124 boolean result = false;
126 ResultSet output = null;
127 output = dataStore.executeCriticalGet(testObject);
128 System.out.println(output);
130 for (Row row : output) {
132 System.out.println(row.toString());
137 assertEquals(true, result);
140 @Test(expected = NullPointerException.class)
141 public void Test7_exception() {
142 PreparedQueryObject queryObject = null;
144 dataStore.executePut(queryObject, "critical");
145 } catch (MusicQueryException | MusicServiceException e) {
146 System.out.println(e.getMessage());
151 public void Test8_columnDataType() {
152 DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
153 String datatype = data.toString();
154 assertEquals("text",datatype);
158 public void Test8_columnMetdaData() {
159 TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");