aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/LICENSE.txt24
-rw-r--r--src/test/java/org/onap/music/eelf/logging/format/AppMessagesTest.java65
-rw-r--r--src/test/java/org/onap/music/exceptions/MusicExceptionMapperTest.java61
-rw-r--r--src/test/java/org/onap/music/exceptions/MusicLockingExceptionTest.java104
-rw-r--r--src/test/java/org/onap/music/exceptions/MusicPolicyVoilationExceptionTest.java106
-rw-r--r--src/test/java/org/onap/music/exceptions/MusicQueryExceptionTest.java118
-rw-r--r--src/test/java/org/onap/music/exceptions/MusicServiceExceptionTest.java145
-rw-r--r--src/test/java/org/onap/music/unittests/CassandraCQL.java243
-rw-r--r--src/test/java/org/onap/music/unittests/JsonResponseTest.java128
-rw-r--r--src/test/java/org/onap/music/unittests/MusicDataStoreTest.java171
-rw-r--r--src/test/java/org/onap/music/unittests/MusicUtilTest.java225
-rw-r--r--src/test/java/org/onap/music/unittests/ResultTypeTest.java43
-rw-r--r--src/test/java/org/onap/music/unittests/ReturnTypeTest.java84
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java1032
-rw-r--r--src/test/java/org/onap/music/unittests/TestsUsingCassandra.java113
-rw-r--r--src/test/java/org/onap/music/unittests/TstCachingUtil.java167
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java449
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java376
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java1261
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java491
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java54
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java44
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java86
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java86
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java73
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java54
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java79
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java56
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java100
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java111
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/MusicDigestTest.java60
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java48
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java56
-rw-r--r--src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker1
-rw-r--r--src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider1
35 files changed, 0 insertions, 6315 deletions
diff --git a/src/test/java/LICENSE.txt b/src/test/java/LICENSE.txt
deleted file mode 100644
index cc6cdea5..00000000
--- a/src/test/java/LICENSE.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-
-The following license applies to all files in this and sub-directories. Licenses
-are included in individual source files where appropriate, and if it differs
-from this text, it supersedes this. Any file that does not have license text
-defaults to being covered by this text; not all files support the addition of
-licenses.
-#
-# -------------------------------------------------------------------------
-# 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.
-#
-# -------------------------------------------------------------------------
-# \ No newline at end of file
diff --git a/src/test/java/org/onap/music/eelf/logging/format/AppMessagesTest.java b/src/test/java/org/onap/music/eelf/logging/format/AppMessagesTest.java
deleted file mode 100644
index cba9c7c2..00000000
--- a/src/test/java/org/onap/music/eelf/logging/format/AppMessagesTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 IBM 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.eelf.logging.format;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-
-public class AppMessagesTest {
-
- private AppMessages messages;
-
- @Before
- public void setUp() {
- messages= AppMessages.ALREADYEXIST;
- }
-
- @Test
- public void testDetails()
- {
- messages.setDetails("details");
- assertEquals("details", messages.getDetails());
- }
-
- @Test
- public void testResolution()
- {
- messages.setResolution("Resolution");
- assertEquals("Resolution", messages.getResolution());
- }
-
- @Test
- public void testErrorCode()
- {
- messages.setErrorCode("ErrorCode");
- assertEquals("ErrorCode", messages.getErrorCode());
- }
-
- @Test
- public void testErrorDescription()
- {
- messages.setErrorDescription("ErrorDescription");
- assertEquals("ErrorDescription", messages.getErrorDescription());
- }
-}
diff --git a/src/test/java/org/onap/music/exceptions/MusicExceptionMapperTest.java b/src/test/java/org/onap/music/exceptions/MusicExceptionMapperTest.java
deleted file mode 100644
index 58135551..00000000
--- a/src/test/java/org/onap/music/exceptions/MusicExceptionMapperTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 IBM 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.exceptions;
-
-import org.codehaus.jackson.map.exc.UnrecognizedPropertyException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import javax.ws.rs.core.Response;
-import java.io.EOFException;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-public class MusicExceptionMapperTest {
-
- @Test
- public void testToResponse() {
- MusicExceptionMapper musicExceptionMapper = new MusicExceptionMapper();
- UnrecognizedPropertyException unrecognizedPropertyException = mock(UnrecognizedPropertyException.class);
- Response response = musicExceptionMapper.toResponse(unrecognizedPropertyException);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertTrue(((Map)response.getEntity()).get("error").toString().startsWith("Unknown field :"));
-
- EOFException eofException = mock(EOFException.class);
- response = musicExceptionMapper.toResponse(eofException);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertTrue(((Map)response.getEntity()).get("error").toString().equals("Request body cannot be empty".trim()));
-
- IllegalArgumentException illegalArgumentException = mock(IllegalArgumentException.class);
- Mockito.when(illegalArgumentException.getMessage()).thenReturn("ERROR MSG");
- response = musicExceptionMapper.toResponse(illegalArgumentException);
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertTrue(((Map)response.getEntity()).get("error").toString().equals("ERROR MSG".trim()));
- }
-} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/exceptions/MusicLockingExceptionTest.java b/src/test/java/org/onap/music/exceptions/MusicLockingExceptionTest.java
deleted file mode 100644
index 583a9fd4..00000000
--- a/src/test/java/org/onap/music/exceptions/MusicLockingExceptionTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 IBM 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.exceptions;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class MusicLockingExceptionTest {
-
- @Test
- public void TestException1() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicLockingException();
- }
- } catch (MusicLockingException mle) {
- assertEquals("org.onap.music.exceptions.MusicLockingException", mle.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException2() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicLockingException("MusicLockingException Exception occured..");
- }
- } catch (MusicLockingException mle) {
- assertEquals(mle.getMessage(), "MusicLockingException Exception occured..");
- }
-
- }
-
- @Test
- public void TestException3() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicLockingException(new Throwable());
- }
- } catch (MusicLockingException mle) {
- assertEquals("org.onap.music.exceptions.MusicLockingException", mle.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException4() {
- String message = "Exception occured";
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicLockingException(message, new Throwable());
- }
- } catch (MusicLockingException mle) {
- assertEquals("org.onap.music.exceptions.MusicLockingException", mle.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException5() {
- String message = "Exception occured";
- boolean enableSuppression = true;
- boolean writableStackTrace = false;
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicLockingException(message, new Throwable(), enableSuppression, writableStackTrace);
- }
- } catch (MusicLockingException mle) {
- assertEquals("org.onap.music.exceptions.MusicLockingException", mle.getClass().getName());
- }
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/exceptions/MusicPolicyVoilationExceptionTest.java b/src/test/java/org/onap/music/exceptions/MusicPolicyVoilationExceptionTest.java
deleted file mode 100644
index 22e2d728..00000000
--- a/src/test/java/org/onap/music/exceptions/MusicPolicyVoilationExceptionTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 IBM 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.exceptions;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class MusicPolicyVoilationExceptionTest {
-
- @Test
- public void TestException1() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicPolicyVoilationException();
- }
- } catch (MusicPolicyVoilationException mve) {
- assertEquals("org.onap.music.exceptions.MusicPolicyVoilationException", mve.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException2() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicPolicyVoilationException("MusicPolicyVoilationException Exception occured..");
- }
- } catch (MusicPolicyVoilationException mve) {
- assertEquals(mve.getMessage(), "MusicPolicyVoilationException Exception occured..");
- }
-
- }
-
- @Test
- public void TestException3() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicPolicyVoilationException(new Throwable());
- }
- } catch (MusicPolicyVoilationException mve) {
- assertEquals("org.onap.music.exceptions.MusicPolicyVoilationException", mve.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException4() {
- String message = "Exception occured";
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicPolicyVoilationException(message, new Throwable());
- }
- } catch (MusicPolicyVoilationException mve) {
- assertEquals("org.onap.music.exceptions.MusicPolicyVoilationException", mve.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException5() {
- String message = "Exception occured";
- boolean enableSuppression = true;
- boolean writableStackTrace = false;
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicPolicyVoilationException(message, new Throwable(), enableSuppression,
- writableStackTrace);
- }
- } catch (MusicPolicyVoilationException mve) {
- assertEquals("org.onap.music.exceptions.MusicPolicyVoilationException", mve.getClass().getName());
- }
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/exceptions/MusicQueryExceptionTest.java b/src/test/java/org/onap/music/exceptions/MusicQueryExceptionTest.java
deleted file mode 100644
index 9096506a..00000000
--- a/src/test/java/org/onap/music/exceptions/MusicQueryExceptionTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 IBM 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.exceptions;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class MusicQueryExceptionTest {
-
- @Test
- public void TestException1() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicQueryException();
- }
- } catch (MusicQueryException mqe) {
- assertEquals("org.onap.music.exceptions.MusicQueryException", mqe.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException2() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicQueryException("MusicQueryException Exception occured..");
- }
- } catch (MusicQueryException mqe) {
- assertEquals(mqe.getMessage(), "MusicQueryException Exception occured..");
- }
-
- }
-
- @Test
- public void TestException3() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicQueryException("MusicQueryException Exception occured..", 001);
- }
- } catch (MusicQueryException mqe) {
- assertEquals(mqe.getMessage(), "MusicQueryException Exception occured..");
- }
-
- }
-
- @Test
- public void TestException4() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicQueryException(new Throwable());
- }
- } catch (MusicQueryException mqe) {
- assertEquals("org.onap.music.exceptions.MusicQueryException", mqe.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException5() {
- String message = "Exception occured";
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicQueryException(message, new Throwable());
- }
- } catch (MusicQueryException mqe) {
- assertEquals("org.onap.music.exceptions.MusicQueryException", mqe.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException6() {
- String message = "Exception occured";
- boolean enableSuppression = true;
- boolean writableStackTrace = false;
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicQueryException(message, new Throwable(), enableSuppression, writableStackTrace);
- }
- } catch (MusicQueryException mqe) {
- assertEquals("org.onap.music.exceptions.MusicQueryException", mqe.getClass().getName());
- }
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/exceptions/MusicServiceExceptionTest.java b/src/test/java/org/onap/music/exceptions/MusicServiceExceptionTest.java
deleted file mode 100644
index bf056b61..00000000
--- a/src/test/java/org/onap/music/exceptions/MusicServiceExceptionTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 IBM 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.exceptions;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class MusicServiceExceptionTest {
- @Test
- public void TestException1() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicServiceException();
- }
- } catch (MusicServiceException mse) {
- assertEquals("org.onap.music.exceptions.MusicServiceException", mse.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException2() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicServiceException("MusicServiceException Exception occured..");
- }
- } catch (MusicServiceException mse) {
- assertEquals(mse.getMessage(), "MusicServiceException Exception occured..");
- }
-
- }
-
- @Test
- public void TestException3() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicServiceException("MusicServiceException Exception occured..", 001);
- }
- } catch (MusicServiceException mse) {
- assertEquals(mse.getMessage(), "MusicServiceException Exception occured..");
- }
-
- }
-
- @Test
- public void TestException4() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicServiceException("MusicServiceException Exception occured..", 001, "errorMsg");
- }
- } catch (MusicServiceException mse) {
- assertEquals(mse.getMessage(), "MusicServiceException Exception occured..");
- }
-
- }
-
- @Test
- public void TestException5() {
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicServiceException(new Throwable());
- }
- } catch (MusicServiceException mse) {
- assertEquals("org.onap.music.exceptions.MusicServiceException", mse.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException6() {
- String message = "Exception occured";
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicServiceException(message, new Throwable());
- }
- } catch (MusicServiceException mse) {
- assertEquals("org.onap.music.exceptions.MusicServiceException", mse.getClass().getName());
- }
-
- }
-
- @Test
- public void TestException7() {
- String message = "Exception occured";
- boolean enableSuppression = true;
- boolean writableStackTrace = false;
- String s1 = "Value1";
- String s2 = "value2";
- try {
- if (!s1.equalsIgnoreCase(s2)) {
- throw new MusicServiceException(message, new Throwable(), enableSuppression, writableStackTrace);
- }
- } catch (MusicServiceException mse) {
- assertEquals("org.onap.music.exceptions.MusicServiceException", mse.getClass().getName());
- }
-
- }
-
- @Test
- public void testErrorCode() {
- MusicServiceException musicServiceException = new MusicServiceException();
- musicServiceException.setErrorCode(0001);
- assertEquals(0001, musicServiceException.getErrorCode());
- }
-
- @Test
- public void testSetErrorMsg() {
- MusicServiceException musicServiceException = new MusicServiceException();
- musicServiceException.setErrorMessage("errorMsg");
- assertEquals("errorMsg", musicServiceException.getErrorMessage());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java
deleted file mode 100644
index 32072145..00000000
--- a/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * ============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;
-
-/**
- * @author srupane
- *
- */
-
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-//import org.apache.thrift.transport.TTransportException;
-import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-
-public class CassandraCQL {
- public static final String createAdminKeyspace = "CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , 'replication_factor': 1} AND DURABLE_WRITES = true";
-
- public static final String createAdminTable = "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
- + " application_name text, is_api boolean,"
- + " password text, username text,"
- + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");";
-
- public static final String createKeySpace =
- "CREATE KEYSPACE IF NOT EXISTS testcassa WITH replication = "
- +"{'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;";
-
- public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testcassa";
-
- public static final String createTableEmployees =
- "CREATE TABLE IF NOT EXISTS testcassa.employees "
- + "(vector_ts text,empid uuid,empname text,empsalary varint,address Map<text,text>,PRIMARY KEY (empname)) "
- + "WITH comment='Financial Info of employees' "
- + "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} "
- + "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};";
-
- public static final String insertIntoTablePrepared1 =
- "INSERT INTO testcassa.employees (vector_ts,empid,empname,empsalary) VALUES (?,?,?,?); ";
-
- public static final String insertIntoTablePrepared2 =
- "INSERT INTO testcassa.employees (vector_ts,empid,empname,empsalary,address) VALUES (?,?,?,?,?);";
-
- public static final String selectALL = "SELECT * FROM testcassa.employees;";
-
- public static final String selectSpecific =
- "SELECT * FROM testcassa.employees WHERE empname= ?;";
-
- public static final String updatePreparedQuery =
- "UPDATE testcassa.employees SET vector_ts=?,address= ? WHERE empname= ?;";
-
- public static final String deleteFromTable = " ";
-
- public static final String deleteFromTablePrepared = " ";
-
- // Set Values for Prepared Query
-
- public static List<Object> setPreparedInsertValues1() {
-
- List<Object> preppreparedInsertValues1 = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID empId = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40cd6");
- BigInteger empSalary = BigInteger.valueOf(23443);
- String empName = "Mr Test one";
- preppreparedInsertValues1.add(vectorTs);
- preppreparedInsertValues1.add(empId);
- preppreparedInsertValues1.add(empName);
- preppreparedInsertValues1.add(empSalary);
- return preppreparedInsertValues1;
- }
-
- public static List<Object> setPreparedInsertValues2() {
-
- List<Object> preparedInsertValues2 = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID empId = UUID.fromString("abc434cc-d657-4e90-b4e5-df4223d40cd6");
- BigInteger empSalary = BigInteger.valueOf(45655);
- String empName = "Mr Test two";
- Map<String, String> address = new HashMap<>();
- preparedInsertValues2.add(vectorTs);
- preparedInsertValues2.add(empId);
- preparedInsertValues2.add(empName);
- preparedInsertValues2.add(empSalary);
- address.put("Street", "1 some way");
- address.put("City", "Some town");
- preparedInsertValues2.add(address);
- return preparedInsertValues2;
- }
-
- public static List<Object> setPreparedUpdateValues() {
-
- List<Object> preparedUpdateValues = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- Map<String, String> address = new HashMap<>();
- preparedUpdateValues.add(vectorTs);
- String empName = "Mr Test one";
- address.put("Street", "101 Some Way");
- address.put("City", "New York");
- preparedUpdateValues.add(address);
- preparedUpdateValues.add(empName);
- return preparedUpdateValues;
- }
-
- // Generate Different Prepared Query Objects
- /**
- * Query Object for Get.
- *
- * @return
- */
- public static PreparedQueryObject setPreparedGetQuery() {
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
- String empName1 = "Mr Test one";
- queryObject.appendQueryString(selectSpecific);
- queryObject.addValue(empName1);
- return queryObject;
- }
-
- /**
- * Query Object 1 for Insert.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedInsertQueryObject1() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(insertIntoTablePrepared1);
- List<Object> values = setPreparedInsertValues1();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- /**
- * Query Object 2 for Insert.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedInsertQueryObject2() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(insertIntoTablePrepared2);
- List<Object> values = setPreparedInsertValues2();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- /**
- * Query Object for Update.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedUpdateQueryObject() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(updatePreparedQuery);
- List<Object> values = setPreparedUpdateValues();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- private static ArrayList<String> getAllPossibleLocalIps() {
- ArrayList<String> allPossibleIps = new ArrayList<String>();
- try {
- Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
- while (en.hasMoreElements()) {
- NetworkInterface ni = (NetworkInterface) en.nextElement();
- Enumeration<InetAddress> ee = ni.getInetAddresses();
- while (ee.hasMoreElements()) {
- InetAddress ia = (InetAddress) ee.nextElement();
- allPossibleIps.add(ia.getHostAddress());
- }
- }
- } catch (SocketException e) {
- System.out.println(e.getMessage());
- }
- return allPossibleIps;
- }
-
- public static MusicDataStore connectToEmbeddedCassandra() throws Exception {
- System.setProperty("log4j.configuration", "log4j.properties");
-
- String address = "localhost";
-
- EmbeddedCassandraServerHelper.startEmbeddedCassandra();
- Cluster cluster = new Cluster.Builder().withoutJMXReporting().withoutMetrics().addContactPoint(address).withPort(9142).build();
- cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(5000);
- Session session = cluster.connect();
-
- return new MusicDataStore(cluster, session);
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/JsonResponseTest.java b/src/test/java/org/onap/music/unittests/JsonResponseTest.java
deleted file mode 100644
index 88fddf4e..00000000
--- a/src/test/java/org/onap/music/unittests/JsonResponseTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * Modifications Copyright (c) 2018-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;
-
-import static org.junit.Assert.*;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
-import org.onap.music.main.ResultType;
-import org.onap.music.response.jsonobjects.JsonResponse;
-
-public class JsonResponseTest {
-
- JsonResponse result = null;
-
- @Test
- public void testJsonResponseBooleanStringString() {
- result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("version");
- assertEquals("error",result.getError());
- }
-
- @Test
- public void testStatus() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setStatus(ResultType.SUCCESS);
- assertEquals(ResultType.SUCCESS, result.getStatus());
- result = new JsonResponse(ResultType.FAILURE).setError("error").setMusicVersion("version");
- assertEquals(ResultType.FAILURE, result.getStatus());
- }
-
- @Test
- public void testError() {
- result = new JsonResponse(ResultType.FAILURE);
- result.setError("error");
- assertTrue(result.getError().equals("error"));
- result.setError("");
- assertFalse(result.getError().equals("error"));
- }
-
- @Test
- public void testVersion() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setMusicVersion("version");
- assertTrue(result.getMusicVersion().equals("version"));
- result.setMusicVersion("");
- assertFalse(result.getMusicVersion().equals("version"));
- }
-
- @Test
- public void testToMap() {
- result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("1.0");
- Map<String,Object> myMap = result.toMap();
- assertTrue(myMap.containsKey("status"));
- assertEquals(ResultType.SUCCESS, myMap.get("status"));
- assertEquals("error", myMap.get("error"));
- assertEquals("1.0", myMap.get("version"));
-
- result = new JsonResponse(ResultType.FAILURE);
- myMap = result.toMap();
- assertTrue(myMap.containsKey("status"));
- assertEquals(ResultType.FAILURE, myMap.get("status"));
- }
-
- @Test
- public void testMessage() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setMessage("message");
- assertEquals("message", result.getMessage());
-
- }
-
- @Test
- public void testDataResult() {
- result = new JsonResponse(ResultType.SUCCESS);
- Map<String, HashMap<String, Object>> dataResult= new HashMap<>();
- result.setDataResult(dataResult);
- assertEquals(dataResult, result.getDataResult());
-
- }
-
- @Test
- public void testLock() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setLock("lock");
- assertEquals("lock", result.getLock());
-
- }
-
- @Test
- public void testLockStatus() {
- result = new JsonResponse(ResultType.SUCCESS);
- LockStatus status = LockStatus.LOCKED;
- result.setLockStatus(status);
- assertEquals(status, result.getLockStatus());
-
- }
-
- @Test
- public void testToString() {
- result = new JsonResponse(ResultType.SUCCESS);
- assertTrue(result.toString() instanceof String);
-
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
deleted file mode 100644
index 6b7dc781..00000000
--- a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * ============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.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.mockito.Mock;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.onap.music.authentication.CachingUtil;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.TableMetadata;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-//@ActiveProfiles(profiles = "OrderRepositoryTest")
-@ContextConfiguration
-public class MusicDataStoreTest {
-
- static MusicDataStore dataStore;
- static PreparedQueryObject testObject;
-
- @BeforeClass
- public static void init()throws Exception {
- dataStore = CassandraCQL.connectToEmbeddedCassandra();
- //CachingUtil.resetStatementBank();
-
- }
-
- @AfterClass
- public static void close() throws MusicServiceException, MusicQueryException {
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.dropKeyspace);
- dataStore.executePut(testObject, "eventual");
- //dataStore.close();
- //CachingUtil.resetStatementBank();
- }
-
- @Test
- public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- boolean result = false;
- //CachingUtil.resetStatementBank();
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createKeySpace);
- result = dataStore.executePut(testObject, "eventual");;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
-
- }
-
- @Test
- public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject1();
- boolean result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
- }
-
- @Test
- public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- boolean result = dataStore.executePut(testObject, "Critical");
- assertEquals(true, result);
- }
-
- @Test
- public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedUpdateQueryObject();
- boolean result = false;
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
- }
-
- @Test
- public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.selectALL);
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeOneConsistencyGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 2) {
- result = true;
- }
- assertEquals(false, result);
- }
-
- @Test
- public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedGetQuery();
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeQuorumConsistencyGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 1) {
- result = true;
- }
- assertEquals(false, result);
- }
-
- @Test(expected = NullPointerException.class)
- public void Test7_exception() {
- PreparedQueryObject queryObject = null;
- try {
- dataStore.executePut(queryObject, "critical");
- } catch (MusicQueryException | MusicServiceException e) {
- System.out.println(e.getMessage());
- }
- }
-
- @Test
- public void Test8_columnDataType() {
- DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
- String datatype = data.toString();
- assertEquals("text",datatype);
- }
-
- @Test
- public void Test8_columnMetdaData() {
- TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");
- assertNotNull(data);
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
deleted file mode 100644
index 04149fc6..00000000
--- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * Modifications 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;
-
-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.authentication.CachingUtil;
-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],"debug");
- }
-
- @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() throws Exception {
- 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() throws Exception {
- 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() throws Exception {
- 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 test_generateUUID() {
- //this function shouldn't be in cachingUtil
- System.out.println("Testing getUUID");
- String uuid1 = MusicUtil.generateUUID();
- String uuid2 = MusicUtil.generateUUID();
- assertFalse(uuid1==uuid2);
- }
-
-
- @Test
- public void testIsValidConsistency(){
- assertTrue(MusicUtil.isValidConsistency("ALL"));
- assertFalse(MusicUtil.isValidConsistency("TEST"));
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/ResultTypeTest.java b/src/test/java/org/onap/music/unittests/ResultTypeTest.java
deleted file mode 100644
index 012629e0..00000000
--- a/src/test/java/org/onap/music/unittests/ResultTypeTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ============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
deleted file mode 100644
index 490020ac..00000000
--- a/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * ============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.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-
-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"));
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
deleted file mode 100644
index 4594ba2c..00000000
--- a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
+++ /dev/null
@@ -1,1032 +0,0 @@
-/*
- * ============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.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-//cjc import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.List;
-//cjc import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.mindrot.jbcrypt.BCrypt;
-//cjcimport org.mindrot.jbcrypt.BCrypt;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-//cjc import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-//import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-import org.onap.music.lockingservice.cassandra.CassaLockStore;
-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.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicQAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-//import com.datastax.driver.core.DataType;
-//import com.datastax.driver.core.ResultSet;
-//import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@RunWith(MockitoJUnitRunner.class)
-public class TestRestMusicQAPI {
-
-
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- RestMusicQAPI qData = new RestMusicQAPI();
- static PreparedQueryObject testObject;
-
- @Mock
- static HttpServletResponse http;
-
- @Mock
- UriInfo info;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- /*
- static String appName = "com.att.ecomp.portal.demeter.aid";//"TestApp";
- static String userId = "m00468@portal.ecomp.att.com";//"TestUser";
- static String password = "happy123";//"TestPassword";
- */
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
-
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String uuidS = "abc66ccc-d857-4e90-b1e5-df98a3d40ce6";
- static String keyspaceName = "testkscjc";
- static String tableName = "employees";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
- static String lockId = null;
- static String lockName = "testkscjc.employees.sample3";
- static String majorV="3";
- static String minorV="0";
- static String patchV="1";
- static String aid=null;
- static JsonKeySpace kspObject=null;
- static RestMusicDataAPI data = new RestMusicDataAPI();
- static Response resp;
-
- @BeforeClass
- public static void init() throws Exception {
- try {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
-
- // 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 ");
- e.printStackTrace();
- }
- // admin keyspace and table
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , "
- + "'replication_factor': 1} AND DURABLE_WRITES = true");
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
- + " application_name text, is_api boolean,"
- + " password text, username text,"
- + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");");
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6")));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(testObject);
- List<Row> rows = rs.all();
- 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<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Response response = data.createKeySpace(majorV, minorV, patchV, null, authorization, appName,
- jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus()+" keyspace="+keyspaceName);
-
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- System.out.println("After class");
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
- MusicCore.eventualPut(testObject);
- if (MusicDataStoreHandle.mDstoreHandle!=null) {}
- //MusicDataStoreHandle.mDstoreHandle.close();
- }
-
-
-/* @Test
- public void Test1_createQ_good() 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");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- jsonTable.setClusteringOrder("uuid ASC");
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableName);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }*/
-
- @Test
- public void Test1_createQ_FieldsEmpty() 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.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableName);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("EmptyFields #######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertNotEquals(200, response.getStatus());
- }
-/* @Test
- public void Test1_createQ_Clustergood() throws Exception {
- String tableNameC="testcjcC";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "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(200, response.getStatus());
- }*/
-
-/* @Test
- public void Test1_createQ_ClusterOrderGood1() throws Exception {
- String tableNameC="testcjcO";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "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(200, response.getStatus());
- } */
-
-/* @Test
- public void Test1_createQ_PartitionKeygood() throws Exception {
- String tableNameP="testcjcP";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_salary),emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameP);
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameP);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameP);
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- } */
-
- @Test
- public void Test1_createQ_PartitionKeybadclose() throws Exception {
- String tableNameC="testcjcP1";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_salary),emp_id))");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "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(400, response.getStatus());
- assertTrue(200 != response.getStatus());
- }
-
-/* @Test
- public void Test1_createQ_ClusterOrderGood2() throws Exception {
- String tableNameC="testcjcO1g";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_salary,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC,emp_id DESC");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "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(200, response.getStatus());
- } */
-
- /* @Test
- public void Test1_createQ_ColPkeyoverridesPrimaryKeyGood() throws Exception {
- String tableNameC="testcjcPr";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC,emp_id DESC");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "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(200, response.getStatus());
- //assertTrue(200 != response.getStatus());
- } */
-
- @Test
- public void Test1_createQ_ClusterOrderBad() throws Exception {
- String tableNameC="testcjcO1b";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id DESCx");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "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());
- }
-
-
- @Test
- public void Test3_createQ_0() throws Exception {
- //duplicate testing ...
- 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.setPrimaryKey("emp_name");
- String tableNameDup=tableName+"X";
- jsonTable.setTableName(tableNameDup);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- System.out.println("#######status for 1st time " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
-
- Response response0 = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- // 400 is the duplicate status found in response
- // Music 113 duplicate testing
- //import static org.junit.Assert.assertNotEquals;
- System.out.println("#######status for 2nd time " + response0.getStatus());
- System.out.println("Entity" + response0.getEntity());
-
- assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus());
- //assertEquals(400, response0.getStatus());
- //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
- @Test
- public void Test3_createQ2() 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.setTableName(tableName);
- jsonTable.setClusteringKey("emp_salary");
- jsonTable.setClusteringOrder("emp_salary 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, authorization,
- jsonTable, "wrong", tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
-
-
-/* @Test
- public void Test4_insertIntoQ() 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", "testName");
- values.put("emp_salary", 500);
- 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, tableName);
- assertEquals(200, response.getStatus());
- }*/
-
-
- @Test
- public void Test4_insertIntoQ_valuesEmpty() 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", "testName");
- values.put("emp_salary", 500);
- */
- 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, tableName);
- assertNotEquals(200, response.getStatus());
- }
-
-/* @Test
- public void Test4_insertIntoQ2() 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, tableName);
- 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();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- row.add("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- 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);
- 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 Test6_filterQ() throws Exception { //select
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- row.add("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.filter(majorV, minorV,patchV,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }*/
-
-/* @Test
- public void Test6_peekQ() throws Exception { //select
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.peek(majorV, minorV,patchV,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- if (result.isEmpty() ) assertTrue(true);
- else assertFalse(false);
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }*/
-/*
- @Test
- public void Test6_peekQ_empty() throws Exception { //select
- // row is not needed in thhis test
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- UriInfo infoe= mockUriInfo("/peek?");//empty queryParam: cause exception
- // 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",
- appName, authorization, keyspaceName, tableName, infoe);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- if (result.isEmpty() ) assertTrue(true);
- else assertFalse(false);
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }*/
-
-/* @Test
- public void Test6_deleteFromQ1() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- 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);
- assertEquals(200, response.getStatus());
- }*/
-
- // Values
- @Test
- @Ignore
- public void Test6_deleteFromQ() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- //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);
- assertEquals(400, response.getStatus());
- }
-
- // delObj
- @Test
- public void Test6_deleteFromQ2() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- //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,
- null, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-/*
- @Test
- public void Test7_dropQ() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.dropQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- 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;
- }
-
-
- //Empty Fields
- @Test
- public void Test8_createQ_fields_empty() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Partition key null
- @Test
- public void Test8_createQ_partitionKey_empty() throws Exception {
- String tableNameC="testcjcC";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Clustering key null
- @Test
- public void Test8_createQ_ClusteringKey_empty() throws Exception {
- String tableNameC="testcjcC";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Clustering Order null
- @Test
- public void Test8_createQ_ClusteringOrder_empty() throws Exception {
- String tableNameC="testcjcC";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Invalid primary key
- @Test
- public void Test8_createQ_primaryKey_invalid() throws Exception {
- String tableNameC="testcjcC";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setPrimaryKey("(emp_name");
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id ASC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Primary key with no clustering key
- @Test
- public void Test8_createQ_primaryKey_with_empty_clusteringKey() throws Exception {
- String tableNameC="testcjcC";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- jsonTable.setClusteringOrder("emp_id ASC");
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
-
- }
-
- //Primary key with no partition key
- @Test
- public void Test8_createQ_primaryKey_with_empty_partitionKey() throws Exception {
- String tableNameC="testcjcC";
- 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_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey(" ");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- jsonTable.setClusteringOrder("emp_id ASC");
-
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
deleted file mode 100644
index ef2867d8..00000000
--- a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 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 java.util.List;
-import java.util.UUID;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-import org.mindrot.jbcrypt.BCrypt;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.lockingservice.cassandra.CassaLockStore;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-
-@RunWith(Suite.class)
-@SuiteClasses({ TstRestMusicDataAPI.class, TstRestMusicLockAPI.class, TstRestMusicAdminAPI.class,
- TstRestMusicConditionalAPI.class, TstCachingUtil.class})
-public class TestsUsingCassandra {
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testcassa";
- static String tableName = "employees";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
- static String aid = "abc66ccc-d857-4e90-b1e5-df98a3d40ce6";
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
- createAdminTable();
- }
-
- @AfterClass
- public static void afterClass() {
- PreparedQueryObject testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
- MusicCore.eventualPut(testObject);
- if(MusicDataStoreHandle.mDstoreHandle!=null)
- MusicDataStoreHandle.mDstoreHandle.close();
- }
-
- private static void createAdminTable() throws Exception {
- PreparedQueryObject testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createAdminKeyspace);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createAdminTable);
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- keyspaceName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(testObject);
- List<Row> rows = rs.all();
- if (rows.size() > 0) {
- System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
- onboardUUID = rows.get(0).getUUID("uuid").toString();
- }
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/TstCachingUtil.java b/src/test/java/org/onap/music/unittests/TstCachingUtil.java
deleted file mode 100644
index ea47b7c1..00000000
--- a/src/test/java/org/onap/music/unittests/TstCachingUtil.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * ============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.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.Response;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.cassandra.CassaLockStore;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TstCachingUtil {
-
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- RestMusicDataAPI data = new RestMusicDataAPI();
- static PreparedQueryObject testObject;
-
- static String appName = TestsUsingCassandra.appName;
- static String userId = TestsUsingCassandra.userId;
- static String password = TestsUsingCassandra.password;
- static String authData = TestsUsingCassandra.authData;
- static String authorization = TestsUsingCassandra.authorization;
- static boolean isAAF = TestsUsingCassandra.isAAF;
- static UUID uuid = TestsUsingCassandra.uuid;
- static String keyspaceName = TestsUsingCassandra.keyspaceName;
- static String tableName = TestsUsingCassandra.tableName;
- static String onboardUUID = null;
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing CachingUtil class");
- try {
-
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @After
- public void afterEachTest( ) throws MusicServiceException {
-
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
-
- @Test
- public void test_verifyOnboard() throws Exception {
- System.out.println("Testing onboarding of app");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- Map<String, Object> authMap = CachingUtil.verifyOnboarding(appName, userId, password);
- assertEquals(0, authMap.size());
- }
-
- @Test
- public void test_authenticateAIDUser() throws Exception {
- System.out.println("Testing authentication of AID user");
- createKeyspace();
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- Map<String, Object> authMap = CachingUtil.authenticateAIDUser(appName,
- userId, password, keyspaceName);
- System.out.println("authMap is: " + authMap);
- assertEquals(0, authMap.size());
- }
-
- @Test
- public void test_getAppName() throws MusicServiceException {
- System.out.println("Testing getAppName");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- assertEquals(appName, CachingUtil.getAppName(keyspaceName));
- }
-
- @Test
- public void test_getUUIDFromCache() throws MusicServiceException {
- System.out.println("Testing getUUID");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- assertEquals(uuid.toString(), CachingUtil.getUuidFromMusicCache(keyspaceName));
- }
-
- @Test
- public void test_isAAFApplcation() throws MusicServiceException {
- System.out.println("Testing to see if cache gets correct isAAF info");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- assertEquals(isAAF, Boolean.valueOf(CachingUtil.isAAFApplication(appName)));
- }
-
- private static void createKeyspace() throws Exception {
- //shouldn't really be doing this here, but create keyspace is currently turned off
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(query);
-
- boolean isAAF = false;
- String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
- query = new PreparedQueryObject();
- query.appendQueryString(
- "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
- MusicCore.eventualPut(query);
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java
deleted file mode 100644
index 02b7f3a4..00000000
--- a/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 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.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.Response;
-
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.internal.util.reflection.FieldSetter;
-import org.onap.music.authentication.MusicAAFAuthentication;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.main.MusicCore;
-import org.onap.music.rest.RestMusicAdminAPI;
-import com.sun.jersey.core.util.Base64;
-
-public class TstRestMusicAdminAPI {
-
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
- static PreparedQueryObject testObject;
-
- @Mock
- MusicAAFAuthentication authMock;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String adminName = "username";
- static String adminPassword = "password";
- static String adminAuthData = adminName +":"+adminPassword;
- static String wrongAdminAuthData = adminName+"123"+":"+adminPassword;
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static String adminAuthorization = new String(Base64.encode(adminAuthData.getBytes()));
- static String wrongAdminAuthorization = new String(Base64.encode(wrongAdminAuthData.getBytes()));
-
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testCassa";
- static String tableName = "employees";
- static String tableNameConditional = "Conductor";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = TestsUsingCassandra.onboardUUID;
- static String lockId = null;
- static String lockName = "testCassa.employees.sample3";
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing RestMusicAdmin class");
- //PowerMockito.mockStatic(MusicAuthentication.class);
- try {
- //MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @Before
- public void beforeEach() throws NoSuchFieldException {
- authenticateAdminTrue();
- }
-
- @After
- public void afterEach() {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DELETE * FROM admin.keyspace_master;");
- MusicCore.eventualPut(testObject);
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
-
- @Test
- public void test6_onboard() throws Exception {
- System.out.println("Testing application onboarding");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false"); jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
-
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test6_onboard_wrongCredentials() throws Exception {
- System.out.println("Testing application onboarding wrong credentials");
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false"); jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
-
- Response response = admin.onboardAppWithMusic(jsonOnboard,wrongAdminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test6_onboard_duplicate() throws Exception {
- System.out.println("Testing a duplicate onboarding call");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // Missing appname
- @Test
- public void test6_onboard_noAppName() throws Exception {
- System.out.println("Testing onboard missing app name");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
-
- @Test
- public void test7_onboardSearch_notOnboarded() throws Exception {
- System.out.println("Testing application onboarding search for app that isn't onboarded");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- //Application is not onboarded
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test7_onboardSearch() throws Exception {
- System.out.println("Testing application onboarding search no matching app");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
-
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test7_onboardSearch_wrongCredentials() throws Exception {
- System.out.println("Testing application onboarding search w/ wrong credentials");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,wrongAdminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- // Missing appname
- @Test
- public void test7_onboardSearch_noAppName() throws Exception {
- System.out.println("Testing application onboarding search w/o appname");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test7_onboardSearch_empty() throws Exception {
- System.out.println("Testing onboard search no app information");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test8_onboardUpdate() throws Exception {
- System.out.println("Testing application onboarding update");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Ignore //not working correctly
- @Test
- public void test8_onboardUpdate_withAppName() throws Exception {
- System.out.println("Testing application onboarding update w appname");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test8_onboardUpdate_noUUID() throws Exception {
- System.out.println("Testing application onboarding update null uuid");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(null);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test8_onboardUpdate_wrongCredentialsNoAAF() throws Exception {
- System.out.println("Testing update application onboarding search w/ wrong credentials");
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,wrongAdminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // All null
- @Test
- public void test8_onboardUpdate_noAppInfo() throws Exception {
- System.out.println("Testing update application onboarding update no app information");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test9_onboardDelete() throws Exception {
- System.out.println("Testing update application onboarding delete");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //only 1 app matches keyspace
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Ignore //not working as expected
- @Test
- public void test9_onboardDelete_noAID() throws Exception {
- System.out.println("Testing update application onboarding delete no AID");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //only 1 app matches name
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test9_onboardDelete_noAIDManyMatch() throws Exception {
- System.out.println("Testing update application onboarding delete no AID many apps in namespace");
- onboardApp();
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //multiple apps matches name
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test9_onboardDelete_noAID_noApp() throws Exception {
- System.out.println("Testing update application onboarding delete no AID, app not onboarded");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test9_onboardDelete_noAppToDelete() throws Exception {
- System.out.println("Testing update application onboarding delete no app information");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname(null);
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //only 1 app matches keyspace
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test9_onboardDelete_wrongCredentials() throws Exception {
- System.out.println("Testing onboard delete with wrong credentials");
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.deleteOnboardApp(jsonOnboard,wrongAdminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test10_delete() throws Exception {
- System.out.println("Testing GUI delete call");
- onboardApp();
-
- assertTrue(admin.delete(adminAuthorization, onboardUUID));
- }
-
- @Test
- public void test11_getAll() {
- System.out.println("Testing GUI getall call");
-
- System.out.println("admin.getall(adminAuthorization)");
- }
-
- /**
- * Inject our mocked class and accept admin credentials
- * @throws NoSuchFieldException
- */
- public void authenticateAdminTrue() throws NoSuchFieldException {
- authMock = Mockito.mock(MusicAAFAuthentication.class);
- FieldSetter.setField(admin, admin.getClass().getDeclaredField("authenticator"), authMock);
-
- Mockito.when(authMock.authenticateAdmin(Mockito.matches(adminAuthorization))).thenReturn(true);
- }
-
- /**
- * onboard the application and store generate uuid into {@link onboardUUID}
- * @param onboard
- * @throws Exception
- */
- public void onboardApp() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
-
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
- Map<String, String> respMap = (Map<String, String>) response.getEntity();
- onboardUUID = respMap.get("Generated AID");
- }
-
-} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java
deleted file mode 100644
index 3adab912..00000000
--- a/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * ============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.assertEquals;
-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 javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
-import org.onap.music.conductor.conditionals.JsonConditional;
-import org.onap.music.conductor.conditionals.RestMusicConditionalAPI;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.rest.RestMusicDataAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TstRestMusicConditionalAPI {
-
- RestMusicDataAPI data = new RestMusicDataAPI();
- RestMusicConditionalAPI cond = new RestMusicConditionalAPI();
- static PreparedQueryObject testObject;
-
- @Mock
- HttpServletResponse http;
-
- @Mock
- UriInfo info;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId + ":" + password;
- static String wrongAuthData = userId + ":" + "pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testcassa";
- static String tableName = "employees";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing RestMusicConditional class");
- try {
- createKeyspace();
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @After
- public void afterEachTest() throws MusicServiceException {
- clearAllTablesFromKeyspace();
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
-
- @Test
- public void test_insertIntoTable() throws Exception {
- System.out.println("Testing conditional insert into table");
- createTable();
-
- JsonConditional jsonCond = new JsonConditional();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("id", "test_id");
- consistencyInfo.put("type", "eventual");
- HashMap<String, Object> cascadeData = new HashMap<>();
- HashMap<String, String> cascadeValue = new HashMap<>();
- cascadeValue.put("created", "hello");
- cascadeValue.put("updated", "world");
- cascadeData.put("key", "p1");
- cascadeData.put("value", cascadeValue);
- HashMap<String, Map<String, String>> condition = new HashMap<>();
- HashMap<String, String> exists = new HashMap<>();
- exists.put("status", "parked");
- HashMap<String, String> nonexists = new HashMap<>();
- nonexists.put("status", "underway");
- condition.put("exists", exists);
- condition.put("nonexists", nonexists);
-
- jsonCond.setPrimaryKey("id");
- jsonCond.setPrimaryKeyValue("testname");
- jsonCond.setCasscadeColumnName("plans");
- jsonCond.setTableValues(values);
- jsonCond.setCasscadeColumnData(cascadeData);
- jsonCond.setConditions(condition);
-
- Response response = cond.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, keyspaceName, tableName, jsonCond);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
- /*
- * @Test public void test4_insertIntoTable2() throws Exception { System.out.println("Testing insert into table #2");
- * createTable(); 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); 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(200, response.getStatus()); }
- *
- * // Auth Error
- *
- * @Test public void test4_insertIntoTable3() throws Exception {
- * System.out.println("Testing insert into table with bad credentials"); createTable(); 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); Response response = data.insertIntoTable("1",
- * "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, jsonInsert, keyspaceName,
- * tableName); System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- *
- * assertEquals(401, response.getStatus()); }
- *
- * // Table wrong
- *
- * @Test public void test4_insertIntoTable4() throws Exception {
- * System.out.println("Testing insert into wrong table"); createTable(); 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); Response response = data.insertIntoTable("1",
- * "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, "wrong");
- * System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- *
- * assertEquals(400, response.getStatus()); }
- */
-
- @Test
- public void test5_updateTable() throws Exception {
- System.out.println("Testing conditional update table");
- createAndInsertIntoTable();
-
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
-
- JsonConditional jsonCond = new JsonConditional();
- Map<String, Object> values = new HashMap<>();
- values.put("id", "test_id");
- HashMap<String, Object> cascadeData = new HashMap<>();
- HashMap<String, String> cascadeValue = new HashMap<>();
- cascadeValue.put("created", "hello");
- cascadeValue.put("updated", "world");
- cascadeData.put("key", "p1");
- cascadeData.put("value", cascadeValue);
-
- jsonCond.setPrimaryKey("id");
- jsonCond.setPrimaryKeyValue("test_id");
- jsonCond.setCasscadeColumnName("plans");
- jsonCond.setTableValues(values);
- jsonCond.setCasscadeColumnData(cascadeData);
-
- Response response = cond.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, keyspaceName, tableName, jsonCond);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
- /*
- * // need mock code to create error for MusicCore methods
- *
- * @Test public void test5_updateTableAuthE() throws Exception { System.out.println("Testing update table #2");
- * createTable(); //MockitoAnnotations.initMocks(this); 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); //add
- * ttl & timestamp //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- * Mockito.when(info.getQueryParameters()).thenReturn(row); //Map<String, Object> m1= new HashMap<>() ;
- * //Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,
- * "abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1); Response response = data.updateTable("1",
- * "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonUpdate, keyspaceName, tableName,
- * info); System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- *
- * assertEquals(200, response.getStatus()); }
- *
- * @Ignore
- *
- * @Test public void test5_updateTableAuthException1() throws Exception {
- * System.out.println("Testing update table authentication error"); createTable(); 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.when(info.getQueryParameters()).thenReturn(row); String authDatax = ":"; String authorizationx = new
- * String(Base64.encode(authDatax.getBytes())); Response response = data.updateTable("1", "1", "1",
- * "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorizationx, jsonUpdate, keyspaceName, tableName, info);
- * System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- *
- * assertEquals(401, response.getStatus()); }
- *
- * @Ignore
- *
- * @Test public void test5_updateTableAuthEmpty() throws Exception {
- * System.out.println("Testing update table without authentication"); createTable();
- *
- * 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.when(info.getQueryParameters()).thenReturn(row); String authDatax =":"+password; String authorizationx =
- * new String(Base64.encode(authDatax.getBytes())); String appNamex="xx"; Response response = data.updateTable("1",
- * "1", "1", "", appNamex, authorizationx, jsonUpdate, keyspaceName, tableName, info); System.out.println("Status: "
- * + response.getStatus() + ". Entity " + response.getEntity());
- *
- * assertEquals(401, response.getStatus()); }
- *
- */
-
- private static void createKeyspace() throws Exception {
- // shouldn't really be doing this here, but create keyspace is currently turned off
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(query);
-
- boolean isAAF = false;
- String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
- query = new PreparedQueryObject();
- query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
- MusicCore.eventualPut(query);
- }
-
- private void clearAllTablesFromKeyspace() throws MusicServiceException {
- ArrayList<String> tableNames = new ArrayList<>();
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(
- "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspaceName + "';");
- ResultSet rs = MusicCore.get(query);
- for (Row row : rs) {
- tableNames.add(row.getString("table_name"));
- }
- for (String table : tableNames) {
- query = new PreparedQueryObject();
- query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
- MusicCore.eventualPut(query);
- }
- }
-
- /**
- * Create a table {@link tableName} in {@link keyspaceName}
- *
- * @throws Exception
- */
- private void createTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("id", "text");
- fields.put("plans", "map<text,text>");
- fields.put("PRIMARY KEY", "(id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("id");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableName);
- }
-
- /**
- * Create table {@link createTable} and insert into said table
- *
- * @throws Exception
- */
- private void createAndInsertIntoTable() throws Exception {
- createTable();
-
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- JsonConditional jsonCond = new JsonConditional();
- Map<String, Object> values = new HashMap<>();
- values.put("id", "test_id");
- HashMap<String, Object> cascadeData = new HashMap<>();
- HashMap<String, String> cascadeValue = new HashMap<>();
- cascadeValue.put("created", "hello");
- cascadeValue.put("updated", "world");
- cascadeData.put("key", "p1");
- cascadeData.put("value", cascadeValue);
- HashMap<String, Map<String, String>> condition = new HashMap<>();
- HashMap<String, String> exists = new HashMap<>();
- exists.put("status", "parked");
- HashMap<String, String> nonexists = new HashMap<>();
- nonexists.put("status", "underway");
- condition.put("exists", exists);
- condition.put("nonexists", nonexists);
-
- jsonCond.setPrimaryKey("id");
- jsonCond.setPrimaryKeyValue("test_id");
- jsonCond.setCasscadeColumnName("plans");
- jsonCond.setTableValues(values);
- jsonCond.setCasscadeColumnData(cascadeData);
- jsonCond.setConditions(condition);
-
- Response response = cond.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, keyspaceName, tableName, jsonCond);
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
deleted file mode 100644
index 18692915..00000000
--- a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
+++ /dev/null
@@ -1,1261 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 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.assertEquals;
-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 javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TstRestMusicDataAPI {
-
- RestMusicDataAPI data = new RestMusicDataAPI();
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- static PreparedQueryObject testObject;
-
- @Mock
- HttpServletResponse http;
-
- @Mock
- UriInfo info;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId + ":" + password;
- static String wrongAuthData = userId + ":" + "pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testcassa";
- static String tableName = "employees";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
- static String aid = TestsUsingCassandra.aid;
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing RestMusicData class");
- try {
- createKeyspace();
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @After
- public void afterEachTest() throws MusicServiceException {
- clearAllTablesFromKeyspace();
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
-
- @Test
- public void test1_createKeyspace() throws Exception {
- System.out.println("Testing create keyspace");
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response =
- data.createKeySpace("1", "1", "1", null, authorization, appName, jsonKeyspace, keyspaceName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- Map<String, String> respMap = (Map<String, String>) response.getEntity();
- assertEquals(ResultType.FAILURE, respMap.get("status"));
- }
-
- @Test
- public void test3_createTable() throws Exception {
- System.out.println("Testing create table");
- 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.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test3_createTableNoName() throws Exception {
- System.out.println("Testing create table without name");
- 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.setPrimaryKey("emp_name");
- jsonTable.setTableName("");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, "");
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
-
- @Test
- public void test3_createTableClusterOrderBad() throws Exception {
- System.out.println("Testing create table bad clustering");
- 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,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_salary");
- jsonTable.setClusteringOrder("ASC");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test3_createTable_withPropertiesNotNull() throws Exception {
- System.out.println("Testing create table with properties");
- 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");
- Map<String, Object> properties = new HashMap<>();
- properties.put("comment", "Testing prperties not null");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableName_prop = tableName + "_Prop";
- jsonTable.setTableName(tableName_prop);
- jsonTable.setFields(fields);
- jsonTable.setProperties(properties);
-
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableName_prop);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test3_createTable_duplicateTable() throws Exception {
- System.out.println("Testing creating duplicate tables");
- 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.setPrimaryKey("emp_name");
- String tableNameDup = tableName + "x";
- jsonTable.setTableName(tableNameDup);
- jsonTable.setFields(fields);
- // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response1 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameDup);
-
- Response response2 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameDup);
- System.out.println("Status: " + response2.getStatus() + ". Entity " + response2.getEntity());
-
- 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"));
- }
-
- // Improper Auth
- @Test
- public void test3_createTable1() throws Exception {
- System.out.println("Testing create table w/ improper authentication");
- 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.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonTable, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper keyspace
- @Test
- public void test3_createTable3() throws Exception {
- System.out.println("Testing create table for wrong keyspace");
- 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.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, "wrong", tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper parenthesis in key field
- @Test
- public void test3_createTable_badParantesis() throws Exception {
- System.out.println("Testing malformed create table request");
- String tableNameC = "testTable0";
- 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),emp_id)");
- fields.put("emp_id", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id Desc");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
-
- // good clustering key
- @Test
- public void test3_createTable_1_clusterKey_good() throws Exception {
- System.out.println("Testing create w/ clusterKey");
-
- String tableNameC = "testTableC1";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- // jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- // bad partition key=clustering key
- @Test
- public void test3_createTable_2_clusterKey_bad() throws Exception {
- System.out.println("Testing create w/ bad clusterKey");
- String tableNameC = "testTableC2";
- 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),emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- // good composite partition key,clustering key
- @Test
- public void test3_createTable_3_pfartition_clusterKey_good() throws Exception {
- System.out.println("Testing create w/ composite partition key, clusterKey");
-
- String tableNameC = "testTableC3";
- 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_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void test3_createTable_5_clusteringOrder_bad() throws Exception {
- System.out.println("Testing create table bad request with clustering & composite keys");
- String tableNameC = "testTableC5";
- 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_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
-
- // good clustering key, need to pass queryparameter
- @Test
- public void test3_createTableIndex_1() throws Exception {
- System.out.println("Testing index in create table");
- String tableNameC = "testTableCinx";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
- // info.setQueryParameters("index_name=inx_uuid");
- Map<String, String> queryParametersMap = new HashMap<String, String>();
-
- queryParametersMap.put("index_name", "inxuuid");
- Mockito.when(info.getQueryParameters()).thenReturn(new MultivaluedHashMap<String, String>(queryParametersMap));
- response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC, "uuid", info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- // good clustering key, need to pass queryparameter
- @Test
- public void test3_createTableIndex_badAuth() throws Exception {
- System.out.println("Testing index in create table w/ wrong authorization");
- String tableNameC = "testTableCinx";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
- // info.setQueryParameters("index_name=inx_uuid");
- Map<String, String> queryParametersMap = new HashMap<String, String>();
-
- queryParametersMap.put("index_name", "inxuuid");
- response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, keyspaceName, tableNameC, "uuid", info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- // create index without table name
- @Test
- public void test3_createTableIndexNoName() throws Exception {
- System.out.println("Testing index in create table w/o tablename");
- String tableNameC = "testTableCinx";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
- // info.setQueryParameters("index_name=inx_uuid");
- Map<String, String> queryParametersMap = new HashMap<String, String>();
-
- queryParametersMap.put("index_name", "inxuuid");
- response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, "",
- "", "uuid", info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test4_insertIntoTable() throws Exception {
- System.out.println("Testing insert into table");
- createTable();
- 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", "testname");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- 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(200, response.getStatus());
- }
-
- @Test
- public void test4_insertIntoTableCriticalNoLockID() throws Exception {
- System.out.println("Testing critical insert into table without lockid");
- createTable();
- 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", "testname");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "critical");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- 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_insertIntoTableAtomic() throws Exception {
- System.out.println("Testing atomic insert into table without lockid");
- createTable();
- 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", "testname");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- 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(200, response.getStatus());
- }
-
- @Test
- public void test4_insertIntoTableNoName() throws Exception {
- System.out.println("Testing insert into table w/o table name");
- createTable();
- 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", "testname");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, "", "");
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test4_insertIntoTable2() throws Exception {
- System.out.println("Testing insert into table #2");
- createTable();
- 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);
- 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(200, response.getStatus());
- }
-
- // Auth Error
- @Test
- public void test4_insertIntoTable3() throws Exception {
- System.out.println("Testing insert into table with bad credentials");
- createTable();
- 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);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonInsert, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- // Table wrong
- @Test
- public void test4_insertIntoTable4() throws Exception {
- System.out.println("Testing insert into wrong table");
- createTable();
- 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);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonInsert, keyspaceName, "wrong");
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test4_insertBlobIntoTable() throws Exception {
- System.out.println("Testing insert a blob into table");
- createTable();
- 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", "testname");
- values.put("emp_salary", 500);
- values.put("binary", "somestuffhere");
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- 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(200, response.getStatus());
- }
-
- @Test
- public void test5_updateTable() throws Exception {
- System.out.println("Testing update table");
- createTable();
-
- 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.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test5_updateTable_wrongAuth() throws Exception {
- System.out.println("Testing update table w/ wrong credentials");
- createTable();
-
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonUpdate, keyspaceName, tableName, info);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test5_updateTable_tableDNE() throws Exception {
- System.out.println("Testing update table that does not exist");
- createTable();
-
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName("wrong_"+tableName);
- jsonUpdate.setValues(values);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, "wrong_"+ tableName, info);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test5_updateTableNoName() throws Exception {
- System.out.println("Testing update table without tablename");
- createTable();
-
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, "", "", info);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- // need mock code to create error for MusicCore methods
- @Test
- public void test5_updateTableAuthE() throws Exception {
- System.out.println("Testing update table #2");
- createTable();
- // MockitoAnnotations.initMocks(this);
- 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);
- // add ttl & timestamp
- // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- // Map<String, Object> m1= new HashMap<>() ;
- // Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test5_updateTableAuthException1() throws Exception {
- System.out.println("Testing update table authentication error");
- createTable();
- 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.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":";
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test5_updateTableAuthEmpty() throws Exception {
- System.out.println("Testing update table without authentication");
- createTable();
-
- 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.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":" + password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- String appNamex = "xx";
- Response response = data.updateTable("1", "1", "1", "", appNamex, authorizationx, jsonUpdate, keyspaceName,
- tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test6_critical_selectAtomic() throws Exception {
- System.out.println("Testing critical select atomic");
- createAndInsertIntoTable();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testname");
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, 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());
-
- Map<String, String> row0 = (Map<String, String>) result.get("row 0");
- assertEquals("testname", row0.get("emp_name"));
- assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
- }
-
- @Test
- public void test6_critical_selectCritical_nolockid() throws Exception {
- System.out.println("Testing critical select critical w/o lockid");
- createAndInsertIntoTable();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testname");
- consistencyInfo.put("type", "critical");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, 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());
- }
-
- @Test
- public void test6_critical_select_wrongAuth() throws Exception {
- System.out.println("Testing critical select w/ wrong authentication");
- createAndInsertIntoTable();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, jsonInsert, keyspaceName, tableName,info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test6_critical_select_nulltable() throws Exception {
- System.out.println("Testing critical select w/ null tablename");
- createAndInsertIntoTable();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, null,info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test6_select() throws Exception {
- System.out.println("Testing select");
- createAndInsertIntoTable();
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testname");
- 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);
- 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());
-
- Map<String, String> row0 = (Map<String, String>) result.get("row 0");
- assertEquals("testname", row0.get("emp_name"));
- assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
- }
-
- @Test
- public void test6_select_wrongAuth() throws Exception {
- System.out.println("Testing select w/ wrong authentication");
- createAndInsertIntoTable();
- JsonSelect jsonSelect = new JsonSelect();
- 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, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test6_select_nullTablename() throws Exception {
- System.out.println("Testing select w/ null tablename");
- createAndInsertIntoTable();
- JsonSelect jsonSelect = new JsonSelect();
- 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);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test6_deleteFromTable() throws Exception {
- System.out.println("Testing delete from table");
- createAndInsertIntoTable();
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonDelete, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test6_deleteFromTable_wrongAuth() throws Exception {
- System.out.println("Testing delete from table");
- createAndInsertIntoTable();
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonDelete, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test6_deleteFromTable_missingTablename() throws Exception {
- System.out.println("Testing delete from table w/ null tablename");
- createAndInsertIntoTable();
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonDelete, keyspaceName, null, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- // Values
- @Ignore
- @Test
- public void test6_deleteFromTable1() throws Exception {
- System.out.println("Testing delete from table missing delete object");
- createAndInsertIntoTable();
-
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonDelete, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- // delObj
- @Test
- public void test6_deleteFromTable2() throws Exception {
- System.out.println("Testing delete from table missing delete object");
- createAndInsertIntoTable();
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, null, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test7_dropTable() throws Exception {
- System.out.println("Testing drop table");
- createTable();
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test7_dropTable_wrongAuth() throws Exception {
- System.out.println("Testing drop table w/ wrong auth");
- createTable();
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test7_dropTable_nullTablename() throws Exception {
- System.out.println("Testing drop table w/ null tablename");
- createTable();
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, keyspaceName, null);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
-
- @Test
- public void test8_deleteKeyspace() throws Exception {
- System.out.println("Testing drop keyspace");
-
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization,
- appName, keyspaceName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- private static void createKeyspace() throws Exception {
- // shouldn't really be doing this here, but create keyspace is currently turned off
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(query);
-
- boolean isAAF = false;
- String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
- query = new PreparedQueryObject();
- query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
- MusicCore.eventualPut(query);
- }
-
- private void clearAllTablesFromKeyspace() throws MusicServiceException {
- ArrayList<String> tableNames = new ArrayList<>();
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(
- "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspaceName + "';");
- ResultSet rs = MusicCore.get(query);
- for (Row row : rs) {
- tableNames.add(row.getString("table_name"));
- }
- for (String table : tableNames) {
- query = new PreparedQueryObject();
- query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
- MusicCore.eventualPut(query);
- }
- }
-
- /**
- * Create a table {@link tableName} in {@link keyspaceName}
- *
- * @throws Exception
- */
- private void createTable() 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("binary", "blob");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableName);
- }
-
- /**
- * Create table {@link createTable} and insert into said table
- *
- * @throws Exception
- */
- private void createAndInsertIntoTable() throws Exception {
- createTable();
-
- 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", "testname");
- values.put("emp_salary", 500);
- values.put("binary", "binarydatahere");
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonInsert, keyspaceName, tableName);
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
deleted file mode 100644
index 92c5d818..00000000
--- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * ============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.assertEquals;
-import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.Response;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.cassandra.CassaLockStore;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TstRestMusicLockAPI {
-
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- RestMusicDataAPI data = new RestMusicDataAPI();
- static PreparedQueryObject testObject;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testcassa";
- static String tableName = "employees";
- static String onboardUUID = null;
- static String lockName = "testcassa.employees.testname";
- static String malformedLock = "malformedLock";
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing RestMusicLock class");
- try {
- createKeyspace();
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @After
- public void afterEachTest( ) throws MusicServiceException {
- clearAllTablesFromKeyspace();
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void test_createLockReference() throws Exception {
- System.out.println("Testing create lockref");
- createAndInsertIntoTable();
- Response response =lock.createLockReference(lockName,"1","1",authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- assertTrue(respMap.containsKey("lock"));
- assertTrue(((Map<String,String>) respMap.get("lock")).containsKey("lock"));
- }
-
- @Test
- public void test_createLockReference_wrongAuth() throws Exception {
- System.out.println("Testing create lockref with wrong auth");
- createAndInsertIntoTable();
- Response response =lock.createLockReference(lockName,"1","1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test_createLockReference_malformedLockName() throws Exception {
- System.out.println("Testing create lockref w/ malformed lock");
- createAndInsertIntoTable();
- Response response =lock.createLockReference(malformedLock,"1","1",authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test_accquireLock() throws Exception {
- System.out.println("Testing acquire lock");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.accquireLock(lockRef, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test_accquireLock_wrongAuth() throws Exception {
- System.out.println("Testing acquire lock w/ wrong auth");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.accquireLock(lockRef, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test_accquireBadLock() throws Exception {
- System.out.println("Testing acquire lock that is not lock-holder");
- createAndInsertIntoTable();
-
- String lockRef1 = createLockReference();
- String lockRef2 = createLockReference();
-
-
- Response response = lock.accquireLock(lockRef2, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test_accquireLock_malformedLock() throws Exception {
- System.out.println("Testing acquire lock w/ malformedLock");
- createAndInsertIntoTable();
-
- Response response = lock.accquireLock(malformedLock, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test_accquireLockWLease() throws Exception {
- System.out.println("Testing acquire lock with lease");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- JsonLeasedLock jsonLock = new JsonLeasedLock();
- jsonLock.setLeasePeriod(10000); //10 second lease period?
- Response response = lock.accquireLockWithLease(jsonLock, lockRef, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test_accquireLockWLease_wrongAuth() throws Exception {
- System.out.println("Testing acquire lock with lease w/ wrong Auth");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- JsonLeasedLock jsonLock = new JsonLeasedLock();
- jsonLock.setLeasePeriod(10000); //10 second lease period?
- Response response = lock.accquireLockWithLease(jsonLock, lockRef, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test_accquireLockWLease_malformedLock() throws Exception {
- System.out.println("Testing acquire lock with lease w/ malformed lock");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- JsonLeasedLock jsonLock = new JsonLeasedLock();
- jsonLock.setLeasePeriod(10000); //10 second lease period?
- Response response = lock.accquireLockWithLease(jsonLock, malformedLock, "1", "1",
- wrongAuthorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test_currentLockHolder() throws Exception {
- System.out.println("Testing get current lock holder");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.currentLockHolder(lockName, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
- assertEquals(lockRef, ((Map<String,String>) respMap.get("lock")).get("lock-holder"));
- }
-
- @Test
- public void test_currentLockHolder_wrongAuth() throws Exception {
- System.out.println("Testing get current lock holder w/ wrong Auth");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.currentLockHolder(lockName, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test_currentLockHolder_malformedLock() throws Exception {
- System.out.println("Testing get current lock holder w/ malformed lock");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.currentLockHolder(malformedLock, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test_unLock() throws Exception {
- System.out.println("Testing unlock");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.unLock(lockRef, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test_unLock_wrongAuth() throws Exception {
- System.out.println("Testing unlock w/ wrong auth");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.unLock(lockRef, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test_unLock_malformedLock() throws Exception {
- System.out.println("Testing unlock w/ malformedLock");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.unLock("malformedLock", "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test_getLockState() throws Exception {
- System.out.println("Testing get lock state");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.currentLockState(lockName, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
- assertEquals(lockRef, ((Map<String,String>) respMap.get("lock")).get("lock-holder"));
- }
-
- @Test
- public void test_getLockState_wrongAuth() throws Exception {
- System.out.println("Testing get lock state w/ wrong auth");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.currentLockState(lockName, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test_getLockState_malformedLock() throws Exception {
- System.out.println("Testing get lock state w/ malformedLock");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.currentLockState(malformedLock, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test_deleteLock() throws Exception {
- System.out.println("Testing delete lock");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.deleteLock(lockName, "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization, appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test_deleteLock_wrongAuth() throws Exception {
- System.out.println("Testing delete lock w/ wrong auth");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.deleteLock(lockName, "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", wrongAuthorization, appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void test_deleteLock_malformedLock() throws Exception {
- System.out.println("Testing delete lock w/ malformed lock");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.deleteLock(malformedLock, "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", wrongAuthorization, appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- /**
- * Create table and lock reference
- * @return the lock ref created
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- private String createLockReference() throws Exception {
- Response response =lock.createLockReference(lockName,"1","1",authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
- return ((Map<String,String>) respMap.get("lock")).get("lock");
- }
-
-
-
-
- private static void createKeyspace() throws Exception {
- //shouldn't really be doing this here, but create keyspace is currently turned off
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(query);
-
- boolean isAAF = false;
- String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
- query = new PreparedQueryObject();
- query.appendQueryString(
- "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
- MusicCore.eventualPut(query);
- }
-
- private void clearAllTablesFromKeyspace() throws MusicServiceException {
- ArrayList<String> tableNames = new ArrayList<>();
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString("SELECT table_name FROM system_schema.tables WHERE keyspace_name = '"+keyspaceName+"';");
- ResultSet rs = MusicCore.get(query);
- for (Row row: rs) {
- tableNames.add(row.getString("table_name"));
- }
- for (String table: tableNames) {
- query = new PreparedQueryObject();
- query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
- MusicCore.eventualPut(query);
- }
- }
-
- /**
- * Create a table {@link tableName} in {@link keyspaceName}
- * @throws Exception
- */
- private void createTable() 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.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- }
-
- /**
- * Create table {@link createTable} and insert into said table
- * @throws Exception
- */
- private void createAndInsertIntoTable() throws Exception {
- createTable();
-
- 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", "testname");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName);
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
deleted file mode 100644
index 354668c7..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ============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.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.ArrayList;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.AAFResponse;
-import org.onap.music.datastore.jsonobjects.NameSpace;
-
-public class AAFResponseTest {
-
- @Test
- public void testGetNs() {
- NameSpace ns = new NameSpace();
- AAFResponse ar = new AAFResponse();
- ArrayList<NameSpace> nsArray = new ArrayList<>();
- ns.setName("tom");
- ArrayList<String> admin = new ArrayList<>();
- admin.add("admin1");
- ns.setAdmin(admin);
- nsArray.add(ns);
- ar.setNs(nsArray);
- assertEquals("tom",ar.getNs().get(0).getName());
- assertEquals("admin1",ar.getNs().get(0).getAdmin().get(0));
-
- }
-
-// @Test
-// public void testSetNs() {
-// fail("Not yet implemented");
-// }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java
deleted file mode 100644
index 7f6af4c5..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 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 org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.JSONObject;
-
-public class JSONObjectTest {
- private JSONObject jsonObject;
-
- @Before
- public void setUp() {
- jsonObject = new JSONObject();
- }
-
- @Test
- public void testGetSetData() {
- jsonObject.setData("data");
- Assert.assertEquals("data", jsonObject.getData());
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
deleted file mode 100644
index a069b81d..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * Modifications Copyright (c) 2019 Samsung
- * ===================================================================
- * 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.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-
-public class JsonDeleteTest {
-
- JsonDelete jd = null;
-
- @Before
- public void init() {
- jd = new JsonDelete();
- }
-
- @Test
- public void testGetConditions() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo.put("key1","one");
- mapSo.put("key2","two");
- jd.setConditions(mapSo);
- assertEquals("one",jd.getConditions().get("key1"));
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String,String> mapSs = new HashMap<>();
- mapSs.put("key3","three");
- mapSs.put("key4","four");
- jd.setConsistencyInfo(mapSs);
- assertEquals("three",jd.getConsistencyInfo().get("key3"));
- }
-
- @Test
- public void testGetColumns() {
- List<String> ary = new ArrayList<>();
- ary.add("e1");
- ary.add("e2");
- ary.add("e3");
- jd.setColumns(ary);
- assertEquals("e1",jd.getColumns().get(0));
- }
-
- @Test
- public void testGetTtl() {
- jd.setTtl("2000");
- assertEquals("2000",jd.getTtl());
- }
-
- @Test
- public void testGetTimestamp() {
- jd.setTimestamp("20:00");
- assertEquals("20:00",jd.getTimestamp());
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
deleted file mode 100644
index 69403cc7..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============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.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-
-public class JsonInsertTest {
-
- JsonInsert ji = new JsonInsert();
-
- @Test
- public void testGetKeyspaceName() {
- ji.setKeyspaceName("keyspace");
- assertEquals("keyspace",ji.getKeyspaceName());
- }
-
- @Test
- public void testGetTableName() {
- ji.setTableName("table");
- assertEquals("table",ji.getTableName());
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String,String> cons = new HashMap<>();
- cons.put("test","true");
- ji.setConsistencyInfo(cons);
- assertEquals("true",ji.getConsistencyInfo().get("test"));
- }
-
- @Test
- public void testGetTtl() {
- ji.setTtl("ttl");
- assertEquals("ttl",ji.getTtl());
- }
-
- @Test
- public void testGetTimestamp() {
- ji.setTimestamp("10:30");
- assertEquals("10:30",ji.getTimestamp());
- }
-
- @Test
- public void testGetValues() {
- Map<String,Object> cons = new HashMap<>();
- cons.put("val1","one");
- cons.put("val2","two");
- ji.setValues(cons);
- assertEquals("one",ji.getValues().get("val1"));
- }
-
- @Test
- public void testGetRow_specification() {
- Map<String,Object> cons = new HashMap<>();
- cons.put("val1","one");
- cons.put("val2","two");
- ji.setRow_specification(cons);
- assertEquals("two",ji.getRow_specification().get("val2"));
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
deleted file mode 100644
index 0f4abd7c..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * ============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.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-
-public class JsonKeySpaceTest {
-
- JsonKeySpace jk = null;
-
-
- @Before
- public void init() {
- jk = new JsonKeySpace();
- }
-
-
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- jk.setConsistencyInfo(mapSs);
- assertEquals("one",jk.getConsistencyInfo().get("k1"));
- }
-
- @Test
- public void testGetReplicationInfo() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo.put("k1", "one");
- jk.setReplicationInfo(mapSo);
- assertEquals("one",jk.getReplicationInfo().get("k1"));
-
- }
-
- @Test
- public void testGetDurabilityOfWrites() {
- jk.setDurabilityOfWrites("1");
- assertEquals("1",jk.getDurabilityOfWrites());
- }
-
- @Test
- public void testGetKeyspaceName() {
- jk.setKeyspaceName("Keyspace");
- assertEquals("Keyspace",jk.getKeyspaceName());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
deleted file mode 100644
index 0014093d..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ============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.jsonobjects;
-
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
-
-public class JsonLeasedLockTest {
-
- JsonLeasedLock jl = null;
-
- @Before
- public void init() {
- jl = new JsonLeasedLock();
- }
-
-
- @Test
- public void testGetLeasePeriod() {
- long lease = 20000;
- jl.setLeasePeriod(lease);
- 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/JsonOnboardTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
deleted file mode 100644
index 1e66ed58..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ============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.jsonobjects;
-
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-
-public class JsonOnboardTest {
-
- JsonOnboard jo = null;
-
- @Before
- public void init() {
- jo = new JsonOnboard();
- }
-
-
- @Test
- public void testGetPassword() {
- String password = "password";
- jo.setPassword(password);
- assertEquals(password,jo.getPassword());
- }
-
- @Test
- public void testGetAid() {
- String aid = "aid";
- jo.setAid(aid);
- assertEquals(aid,jo.getAid());
-
- }
-
- @Test
- public void testGetAppname() {
- String appName = "appName";
- jo.setAppname(appName);
- assertEquals(appName,jo.getAppname());
-
- }
-
- @Test
- public void testGetUserId() {
- String userId = "userId";
- jo.setUserId(userId);
- assertEquals(userId,jo.getUserId());
-
- }
-
- @Test
- public void testGetIsAAF() {
- String aaf = "true";
- jo.setIsAAF(aaf);
- assertEquals(aaf,jo.getIsAAF());
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
deleted file mode 100644
index 37d1787a..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * Modifications Copyright (c) 2018-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 java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-
-public class JsonSelectTest {
-
- @Test
- public void testGetConsistencyInfo() {
- JsonSelect js = new JsonSelect();
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- js.setConsistencyInfo(mapSs);
- assertEquals("one", js.getConsistencyInfo().get("k1"));
- }
-
- @Test
- public void testSerialize() throws IOException {
- JsonSelect js = new JsonSelect();
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("Key", "Value");
- js.setConsistencyInfo(mapSs);
- js.serialize();
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
deleted file mode 100644
index 4e3b4629..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * Modifications 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.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-
-public class JsonTableTest {
-
- JsonTable jt = null;
-
- @Before
- public void init() {
- jt = new JsonTable();
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- jt.setConsistencyInfo(mapSs);
- assertEquals("one",jt.getConsistencyInfo().get("k1"));
- }
-
- @Test
- public void testGetProperties() {
- Map<String, Object> properties = new HashMap<>();
- properties.put("k1", "one");
- jt.setProperties(properties);
- }
-
- @Test
- public void testGetFields() {
- Map<String, String> fields = new HashMap<>();
- fields.put("k1", "one");
- jt.setFields(fields);
- assertEquals("one",jt.getFields().get("k1"));
- }
-
- @Test
- public void testGetKeyspaceName() {
- String keyspace = "keyspace";
- jt.setKeyspaceName(keyspace);
- assertEquals(keyspace,jt.getKeyspaceName());
- }
-
- @Test
- public void testGetTableName() {
- String table = "table";
- jt.setTableName(table);
- assertEquals(table,jt.getTableName());
- }
-
- @Test
- public void testGetClusteringOrder() {
- String clusteringOrder = "clusteringOrder";
- jt.setClusteringOrder(clusteringOrder);
- assertEquals(clusteringOrder,jt.getClusteringOrder());
- }
-
- @Test
- public void testGetPrimaryKey() {
- String primaryKey = "primaryKey";
- jt.setPrimaryKey(primaryKey);
- assertEquals(primaryKey,jt.getPrimaryKey());
- }
-
- @Test
- public void testFilteringKey() {
- jt.setFilteringKey("FilteringKey");
- assertEquals("FilteringKey",jt.getFilteringKey());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
deleted file mode 100644
index e00cb463..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 AT&T Intellectual Property
- * ===================================================================
- * Modifications 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.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-
-public class JsonUpdateTest {
-
- JsonUpdate ju = null;
-
- @Before
- public void init() {
- ju = new JsonUpdate();
- }
-
-
- @Test
- public void testGetConditions() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo.put("key1","one");
- mapSo.put("key2","two");
- ju.setConditions(mapSo);
- assertEquals("one",ju.getConditions().get("key1"));
- }
-
- @Test
- public void testGetRow_specification() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo.put("key1","one");
- mapSo.put("key2","two");
- ju.setRow_specification(mapSo);
- assertEquals("one",ju.getRow_specification().get("key1"));
- }
-
- @Test
- public void testGetKeyspaceName() {
- String keyspace = "keyspace";
- ju.setKeyspaceName(keyspace);
- assertEquals(keyspace,ju.getKeyspaceName());
- }
-
- @Test
- public void testGetTableName() {
- String table = "table";
- ju.setTableName(table);
- assertEquals(table,ju.getTableName());
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- ju.setConsistencyInfo(mapSs);
- assertEquals("one",ju.getConsistencyInfo().get("k1"));
- }
-
- @Test
- public void testGetTtl() {
- ju.setTtl("2000");
- assertEquals("2000",ju.getTtl());
- }
-
- @Test
- public void testGetTimestamp() {
- ju.setTimestamp("20:00");
- assertEquals("20:00",ju.getTimestamp());
-
- }
-
- @Test
- public void testGetValues() {
- Map<String,Object> cons = new HashMap<>();
- cons.put("val1","one");
- cons.put("val2","two");
- ju.setValues(cons);
- assertEquals("one",ju.getValues().get("val1"));
- }
-
- @Test
- public void testSerialize() {
- assertTrue(ju.serialize() instanceof byte[]);
- }
-
-}
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());
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java
deleted file mode 100644
index ceda3f3a..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java
+++ /dev/null
@@ -1,48 +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.eelf.healthcheck.MusicHealthCheck;
-
-public class MusicHealthCheckTest {
-
- private MusicHealthCheck musicHealthCheck;
-
- @Before
- public void setUp()
- {
- musicHealthCheck= new MusicHealthCheck();
- }
-
- @Test
- public void testCassandraHost()
- {
- musicHealthCheck.setCassandrHost("9042");
- assertEquals("9042", musicHealthCheck.getCassandrHost());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java
deleted file mode 100644
index ee4d3933..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 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 org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.NameSpace;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class NameSpaceTest {
- private NameSpace nameSpace;
-
- @Before
- public void setUp() {
- nameSpace = new NameSpace();
- }
-
- @Test
- public void testGetSetAdmin() {
- List<String> list = new ArrayList<String>();
- list.add("admin");
- nameSpace.setAdmin(list);
- Assert.assertEquals(list, nameSpace.getAdmin());
- }
-
- @Test
- public void testGetSetName() {
- nameSpace.setName("name");
- Assert.assertEquals("name", nameSpace.getName());
- }
-}
diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
deleted file mode 100644
index 1f0955d4..00000000
--- a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
+++ /dev/null
@@ -1 +0,0 @@
-mock-maker-inline
diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider b/src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider
deleted file mode 100644
index bc2f0992..00000000
--- a/src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider
+++ /dev/null
@@ -1 +0,0 @@
-org.mockito.internal.exceptions.stacktrace.DefaultStackTraceCleanerProvider