2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.widget.test.controller;
40 import static org.junit.Assert.assertEquals;
41 import static org.mockito.Mockito.times;
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;
59 @RunWith(MockitoJUnitRunner.class)
60 public class WidgetFileControllerTest {
61 private MockMvc mockMvc;
64 private StorageServiceImpl storageService;
67 private DatabaseFileUploadController controller;
71 MockitoAnnotations.initMocks(this);
72 mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
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);
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);
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);
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);