Junit test case coverage for some classes in music-rest
[music.git] / music-rest / src / test / java / org / onap / music / rest / RestMusicVersionAPITest.java
1 /*******************************************************************************
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2019 AT&T Intellectual Property
6  * ===================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *  
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  *******************************************************************************/
22 package org.onap.music.rest;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Mockito.doNothing;
26 import java.util.Map;
27 import javax.servlet.http.HttpServletResponse;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.music.main.MusicUtil;
32
33 public class RestMusicVersionAPITest {
34     
35     RestMusicVersionAPI restMusicVersionAPI;
36     
37     @Before
38     public void setup() {
39         restMusicVersionAPI = new RestMusicVersionAPI();
40     }
41     
42     @Test
43     public void testVersion() {
44         MusicUtil.setVersion("x.x.x");
45         HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
46         doNothing().when(httpServletResponse).addHeader(Mockito.anyString(), Mockito.anyString());
47         Map<String,Object> map = restMusicVersionAPI.version(httpServletResponse);
48         assertEquals("MUSIC:x.x.x", map.get("version").toString());
49         assertEquals("SUCCESS", map.get("status").toString());
50     }
51     
52     @Test
53     public void testBuild() {
54         MusicUtil.setBuild("y.y");
55         MusicUtil.setVersion("x.x.x");
56         HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
57         doNothing().when(httpServletResponse).addHeader(Mockito.anyString(), Mockito.anyString());
58         Map<String,Object> map = restMusicVersionAPI.build(httpServletResponse);
59         assertEquals("MUSIC:x.x.x", map.get("version").toString());
60         assertEquals("SUCCESS", map.get("status").toString());
61         assertEquals("MUSIC:y.y", map.get("build").toString());
62     }
63 }