88fddf4efebac192e378681dc97c7326965e3a56
[music.git] / src / test / java / org / onap / music / unittests / JsonResponseTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
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
12  * 
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ============LICENSE_END=============================================
22  * ====================================================================
23  */
24
25 package org.onap.music.unittests;
26
27 import static org.junit.Assert.*;
28
29 import java.util.HashMap;
30 import java.util.Map;
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;
35
36 public class JsonResponseTest {
37
38     JsonResponse result = null;
39     
40     @Test
41     public void testJsonResponseBooleanStringString() {
42         result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("version");
43         assertEquals("error",result.getError());
44     }
45
46     @Test
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());
53     }
54
55     @Test
56     public void testError() {
57         result = new JsonResponse(ResultType.FAILURE);
58         result.setError("error");
59         assertTrue(result.getError().equals("error"));
60         result.setError("");
61         assertFalse(result.getError().equals("error"));
62     }
63
64     @Test
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"));
71     }
72
73     @Test
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"));
81         
82         result = new JsonResponse(ResultType.FAILURE);
83         myMap = result.toMap();
84         assertTrue(myMap.containsKey("status"));
85         assertEquals(ResultType.FAILURE, myMap.get("status"));
86     }
87
88     @Test
89     public void testMessage() {
90         result = new JsonResponse(ResultType.SUCCESS);
91         result.setMessage("message");
92         assertEquals("message", result.getMessage());
93         
94     }
95     
96     @Test
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());
102         
103     }
104     
105     @Test
106     public void testLock() {
107         result = new JsonResponse(ResultType.SUCCESS);
108         result.setLock("lock");
109         assertEquals("lock", result.getLock());
110         
111     }
112     
113     @Test
114     public void testLockStatus() {
115         result = new JsonResponse(ResultType.SUCCESS);
116         LockStatus status = LockStatus.LOCKED;
117         result.setLockStatus(status);
118         assertEquals(status, result.getLockStatus());
119         
120     }
121     
122     @Test
123     public void testToString() {
124         result = new JsonResponse(ResultType.SUCCESS);
125         assertTrue(result.toString() instanceof String);
126         
127     }
128 }