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.Mock;
 
  53 import org.mockito.Mockito;
 
  54 import org.mockito.MockitoAnnotations;
 
  55 import org.onap.portalapp.portal.domain.AppContactUs;
 
  56 import org.onap.portalapp.portal.domain.EPApp;
 
  57 import org.onap.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;
 
  58 import org.onap.portalapp.portal.ecomp.model.AppContactUsItem;
 
  59 import org.onap.portalapp.portal.framework.MockitoTestSuite;
 
  60 import org.onap.portalapp.portal.service.AppContactUsService;
 
  61 import org.onap.portalapp.portal.service.AppContactUsServiceImpl;
 
  62 import org.onap.portalsdk.core.service.DataAccessService;
 
  63 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
 
  65 public class AppContactUsServiceImplTest {
 
  69          DataAccessService dataAccessService = new DataAccessServiceImpl();
 
  72      AppContactUsService AppContactUsService = new AppContactUsServiceImpl();
 
  76                 MockitoAnnotations.initMocks(this);
 
  80      AppContactUsServiceImpl appContactUsServiceImpl = new AppContactUsServiceImpl();
 
  82         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
 
  84         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
 
  85         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
 
  86         NullPointerException nullPointerException = new NullPointerException();
 
  89         public EPApp getApp() {
 
  90                 EPApp app = new EPApp();
 
  92                 app.setImageUrl("test");
 
  93                 app.setDescription("test");
 
  97                 app.setAppRestEndpoint("test");
 
  98                 app.setAlternateUrl("test");
 
 100                 app.setMlAppName("test");
 
 101                 app.setMlAppAdminId("test");
 
 102                 app.setUsername("test");
 
 103                 app.setAppPassword("test");
 
 105                 app.setEnabled(false);
 
 106                 app.setUebKey("test");
 
 107                 app.setUebSecret("test");
 
 108                 app.setUebTopicName("test");
 
 113         public void getAppContactUsTest() throws Exception
 
 116                 List<AppContactUsItem> contactUsItemList  = new ArrayList<>();
 
 117                 AppContactUsItem appContactUsItem= new AppContactUsItem();
 
 118                 appContactUsItem.setAppName("testNew");
 
 119                 contactUsItemList.add(appContactUsItem);
 
 120                 AppContactUsItem appContactUsItem1= new AppContactUsItem();
 
 121                 appContactUsItem1.setAppName("test");
 
 122                 contactUsItemList.add(appContactUsItem1);
 
 123                 Mockito.when(dataAccessService.executeNamedQuery("getAppContactUsItems", null, null)).thenReturn(contactUsItemList);
 
 124                 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppContactUs();
 
 125                 assertEquals(expectedcontactUsItemList, contactUsItemList);             
 
 129         public void getAppsAndContactsTest() throws Exception
 
 131                 List<AppContactUsItem> contactUsItemList  = new ArrayList<>();
 
 132                 AppContactUsItem appContactUsItem= new AppContactUsItem();
 
 133                 appContactUsItem.setAppName("testNew");
 
 134                 contactUsItemList.add(appContactUsItem);
 
 135                 AppContactUsItem appContactUsItem1= new AppContactUsItem();
 
 136                 appContactUsItem1.setAppName("test");
 
 137                 contactUsItemList.add(appContactUsItem1);
 
 138                 Mockito.when(dataAccessService.executeNamedQuery("getAppsAndContacts", null, null)).thenReturn(contactUsItemList);
 
 139                 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppsAndContacts();
 
 140                 assertEquals(expectedcontactUsItemList, contactUsItemList);             
 
 144         public void getAppCategoryFunctionsTest() throws Exception
 
 146                 List<AppCategoryFunctionsItem> list  = new ArrayList<>();
 
 147                 Mockito.when(dataAccessService.executeNamedQuery("getAppCategoryFunctions", null, null)).thenReturn(list);
 
 148                 List<AppCategoryFunctionsItem> expectedlist = appContactUsServiceImpl.getAppCategoryFunctions();
 
 149                 assertEquals(list, expectedlist); 
 
 152         @Test(expected = java.lang.Exception.class)
 
 153         public void saveAppContactUsTest() throws Exception
 
 155                 HashMap<String, Object> map = new HashMap<String, Object>();
 
 156                 List<AppContactUsItem> contactUsModelList = new ArrayList<>();
 
 157                 AppContactUsItem appContactUsItem= new AppContactUsItem();
 
 158                 appContactUsItem.setAppId((long) 1);
 
 159                 contactUsModelList.add(appContactUsItem);
 
 160                 AppContactUs appContact = new AppContactUs();
 
 161                 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(appContact);
 
 162                 EPApp app = getApp();
 
 163                 Mockito.when(dataAccessService.getDomainObject(EPApp.class, 1, new HashMap<String, Object>())).thenReturn(app);
 
 164                 AppContactUs contactUs  = new AppContactUs();
 
 165                 contactUs.setApp(app);
 
 166                 contactUs.setDescription(appContactUsItem.getDescription());
 
 167                 contactUs.setContactName(appContactUsItem.getContactName());
 
 168                 contactUs.setContactEmail(appContactUsItem.getContactEmail());
 
 169                 contactUs.setActiveYN(appContactUsItem.getActiveYN());
 
 170                 contactUs.setUrl(appContactUsItem.getUrl());
 
 171                 Mockito.doNothing().when(dataAccessService).saveDomainObject(contactUs,map);
 
 172                 appContactUsServiceImpl.saveAppContactUs(contactUsModelList);
 
 175         @Test(expected = java.lang.NullPointerException.class)
 
 176         public void deleteContactUsTest() throws Exception
 
 178                 HashMap<String, Object> map = new HashMap<String, Object>();
 
 179                 AppContactUs contactUs = new AppContactUs();
 
 180                 Mockito.when((AppContactUs) dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(contactUs);
 
 181                 appContactUsServiceImpl.deleteContactUs((long) 1);