/*
- * ============LICENSE_START========================================== org.onap.music
- * =================================================================== Copyright (c) 2017 AT&T
- * Intellectual Property ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*
* ============LICENSE_END=============================================
* ====================================================================
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-import org.apache.curator.test.TestingServer;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
//import org.onap.music.main.ResultType;
-import org.onap.music.rest.RestMusicAdminAPI;
+//import org.onap.music.rest.RestMusicAdminAPI;
import org.onap.music.rest.RestMusicDataAPI;
import org.onap.music.rest.RestMusicQAPI;
+import org.springframework.test.util.ReflectionTestUtils;
import org.onap.music.rest.RestMusicLocksAPI;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
@RunWith(MockitoJUnitRunner.class)
public class TestRestMusicQAPI {
-
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
+
+ //RestMusicAdminAPI admin = new RestMusicAdminAPI();
RestMusicLocksAPI lock = new RestMusicLocksAPI();
RestMusicQAPI qData = new RestMusicQAPI();
static PreparedQueryObject testObject;
- static TestingServer zkServer;
@Mock
static HttpServletResponse http;
@Mock
UriInfo info;
-
+
static String appName = "TestApp";
static String userId = "TestUser";
static String password = "TestPassword";
@BeforeClass
public static void init() throws Exception {
try {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
+ ReflectionTestUtils.setField(MusicDataStoreHandle.class, "mDstoreHandle",
+ CassandraCQL.connectToEmbeddedCassandra());
+ MusicCore.setmLockHandle(new CassaLockStore(MusicDataStoreHandle.getDSHandle()));
- // System.out.println("before class keysp");
+ // System.out.println("before class keysp");
//resp=data.createKeySpace(majorV,minorV,patchV,aid,appName,userId,password,kspObject,keyspaceName);
//System.out.println("after keyspace="+keyspaceName);
} catch (Exception e) {
- System.out.println("before class exception ");
+ System.out.println("before class exception ");
e.printStackTrace();
}
- // admin keyspace and table
+ // admin keyspace and table
testObject = new PreparedQueryObject();
testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
+ "{'class' : 'SimpleStrategy' , "
if (rows.size() > 0) {
System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
}
-
+
JsonKeySpace jsonKeyspace = new JsonKeySpace();
Map<String, String> consistencyInfo = new HashMap<>();
Map<String, Object> replicationInfo = new HashMap<>();
testObject = new PreparedQueryObject();
testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
MusicCore.eventualPut(testObject);
- if (MusicDataStoreHandle.mDstoreHandle!=null)
- MusicDataStoreHandle.mDstoreHandle.close();
- if (zkServer!=null)
- zkServer.stop();
+ MusicDataStore mds = (MusicDataStore) ReflectionTestUtils.getField(MusicDataStoreHandle.class, "mDstoreHandle");
+ if (mds != null)
+ mds.close();
}
System.out.println("Entity" + response.getEntity());
assertEquals(200, response.getStatus());
}*/
-
+
@Test
public void Test1_createQ_FieldsEmpty() throws Exception {
JsonTable jsonTable = new JsonTable();
System.out.println("Entity" + response.getEntity());
assertEquals(200, response.getStatus());
}*/
-
+
/* @Test
public void Test1_createQ_ClusterOrderGood1() throws Exception {
String tableNameC="testcjcO";
// "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
+ assertEquals(400, response.getStatus());
}
@Test
public void Test3_createQ_0() throws Exception {
- //duplicate testing ...
+ //duplicate testing ...
JsonTable jsonTable = new JsonTable();
Map<String, String> consistencyInfo = new HashMap<>();
Map<String, String> fields = new HashMap<>();
//assertNotEquals(200,response0.getStatus());
}
- // Improper Auth
- @Test
- public void Test3_createQ1() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- jsonTable.setTableName(tableName);
- jsonTable.setClusteringOrder("uuid DESC");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
// Improper keyspace
+ @Ignore
@Test
public void Test3_createQ2() throws Exception {
JsonTable jsonTable = new JsonTable();
assertEquals(200, response.getStatus());
}*/
- // Auth Error
- @Test
- public void Test4_insertIntoQ3() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
- // Table wrong
- @Test
- public void Test4_insertIntoQ4() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, "wrong");
- assertEquals(401, response.getStatus());
- }
-
+
/* @Test
public void Test5_updateQ() throws Exception {
JsonUpdate jsonUpdate = new JsonUpdate();
assertEquals(200, response.getStatus());
}*/
- @Test
- public void Test5_updateQEmptyValues() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- //values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.updateQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertNotEquals(200, response.getStatus());
- }
+ @Test
+ public void Test5_updateQEmptyValues() throws Exception {
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testName");
+ //values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+ //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ //Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = qData.updateQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonUpdate, keyspaceName, tableName, info);
+ assertNotEquals(200, response.getStatus());
+ }
/* @Test
public void Test6_filterQ() throws Exception { //select
jsonSelect.setConsistencyInfo(consistencyInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
UriInfo infoe= mockUriInfo("/peek?");//empty queryParam: cause exception
- // infoe.setQueryParameters("");
+ // infoe.setQueryParameters("");
System.out.println("uriinfo="+infoe.getQueryParameters());
Mockito.when(infoe.getQueryParameters()).thenReturn(row);
Response response = qData.peek(majorV, minorV,patchV,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
//Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
Response response = qData.deleteFromQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonDelete, keyspaceName, tableName, info);
assertEquals(400, response.getStatus());
}
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Response response = qData.dropQ(majorV, minorV,patchV,
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableName);
+ keyspaceName, tableName);
assertEquals(200, response.getStatus());
}*/
-
+
private UriInfo mockUriInfo(String urix) throws URISyntaxException {
- String uri="http://localhost:8080/MUSIC/rest/v"+majorV+"/priorityq/keyspaces/"+keyspaceName+"/"+tableName+urix;
- UriInfo uriInfo = Mockito.mock(UriInfo.class);
- System.out.println("mock urix="+urix+" uri="+uri);
- Mockito.when(uriInfo.getRequestUri()).thenReturn(new URI(uri));
- return uriInfo;
- }
+ String uri="http://localhost:8080/MUSIC/rest/v"+majorV+"/priorityq/keyspaces/"+keyspaceName+"/"+tableName+urix;
+ UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ System.out.println("mock urix="+urix+" uri="+uri);
+ Mockito.when(uriInfo.getRequestUri()).thenReturn(new URI(uri));
+ return uriInfo;
+ }
//Empty Fields
assertEquals(400, response.getStatus());
}
- //Clustering key null
+ //Clustering key null
@Test
public void Test8_createQ_ClusteringKey_empty() throws Exception {
String tableNameC="testcjcC";
assertEquals(400, response.getStatus());
}
- //Invalid primary key
+ //Invalid primary key
@Test
public void Test8_createQ_primaryKey_invalid() throws Exception {
String tableNameC="testcjcC";