aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java2
-rw-r--r--src/test/java/org/onap/music/unittests/JsonLockResponseTest.java186
-rw-r--r--src/test/java/org/onap/music/unittests/JsonResponseTest.java83
-rw-r--r--src/test/java/org/onap/music/unittests/MusicUtilTest.java217
-rw-r--r--src/test/java/org/onap/music/unittests/ResultTypeTest.java43
-rw-r--r--src/test/java/org/onap/music/unittests/ReturnTypeTest.java83
6 files changed, 613 insertions, 1 deletions
diff --git a/src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java b/src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java
index a9b40aec..c267d254 100644
--- a/src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java
+++ b/src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java
@@ -37,7 +37,7 @@ import com.sun.jersey.api.json.JSONConfiguration;
public class MicroBenchMarks {
final String keyspaceName = "shankarks";
- final String musicurl = "http://" + MusicUtil.musicRestIp + ":8080/MUSIC/rest/formal";
+ final String musicurl = "http://" + MusicUtil.getMusicRestIp() + ":8080/MUSIC/rest/formal";
final String userForGets = "shankarUserForGets";
public MicroBenchMarks() {
diff --git a/src/test/java/org/onap/music/unittests/JsonLockResponseTest.java b/src/test/java/org/onap/music/unittests/JsonLockResponseTest.java
new file mode 100644
index 00000000..cd5773dc
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/JsonLockResponseTest.java
@@ -0,0 +1,186 @@
+/*
+ * ============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
+ *
+ * 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;
+
+import static org.junit.Assert.*;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.lockingservice.MusicLockState;
+import org.onap.music.lockingservice.MusicLockState.LockStatus;
+import org.onap.music.main.ResultType;
+import org.onap.music.response.jsonobjects.JsonLockResponse;
+
+public class JsonLockResponseTest {
+
+ JsonLockResponse response = new JsonLockResponse(ResultType.SUCCESS);
+
+ @Test
+ public void error1() {
+ Boolean result = false;
+ response.setError("");
+ result = response.getError().equals("error1");
+ assertFalse("Success",result);
+ }
+
+ @Test
+ public void error() {
+ Boolean result = false;
+ response.setError("error1");
+ result = response.getError().equals("error1");
+ assertTrue("Success",result);
+ }
+
+ @Test
+ public void lock1() {
+ Boolean result = false;
+ response.setLock("");
+ result = response.getLock().equals("lock1");
+ assertFalse("Success",result);
+ }
+
+ @Test
+ public void lock() {
+ Boolean result = false;
+ response.setLock("lock1");
+ result = response.getLock().equals("lock1");
+ assertTrue("Success",result);
+ }
+
+ @Test
+ public void status1() {
+ Boolean result = false;
+ response.setStatus(null);
+ result = response.getStatus() == ResultType.SUCCESS;
+ assertFalse("Success",result);
+ }
+
+ @Test
+ public void status() {
+ Boolean result = false;
+ response.setStatus(ResultType.SUCCESS);
+ result = response.getStatus() == ResultType.SUCCESS;
+ assertTrue("Success",result);
+ }
+
+
+
+ @Test
+ public void lockHolder1() {
+ Boolean result = false;
+ response.setLockHolder("");
+ result = response.getLockHolder().equals("LockHolder");
+ assertFalse("Success",result);
+ }
+
+ @Test
+ public void lockHolder() {
+ Boolean result = false;
+ response.setLockHolder("LockHolder");
+ result = response.getLockHolder().equals("LockHolder");
+ assertTrue("Success",result);
+ }
+
+ @Test
+ public void lockLease1() {
+ Boolean result = false;
+ response.setLockLease("");
+ result = response.getLockLease().equals("lockLease");
+ assertFalse("Success",result);
+ }
+
+ @Test
+ public void lockLease() {
+ Boolean result = false;
+ response.setLockLease("lockLease");
+ result = response.getLockLease().equals("lockLease");
+ assertTrue("Success",result);
+ }
+
+ @Test
+ public void lockStatus1() {
+ Boolean result = false;
+ response.setLockStatus(null);
+ result = response.getLockStatus() == MusicLockState.LockStatus.LOCKED;
+ assertFalse("Success",result);
+ }
+
+ @Test
+ public void lockStatus() {
+ Boolean result = false;
+ response.setLockStatus(MusicLockState.LockStatus.LOCKED);
+ result = response.getLockStatus() == MusicLockState.LockStatus.LOCKED;
+ assertTrue("Success",result);
+ }
+
+ @Test
+ public void message1() {
+ Boolean result = false;
+ response.setMessage("");
+ result = response.getMessage().equals("message");
+ assertFalse("Success",result);
+ }
+
+ @Test
+ public void message() {
+ Boolean result = false;
+ response.setMessage("message");
+ result = response.getMessage().equals("message");
+ assertTrue("Success",result);
+ }
+
+ @Test
+ public void map() {
+ Boolean result = false;
+ response.setMessage("message");
+ response.setLockStatus(MusicLockState.LockStatus.LOCKED);
+ response.setLockHolder("LockHolder");
+ response.setLockLease("lockLease");
+ response.setStatus(ResultType.SUCCESS);
+ response.setLock("lock1");
+ response.setError("error1");
+ Map<String,Object> myMap = response.toMap();
+ result = myMap.containsKey("status");
+ System.out.println(response.toString());
+ assertTrue("Success",result);
+ }
+
+ @Test
+ public void map1() {
+ Boolean result = false;
+ response.setMessage(null);
+ response.setLockStatus(null);
+ response.setLockHolder(null);
+ response.setLockLease(null);
+ response.setStatus(null);
+ response.setLock(null);
+ response.setError(null);
+ Map<String,Object> myMap = response.toMap();
+ result = myMap.containsKey("error");
+ System.out.println(result);
+ assertFalse("Success",result);
+ }
+
+
+
+
+}
diff --git a/src/test/java/org/onap/music/unittests/JsonResponseTest.java b/src/test/java/org/onap/music/unittests/JsonResponseTest.java
new file mode 100644
index 00000000..55e5965e
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/JsonResponseTest.java
@@ -0,0 +1,83 @@
+/*
+ * ============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
+ *
+ * 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;
+
+import static org.junit.Assert.*;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.music.response.jsonobjects.JsonResponse;
+
+public class JsonResponseTest {
+
+ JsonResponse result = null;
+
+ @Test
+ public void testJsonResponseBooleanStringString() {
+ result = new JsonResponse(true,"error","version");
+ assertEquals("error",result.getError());
+ }
+
+ @Test
+ public void testJsonResponse() {
+ result = new JsonResponse();
+ assertFalse(result.getStatus());
+ }
+
+ @Test
+ public void testStatus() {
+ result = new JsonResponse();
+ result.setStatus(true);
+ assertTrue(result.getStatus());
+ result = new JsonResponse(false,"error","version");
+ assertFalse(result.getStatus());
+ }
+
+ @Test
+ public void testError() {
+ result = new JsonResponse();
+ result.setError("error");
+ assertTrue(result.getError().equals("error"));
+ result.setError("");
+ assertFalse(result.getError().equals("error"));
+ }
+
+ @Test
+ public void testVersion() {
+ result = new JsonResponse();
+ result.setVersion("version");
+ assertTrue(result.getVersion().equals("version"));
+ result.setVersion("");
+ assertFalse(result.getVersion().equals("version"));
+ }
+
+ @Test
+ public void testToMap() {
+ result = new JsonResponse(true,"error","version");
+ Map<String,Object> myMap = result.toMap();
+ assertTrue(myMap.containsKey("status"));
+ result = new JsonResponse(false,"","");
+ myMap = result.toMap();
+ assertTrue(myMap.containsKey("status"));
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
new file mode 100644
index 00000000..35ec3791
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
@@ -0,0 +1,217 @@
+/*
+ * ============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
+ *
+ * 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;
+
+import static org.junit.Assert.*;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.cassandra.exceptions.PreparedQueryNotFoundException;
+import org.junit.Test;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.main.MusicUtil;
+import com.datastax.driver.core.DataType;
+import javassist.CodeConverter.ArrayAccessReplacementMethodNames;
+
+public class MusicUtilTest {
+
+ @Test
+ public void testGetCassName() {
+ MusicUtil.setCassName("Cassandra");
+ assertTrue(MusicUtil.getCassName().equals("Cassandra"));
+ }
+
+ @Test
+ public void testGetCassPwd() {
+ MusicUtil.setCassPwd("Cassandra");
+ assertTrue(MusicUtil.getCassPwd().equals("Cassandra"));
+ }
+
+ @Test
+ public void testGetAafEndpointUrl() {
+ MusicUtil.setAafEndpointUrl("url");
+ assertEquals(MusicUtil.getAafEndpointUrl(),"url");
+ }
+
+ @Test
+ public void testGetMyId() {
+ MusicUtil.setMyId(1);
+ assertEquals(MusicUtil.getMyId(),1);
+ }
+
+ @Test
+ public void testGetAllIds() {
+ List<String> ids = new ArrayList<String>();
+ ids.add("1");
+ ids.add("2");
+ ids.add("3");
+ MusicUtil.setAllIds(ids);
+ assertEquals(MusicUtil.getAllIds().get(0),"1");
+ }
+
+ @Test
+ public void testGetPublicIp() {
+ MusicUtil.setPublicIp("10.0.0.1");
+ assertEquals(MusicUtil.getPublicIp(),"10.0.0.1");
+ }
+
+ @Test
+ public void testGetAllPublicIps() {
+ List<String> ips = new ArrayList<String>();
+ ips.add("10.0.0.1");
+ ips.add("10.0.0.2");
+ ips.add("10.0.0.3");
+ MusicUtil.setAllPublicIps(ips);
+ assertEquals(MusicUtil.getAllPublicIps().get(1),"10.0.0.2");
+ }
+
+ @Test
+ public void testGetPropkeys() {
+ assertEquals(MusicUtil.getPropkeys()[2],"music.ip");
+ }
+
+ @Test
+ public void testGetMusicRestIp() {
+ MusicUtil.setMusicRestIp("localhost");
+ assertEquals(MusicUtil.getMusicRestIp(),"localhost");
+ }
+
+ @Test
+ public void testGetMusicPropertiesFilePath() {
+ MusicUtil.setMusicPropertiesFilePath("filepath");
+ assertEquals(MusicUtil.getMusicPropertiesFilePath(),"filepath");
+ }
+
+ @Test
+ public void testGetDefaultLockLeasePeriod() {
+ MusicUtil.setDefaultLockLeasePeriod(5000);
+ assertEquals(MusicUtil.getDefaultLockLeasePeriod(),5000);
+ }
+
+ @Test
+ public void testIsDebug() {
+ MusicUtil.setDebug(true);
+ assertTrue(MusicUtil.isDebug());
+ }
+
+ @Test
+ public void testGetVersion() {
+ MusicUtil.setVersion("1.0.0");
+ 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 testGetMyCassaHost() {
+ MusicUtil.setMyCassaHost("10.0.0.2");
+ assertEquals(MusicUtil.getMyCassaHost(),"10.0.0.2");
+ }
+
+ @Test
+ public void testGetDefaultMusicIp() {
+ MusicUtil.setDefaultMusicIp("10.0.0.2");
+ assertEquals(MusicUtil.getDefaultMusicIp(),"10.0.0.2");
+ }
+
+// @Test
+// public void testGetTestType() {
+// fail("Not yet implemented"); // TODO
+// }
+
+ @Test
+ public void testIsValidQueryObject() {
+ PreparedQueryObject myQueryObject = new PreparedQueryObject();
+ myQueryObject.appendQueryString("select * from apple where type = ?");
+ myQueryObject.addValue("macintosh");
+ assertTrue(MusicUtil.isValidQueryObject(true,myQueryObject));
+
+ myQueryObject.appendQueryString("select * from apple");
+ assertTrue(MusicUtil.isValidQueryObject(false,myQueryObject));
+
+ myQueryObject.appendQueryString("select * from apple where type = ?");
+ assertFalse(MusicUtil.isValidQueryObject(true,myQueryObject));
+
+ myQueryObject = new PreparedQueryObject();
+ myQueryObject.appendQueryString("");
+ System.out.println("#######" + myQueryObject.getQuery().isEmpty());
+ assertFalse(MusicUtil.isValidQueryObject(false,myQueryObject));
+
+
+ }
+
+ @Test
+ public void testConvertToCQLDataType() {
+ Map<String,Object> myMap = new HashMap<String,Object>();
+ myMap.put("name","tom");
+ assertEquals(MusicUtil.convertToCQLDataType(DataType.varchar(),"Happy People"),"'Happy People'");
+ assertEquals(MusicUtil.convertToCQLDataType(DataType.uuid(),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")),"29dc2afa-c2c0-47ae-afae-e72a645308ab");
+ assertEquals(MusicUtil.convertToCQLDataType(DataType.blob(),"Hi"),"Hi");
+ assertEquals(MusicUtil.convertToCQLDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),"{'name':'tom'}");
+ }
+
+ @Test
+ public void testConvertToActualDataType() {
+ assertEquals(MusicUtil.convertToActualDataType(DataType.varchar(),"Happy People"),"Happy People");
+ assertEquals(MusicUtil.convertToActualDataType(DataType.uuid(),"29dc2afa-c2c0-47ae-afae-e72a645308ab"),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab"));
+ assertEquals(MusicUtil.convertToActualDataType(DataType.varint(),"1234"),BigInteger.valueOf(Long.parseLong("1234")));
+ assertEquals(MusicUtil.convertToActualDataType(DataType.bigint(),"123"),Long.parseLong("123"));
+ assertEquals(MusicUtil.convertToActualDataType(DataType.cint(),"123"),Integer.parseInt("123"));
+ 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"));
+ Map<String,Object> myMap = new HashMap<String,Object>();
+ myMap.put("name","tom");
+ assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),myMap);
+
+ }
+
+ @Test
+ public void testJsonMaptoSqlString() {
+ Map<String,Object> myMap = new HashMap<>();
+ myMap.put("name","tom");
+ myMap.put("value",5);
+ String result = MusicUtil.jsonMaptoSqlString(myMap,",");
+ assertTrue(result.contains("name"));
+ assertTrue(result.contains("value"));
+ }
+
+ @Test
+ public void testSetErrorResponse() {
+ Map<String,Object> myMap = new HashMap<>();
+ myMap.put("name","tom");
+ Map<String,HashMap<String,Object>> result = MusicUtil.setErrorResponse(new MusicServiceException("This is the error"));
+ Map<String,Object> testMap = (Map<String,Object>) result.get("result");
+ Map<String,Object> error = (Map<String,Object>) testMap.get("error");
+ assertTrue(error.containsKey("error-description"));
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/ResultTypeTest.java b/src/test/java/org/onap/music/unittests/ResultTypeTest.java
new file mode 100644
index 00000000..012629e0
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/ResultTypeTest.java
@@ -0,0 +1,43 @@
+/*
+ * ============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
+ *
+ * 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;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.onap.music.main.ResultType;
+
+public class ResultTypeTest {
+
+ @Test
+ public void testResultType() {
+ assertEquals("SUCCESS",ResultType.SUCCESS.name());
+ assertEquals("FAILURE",ResultType.FAILURE.name());
+ }
+
+ @Test
+ public void testGetResult() {
+ assertEquals("Success",ResultType.SUCCESS.getResult());
+ assertEquals("Failure",ResultType.FAILURE.getResult());
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/ReturnTypeTest.java b/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
new file mode 100644
index 00000000..c22b0155
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
@@ -0,0 +1,83 @@
+/*
+ * ============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
+ *
+ * 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;
+
+import static org.junit.Assert.*;
+import java.util.Map;
+import org.apache.tools.ant.filters.TokenFilter.ContainsString;
+import org.hamcrest.core.AnyOf;
+import org.junit.Test;
+import org.onap.music.main.ResultType;
+import org.onap.music.main.ReturnType;
+
+public class ReturnTypeTest {
+
+ @Test
+ public void testReturnType() {
+ ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
+ assertEquals(result.getMessage(),"message");
+ assertEquals(result.getResult(),ResultType.SUCCESS);
+ }
+
+ @Test
+ public void testTimingInfo() {
+ ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
+ result.setTimingInfo("123");
+ assertEquals(result.getTimingInfo(),"123");
+ }
+
+ @Test
+ public void testGetResult() {
+ ReturnType result = new ReturnType(ResultType.FAILURE,"message");
+ assertEquals(result.getResult(),ResultType.FAILURE);
+ }
+
+ @Test
+ public void testGetMessage() {
+ ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
+ result.setMessage("NewMessage");
+ assertEquals(result.getMessage(),"NewMessage");
+ }
+
+ @Test
+ public void testToJson() {
+ ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
+ String myJson = result.toJson();
+ assertTrue(myJson.contains("message"));
+ }
+
+ @Test
+ public void testToString() {
+ ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
+ String test = result.toString();
+ assertTrue(test.contains("message"));
+ }
+
+ @Test
+ public void testToMap() {
+ ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
+ Map<String, Object> myMap = result.toMap();
+ assertTrue(myMap.containsKey("message"));
+ }
+
+}