2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
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 * 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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.music.util;
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;
45 import java.util.ArrayList;
46 import java.util.List;
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;
62 import com.datastax.driver.core.ResultSet;
63 import com.datastax.driver.core.Row;
65 @RunWith(PowerMockRunner.class)
66 @PrepareForTest({ MusicProperties.class, MusicSession.class, MusicService.class, MusicCleanUp.class })
67 public class MusicUtilTest {
69 ResultSet result = Mockito.mock(ResultSet.class);
71 Row rw = Mockito.mock(Row.class);
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);
91 public void isSessionMetaAttrTest() {
92 assertTrue(MusicUtil.isSessionMetaAttr("CREATION_TIME"));
96 public void musicRestResponseDataParsingTest() throws Exception {
97 List<Row> rows = new ArrayList<Row>();
98 Mockito.doReturn("creation time").when(rw).getString("CREATION_TIME");
100 Mockito.doReturn(rows.get(0)).when(result).one();
101 assertNotNull(MusicUtil.musicRestResponseDataParsing(result, "CREATION_TIME"));
105 public void getMusicExcludedAPITest() {
106 assertNotNull(MusicUtil.getMusicExcludedAPI());
110 public void isExcludedApiTest() {
111 assertTrue(MusicUtil.isExcludedApi("test1"));
115 public void isExcludedApiFalseTest() {
116 assertFalse(MusicUtil.isExcludedApi("test3"));
120 public void isMusicSerializeCompressReturnFalseTest() {
121 assertFalse(MusicUtil.isMusicSerializeCompress());
125 public void isAtomicPutTest() {
126 assertFalse(MusicUtil.isAtomicPut());
130 public void isAtomicGetTest() {
131 assertFalse(MusicUtil.isAtomicGet());
135 public void isCachedTest() {
136 assertFalse(MusicUtil.isCached());
140 public void convertHoursToMillSecTest() {
141 assertNotNull(MusicUtil.convertHoursToMillSec(1));
145 public void cleanUpTest() {
146 assertFalse(MusicUtil.cleanUp());