diff options
author | 2017-09-25 16:07:54 -0400 | |
---|---|---|
committer | 2017-09-25 16:09:15 -0400 | |
commit | 23634dba70b166ad3c79b5eadfbd32b5375d44be (patch) | |
tree | ab0ea364c8da4f91fb8c7e2819692498939fb419 /ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImplTest.java | |
parent | 4ba6a0f20a190030700917a6065a6779ca9d308f (diff) |
MariaDB Connector and Sonar Scans; clean nl
PORTAL-50: Fix to get the Sonar coverage for ONAP
PORTAL-72: Sonar scan - resolving severity Blocker issues
PORTAL-86: Remove internal att.com usages from tests and other files
PORTAL-102: Fixed the page refresh issue on App Account Management page
PORTAL-103: Fix to enhanced notification ticket source for ONAP
PORTAL-104: Replaced mysql DB connector with mariaDB
Issue: PORTAL-50 PORTAL-72 PORTAL-86 PORTAL-102 PORTAL-103 PORTAL-104
Change-Id: Iae78ad34ed9ce5ae1f2d36fcbb93fbc1e39944e5
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImplTest.java')
-rw-r--r-- | ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImplTest.java | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImplTest.java new file mode 100644 index 00000000..5c6d04f5 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImplTest.java @@ -0,0 +1,147 @@ +package org.openecomp.portalapp.portal.service; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.domain.AppContactUs; +import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem; +import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem; +import org.openecomp.portalapp.portal.service.AppContactUsService; +import org.openecomp.portalapp.portal.service.AppContactUsServiceImpl; +import org.openecomp.portalapp.portal.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.service.DataAccessServiceImpl; + +public class AppContactUsServiceImplTest { + + + @Mock + DataAccessService dataAccessService = new DataAccessServiceImpl(); + + @Mock + AppContactUsService AppContactUsService = new AppContactUsServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + AppContactUsServiceImpl appContactUsServiceImpl = new AppContactUsServiceImpl(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + + public EPApp getApp() { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(true); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + @Test + public void getAppContactUsTest() throws Exception + { + + List<AppContactUsItem> contactUsItemList = new ArrayList<>(); + AppContactUsItem appContactUsItem= new AppContactUsItem(); + appContactUsItem.setAppName("testNew"); + contactUsItemList.add(appContactUsItem); + AppContactUsItem appContactUsItem1= new AppContactUsItem(); + appContactUsItem1.setAppName("test"); + contactUsItemList.add(appContactUsItem1); + Mockito.when(dataAccessService.executeNamedQuery("getAppContactUsItems", null, null)).thenReturn(contactUsItemList); + List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppContactUs(); + assertEquals(expectedcontactUsItemList, contactUsItemList); + } + + @Test + public void getAppsAndContactsTest() throws Exception + { + List<AppContactUsItem> contactUsItemList = new ArrayList<>(); + AppContactUsItem appContactUsItem= new AppContactUsItem(); + appContactUsItem.setAppName("testNew"); + contactUsItemList.add(appContactUsItem); + AppContactUsItem appContactUsItem1= new AppContactUsItem(); + appContactUsItem1.setAppName("test"); + contactUsItemList.add(appContactUsItem1); + Mockito.when(dataAccessService.executeNamedQuery("getAppsAndContacts", null, null)).thenReturn(contactUsItemList); + List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppsAndContacts(); + assertEquals(expectedcontactUsItemList, contactUsItemList); + } + + @Test + public void getAppCategoryFunctionsTest() throws Exception + { + List<AppCategoryFunctionsItem> list = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getAppCategoryFunctions", null, null)).thenReturn(list); + List<AppCategoryFunctionsItem> expectedlist = appContactUsServiceImpl.getAppCategoryFunctions(); + assertEquals(list, expectedlist); + } + + @Test(expected = java.lang.Exception.class) + public void saveAppContactUsTest() throws Exception + { + HashMap<String, Object> map = new HashMap<String, Object>(); + List<AppContactUsItem> contactUsModelList = new ArrayList<>(); + AppContactUsItem appContactUsItem= new AppContactUsItem(); + appContactUsItem.setAppId((long) 1); + contactUsModelList.add(appContactUsItem); + AppContactUs appContact = new AppContactUs(); + Mockito.when(dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(appContact); + EPApp app = getApp(); + Mockito.when(dataAccessService.getDomainObject(EPApp.class, 1, new HashMap<String, Object>())).thenReturn(app); + AppContactUs contactUs = new AppContactUs(); + contactUs.setApp(app); + contactUs.setDescription(appContactUsItem.getDescription()); + contactUs.setContactName(appContactUsItem.getContactName()); + contactUs.setContactEmail(appContactUsItem.getContactEmail()); + contactUs.setActiveYN(appContactUsItem.getActiveYN()); + contactUs.setUrl(appContactUsItem.getUrl()); + Mockito.doNothing().when(dataAccessService).saveDomainObject(contactUs,map); + appContactUsServiceImpl.saveAppContactUs(contactUsModelList); + } + + @Test(expected = java.lang.NullPointerException.class) + public void deleteContactUsTest() throws Exception + { + HashMap<String, Object> map = new HashMap<String, Object>(); + AppContactUs contactUs = new AppContactUs(); + Mockito.when((AppContactUs) dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(contactUs); + appContactUsServiceImpl.deleteContactUs((long) 1); + } + +} |