2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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============================================
38 package org.onap.portalapp.portal.service;
40 import static org.junit.Assert.assertEquals;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
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;
67 public class AppContactUsServiceImplTest {
71 DataAccessService dataAccessService ;
74 AppContactUsService AppContactUsService ;
76 AppContactUsServiceImpl appContactUsServiceImpl = new AppContactUsServiceImpl();
78 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
80 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
81 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
85 MockitoAnnotations.initMocks(this);
89 NullPointerException nullPointerException = new NullPointerException();
92 public EPApp getApp() {
93 EPApp app = new EPApp();
95 app.setImageUrl("test");
96 app.setAppDescription("test");
97 app.setAppNotes("test");
98 app.setLandingPage("test");
100 app.setAppRestEndpoint("test");
101 app.setAlternateLandingPage("test");
103 app.setMlAppName("test");
104 app.setMlAppAdminId("test");
105 app.setAppBasicAuthUsername("test");
106 app.setAppBasicAuthPassword("test");
108 app.setEnabled(false);
109 app.setUebKey("test");
110 app.setUebSecret("test");
111 app.setUebTopicName("test");
112 app.setAppType(EpAppType.GUI);
116 public void getAppContactUsTest() throws Exception
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);
132 public void getAppsAndContactsTest() throws Exception
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);
148 public void getAppCategoryFunctionsTest() throws Exception
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);
156 @Test(expected = java.lang.Exception.class)
157 public void saveAppContactUsTest() throws Exception
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);
180 public void saveAppContacts()throws Exception {
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>();
188 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class,
189 appContactUsItem.getAppId(), map)).thenReturn(appContactUsItem);
191 Mockito.when(dataAccessService.getDomainObject(EPApp.class, appContactUsItem.getAppId(), map)).thenReturn(getApp());
192 appContactUsServiceImpl.saveAppContactUs(contactUsModelList);
195 @Test(expected = java.lang.NullPointerException.class)
196 public void deleteContactUs_error_Test() throws Exception
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);
203 @Test(expected=Exception.class)
204 public void deleteContactUsTest()throws Exception {
205 HashMap<String, Object> map = new HashMap<String, Object>();
207 AppContactUs contactUs = new AppContactUs();
209 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class,
210 contactUs.getId(), map)).thenReturn(contactUs);
211 appContactUsServiceImpl.deleteContactUs( contactUs.getId());