2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2019 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 java.util.List;
26 import java.util.UUID;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.runner.RunWith;
31 import org.junit.runners.Suite;
32 import org.junit.runners.Suite.SuiteClasses;
33 import org.mindrot.jbcrypt.BCrypt;
34 import org.onap.music.datastore.MusicDataStoreHandle;
35 import org.onap.music.datastore.PreparedQueryObject;
36 import org.onap.music.lockingservice.cassandra.CassaLockStore;
37 import org.onap.music.main.MusicCore;
38 import org.onap.music.main.MusicUtil;
40 import com.datastax.driver.core.DataType;
41 import com.datastax.driver.core.ResultSet;
42 import com.datastax.driver.core.Row;
43 import com.sun.jersey.core.util.Base64;
46 @SuiteClasses({ TstRestMusicDataAPI.class, TstRestMusicLockAPI.class, TstRestMusicAdminAPI.class,
47 TstRestMusicConditionalAPI.class})
48 public class TestAPISuite {
50 static String appName = "TestApp";
51 static String userId = "TestUser";
52 static String password = "TestPassword";
53 static String authData = userId+":"+password;
54 static String wrongAuthData = userId+":"+"pass";
55 static String authorization = new String(Base64.encode(authData.getBytes()));
56 static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
57 static boolean isAAF = false;
58 static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
59 static String keyspaceName = "testcassa";
60 static String tableName = "employees";
61 static String xLatestVersion = "X-latestVersion";
62 static String onboardUUID = null;
65 public static void beforeClass() throws Exception {
66 MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
67 MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
72 public static void afterClass() {
73 PreparedQueryObject testObject = new PreparedQueryObject();
74 testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
75 MusicCore.eventualPut(testObject);
76 if(MusicDataStoreHandle.mDstoreHandle!=null)
77 MusicDataStoreHandle.mDstoreHandle.close();
80 private static void createAdminTable() throws Exception {
81 PreparedQueryObject testObject = new PreparedQueryObject();
82 testObject.appendQueryString(CassandraCQL.createAdminKeyspace);
83 MusicCore.eventualPut(testObject);
84 testObject = new PreparedQueryObject();
85 testObject.appendQueryString(CassandraCQL.createAdminTable);
86 MusicCore.eventualPut(testObject);
88 testObject = new PreparedQueryObject();
89 testObject.appendQueryString(
90 "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
91 + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
92 testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
93 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
94 MusicUtil.DEFAULTKEYSPACENAME));
95 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
96 testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
97 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
98 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
99 testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
100 MusicCore.eventualPut(testObject);
102 testObject = new PreparedQueryObject();
103 testObject.appendQueryString(
104 "select uuid from admin.keyspace_master where application_name = ? allow filtering");
105 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
106 ResultSet rs = MusicCore.get(testObject);
107 List<Row> rows = rs.all();
108 if (rows.size() > 0) {
109 System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));