a570ab891921404b0ff8459b90c73f76d6c0377f
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / music / util / MusicUtilTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software 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  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  *
37  */
38 package org.onap.portalapp.music.util;
39
40 import static org.junit.Assert.assertFalse;
41 import static org.junit.Assert.assertNotNull;
42 import static org.junit.Assert.assertTrue;
43 import static org.mockito.Mockito.mock;
44
45 import java.util.ArrayList;
46 import java.util.List;
47
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.mockito.Mockito;
52 import org.mockito.MockitoAnnotations;
53 import org.onap.portalapp.music.conf.MusicSession;
54 import org.onap.portalapp.music.service.MusicService;
55 import org.onap.portalapp.music.util.MusicCleanUp;
56 import org.onap.portalapp.music.util.MusicProperties;
57 import org.onap.portalapp.music.util.MusicUtil;
58 import org.powermock.api.mockito.PowerMockito;
59 import org.powermock.core.classloader.annotations.PrepareForTest;
60 import org.powermock.modules.junit4.PowerMockRunner;
61
62 import com.datastax.driver.core.ResultSet;
63 import com.datastax.driver.core.Row;
64
65 @RunWith(PowerMockRunner.class)
66 @PrepareForTest({  MusicProperties.class, MusicSession.class, MusicService.class, MusicCleanUp.class })
67 public class MusicUtilTest {
68
69         ResultSet result = Mockito.mock(ResultSet.class);
70
71         Row rw = Mockito.mock(Row.class);
72         
73         @Before
74         public void setUp() throws Exception {
75                 MusicCleanUp musCleapUp = mock(MusicCleanUp.class);
76                 PowerMockito.mockStatic(MusicProperties.class);
77                 PowerMockito.mockStatic(MusicSession.class);
78                 PowerMockito.mockStatic(MusicService.class);
79                 PowerMockito.mockStatic(MusicCleanUp.class);
80                 Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_ATOMIC_PUT)).thenReturn("atomic-put");
81                 Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_ATOMIC_GET)).thenReturn("atomic-get");
82                 Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_CACHE)).thenReturn("cache");
83                 Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_EXCLUDE_API)).thenReturn("test1,test2");
84                 PowerMockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_SERIALIZE_COMPRESS)).thenReturn("compress");
85                 PowerMockito.when(MusicCleanUp.getInstance()).thenReturn(musCleapUp);
86                 PowerMockito.when(musCleapUp.getLastCleanUpTime()).thenReturn(null);
87                 MockitoAnnotations.initMocks(this);
88         }
89
90         @Test
91         public void isSessionMetaAttrTest() {
92                 assertTrue(MusicUtil.isSessionMetaAttr("CREATION_TIME"));
93         }
94
95         @Test
96         public void musicRestResponseDataParsingTest() throws Exception {
97                 List<Row> rows = new ArrayList<Row>();
98                 Mockito.doReturn("creation time").when(rw).getString("CREATION_TIME");
99                 rows.add(rw);
100                 Mockito.doReturn(rows.get(0)).when(result).one();
101                 assertNotNull(MusicUtil.musicRestResponseDataParsing(result, "CREATION_TIME"));
102         }
103
104         @Test
105         public void getMusicExcludedAPITest() {
106                 assertNotNull(MusicUtil.getMusicExcludedAPI());
107         }
108
109         @Test
110         public void isExcludedApiTest() {
111                 assertTrue(MusicUtil.isExcludedApi("test1"));
112         }
113
114         @Test
115         public void isExcludedApiFalseTest() {
116                 assertFalse(MusicUtil.isExcludedApi("test3"));
117         }
118
119         @Test
120         public void isMusicSerializeCompressReturnFalseTest() {
121                 assertFalse(MusicUtil.isMusicSerializeCompress());
122         }
123
124         @Test
125         public void isAtomicPutTest() {
126                 assertFalse(MusicUtil.isAtomicPut());
127         }
128
129         @Test
130         public void isAtomicGetTest() {
131                 assertFalse(MusicUtil.isAtomicGet());
132         }
133
134         @Test
135         public void isCachedTest() {
136                 assertFalse(MusicUtil.isCached());
137         }
138
139         @Test
140         public void convertHoursToMillSecTest() {
141                 assertNotNull(MusicUtil.convertHoursToMillSec(1));
142         }
143
144         @Test
145         public void cleanUpTest() {
146                 assertFalse(MusicUtil.cleanUp());
147         }
148 }