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.onap.music.main.CachingUtil;
38 import org.springframework.test.context.ActiveProfiles;
39 import org.springframework.test.context.ContextConfiguration;
40 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41 import org.onap.music.datastore.MusicDataStore;
42 import org.onap.music.datastore.PreparedQueryObject;
44 import com.datastax.driver.core.DataType;
45 import com.datastax.driver.core.ResultSet;
46 import com.datastax.driver.core.Row;
47 import com.datastax.driver.core.TableMetadata;
49 @RunWith(SpringJUnit4ClassRunner.class)
50 //@ActiveProfiles(profiles = "OrderRepositoryTest")
52 public class MusicDataStoreTest {
54 static MusicDataStore dataStore;
55 static PreparedQueryObject testObject;
58 public static void init()throws Exception {
59 dataStore = CassandraCQL.connectToEmbeddedCassandra();
60 //CachingUtil.resetStatementBank();
65 public static void close() throws MusicServiceException, MusicQueryException {
67 testObject = new PreparedQueryObject();
68 testObject.appendQueryString(CassandraCQL.dropKeyspace);
69 dataStore.executePut(testObject, "eventual");
71 //CachingUtil.resetStatementBank();
75 public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
76 boolean result = false;
77 //CachingUtil.resetStatementBank();
78 testObject = new PreparedQueryObject();
79 testObject.appendQueryString(CassandraCQL.createKeySpace);
80 result = dataStore.executePut(testObject, "eventual");;
81 testObject = new PreparedQueryObject();
82 testObject.appendQueryString(CassandraCQL.createTableEmployees);
83 result = dataStore.executePut(testObject, "eventual");
84 assertEquals(true, result);
89 public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
90 testObject = CassandraCQL.setPreparedInsertQueryObject1();
91 boolean result = dataStore.executePut(testObject, "eventual");
92 assertEquals(true, result);
96 public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
97 testObject = CassandraCQL.setPreparedInsertQueryObject2();
98 boolean result = dataStore.executePut(testObject, "Critical");
99 assertEquals(true, result);
103 public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
104 testObject = CassandraCQL.setPreparedUpdateQueryObject();
105 boolean result = false;
106 result = dataStore.executePut(testObject, "eventual");
107 assertEquals(true, result);
111 public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
112 testObject = new PreparedQueryObject();
113 testObject.appendQueryString(CassandraCQL.selectALL);
114 boolean result = false;
116 ResultSet output = null;
117 output = dataStore.executeOneConsistencyGet(testObject);
118 System.out.println(output);
120 for (Row row : output) {
122 System.out.println(row.toString());
127 assertEquals(false, result);
131 public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
132 testObject = CassandraCQL.setPreparedGetQuery();
133 boolean result = false;
135 ResultSet output = null;
136 output = dataStore.executeQuorumConsistencyGet(testObject);
137 System.out.println(output);
139 for (Row row : output) {
141 System.out.println(row.toString());
146 assertEquals(false, result);
149 @Test(expected = NullPointerException.class)
150 public void Test7_exception() {
151 PreparedQueryObject queryObject = null;
153 dataStore.executePut(queryObject, "critical");
154 } catch (MusicQueryException | MusicServiceException e) {
155 System.out.println(e.getMessage());
160 public void Test8_columnDataType() {
161 DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
162 String datatype = data.toString();
163 assertEquals("text",datatype);
167 public void Test8_columnMetdaData() {
168 TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");