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 public class TestAPISuite {
49 static String appName = "TestApp";
50 static String userId = "TestUser";
51 static String password = "TestPassword";
52 static String authData = userId+":"+password;
53 static String wrongAuthData = userId+":"+"pass";
54 static String authorization = new String(Base64.encode(authData.getBytes()));
55 static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
56 static boolean isAAF = false;
57 static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
58 static String keyspaceName = "testcassa";
59 static String tableName = "employees";
60 static String xLatestVersion = "X-latestVersion";
61 static String onboardUUID = null;
64 public static void beforeClass() throws Exception {
65 MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
66 MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
71 public static void afterClass() {
72 PreparedQueryObject testObject = new PreparedQueryObject();
73 testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
74 MusicCore.eventualPut(testObject);
75 if(MusicDataStoreHandle.mDstoreHandle!=null)
76 MusicDataStoreHandle.mDstoreHandle.close();
79 private static void createAdminTable() throws Exception {
80 PreparedQueryObject testObject = new PreparedQueryObject();
81 testObject.appendQueryString(CassandraCQL.createAdminKeyspace);
82 MusicCore.eventualPut(testObject);
83 testObject = new PreparedQueryObject();
84 testObject.appendQueryString(CassandraCQL.createAdminTable);
85 MusicCore.eventualPut(testObject);
87 testObject = new PreparedQueryObject();
88 testObject.appendQueryString(
89 "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
90 + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
91 testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
92 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
93 MusicUtil.DEFAULTKEYSPACENAME));
94 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
95 testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
96 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
97 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
98 testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
99 MusicCore.eventualPut(testObject);
101 testObject = new PreparedQueryObject();
102 testObject.appendQueryString(
103 "select uuid from admin.keyspace_master where application_name = ? allow filtering");
104 testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
105 ResultSet rs = MusicCore.get(testObject);
106 List<Row> rows = rs.all();
107 if (rows.size() > 0) {
108 System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));