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.ecomp.model.AppCategoryFunctionsItem;
59 import org.onap.portalapp.portal.ecomp.model.AppContactUsItem;
60 import org.onap.portalapp.portal.framework.MockitoTestSuite;
61 import org.onap.portalapp.portal.service.AppContactUsService;
62 import org.onap.portalapp.portal.service.AppContactUsServiceImpl;
63 import org.onap.portalsdk.core.service.DataAccessService;
64 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
66 public class AppContactUsServiceImplTest {
70 DataAccessService dataAccessService ;
73 AppContactUsService AppContactUsService ;
75 AppContactUsServiceImpl appContactUsServiceImpl = new AppContactUsServiceImpl();
77 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
79 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
80 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
84 MockitoAnnotations.initMocks(this);
88 NullPointerException nullPointerException = new NullPointerException();
91 public EPApp getApp() {
92 EPApp app = new EPApp();
94 app.setImageUrl("test");
95 app.setDescription("test");
99 app.setAppRestEndpoint("test");
100 app.setAlternateUrl("test");
102 app.setMlAppName("test");
103 app.setMlAppAdminId("test");
104 app.setUsername("test");
105 app.setAppPassword("test");
107 app.setEnabled(false);
108 app.setUebKey("test");
109 app.setUebSecret("test");
110 app.setUebTopicName("test");
115 public void getAppContactUsTest() throws Exception
118 List<AppContactUsItem> contactUsItemList = new ArrayList<>();
119 AppContactUsItem appContactUsItem= new AppContactUsItem();
120 appContactUsItem.setAppName("testNew");
121 contactUsItemList.add(appContactUsItem);
122 AppContactUsItem appContactUsItem1= new AppContactUsItem();
123 appContactUsItem1.setAppName("test");
124 contactUsItemList.add(appContactUsItem1);
125 Mockito.when(dataAccessService.executeNamedQuery("getAppContactUsItems", null, null)).thenReturn(contactUsItemList);
126 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppContactUs();
127 assertEquals(expectedcontactUsItemList, contactUsItemList);
131 public void getAppsAndContactsTest() throws Exception
133 List<AppContactUsItem> contactUsItemList = new ArrayList<>();
134 AppContactUsItem appContactUsItem= new AppContactUsItem();
135 appContactUsItem.setAppName("testNew");
136 contactUsItemList.add(appContactUsItem);
137 AppContactUsItem appContactUsItem1= new AppContactUsItem();
138 appContactUsItem1.setAppName("test");
139 contactUsItemList.add(appContactUsItem1);
140 Mockito.when(dataAccessService.executeNamedQuery("getAppsAndContacts", null, null)).thenReturn(contactUsItemList);
141 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppsAndContacts();
142 assertEquals(expectedcontactUsItemList, contactUsItemList);
147 public void getAppCategoryFunctionsTest() throws Exception
149 List<AppCategoryFunctionsItem> list = new ArrayList<>();
150 Mockito.when(dataAccessService.executeNamedQuery("getAppCategoryFunctions", null, null)).thenReturn(list);
151 List<AppCategoryFunctionsItem> expectedlist = appContactUsServiceImpl.getAppCategoryFunctions();
152 assertEquals(list, expectedlist);
155 @Test(expected = java.lang.Exception.class)
156 public void saveAppContactUsTest() throws Exception
158 HashMap<String, Object> map = new HashMap<String, Object>();
159 List<AppContactUsItem> contactUsModelList = new ArrayList<>();
160 AppContactUsItem appContactUsItem= new AppContactUsItem();
161 appContactUsItem.setAppId((long) 1);
162 contactUsModelList.add(appContactUsItem);
163 AppContactUs appContact = new AppContactUs();
164 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(appContact);
165 EPApp app = getApp();
166 Mockito.when(dataAccessService.getDomainObject(EPApp.class, 1, new HashMap<String, Object>())).thenReturn(app);
167 AppContactUs contactUs = new AppContactUs();
168 contactUs.setApp(app);
169 contactUs.setDescription(appContactUsItem.getDescription());
170 contactUs.setContactName(appContactUsItem.getContactName());
171 contactUs.setContactEmail(appContactUsItem.getContactEmail());
172 contactUs.setActiveYN(appContactUsItem.getActiveYN());
173 contactUs.setUrl(appContactUsItem.getUrl());
174 Mockito.doNothing().when(dataAccessService).saveDomainObject(contactUs,map);
175 appContactUsServiceImpl.saveAppContactUs(contactUsModelList);
179 public void saveAppContacts()throws Exception {
181 List<AppContactUsItem> contactUsModelList = new ArrayList<>();
182 AppContactUsItem appContactUsItem= new AppContactUsItem();
183 appContactUsItem.setAppId((long) 1);
184 contactUsModelList.add(appContactUsItem);
185 HashMap<String, Object> map = new HashMap<String, Object>();
187 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class,
188 appContactUsItem.getAppId(), map)).thenReturn(appContactUsItem);
190 Mockito.when(dataAccessService.getDomainObject(EPApp.class, appContactUsItem.getAppId(), map)).thenReturn(getApp());
191 appContactUsServiceImpl.saveAppContactUs(contactUsModelList);
194 @Test(expected = java.lang.NullPointerException.class)
195 public void deleteContactUs_error_Test() throws Exception
197 HashMap<String, Object> map = new HashMap<String, Object>();
198 AppContactUs contactUs = new AppContactUs();
199 Mockito.when((AppContactUs) dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(contactUs);
200 appContactUsServiceImpl.deleteContactUs((long) 1);
202 @Test(expected=Exception.class)
203 public void deleteContactUsTest()throws Exception {
204 HashMap<String, Object> map = new HashMap<String, Object>();
206 AppContactUs contactUs = new AppContactUs();
208 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class,
209 contactUs.getId(), map)).thenReturn(contactUs);
210 appContactUsServiceImpl.deleteContactUs( contactUs.getId());