Null check for ClientResponse in PolicyUril.java
[portal.git] / ecomp-portal-widget-ms / widget-ms / src / test / java / org / openecomp / portalapp / widget / test / controller / WidgetFileControllerTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.openecomp.portalapp.widget.test.controller;
39
40 import static org.junit.Assert.assertEquals;
41 import static org.mockito.Mockito.times;
42
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.mockito.ArgumentCaptor;
47 import org.mockito.InjectMocks;
48 import org.mockito.Mock;
49 import org.mockito.Mockito;
50 import org.mockito.MockitoAnnotations;
51 import org.mockito.runners.MockitoJUnitRunner;
52 import org.openecomp.portalapp.widget.controller.DatabaseFileUploadController;
53 import org.openecomp.portalapp.widget.service.impl.StorageServiceImpl;
54 import org.springframework.test.web.servlet.MockMvc;
55 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
56 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
57
58
59 @RunWith(MockitoJUnitRunner.class)
60 public class WidgetFileControllerTest {
61         private MockMvc mockMvc;
62         
63         @Mock
64         private StorageServiceImpl storageService;
65         
66         @InjectMocks
67         private DatabaseFileUploadController controller;
68         
69         @Before
70         public void setUp() {
71                 MockitoAnnotations.initMocks(this);
72                 mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
73         }
74         
75         @Test
76         public void getWidgetMarkup_NoError() throws Exception{
77                 ArgumentCaptor<Long> storageServiceArg = ArgumentCaptor.forClass(Long.class);
78                 Long widgetId = new Long(1);
79                 mockMvc.perform(MockMvcRequestBuilders.get("/microservices/markup/" + widgetId)).andReturn();;
80                 Mockito.verify(storageService, times(1)).getWidgetMarkup(storageServiceArg.capture());
81                 assertEquals(storageServiceArg.getValue(), widgetId);
82         }
83         
84         @Test
85         public void getWidgetController_NoError() throws Exception{
86                 ArgumentCaptor<Long> storageServiceArg = ArgumentCaptor.forClass(Long.class);
87                 Long widgetId = new Long(1);
88                 mockMvc.perform(MockMvcRequestBuilders.get("/microservices/" + widgetId + "/controller.js")).andReturn();;
89                 Mockito.verify(storageService, times(1)).getWidgetController(storageServiceArg.capture());
90                 assertEquals(storageServiceArg.getValue(), widgetId);
91         }
92         
93         @Test
94         public void getWidgetFramework_NoError() throws Exception{
95                 ArgumentCaptor<Long> storageServiceArg = ArgumentCaptor.forClass(Long.class);
96                 Long widgetId = new Long(1);
97                 mockMvc.perform(MockMvcRequestBuilders.get("/microservices/" + widgetId + "/framework.js")).andReturn();;
98                 Mockito.verify(storageService, times(1)).getWidgetFramework(storageServiceArg.capture());
99                 assertEquals(storageServiceArg.getValue(), widgetId);
100         }
101         
102         @Test
103         public void getWidgetCSS_NoError() throws Exception{
104                 ArgumentCaptor<Long> storageServiceArg = ArgumentCaptor.forClass(Long.class);
105                 Long widgetId = new Long(1);
106                 mockMvc.perform(MockMvcRequestBuilders.get("/microservices/" + widgetId + "/styles.css")).andReturn();;
107                 Mockito.verify(storageService, times(1)).getWidgetCSS(storageServiceArg.capture());
108                 assertEquals(storageServiceArg.getValue(), widgetId);
109         }
110         
111 }