2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * ===================================================================
7 * Modifications Copyright (c) 2018-2019 IBM.
8 * ===================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=============================================
22 * ====================================================================
25 package org.onap.music.unittests;
27 import static org.junit.Assert.*;
29 import java.util.HashMap;
31 import org.junit.Test;
32 import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
33 import org.onap.music.main.ResultType;
34 import org.onap.music.response.jsonobjects.JsonResponse;
36 public class JsonResponseTest {
38 JsonResponse result = null;
41 public void testJsonResponseBooleanStringString() {
42 result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("version");
43 assertEquals("error",result.getError());
47 public void testStatus() {
48 result = new JsonResponse(ResultType.SUCCESS);
49 result.setStatus(ResultType.SUCCESS);
50 assertEquals(ResultType.SUCCESS, result.getStatus());
51 result = new JsonResponse(ResultType.FAILURE).setError("error").setMusicVersion("version");
52 assertEquals(ResultType.FAILURE, result.getStatus());
56 public void testError() {
57 result = new JsonResponse(ResultType.FAILURE);
58 result.setError("error");
59 assertTrue(result.getError().equals("error"));
61 assertFalse(result.getError().equals("error"));
65 public void testVersion() {
66 result = new JsonResponse(ResultType.SUCCESS);
67 result.setMusicVersion("version");
68 assertTrue(result.getMusicVersion().equals("version"));
69 result.setMusicVersion("");
70 assertFalse(result.getMusicVersion().equals("version"));
74 public void testToMap() {
75 result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("1.0");
76 Map<String,Object> myMap = result.toMap();
77 assertTrue(myMap.containsKey("status"));
78 assertEquals(ResultType.SUCCESS, myMap.get("status"));
79 assertEquals("error", myMap.get("error"));
80 assertEquals("1.0", myMap.get("version"));
82 result = new JsonResponse(ResultType.FAILURE);
83 myMap = result.toMap();
84 assertTrue(myMap.containsKey("status"));
85 assertEquals(ResultType.FAILURE, myMap.get("status"));
89 public void testMessage() {
90 result = new JsonResponse(ResultType.SUCCESS);
91 result.setMessage("message");
92 assertEquals("message", result.getMessage());
97 public void testDataResult() {
98 result = new JsonResponse(ResultType.SUCCESS);
99 Map<String, HashMap<String, Object>> dataResult= new HashMap<>();
100 result.setDataResult(dataResult);
101 assertEquals(dataResult, result.getDataResult());
106 public void testLock() {
107 result = new JsonResponse(ResultType.SUCCESS);
108 result.setLock("lock");
109 assertEquals("lock", result.getLock());
114 public void testLockStatus() {
115 result = new JsonResponse(ResultType.SUCCESS);
116 LockStatus status = LockStatus.LOCKED;
117 result.setLockStatus(status);
118 assertEquals(status, result.getLockStatus());
123 public void testToString() {
124 result = new JsonResponse(ResultType.SUCCESS);
125 assertTrue(result.toString() instanceof String);