fixes for supporting non-gui application access provisioning
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / AppContactUsServiceImplTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 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  * 
37  */
38 package org.onap.portalapp.portal.service;
39
40 import static org.junit.Assert.assertEquals;
41
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
45
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
48
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.mockito.InjectMocks;
52 import org.mockito.Matchers;
53 import org.mockito.Mock;
54 import org.mockito.Mockito;
55 import org.mockito.MockitoAnnotations;
56 import org.onap.portalapp.portal.domain.AppContactUs;
57 import org.onap.portalapp.portal.domain.EPApp;
58 import org.onap.portalapp.portal.domain.EpAppType;
59 import org.onap.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;
60 import org.onap.portalapp.portal.ecomp.model.AppContactUsItem;
61 import org.onap.portalapp.portal.framework.MockitoTestSuite;
62 import org.onap.portalapp.portal.service.AppContactUsService;
63 import org.onap.portalapp.portal.service.AppContactUsServiceImpl;
64 import org.onap.portalsdk.core.service.DataAccessService;
65 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
66
67 public class AppContactUsServiceImplTest {
68
69         
70      @Mock
71          DataAccessService dataAccessService ;
72     
73      @Mock
74      AppContactUsService AppContactUsService ;
75      @InjectMocks
76      AppContactUsServiceImpl appContactUsServiceImpl = new AppContactUsServiceImpl();
77
78         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
79
80         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
81         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
82      
83      @Before
84         public void setup() {
85                 MockitoAnnotations.initMocks(this);
86         }
87         
88    
89         NullPointerException nullPointerException = new NullPointerException();
90         
91         
92         public EPApp getApp() {
93                 EPApp app = new EPApp();
94                 app.setName("Test");
95                 app.setImageUrl("test");
96                 app.setAppDescription("test");
97                 app.setAppNotes("test");
98                 app.setLandingPage("test");
99                 app.setId((long) 1);
100                 app.setAppRestEndpoint("test");
101                 app.setAlternateLandingPage("test");
102                 app.setName("test");
103                 app.setMlAppName("test");
104                 app.setMlAppAdminId("test");
105                 app.setAppBasicAuthUsername("test");
106                 app.setAppBasicAuthPassword("test");
107                 app.setOpen(true);
108                 app.setEnabled(false);
109                 app.setUebKey("test");
110                 app.setUebSecret("test");
111                 app.setUebTopicName("test");
112                 app.setAppType(EpAppType.GUI);
113                 return app;
114         }
115         @Test
116         public void getAppContactUsTest() throws Exception
117         {
118                 
119                 List<AppContactUsItem> contactUsItemList  = new ArrayList<>();
120                 AppContactUsItem appContactUsItem= new AppContactUsItem();
121                 appContactUsItem.setAppName("testNew");
122                 contactUsItemList.add(appContactUsItem);
123                 AppContactUsItem appContactUsItem1= new AppContactUsItem();
124                 appContactUsItem1.setAppName("test");
125                 contactUsItemList.add(appContactUsItem1);
126                 Mockito.when(dataAccessService.executeNamedQuery("getAppContactUsItems", null, null)).thenReturn(contactUsItemList);
127                 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppContactUs();
128                 assertEquals(expectedcontactUsItemList, contactUsItemList);             
129         }
130         
131         @Test
132         public void getAppsAndContactsTest() throws Exception
133         {
134                 List<AppContactUsItem> contactUsItemList  = new ArrayList<>();
135                 AppContactUsItem appContactUsItem= new AppContactUsItem();
136                 appContactUsItem.setAppName("testNew");
137                 contactUsItemList.add(appContactUsItem);
138                 AppContactUsItem appContactUsItem1= new AppContactUsItem();
139                 appContactUsItem1.setAppName("test");
140                 contactUsItemList.add(appContactUsItem1);
141                 Mockito.when(dataAccessService.executeNamedQuery("getAppsAndContacts", null, null)).thenReturn(contactUsItemList);
142                 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppsAndContacts();
143                 assertEquals(expectedcontactUsItemList, contactUsItemList);             
144         }
145         
146         
147         @Test
148         public void getAppCategoryFunctionsTest() throws Exception
149         {
150                 List<AppCategoryFunctionsItem> list  = new ArrayList<>();
151                 Mockito.when(dataAccessService.executeNamedQuery("getAppCategoryFunctions", null, null)).thenReturn(list);
152                 List<AppCategoryFunctionsItem> expectedlist = appContactUsServiceImpl.getAppCategoryFunctions();
153                 assertEquals(list, expectedlist); 
154         }
155         
156         @Test(expected = java.lang.Exception.class)
157         public void saveAppContactUsTest() throws Exception
158         {
159                 HashMap<String, Object> map = new HashMap<String, Object>();
160                 List<AppContactUsItem> contactUsModelList = new ArrayList<>();
161                 AppContactUsItem appContactUsItem= new AppContactUsItem();
162                 appContactUsItem.setAppId((long) 1);
163                 contactUsModelList.add(appContactUsItem);
164                 AppContactUs appContact = new AppContactUs();
165                 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(appContact);
166                 EPApp app = getApp();
167                 Mockito.when(dataAccessService.getDomainObject(EPApp.class, 1, new HashMap<String, Object>())).thenReturn(app);
168                 AppContactUs contactUs  = new AppContactUs();
169                 contactUs.setApp(app);
170                 contactUs.setDescription(appContactUsItem.getDescription());
171                 contactUs.setContactName(appContactUsItem.getContactName());
172                 contactUs.setContactEmail(appContactUsItem.getContactEmail());
173                 contactUs.setActiveYN(appContactUsItem.getActiveYN());
174                 contactUs.setUrl(appContactUsItem.getUrl());
175                 Mockito.doNothing().when(dataAccessService).saveDomainObject(contactUs,map);
176                 appContactUsServiceImpl.saveAppContactUs(contactUsModelList);
177         }
178         
179         @Test
180         public void saveAppContacts()throws Exception {
181                 
182                 List<AppContactUsItem> contactUsModelList = new ArrayList<>();
183                 AppContactUsItem appContactUsItem= new AppContactUsItem();
184                 appContactUsItem.setAppId((long) 1);
185                 contactUsModelList.add(appContactUsItem);
186                 HashMap<String, Object> map = new HashMap<String, Object>();
187                 
188                 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class,
189                                                 appContactUsItem.getAppId(), map)).thenReturn(appContactUsItem);
190                 
191                 Mockito.when(dataAccessService.getDomainObject(EPApp.class, appContactUsItem.getAppId(), map)).thenReturn(getApp());
192                 appContactUsServiceImpl.saveAppContactUs(contactUsModelList);
193         }
194         
195         @Test(expected = java.lang.NullPointerException.class)
196         public void deleteContactUs_error_Test() throws Exception
197         {
198                 HashMap<String, Object> map = new HashMap<String, Object>();
199                 AppContactUs contactUs = new AppContactUs();
200                 Mockito.when((AppContactUs) dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(contactUs);
201                 appContactUsServiceImpl.deleteContactUs((long) 1);
202         }
203         @Test(expected=Exception.class)
204         public void deleteContactUsTest()throws Exception {
205                 HashMap<String, Object> map = new HashMap<String, Object>();
206                 
207                 AppContactUs contactUs = new AppContactUs();
208                 contactUs.setId(1l);
209                 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class,
210                                 contactUs.getId(), map)).thenReturn(contactUs);
211                 appContactUsServiceImpl.deleteContactUs(        contactUs.getId());
212         }
213         
214 }