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;
26 import org.junit.AfterClass;
27 import org.junit.BeforeClass;
28 import org.junit.FixMethodOrder;
29 import org.junit.Test;
30 import org.junit.runners.MethodSorters;
31 import org.mockito.Mock;
32 import org.onap.music.exceptions.MusicQueryException;
33 import org.onap.music.exceptions.MusicServiceException;
35 import org.onap.music.datastore.MusicDataStore;
36 import org.onap.music.datastore.PreparedQueryObject;
37 import com.datastax.driver.core.ResultSet;
38 import com.datastax.driver.core.Row;
40 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
41 public class MusicDataStoreTest {
43 static MusicDataStore dataStore;
44 static PreparedQueryObject testObject;
47 public static void init() {
48 dataStore = CassandraCQL.connectToEmbeddedCassandra();
53 public static void close() throws MusicServiceException, MusicQueryException {
55 testObject = new PreparedQueryObject();
56 testObject.appendQueryString(CassandraCQL.dropKeyspace);
57 dataStore.executePut(testObject, "eventual");
63 public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
64 boolean result = false;
65 testObject = new PreparedQueryObject();
66 testObject.appendQueryString(CassandraCQL.createKeySpace);
67 result = dataStore.executePut(testObject, "eventual");;
68 testObject = new PreparedQueryObject();
69 testObject.appendQueryString(CassandraCQL.createTableEmployees);
70 result = dataStore.executePut(testObject, "eventual");
71 assertEquals(true, result);
76 public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
77 testObject = CassandraCQL.setPreparedInsertQueryObject1();
78 boolean result = dataStore.executePut(testObject, "eventual");
79 assertEquals(true, result);
83 public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
84 testObject = CassandraCQL.setPreparedInsertQueryObject2();
85 boolean result = dataStore.executePut(testObject, "Critical");
86 assertEquals(true, result);
90 public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
91 testObject = CassandraCQL.setPreparedUpdateQueryObject();
92 boolean result = false;
93 result = dataStore.executePut(testObject, "eventual");
94 assertEquals(true, result);
98 public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
99 testObject = new PreparedQueryObject();
100 testObject.appendQueryString(CassandraCQL.selectALL);
101 boolean result = false;
103 ResultSet output = null;
104 output = dataStore.executeEventualGet(testObject);
105 System.out.println(output);
107 for (Row row : output) {
109 System.out.println(row.toString());
114 assertEquals(true, result);
118 public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
119 testObject = CassandraCQL.setPreparedGetQuery();
120 boolean result = false;
122 ResultSet output = null;
123 output = dataStore.executeCriticalGet(testObject);
124 System.out.println(output);
126 for (Row row : output) {
128 System.out.println(row.toString());
133 assertEquals(true, result);
136 @Test(expected = NullPointerException.class)
137 public void Test7_exception() {
138 PreparedQueryObject queryObject = null;
140 dataStore.executePut(queryObject, "critical");
141 } catch (MusicQueryException | MusicServiceException e) {
142 System.out.println(e.getMessage());