From 2036d5039c90736c54484e539f37dfb8f661e4f1 Mon Sep 17 00:00:00 2001 From: Hari Om Verma Date: Tue, 13 Feb 2018 13:35:03 +0530 Subject: Unit Test Case for PersUserWidgetServiceImpl.java Added JUnit test cases for PersUserWidgetServiceImpl.java Change-Id: I21ba2fbe3ddc230db9d67e85b8a9d1ea6944c6aa Issue-ID: PORTAL-192 Signed-off-by: Hari Om Verma --- .../service/PersUserWidgetServiceImplTest.java | 145 +++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserWidgetServiceImplTest.java (limited to 'ecomp-portal-BE-common/src/test/java/org') diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserWidgetServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserWidgetServiceImplTest.java new file mode 100644 index 00000000..67c56eb3 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserWidgetServiceImplTest.java @@ -0,0 +1,145 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : PORTAL +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package org.onap.portalapp.portal.service; + +import java.util.ArrayList; +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.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.domain.PersUserWidgetSelection; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalsdk.core.service.DataAccessService; + +public class PersUserWidgetServiceImplTest { + + @Mock + DataAccessService dataAccessService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + PersUserWidgetServiceImpl persUserWidgetServiceImpl = new PersUserWidgetServiceImpl(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + + @Test(expected = IllegalArgumentException.class) + public void setPersUserAppValueIfUserNull() { + persUserWidgetServiceImpl.setPersUserAppValue(null, null, false); + } + + @Test + public void setPersUserAppValueTest() { + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + persUserWidgetSelection.setId((long) 1); + persUserAppSelectionList.add(persUserWidgetSelection); + Mockito.when(dataAccessService.getList(PersUserWidgetSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + persUserWidgetServiceImpl.setPersUserAppValue(user, (long)999, false); + } + + public void setPersUserAppValueTestPass() { + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + persUserWidgetSelection.setId((long) 1); + persUserAppSelectionList.add(persUserWidgetSelection); + Mockito.when(dataAccessService.getList(PersUserWidgetSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + persUserWidgetServiceImpl.setPersUserAppValue(user, (long)999, false); + } + + @Test + public void setPersUserAppValueIfSelectTest_DeleteDomain() { + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + persUserWidgetSelection.setId((long) 1); + persUserAppSelectionList.add(persUserWidgetSelection); + Mockito.when(dataAccessService.getList(PersUserWidgetSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + persUserWidgetServiceImpl.setPersUserAppValue(user, (long)999, true); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserWidgetSelection, null); + } + + @Test + public void setPersUserAppValueIfSelectTest_SaveDomain() { + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + persUserWidgetSelection.setId(null); + persUserAppSelectionList.add(persUserWidgetSelection); + Mockito.when(dataAccessService.getList(PersUserWidgetSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserWidgetSelection, null); + persUserWidgetServiceImpl.setPersUserAppValue(user, (long)999, true); + persUserWidgetSelection.setStatusCode("S"); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserWidgetSelection, null); + } + + @Test + public void setPersUserAppValueWithoutSelectTest_DeleteDomain() { + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + persUserAppSelectionList.add(persUserWidgetSelection); + Mockito.when(dataAccessService.getList(PersUserWidgetSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + persUserWidgetServiceImpl.setPersUserAppValue(user, (long)999, false); + persUserWidgetSelection.setId((long) 1); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserWidgetSelection, null); + } + + @Test + public void setPersUserAppValueWithoutSelectTest_SaveDomain() { + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + persUserWidgetSelection.setId(null); + persUserAppSelectionList.add(persUserWidgetSelection); + Mockito.when(dataAccessService.getList(PersUserWidgetSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + persUserWidgetServiceImpl.setPersUserAppValue(user, (long)999, false); + persUserWidgetSelection.setStatusCode("H"); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserWidgetSelection, null); + } + + +} -- cgit 1.2.3-korg