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.runner.RunWith;
33 import org.junit.runners.MethodSorters;
34 import org.mockito.Mock;
35 import org.onap.music.exceptions.MusicQueryException;
36 import org.onap.music.exceptions.MusicServiceException;
37 import org.springframework.test.context.ActiveProfiles;
38 import org.springframework.test.context.ContextConfiguration;
39 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
40 import org.onap.music.datastore.MusicDataStore;
41 import org.onap.music.datastore.PreparedQueryObject;
43 import com.datastax.driver.core.DataType;
44 import com.datastax.driver.core.ResultSet;
45 import com.datastax.driver.core.Row;
46 import com.datastax.driver.core.TableMetadata;
48 @RunWith(SpringJUnit4ClassRunner.class)
49 //@ActiveProfiles(profiles = "OrderRepositoryTest")
51 public class MusicDataStoreTest {
53 static MusicDataStore dataStore;
54 static PreparedQueryObject testObject;
57 public static void init()throws Exception {
58 dataStore = CassandraCQL.connectToEmbeddedCassandra();
59 //CachingUtil.resetStatementBank();
64 public static void close() throws MusicServiceException, MusicQueryException {
66 testObject = new PreparedQueryObject();
67 testObject.appendQueryString(CassandraCQL.dropKeyspace);
68 dataStore.executePut(testObject, "eventual");
70 //CachingUtil.resetStatementBank();
74 public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
75 boolean result = false;
76 //CachingUtil.resetStatementBank();
77 testObject = new PreparedQueryObject();
78 testObject.appendQueryString(CassandraCQL.createKeySpace);
79 result = dataStore.executePut(testObject, "eventual");;
80 testObject = new PreparedQueryObject();
81 testObject.appendQueryString(CassandraCQL.createTableEmployees);
82 result = dataStore.executePut(testObject, "eventual");
83 assertEquals(true, result);
88 public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
89 testObject = CassandraCQL.setPreparedInsertQueryObject1();
90 boolean result = dataStore.executePut(testObject, "eventual");
91 assertEquals(true, result);
95 public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
96 testObject = CassandraCQL.setPreparedInsertQueryObject2();
97 boolean result = dataStore.executePut(testObject, "Critical");
98 assertEquals(true, result);
102 public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
103 testObject = CassandraCQL.setPreparedUpdateQueryObject();
104 boolean result = false;
105 result = dataStore.executePut(testObject, "eventual");
106 assertEquals(true, result);
110 public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
111 testObject = new PreparedQueryObject();
112 testObject.appendQueryString(CassandraCQL.selectALL);
113 boolean result = false;
115 ResultSet output = null;
116 output = dataStore.executeOneConsistencyGet(testObject);
117 System.out.println(output);
119 for (Row row : output) {
121 System.out.println(row.toString());
126 assertEquals(false, result);
130 public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
131 testObject = CassandraCQL.setPreparedGetQuery();
132 boolean result = false;
134 ResultSet output = null;
135 output = dataStore.executeQuorumConsistencyGet(testObject);
136 System.out.println(output);
138 for (Row row : output) {
140 System.out.println(row.toString());
145 assertEquals(false, result);
148 @Test(expected = NullPointerException.class)
149 public void Test7_exception() {
150 PreparedQueryObject queryObject = null;
152 dataStore.executePut(queryObject, "critical");
153 } catch (MusicQueryException | MusicServiceException e) {
154 System.out.println(e.getMessage());
159 public void Test8_columnDataType() {
160 DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
161 String datatype = data.toString();
162 assertEquals("text",datatype);
166 public void Test8_columnMetdaData() {
167 TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");