summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/music/unittests/MusicUtilTest.java182
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java66
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java3
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java7
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/MusicDigestTest.java60
5 files changed, 166 insertions, 152 deletions
diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
index 930959ba..c4c8ba2e 100644
--- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
@@ -25,20 +25,28 @@ package org.onap.music.unittests;
import static org.junit.Assert.*;
import java.math.BigInteger;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+
import org.junit.Test;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.PropertiesLoader;
-import org.springframework.test.context.TestPropertySource;
+import org.onap.music.service.MusicCoreService;
+
+import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.DataType;
public class MusicUtilTest {
+ private static final String XLATESTVERSION = "X-latestVersion";
+ private static final String XMINORVERSION = "X-minorVersion";
+ private static final String XPATCHVERSION = "X-patchVersion";
+
@Test
public void testGetCassName() {
MusicUtil.setCassName("Cassandra");
@@ -52,14 +60,28 @@ public class MusicUtilTest {
}
@Test
- public void testGetAafEndpointUrl() {
- MusicUtil.setAafEndpointUrl("url");
- assertEquals(MusicUtil.getAafEndpointUrl(),"url");
+ public void testMusicAafNs() {
+ MusicUtil.setMusicAafNs("ns");
+ assertTrue("ns".equals(MusicUtil.getMusicAafNs()));
+ }
+
+ @Test
+ public void testMusicCoreService() {
+ MusicUtil.setLockUsing(MusicUtil.CASSANDRA);
+ MusicCoreService mc = null;
+ mc = MusicUtil.getMusicCoreService();
+ assertTrue(mc != null);
+ MusicUtil.setLockUsing("nothing");
+ mc = null;
+ mc = MusicUtil.getMusicCoreService();
+ assertTrue(mc != null);
+
}
@Test
- public void testGetPropkeys() {
- assertEquals(MusicUtil.getPropkeys()[2],"debug");
+ public void testCipherEncKey() {
+ MusicUtil.setCipherEncKey("cipherEncKey");
+ assertTrue("cipherEncKey".equals(MusicUtil.getCipherEncKey()));
}
@Test
@@ -86,28 +108,53 @@ public class MusicUtilTest {
assertEquals(MusicUtil.getVersion(),"1.0.0");
}
- /*@Test
- public void testGetMyZkHost() {
- MusicUtil.setMyZkHost("10.0.0.2");
- assertEquals(MusicUtil.getMyZkHost(),"10.0.0.2");
- }*/
+ @Test
+ public void testBuildVersionA() {
+ assertEquals(MusicUtil.buildVersion("1","2","3"),"1.2.3");
+ }
+
+ @Test
+ public void testBuildVersionB() {
+ assertEquals(MusicUtil.buildVersion("1",null,"3"),"1");
+ }
+
+ @Test
+ public void testBuildVersionC() {
+ assertEquals(MusicUtil.buildVersion("1","2",null),"1.2");
+ }
+
@Test
- public void testGetMyCassaHost() {
- MusicUtil.setMyCassaHost("10.0.0.2");
- assertEquals(MusicUtil.getMyCassaHost(),"10.0.0.2");
+ public void testBuileVersionResponse() {
+ assertTrue(MusicUtil.buildVersionResponse("1","2","3").getClass().getSimpleName().equals("Builder"));
+ assertTrue(MusicUtil.buildVersionResponse("1",null,"3").getClass().getSimpleName().equals("Builder"));
+ assertTrue(MusicUtil.buildVersionResponse("1","2",null).getClass().getSimpleName().equals("Builder"));
+ assertTrue(MusicUtil.buildVersionResponse(null,null,null).getClass().getSimpleName().equals("Builder"));
+ }
+
+ @Test
+ public void testGetConsistency() {
+ assertTrue(ConsistencyLevel.ONE.equals(MusicUtil.getConsistencyLevel("one")));
+ }
+
+ @Test
+ public void testRetryCount() {
+ MusicUtil.setRetryCount(1);
+ assertEquals(MusicUtil.getRetryCount(),1);
}
@Test
- public void testGetDefaultMusicIp() {
- MusicUtil.setDefaultMusicIp("10.0.0.2");
- assertEquals(MusicUtil.getDefaultMusicIp(),"10.0.0.2");
+ public void testIsCadi() {
+ MusicUtil.setIsCadi(true);
+ assertEquals(MusicUtil.getIsCadi(),true);
}
-// @Test
-// public void testGetTestType() {
-// fail("Not yet implemented"); // TODO
-// }
+
+ @Test
+ public void testGetMyCassaHost() {
+ MusicUtil.setMyCassaHost("10.0.0.2");
+ assertEquals(MusicUtil.getMyCassaHost(),"10.0.0.2");
+ }
@Test
public void testIsValidQueryObject() {
@@ -130,6 +177,16 @@ public class MusicUtilTest {
}
+
+
+
+ @Test(expected = IllegalStateException.class)
+ public void testMusicUtil() {
+ System.out.println("MusicUtil Constructor Test");
+ MusicUtil mu = new MusicUtil();
+ System.out.println(mu.toString());
+ }
+
@Test
public void testConvertToCQLDataType() throws Exception {
Map<String,Object> myMap = new HashMap<String,Object>();
@@ -150,9 +207,20 @@ public class MusicUtilTest {
assertEquals(MusicUtil.convertToActualDataType(DataType.cfloat(),"123.01"),Float.parseFloat("123.01"));
assertEquals(MusicUtil.convertToActualDataType(DataType.cdouble(),"123.02"),Double.parseDouble("123.02"));
assertEquals(MusicUtil.convertToActualDataType(DataType.cboolean(),"true"),Boolean.parseBoolean("true"));
+ List<String> myList = new ArrayList<String>();
+ List<String> newList = myList;
+ myList.add("TOM");
+ assertEquals(MusicUtil.convertToActualDataType(DataType.list(DataType.varchar()),myList),newList);
Map<String,Object> myMap = new HashMap<String,Object>();
myMap.put("name","tom");
- assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),myMap);
+ Map<String,Object> newMap = myMap;
+ assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),newMap);
+ }
+
+ @Test
+ public void testConvertToActualDataTypeByte() throws Exception {
+ byte[] testByte = "TOM".getBytes();
+ assertEquals(MusicUtil.convertToActualDataType(DataType.blob(),testByte),ByteBuffer.wrap(testByte));
}
@@ -189,42 +257,6 @@ public class MusicUtilTest {
}
@Test
- public void testAAFAdminUrl() {
- MusicUtil.setAafAdminUrl("aafAdminURL.com");
- assertEquals("aafAdminURL.com", MusicUtil.getAafAdminUrl());
- }
-
- @Test
- public void testAAFEndpointUrl() {
- MusicUtil.setAafEndpointUrl("aafEndpointURL.com");
- assertEquals("aafEndpointURL.com", MusicUtil.getAafEndpointUrl());
- }
-
- @Test
- public void testNamespace() {
- MusicUtil.setMusicNamespace("musicNamespace");
- assertEquals("musicNamespace", MusicUtil.getMusicNamespace());
- }
-
- @Test
- public void testAAFRole() {
- MusicUtil.setAdminAafRole("aafRole");
- assertEquals("aafRole", MusicUtil.getAdminAafRole());
- }
-
- @Test
- public void testAdminId() {
- MusicUtil.setAdminId("adminId");
- assertEquals("adminId", MusicUtil.getAdminId());
- }
-
- @Test
- public void testAdminPass() {
- MusicUtil.setAdminPass("pass");
- assertEquals("pass", MusicUtil.getAdminPass());
- }
-
- @Test
public void testCassaPort() {
MusicUtil.setCassandraPort(1234);
assertEquals(1234, MusicUtil.getCassandraPort());
@@ -237,18 +269,6 @@ public class MusicUtilTest {
}
@Test
- public void testNotifyInterval() {
- MusicUtil.setNotifyInterval(123);
- assertEquals(123, MusicUtil.getNotifyInterval());
- }
-
- @Test
- public void testNotifyTimeout() {
- MusicUtil.setNotifyTimeOut(789);
- assertEquals(789, MusicUtil.getNotifyTimeout());
- }
-
- @Test
public void testTransId() {
MusicUtil.setTransIdPrefix("prefix");
assertEquals("prefix-", MusicUtil.getTransIdPrefix());
@@ -280,23 +300,29 @@ public class MusicUtilTest {
}
@Test
- public void testconvIdReq() {
- MusicUtil.setConversationIdRequired("conversationIdRequired");
- assertEquals("conversationIdRequired", MusicUtil.getConversationIdRequired());
+ public void testConvIdReq() {
+ MusicUtil.setConversationIdRequired(true);
+ assertEquals(true, MusicUtil.getConversationIdRequired());
}
@Test
public void testClientIdRequired() {
- MusicUtil.setClientIdRequired("conversationIdRequired");
- assertEquals("conversationIdRequired", MusicUtil.getClientIdRequired());
+ MusicUtil.setClientIdRequired(true);
+ assertEquals(true, MusicUtil.getClientIdRequired());
}
@Test
public void testMessageIdRequired() {
- MusicUtil.setMessageIdRequired("msgIdRequired");
- assertEquals("msgIdRequired", MusicUtil.getMessageIdRequired());
+ MusicUtil.setMessageIdRequired(true);
+ assertEquals(true, MusicUtil.getMessageIdRequired());
}
-
+
+ @Test
+ public void testTransIdRequired() {
+ MusicUtil.setTransIdRequired(true);
+ assertEquals(true,MusicUtil.getTransIdRequired());
+ }
+
@Test
public void testLoadProperties() {
PropertiesLoader pl = new PropertiesLoader();
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
index 3bf33179..407d0323 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
@@ -194,6 +194,16 @@ public class TstRestMusicDataAPI {
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(200, response.getStatus());
}
+
+ @Test
+ public void test3_createTableNoBody() throws Exception {
+ System.out.println("Testing create table w/o body");
+
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, null, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(400, response.getStatus());
+ }
@Test
public void test3_createTableNoName() throws Exception {
@@ -312,7 +322,7 @@ public class TstRestMusicDataAPI {
assertEquals(400, response2.getStatus());
Map<String, String> respMap = (Map<String, String>) response2.getEntity();
assertEquals(ResultType.FAILURE, respMap.get("status"));
- assertEquals("Table " + keyspaceName + "." + tableNameDup + " already exists", respMap.get("error"));
+ assertEquals("AlreadyExistsException: Table " + keyspaceName + "." + tableNameDup + " already exists", respMap.get("error"));
}
@@ -539,8 +549,37 @@ public class TstRestMusicDataAPI {
assertEquals(200, response.getStatus());
}
+
+ @Test
+ public void test4_insertIntoTableNoBody() throws Exception {
+ System.out.println("Testing insert into table w/o body");
+ createTable();
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, null, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
@Test
+ public void test4_insertIntoTableNoaValues() throws Exception {
+ System.out.println("Testing insert into table");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
public void test4_insertIntoTableNoValues() throws Exception {
System.out.println("Testing insert into table");
createTable();
@@ -827,6 +866,23 @@ public class TstRestMusicDataAPI {
@Test
+ public void test6_critical_select() throws Exception {
+ System.out.println("Testing critical select w/o body");
+ createAndInsertIntoTable();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "testname");
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, authorization, null, keyspaceName, tableName,info);
+ HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
+ HashMap<String, Object> result = map.get("result");
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ // Added during merge?
+ @Test
public void test6_critical_selectCritical_nolockid() throws Exception {
System.out.println("Testing critical select critical w/o lockid");
createAndInsertIntoTable();
@@ -872,8 +928,8 @@ public class TstRestMusicDataAPI {
consistencyInfo.put("type", "atomic");
jsonSelect.setConsistencyInfo(consistencyInfo);
Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableName, info);
+ Response response = data.selectWithCritical("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ null,keyspaceName, tableName, info);
HashMap<String, HashMap<String, Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
HashMap<String, Object> result = map.get("result");
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
@@ -891,8 +947,8 @@ public class TstRestMusicDataAPI {
Map<String, String> consistencyInfo = new HashMap<>();
consistencyInfo.put("type", "atomic");
jsonSelect.setConsistencyInfo(consistencyInfo);
- Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, null, info);
+ Response response = data.selectWithCritical("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, wrongAuthorization,null, keyspaceName, null, info);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(400, response.getStatus());
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
index 1e9ed79a..ec7659a6 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
@@ -371,8 +371,7 @@ public class TstRestMusicLockAPI {
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(200, response.getStatus());
Map<String, Object> respMap = (Map<String, Object>) response.getEntity();
- //TODO: this should be lockRef
- assertEquals("1", ((Map<String, String>) respMap.get("lock")).get("lock-holder"));
+ assertEquals(lockRef, ((Map<String, List>) respMap.get("lock")).get("lock-holder").get(0));
}
@Test
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
index 0014093d..b7dfa075 100644
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
@@ -44,11 +44,4 @@ public class JsonLeasedLockTest {
assertEquals(lease,jl.getLeasePeriod());
}
- @Test
- public void testGetNotifyUrl() {
- String url = "http://somewhere.com";
- jl.setNotifyUrl(url);
- assertEquals(url,jl.getNotifyUrl());
- }
-
}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/MusicDigestTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/MusicDigestTest.java
deleted file mode 100644
index cf8a9c63..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/MusicDigestTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 IBM.
- * ===================================================================
- * 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
- *
- * 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=============================================
- * ====================================================================
- */
-
-package org.onap.music.unittests.jsonobjects;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.main.MusicDigest;
-
-public class MusicDigestTest {
-
- private MusicDigest musicDigest;
-
- @Before
- public void setUp()
- {
- musicDigest= new MusicDigest("evPutStatus", "vectorTs");
- }
-
- @Test
- public void testGetSetEvPutStatus()
- {
- musicDigest.setEvPutStatus("evPutStatus");
- assertEquals("evPutStatus", musicDigest.getEvPutStatus());
- }
-
- @Test
- public void testGetSetVectorTs()
- {
- musicDigest.setVectorTs("vectorTs");
- assertEquals("vectorTs", musicDigest.getVectorTs());
- }
-
- @Test
- public void testToString()
- {
- assertEquals("vectorTs|evPutStatus", musicDigest.toString());
- }
-}