diff options
author | Christopher Lott (cl778h) <clott@research.att.com> | 2017-09-25 16:07:54 -0400 |
---|---|---|
committer | Christopher Lott (cl778h) <clott@research.att.com> | 2017-09-25 16:09:15 -0400 |
commit | 23634dba70b166ad3c79b5eadfbd32b5375d44be (patch) | |
tree | ab0ea364c8da4f91fb8c7e2819692498939fb419 /ecomp-portal-BE-common-test/src/main | |
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-test/src/main')
107 files changed, 6823 insertions, 94 deletions
diff --git a/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppCatalogItemTest.java b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppCatalogItemTest.java new file mode 100644 index 00000000..6fb89146 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppCatalogItemTest.java @@ -0,0 +1,35 @@ +package com.openecomp.portalapp.portal.ecomp.test.model; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.ecomp.model.AppCatalogItem; + +public class AppCatalogItemTest { + + public AppCatalogItem mockAppCatalogItem(){ + AppCatalogItem appCatalogItem = new AppCatalogItem(); + + appCatalogItem.setAlternateUrl("test"); + appCatalogItem.setMlAppName("test"); + + return appCatalogItem; + } + + @Test + public void appCatalogItemTest(){ + AppCatalogItem appCatalogItem = mockAppCatalogItem(); + + AppCatalogItem appCatalogItem1 = new AppCatalogItem(); + appCatalogItem1.setAlternateUrl("test"); + appCatalogItem1.setMlAppName("test"); + + assertEquals(appCatalogItem.getAlternateUrl(), appCatalogItem1.getAlternateUrl()); + assertEquals(appCatalogItem.getMlAppName(), appCatalogItem1.getMlAppName()); + + assertEquals(appCatalogItem.toString(), "AppCatalogItem [id=null, name=null, access=null, select=null, pending=null]"); + assertEquals(appCatalogItem.hashCode(), appCatalogItem1.hashCode()); + assertTrue(appCatalogItem.equals(appCatalogItem1)); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppCategoryFunctionsItemTest.java b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppCategoryFunctionsItemTest.java new file mode 100644 index 00000000..74e74b37 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppCategoryFunctionsItemTest.java @@ -0,0 +1,42 @@ +package com.openecomp.portalapp.portal.ecomp.test.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem; + +public class AppCategoryFunctionsItemTest { + + public AppCategoryFunctionsItem mockAppCategoryFunctionsItem(){ + AppCategoryFunctionsItem appCategoryFunctionsItem = new AppCategoryFunctionsItem(); + + appCategoryFunctionsItem.setRowId("test"); + appCategoryFunctionsItem.setAppId("test"); + appCategoryFunctionsItem.setApplication("test"); + appCategoryFunctionsItem.setFunctions("test"); + + return appCategoryFunctionsItem; + } + + @Test + public void appCategoryFunctionsItemTest(){ + AppCategoryFunctionsItem appCategoryFunctionsItem = mockAppCategoryFunctionsItem(); + + AppCategoryFunctionsItem appCategoryFunctionsItem1 = new AppCategoryFunctionsItem(); + + appCategoryFunctionsItem1.setRowId("test"); + appCategoryFunctionsItem1.setAppId("test"); + appCategoryFunctionsItem1.setApplication("test"); + appCategoryFunctionsItem1.setFunctions("test"); + + assertEquals(appCategoryFunctionsItem.getRowId(), appCategoryFunctionsItem1.getRowId()); + assertEquals(appCategoryFunctionsItem.getAppId(), appCategoryFunctionsItem1.getAppId()); + assertEquals(appCategoryFunctionsItem.getApplication(), appCategoryFunctionsItem1.getApplication()); + assertEquals(appCategoryFunctionsItem.getFunctions(), appCategoryFunctionsItem1.getFunctions()); + assertEquals(appCategoryFunctionsItem.toString(), "AppCategoryFunctionsItem [rowId=test, appId=test, application=test, category=null, functions=test]"); + assertEquals(appCategoryFunctionsItem.hashCode(), appCategoryFunctionsItem1.hashCode()); + assertTrue(appCategoryFunctionsItem.equals(appCategoryFunctionsItem1)); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppContactUsItemTest.java b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppContactUsItemTest.java new file mode 100644 index 00000000..41539282 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/AppContactUsItemTest.java @@ -0,0 +1,49 @@ +package com.openecomp.portalapp.portal.ecomp.test.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem; + +public class AppContactUsItemTest { + + public AppContactUsItem mockAppContactUsItem(){ + AppContactUsItem appContactUsItem = new AppContactUsItem(); + + appContactUsItem.setAppId((long)1); + appContactUsItem.setAppName("test"); + appContactUsItem.setDescription("test"); + appContactUsItem.setContactName("test"); + appContactUsItem.setContactEmail("test"); + appContactUsItem.setUrl("test"); + appContactUsItem.setActiveYN("test"); + + return appContactUsItem; + } + + @Test + public void appContactUsItemTest(){ + AppContactUsItem appContactUsItem = mockAppContactUsItem(); + + AppContactUsItem appContactUsItem1 = new AppContactUsItem(); + appContactUsItem1.setAppId((long)1); + appContactUsItem1.setAppName("test"); + appContactUsItem1.setDescription("test"); + appContactUsItem1.setContactName("test"); + appContactUsItem1.setContactEmail("test"); + appContactUsItem1.setUrl("test"); + appContactUsItem1.setActiveYN("test"); + + assertEquals(appContactUsItem.getAppId(), appContactUsItem1.getAppId()); + assertEquals(appContactUsItem.getAppName(), appContactUsItem1.getAppName()); + assertEquals(appContactUsItem.getDescription(), appContactUsItem1.getDescription()); + assertEquals(appContactUsItem.getContactName(), appContactUsItem1.getContactName()); + assertEquals(appContactUsItem.getContactEmail(), appContactUsItem1.getContactEmail()); + assertEquals(appContactUsItem.getUrl(), appContactUsItem1.getUrl()); + assertEquals(appContactUsItem.getActiveYN(), appContactUsItem1.getActiveYN()); + assertEquals(appContactUsItem.toString(), "AppContactUsItem [appId=1, appName=test, description=test, contactName=test, contactEmail=test, url=test, activeYN=test]"); + assertEquals(appContactUsItem.hashCode(), appContactUsItem1.hashCode()); + assertTrue(appContactUsItem.equals(appContactUsItem1)); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/SearchResultItemTest.java b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/SearchResultItemTest.java new file mode 100644 index 00000000..97e3be6c --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/com/openecomp/portalapp/portal/ecomp/test/model/SearchResultItemTest.java @@ -0,0 +1,41 @@ +package com.openecomp.portalapp.portal.ecomp.test.model; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem; + +public class SearchResultItemTest { + + public SearchResultItem mockSearchResultItem(){ + SearchResultItem searchResultItem = new SearchResultItem(); + + searchResultItem.setRowId("test"); + searchResultItem.setCategory("test"); + searchResultItem.setName("test"); + searchResultItem.setTarget("test"); + searchResultItem.setUuid("test"); + + return searchResultItem; + } + + @Test + public void searchResultItemTest(){ + SearchResultItem searchResultItem = mockSearchResultItem(); + + SearchResultItem searchResultItem1 = new SearchResultItem(); + searchResultItem1.setRowId("test"); + searchResultItem1.setCategory("test"); + searchResultItem1.setName("test"); + searchResultItem1.setTarget("test"); + searchResultItem1.setUuid("test"); + + assertEquals(searchResultItem.getRowId(), searchResultItem.getRowId()); + assertEquals(searchResultItem.getCategory(), searchResultItem.getCategory()); + assertEquals(searchResultItem.getName(), searchResultItem.getName()); + assertEquals(searchResultItem.getTarget(), searchResultItem.getTarget()); + assertEquals(searchResultItem.getUuid(), searchResultItem.getUuid()); + assertEquals(searchResultItem.toString(), searchResultItem.toString()); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/lm/FusionLicenseManagerImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/lm/FusionLicenseManagerImplTest.java new file mode 100644 index 00000000..23e4c28e --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/lm/FusionLicenseManagerImplTest.java @@ -0,0 +1,28 @@ +package org.openecomp.portalapp.lm; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; + +public class FusionLicenseManagerImplTest { + + + @Test + public void FusionLicenseManagerImplTest(){ + FusionLicenseManagerImpl fusionLicenseManagerImpl = new FusionLicenseManagerImpl(); + + String nvlReturn = null; + + int installLicenseInt = fusionLicenseManagerImpl.installLicense(); + nvlReturn = fusionLicenseManagerImpl.nvl("test"); + Date expiredDateReturn = fusionLicenseManagerImpl.getExpiredDate(); + + assertEquals(installLicenseInt, 0); + assertEquals(nvlReturn, null); + assertEquals(expiredDateReturn, null); + + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/lm/LicenseableClassImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/lm/LicenseableClassImplTest.java new file mode 100644 index 00000000..1d9f4a64 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/lm/LicenseableClassImplTest.java @@ -0,0 +1,30 @@ +package org.openecomp.portalapp.lm; + +import static org.junit.Assert.assertEquals; + +import java.io.FileNotFoundException; + +import org.junit.Test; + +public class LicenseableClassImplTest { + + @Test + public void licenseableClassImplTest() throws FileNotFoundException{ + LicenseableClassImpl licenseableClassImpl = new LicenseableClassImpl(); + + String appNameReturn = licenseableClassImpl.getApplicationName(); + java.io.InputStream inputStream = licenseableClassImpl.getPublicKeystoreAsInputStream(); + String aliasReturn = licenseableClassImpl.getAlias(); + String pswdReturn = licenseableClassImpl.getKeyPasswd(); + String pkPswd = licenseableClassImpl.getPublicKeystorePassword(); + String cpPswd = licenseableClassImpl.getCipherParamPassword(); + + assertEquals(appNameReturn, ""); + assertEquals(inputStream, null); + assertEquals(aliasReturn, ""); + assertEquals(pswdReturn, ""); + assertEquals(pkPswd, ""); + assertEquals(cpPswd, ""); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerExternalRequestTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerExternalRequestTest.java index 52993d65..1db55526 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerExternalRequestTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerExternalRequestTest.java @@ -67,8 +67,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Missing required field: email, loginId, or loginPwd"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); EPUser user = mockUser.mockEPUser(); user.setEmail("guestT@test.portal.onap.org"); Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); @@ -82,8 +81,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("java.lang.NullPointerException"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); EPUser user = mockUser.mockEPUser(); user.setEmail("guestT@test.portal.onap.org"); user.setLoginPwd("pwd"); @@ -100,8 +98,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage(null); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); EPUser user = mockUser.mockEPUser(); user.setEmail("guestT@test.portal.onap.org"); user.setLoginPwd("pwd"); @@ -120,8 +117,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage(null); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); EPUser user = mockUser.mockEPUser(); user.setEmail("guestT@test.portal.onap.org"); user.setLoginPwd("pwd"); @@ -142,8 +138,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage(null); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); EPUser user = mockUser.mockEPUser(); user.setEmail("guestT@test.portal.onap.org"); user.setLoginPwd("pwd"); @@ -175,8 +170,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("FieldsValidator [httpStatusCode=500, errorCode=null, fields=null]"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); EPUser user = mockUser.mockEPUser(); user.setEmail("guestT@test.portal.onap.org"); user.setLoginPwd("pwd"); @@ -210,8 +204,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Unexpected field: id"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); OnboardingApp expectedOnboardingApp = new OnboardingApp(); expectedOnboardingApp.id = (long) 1; @@ -227,8 +220,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { expectedportalRestResponse.setMessage( "Missing required field: name, url, restUrl, restrictedApp, isOpen, isEnabled, myLoginsAppOwner"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); OnboardingApp expectedOnboardingApp = new OnboardingApp(); expectedOnboardingApp.id = null; @@ -244,8 +236,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Unexpected value for field: id"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); Long appId = null; OnboardingApp expectedOnboardingApp = new OnboardingApp(); expectedOnboardingApp.id = null; @@ -261,8 +252,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite { expectedportalRestResponse.setMessage( "Missing required field: name, url, restUrl, restrictedApp, isOpen, isEnabled, myLoginsAppOwner"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); Long appId = (long) 1; OnboardingApp expectedOnboardingApp = new OnboardingApp(); expectedOnboardingApp.id = (long) 1; diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AuditLogControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AuditLogControllerTest.java new file mode 100644 index 00000000..33079b0c --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AuditLogControllerTest.java @@ -0,0 +1,102 @@ +package org.openecomp.portalapp.portal.test.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.controller.AuditLogController; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.service.AuditService; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(EPUserUtils.class) +public class AuditLogControllerTest { + + + @Mock + AuditService auditService; + + @InjectMocks + AuditLogController auditLogController = new AuditLogController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + @Test + public void auditLogTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "app", "test"); + } + + @Test + public void auditLogTabTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "tab", "test"); + } + + @Test + public void auditLogfunctionalTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "functional", "test"); + } + + @Test + public void auditLogleftMenuTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "leftMenu", "test"); + } + + @Test(expected = NumberFormatException.class) + public void auditLogExceptionTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "app", "test"); + } + + @Test + public void auditLogerrorTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenThrow(nullPointerException); + auditLogController.auditLog(mockedRequest, "1", "app", "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java index b621d9ad..e4d34ceb 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java @@ -66,7 +66,6 @@ public class BEPropertyReaderControllerTest extends MockitoTestSuite { PowerMockito.mockStatic(SystemProperties.class); Mockito.when(new BEProperty(key, SystemProperties.getProperty(key))).thenThrow(nullPointerException); actualPortalRestResponse = bEPropertyReaderController.readProperty(mockedRequest, key); - System.out.println(actualPortalRestResponse); assertTrue(actualPortalRestResponse.equals(ecpectedPortalRestResponse)); } diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java index 70505274..8f9549ce 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java @@ -86,8 +86,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("SUCCESS"); expectedResponse.setResponse(""); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.OK); + expectedResponse.setStatus(PortalRestStatusEnum.OK); long accountd = 1; Mockito.when(basicAuthAccountService.saveBasicAuthAccount(basicAuthCredentials)).thenReturn(accountd); @@ -106,8 +105,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("Authorization Required"); expectedResponse.setResponse("Admin Only Operation! "); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); PortalRestResponse<String> actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest, mockedResponse, basicAuthCredentials); @@ -123,8 +121,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("FAILURE"); expectedResponse.setResponse("newBasicAuthAccount cannot be null or empty"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); PortalRestResponse<String> actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest, mockedResponse, basicAuthCredentials); assertEquals(actualResponse, expectedResponse); @@ -139,8 +136,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { expectedPortalResponse.setMessage("Success"); expectedPortalResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedPortalResponse.setStatus(portalRestStatusEnum.OK); + expectedPortalResponse.setStatus(PortalRestStatusEnum.OK); EPUser user = mockUser.mockEPUser(); Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); @@ -161,8 +157,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { expectedPortalResponse.setMessage("UnAuthorized! Admin Only Operation"); expectedPortalResponse.setResponse(new ArrayList<>()); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedPortalResponse.setStatus(portalRestStatusEnum.ERROR); + expectedPortalResponse.setStatus(PortalRestStatusEnum.ERROR); EPUser user = mockUser.mockEPUser(); Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); @@ -183,8 +178,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("SUCCESS"); expectedResponse.setResponse(""); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.OK); + expectedResponse.setStatus(PortalRestStatusEnum.OK); long accountd = 1; PortalRestResponse<String> actualResponse = basicAuthAccountController.updateAccount(mockedRequest, mockedResponse, accountd, basicAuthCredentials); @@ -201,8 +195,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("Authorization Required"); expectedResponse.setResponse("Admin Only Operation! "); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); long accountd = 1; PortalRestResponse<String> actualResponse = basicAuthAccountController.updateAccount(mockedRequest, mockedResponse, accountd, basicAuthCredentials); @@ -219,8 +212,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("FAILURE"); expectedResponse.setResponse("BasicAuthCredentials cannot be null or empty"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); long accountd = 1; PortalRestResponse<String> actualResponse = basicAuthAccountController.updateAccount(mockedRequest, mockedResponse, accountd, basicAuthCredentials); @@ -235,8 +227,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("SUCCESS"); expectedResponse.setResponse(""); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.OK); + expectedResponse.setStatus(PortalRestStatusEnum.OK); long accountd = 1; Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); PortalRestResponse<String> actualResponse = basicAuthAccountController.deleteAccount(mockedRequest, @@ -252,8 +243,7 @@ public class BasicAuthAccountControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("Authorization Required"); expectedResponse.setResponse("Admin Only Operation! "); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedResponse.setStatus(portalRestStatusEnum.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); long accountd = 1; Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); PortalRestResponse<String> actualResponse = basicAuthAccountController.deleteAccount(mockedRequest, diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/DashboardControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/DashboardControllerTest.java new file mode 100644 index 00000000..eed560de --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/DashboardControllerTest.java @@ -0,0 +1,427 @@ +package org.openecomp.portalapp.portal.test.controller; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.controller.DashboardController; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.openecomp.portalapp.portal.service.DashboardSearchService; +import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.portal.transport.CommonWidget; +import org.openecomp.portalapp.portal.transport.CommonWidgetMeta; +import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.domain.support.CollaborateList; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EPUserUtils.class, CollaborateList.class, SystemProperties.class, EPCommonSystemProperties.class}) +public class DashboardControllerTest { + + @Mock + DashboardSearchService searchService = new DashboardSearchServiceImpl(); + + @InjectMocks + DashboardController dashboardController = new DashboardController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + public CommonWidgetMeta mockCommonWidgetMeta() { + CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta(); + List<CommonWidget> widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("testhref"); + commonWidget.setTitle("testTitle"); + commonWidget.setContent("testcontent"); + commonWidget.setEventDate("testDate"); + commonWidget.setSortOrder(1); + widgetList.add(commonWidget); + commonWidgetMeta.setItems(widgetList); + + return commonWidgetMeta; + } + + public CommonWidget mockCommonWidget() { + + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("testhref"); + commonWidget.setTitle("testTitle"); + commonWidget.setContent("testcontent"); + commonWidget.setEventDate("testDate"); + commonWidget.setSortOrder(1); + + return commonWidget; + } + + + @Test + public void getWidgetDataTest() throws IOException { + + String resourceType = null; + PortalRestResponse<CommonWidgetMeta> expectedData = new PortalRestResponse<CommonWidgetMeta>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Unexpected resource type null"); + expectedData.setResponse(null); + + PortalRestResponse<CommonWidgetMeta> actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getWidgetDataWithValidResourceTest() throws IOException { + String resourceType = "EVENTS"; + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory(null); + + Mockito.when(searchService.getWidgetData(resourceType)).thenReturn(commonWidgetMeta); + PortalRestResponse<CommonWidgetMeta> expectedData = new PortalRestResponse<CommonWidgetMeta>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse(commonWidgetMeta); + + PortalRestResponse<CommonWidgetMeta> actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType); + System.out.println(actualResponse); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataBulkNullTest() throws IOException { + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory(null); + + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("ERROR"); + expectedData.setResponse("Category cannot be null or empty"); + + PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetUnexpectedDataBulkTest() throws IOException { + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory("Unexpected Data"); + + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Unexpected resource type Unexpected Data"); + expectedData.setResponse(null); + + PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void saveWidgetInvalidDataBulkTest() throws IOException { + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory("EVENTS"); + + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Invalid category: test"); + expectedData.setResponse(null); + + PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataBulkTest() throws IOException { + + List<CommonWidget> widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget("EVENTS", "http://test.com", "testTitle", "testcontent", "2017-07-01", 1); + widgetList.add(commonWidget); + CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta("EVENTS", widgetList); + + + + /* commonWidgetMeta.setItems(widgetList); + + commonWidgetMeta.setCategory("EVENTS");*/ + + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("success"); + + Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn("success"); + + PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataNullTest() throws IOException { + + CommonWidget commonWidget = mockCommonWidget(); + commonWidget.setId((long)1); + commonWidget.setContent("test"); + commonWidget.setCategory(null); + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("ERROR"); + expectedData.setResponse("Category cannot be null or empty"); + + PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void saveWidgetDataErrorTest() throws IOException { + + CommonWidget commonWidget = mockCommonWidget(); + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Invalid category: test"); + expectedData.setResponse(null); + + PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataTest() throws IOException { + + CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta(); + List<CommonWidget> widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("EVENTS"); + commonWidget.setHref("http://test.com"); + commonWidget.setTitle("testTitle"); + commonWidget.setContent("testcontent"); + commonWidget.setEventDate("2017-07-01"); + commonWidget.setSortOrder(1); + widgetList.add(commonWidget); + commonWidgetMeta.setItems(widgetList); + + commonWidgetMeta.setCategory("EVENTS"); + + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("success"); + + Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn("success"); + + PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void deleteWidgetDataTest() throws IOException { + + CommonWidget commonWidget = mockCommonWidget(); + + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse(null); + + Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn("success"); + + PortalRestResponse<String> actualResponse = dashboardController.deleteWidgetData(commonWidget); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void getActiveUsersTest(){ + List<String> activeUsers = new ArrayList<>(); + List<String> expectedUsersList = new ArrayList<>(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String userId = user.getOrgUserId(); + Mockito.when(searchService.getRelatedUsers(userId)).thenReturn(activeUsers); + expectedUsersList= dashboardController.getActiveUsers(mockedRequest); + assertEquals(expectedUsersList, activeUsers); + } + + + @Test + public void getActiveUsersExceptionTest(){ + List<String> activeUsers = new ArrayList<>(); + List<String> expectedUsersList = new ArrayList<>(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String userId = user.getOrgUserId(); + Mockito.when(searchService.getRelatedUsers(userId)).thenThrow(nullPointerException); + expectedUsersList = dashboardController.getActiveUsers(mockedRequest); + assertEquals(expectedUsersList, activeUsers); + } + + @Test + public void getOnlineUserUpdateRateTest(){ + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("{onlineUserUpdateRate=1400000, onlineUserUpdateDuration=1400000}"); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION)).thenReturn("1400"); + + PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest); + assertEquals(expectedData.getStatus(),actualResponse.getStatus()); + } + + @Test + public void getOnlineUserUpdateRateExceptionTest(){ + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("java.lang.NullPointerException"); + expectedData.setResponse(null); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE)).thenThrow(nullPointerException); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION)).thenThrow(nullPointerException); + + PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getWindowWidthThresholdForRightMenuTest(){ + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("{windowWidth=1400}"); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenReturn("1400"); + + PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest); + assertEquals(expectedData.getStatus(),actualResponse.getStatus()); + } + + @Test + public void getWindowWidthThresholdForRightMenuExceptionTest(){ + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("java.lang.NullPointerException"); + expectedData.setResponse(null); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenThrow(nullPointerException); + + PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getWindowWidthThresholdForLeftMenuTest(){ + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("{windowWidth=1400}"); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenReturn("1400"); + + PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest); + assertEquals(expectedData.getStatus(),actualResponse.getStatus()); + } + + @Test + public void getWindowWidthThresholdForLeftMenuExceptionTest(){ + PortalRestResponse<String> expectedData = new PortalRestResponse<String>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("java.lang.NullPointerException"); + expectedData.setResponse(null); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenThrow(nullPointerException); + + PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getActiveUsersNullTest(){ + PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("User object is null? - check logs"); + expectedData.setResponse(new ArrayList<>()); + + PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void activeUsersTest(){ + EPUser user = mockUser.mockEPUser(); + PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse(new ArrayList<>()); + PowerMockito.mockStatic(EPUserUtils.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest); + assertEquals(expectedData,actualResponse); + } + +// @Test +// public void activeUsersExceptionTest(){ +// EPUser user = mockUser.mockEPUser(); +// user.setLoginId("test"); +// String loginId = "abc"; +// PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>(); +// expectedData.setStatus(PortalRestStatusEnum.ERROR); +// expectedData.setMessage("java.lang.NullPointerException"); +// expectedData.setResponse(null); +// +//// PowerMockito.mockStatic(EPUserUtils.class); +// Mockito.when(searchService.getRelatedUsers(user.getLoginId(user.getLoginId()))).thenReturn(nullPointerException); +// PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest); +// System.out.println(actualResponse); +// //assertEquals(expectedData,actualResponse); +// } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/EPFusionBaseControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/EPFusionBaseControllerTest.java new file mode 100644 index 00000000..683738b9 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/EPFusionBaseControllerTest.java @@ -0,0 +1,64 @@ +package org.openecomp.portalapp.portal.test.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.controller.EPFusionBaseController; +import org.openecomp.portalapp.portal.controller.DashboardController; +import org.openecomp.portalapp.portal.service.DashboardSearchService; +import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EPUserUtils.class, SystemProperties.class}) +public class EPFusionBaseControllerTest { + + @Mock + DashboardSearchService searchService = new DashboardSearchServiceImpl(); + + @InjectMocks + EPFusionBaseController epFusionBaseController; /*= mock(EPFusionBaseController.class);*/ + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void messagesTest(){ + Map<String, Object> expectedData = new HashMap<String, Object>(); + Map<String, Object> actualData = null; + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME)).then(null); + actualData = epFusionBaseController.messages(mockedRequest); + System.out.println(); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ExternalAccessRolesControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ExternalAccessRolesControllerTest.java new file mode 100644 index 00000000..d2e1b13c --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ExternalAccessRolesControllerTest.java @@ -0,0 +1,509 @@ +package org.openecomp.portalapp.portal.test.controller; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +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.openecomp.portalapp.portal.controller.ExternalAccessRolesController; +import org.openecomp.portalapp.portal.domain.CentralRoleFunction; +import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.openecomp.portalapp.portal.service.ExternalAccessRolesService; +import org.openecomp.portalapp.portal.service.ExternalAccessRolesServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.portal.transport.CentralRole; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.domain.AuditLog; +import org.openecomp.portalsdk.core.domain.Role; +import org.springframework.http.HttpStatus; +import org.springframework.web.client.HttpClientErrorException; +public class ExternalAccessRolesControllerTest { + + @Mock + ExternalAccessRolesService externalAccessRolesService = new ExternalAccessRolesServiceImpl(); + + @InjectMocks + ExternalAccessRolesController externalAccessRolesController = new ExternalAccessRolesController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Mock + AuditLog auditLog = new AuditLog(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Failed"); + + MockEPUser mockUser = new MockEPUser(); + String loginId = "guestT"; + String uebKey = "testUebKey"; + + @Test + public void getUserTest() throws Exception { + List<EPUser> userList = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getUser(loginId)).thenReturn(userList); + assertNull(externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId)); + } + + @Test + public void getUserExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.getUser(loginId)) + .thenThrow(nullPointerException); + assertNull(externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId)); + } + + public EPApp mockApp() + { + 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(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + + @Test + public void getRolesForAppTest() throws Exception { + List<EPApp> applicationList = new ArrayList<EPApp>(); + List<CentralRole> answer = new ArrayList<>(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app); + Mockito.when(externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey))).thenReturn(answer); + assertEquals(externalAccessRolesController.getRolesForApp(mockedRequest, mockedResponse), answer); + } + + @Test + public void getRolesForAppExceptionTest() throws Exception { + List<EPApp> applicationList = new ArrayList<EPApp>(); + List<CentralRole> answer = new ArrayList<>(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app); + Mockito.when(externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertNull(externalAccessRolesController.getRolesForApp(mockedRequest, mockedResponse)); + } + + @Test + public void getRoleFunctionsListTest() throws Exception { + List<CentralRoleFunction> answer = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getRoleFuncList(mockedRequest.getHeader(uebKey))).thenReturn(answer); + assertEquals(externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse), answer); + } + + @Test + public void getRoleFunctionsListExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.getRoleFuncList(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertNull(externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse)); + } + + @Test + public void getRoleInfoTest() throws Exception { + CentralRole answer = new CentralRole(); + long roleId = 1; + Mockito.when(externalAccessRolesService.getRoleInfo(roleId, mockedRequest.getHeader(uebKey))) + .thenReturn(answer); + assertEquals(externalAccessRolesController.getRoleInfo(mockedRequest, mockedResponse, roleId), answer); + } + + @Test + public void getRoleInfoExceptionTest() throws Exception { + long roleId = 1; + Mockito.when(externalAccessRolesService.getRoleInfo(roleId, mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertNull(externalAccessRolesController.getRoleInfo(mockedRequest, mockedResponse, roleId)); + } + + @Test + public void getRoleFunctionTest() throws Exception { + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + String code = "test_menu"; + Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader(uebKey))) + .thenReturn(centralRoleFunction); + assertEquals(externalAccessRolesController.getRoleFunction(mockedRequest, mockedResponse, code), + centralRoleFunction); + } + + @Test + public void getRoleFunctionExceptionTest() throws Exception { + String code = "test_menu"; + Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertNull(externalAccessRolesController.getRoleFunction(mockedRequest, mockedResponse, code)); + } + + @Test + public void saveRoleFunctionIfIsIsNotDeletedTest() throws Exception { + List<EPApp> applicationList = new ArrayList<EPApp>(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + String data = null; + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + Mockito.when(externalAccessRolesService.saveCentralRoleFunction(centralRoleFunction, app)).thenReturn(false); + portalRestResponse = externalAccessRolesController.saveRoleFunction(mockedRequest, mockedResponse, data); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void saveRoleFunctionExceptionTest() throws Exception { + List<EPApp> applicationList = new ArrayList<EPApp>(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + String data = null; + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + Mockito.when(externalAccessRolesService.saveCentralRoleFunction(centralRoleFunction, app)).thenThrow(nullPointerException); + portalRestResponse = externalAccessRolesController.saveRoleFunction(mockedRequest, mockedResponse, data); + System.out.println(portalRestResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void saveRoleFunctionTest() throws Exception { + List<EPApp> applicationList = new ArrayList<EPApp>(); + List<CentralRole> answer = new ArrayList<>(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + String data = null; + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + Mockito.when(externalAccessRolesService.saveCentralRoleFunction(centralRoleFunction, app)).thenReturn(true); + portalRestResponse = externalAccessRolesController.saveRoleFunction(mockedRequest, mockedResponse, data); + System.out.println(portalRestResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + +// @Test +// public void deleteRoleFunctionTest() throws Exception { +// PortalRestResponse<String> portalRestResponse = null; +// PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); +// expectedportalRestResponse.setMessage("Successfully Deleted"); +// expectedportalRestResponse.setResponse("Success"); +// PortalRestStatusEnum portalRestStatusEnum = null; +// EPUser user = mockUser.mockEPUser(); +// EPApp app = mockApp(); +// expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); +// String code ="testNew"; +// Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LOGIN_ID"))).thenReturn((List<EPUser>) user); +// Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("UEBKEY")).get(0)).thenReturn(app); +// Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(code, app)).thenReturn(true); +// portalRestResponse = externalAccessRolesController.deleteRoleFunction(mockedRequest, mockedResponse, code); +// assertEquals(portalRestResponse, expectedportalRestResponse); +// } + + @Test + public void getActiveRolesTest() throws Exception { + List<CentralRole> cenRole = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))).thenReturn(cenRole); + List<CentralRole> expectedCenRole = externalAccessRolesController.getActiveRoles(mockedRequest, mockedResponse); + assertEquals(expectedCenRole, cenRole); + } + + @Test + public void getActiveRolesExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertNull(externalAccessRolesController.getActiveRoles(mockedRequest, mockedResponse)); + } + + @Test + public void deleteDependcyRoleRecordExceptionTest() throws Exception { + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Failed to deleteDependencyRoleRecord"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + long roleId = 123; + portalRestResponse = externalAccessRolesController.deleteDependencyRoleRecord(mockedRequest, mockedResponse, roleId); + assertEquals(expectedportalRestResponse, portalRestResponse); + } + + @Test + public void bulkUploadFunctionsTest() throws Exception { + Integer result = 0; + Mockito.when(externalAccessRolesService.bulkUploadFunctions(mockedRequest.getHeader(uebKey))) + .thenReturn(result); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + portalRestResponse = externalAccessRolesController.bulkUploadFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadFunctionsExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadFunctions(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Failed to bulkUploadFunctions"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRolesTest() throws Exception { + Integer result = 0; + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + Mockito.when(externalAccessRolesService.bulkUploadRoles(mockedRequest.getHeader(uebKey))).thenReturn(result); + portalRestResponse = externalAccessRolesController.bulkUploadRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRolesTestException() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadRoles(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Failed to bulkUploadRoles"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRoleFunctionsTest() throws Exception { + Integer result = 0; + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + Mockito.when(externalAccessRolesService.bulkUploadRolesFunctions(mockedRequest.getHeader(uebKey))) + .thenReturn(result); + portalRestResponse = externalAccessRolesController.bulkUploadRoleFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRoleFunctionsException() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadRolesFunctions(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Failed to bulkUploadRoleFunctions"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadRoleFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadUserRolesTest() throws Exception { + Integer result = 0; + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + Mockito.when(externalAccessRolesService.bulkUploadUserRoles(mockedRequest.getHeader(uebKey))) + .thenReturn(result); + portalRestResponse = externalAccessRolesController.bulkUploadUserRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadUserRolesExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadUserRoles(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Failed to bulkUploadUserRoles"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadUserRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadPartnerFunctionsTest() throws Exception { + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerFunctions(mockedRequest, mockedResponse, null); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + + @Test + public void bulkUploadPartnerRolesTest() throws Exception { + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + List<Role> upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerRoles(mockedRequest, mockedResponse, + upload); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadPartnerRolesExceptionTest() throws Exception + { + ExternalAccessRolesService externalAccessRolesService = null; + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + List<Role> upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerRoles(mockedRequest, mockedResponse, + upload); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void getMenuFunctionsTest() throws Exception { + List<String> functionsList = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getMenuFunctionsList(mockedRequest.getHeader(uebKey))) + .thenReturn(functionsList); + List<String> expectedFunctionsList = externalAccessRolesController.getMenuFunctions(mockedRequest, + mockedResponse); + assertEquals(functionsList, expectedFunctionsList); + } + + @Test + public void getMenuFunctionsExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.getMenuFunctionsList(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertNull(externalAccessRolesController.getMenuFunctions(mockedRequest, mockedResponse)); + } + +// @Test +// public void getUsersOfApplicationTest() throws Exception { +// List<String> users = new ArrayList<>(); +// Mockito.when(externalAccessRolesService.getAllUsers(mockedRequest.getHeader(uebKey))).thenReturn(users); +// List<String> expectedusers = externalAccessRolesController.getUsersOfApplication(mockedRequest, mockedResponse); +// assertEquals(users, expectedusers); +// } + +// @Test +// public void getUsersOfApplicationExceptionTest() throws Exception { +// Mockito.when(externalAccessRolesService.getAllUsers(mockedRequest.getHeader(uebKey))) +// .thenThrow(httpClientErrorException); +// assertNull(externalAccessRolesController.getUsersOfApplication(mockedRequest, mockedResponse)); +// } + + @Test + public void saveRoleExceptionTest() throws Exception { + Role role = new Role(); + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Failed to saveRole"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + List<Role> upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.saveRole(mockedRequest, mockedResponse,role); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void deleteRoleExceptionTest() throws Exception { + String role = "TestNew"; + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Failed to deleteRole for 'TestNew'"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse,role); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + + @Test + public void bulkUploadPartnerRoleFunctionsTest() throws Exception { + PortalRestResponse<String> portalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + List<Role> upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerRoleFunctions(mockedRequest, mockedResponse,upload); + assertEquals(portalRestResponse, expectedportalRestResponse); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java index 6e1b5d1c..03e2107a 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java @@ -40,21 +40,32 @@ import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; import org.openecomp.portalapp.portal.controller.FunctionalMenuController; import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum; import org.openecomp.portalapp.portal.service.AdminRolesService; import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl; import org.openecomp.portalapp.portal.service.FunctionalMenuService; import org.openecomp.portalapp.portal.service.FunctionalMenuServiceImpl; +import org.openecomp.portalapp.portal.service.SearchService; import org.openecomp.portalapp.portal.test.core.MockEPUser; import org.openecomp.portalapp.portal.test.framework.MockitoTestSuite; import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRole; import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRolesList; +import org.openecomp.portalapp.portal.transport.FavoritesFunctionalMenuItem; +import org.openecomp.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; import org.openecomp.portalapp.portal.transport.FieldsValidator; import org.openecomp.portalapp.portal.transport.FieldsValidator.FieldName; +import org.openecomp.portalapp.portal.transport.FunctionalMenuItem; +import org.openecomp.portalapp.portal.transport.FunctionalMenuItemWithRoles; import org.openecomp.portalapp.util.EPUserUtils; import org.openecomp.portalsdk.core.service.DataAccessService; import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(MockitoJUnitRunner.class) +@RunWith(PowerMockRunner.class) +@PrepareForTest(SystemProperties.class) public class FunctionalMenuControllerTest extends MockitoTestSuite { String userid = "ab1234"; @@ -67,6 +78,9 @@ public class FunctionalMenuControllerTest extends MockitoTestSuite { @Mock private DataAccessService dataAccessService; + + @Mock + SearchService searchService; @Mock AdminRolesService adminRolesService = new AdminRolesServiceImpl(); @@ -184,5 +198,309 @@ public class FunctionalMenuControllerTest extends MockitoTestSuite { acutualFieldValidator = functionalMenuController.regenerateAncestorTable(mockedRequest, mockedResponse); assertTrue(acutualFieldValidator.equals(expectedFieldValidator)); } + + @Test + public void getFunctionalMenuStaticInfoExceptionTest(){ + String fnMenuStaticactualResponse = null; + String fnMenuStaticexpectedResponse = null; + String orgUserIdStr = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(searchService.searchUserByUserId(orgUserIdStr)).thenReturn(user); + fnMenuStaticactualResponse = functionalMenuController.getFunctionalMenuStaticInfo(mockedRequest, mockedResponse); + + assertEquals(fnMenuStaticactualResponse, fnMenuStaticexpectedResponse); + + } + + @Test + public void getFunctionalMenuStaticInfoTest(){ + String fnMenuStaticactualResponse = null; + String fnMenuStaticexpectedResponse = "{\"firstName\":\"test\",\"lastName\":\"test\",\"last_login\":\"09/08/2017 03:48:13-0400\",\"userId\":\"guestT\",\"email\":\"test\"}"; + String orgUserIdStr = null; + + EPUser user = mockUser.mockEPUser(); + user.setEmail("test"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(searchService.searchUserByUserId(orgUserIdStr)).thenReturn(user); + fnMenuStaticactualResponse = functionalMenuController.getFunctionalMenuStaticInfo(mockedRequest, mockedResponse); + assertEquals(fnMenuStaticactualResponse.length(), fnMenuStaticexpectedResponse.length()); + } + + @Test + public void getMenuItemsForAuthUserNullTest(){ + List<FunctionalMenuItem> actualmenuItems = null; + List<FunctionalMenuItem> expectedmenuItems = null; + + actualmenuItems = functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse); + assertEquals(actualmenuItems, expectedmenuItems); + } + + @Test + public void getMenuItemsForAuthUserIsSuperAdminTest(){ + List<FunctionalMenuItem> actualmenuItems = null; + List<FunctionalMenuItem> expectedmenuItems = new ArrayList<FunctionalMenuItem>(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + actualmenuItems = functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse); + assertEquals(actualmenuItems, expectedmenuItems); + } + @Test + public void getMenuItemsForAuthUserTest(){ + List<FunctionalMenuItem> actualmenuItems = null; + List<FunctionalMenuItem> expectedmenuItems = new ArrayList<FunctionalMenuItem>(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + actualmenuItems = functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse); + assertEquals(actualmenuItems, expectedmenuItems); + } + + @Test + public void getFunctionalMenuItemDetailsBadPermissionTest(){ + Integer menuId = 1234; + FunctionalMenuItem actualmenuItem = null; + FunctionalMenuItem expectedmenuItem = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + + actualmenuItem = functionalMenuController.getFunctionalMenuItemDetails(mockedRequest, menuId, mockedResponse); + assertEquals(actualmenuItem, expectedmenuItem); + } + + @Test + public void getFunctionalMenuItemDetailsTest(){ + Integer menuId = 1234; + FunctionalMenuItem actualmenuItem = null; + FunctionalMenuItem expectedmenuItem = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItemDetails(menuId)).thenReturn(actualmenuItem); + + actualmenuItem = functionalMenuController.getFunctionalMenuItemDetails(mockedRequest, menuId, mockedResponse); + assertEquals(actualmenuItem, expectedmenuItem); + } + + @Test + public void getMenuItemsForEditingTest(){ + List<FunctionalMenuItem> actualMenuItems = null; + List<FunctionalMenuItem> expectedMenuItems = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItems(true)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForEditing(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForEditingBadPermissionsTest(){ + List<FunctionalMenuItem> actualMenuItems = null; + List<FunctionalMenuItem> expectedMenuItems = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItems(true)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForEditing(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForNotificationsTest(){ + List<FunctionalMenuItem> actualMenuItems = null; + List<FunctionalMenuItem> expectedMenuItems = new ArrayList<FunctionalMenuItem>(); + Mockito.when(functionalMenuService.getFunctionalMenuItemsForNotificationTree(false)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForNotifications(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForAppTest(){ + Integer appId = 1234; + List<FunctionalMenuItem> actualMenuItems = null; + List<FunctionalMenuItem> expectedMenuItems = null; + Mockito.when(functionalMenuService.getFunctionalMenuItemsForApp(appId)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForApp(mockedRequest, appId); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForUserTest(){ + String orgUserId ="test"; + List<FunctionalMenuItem> actualMenuItems = null; + List<FunctionalMenuItem> expectedMenuItems = null; + Mockito.when(functionalMenuService.getFunctionalMenuItemsForUser(orgUserId)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForUser(mockedRequest, orgUserId); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void createFunctionalMenuItemTest(){ + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(functionalMenuService.createFunctionalMenuItem(menuItemJson)).thenReturn(expectedFieldsValidator); + actualFieldsValidator = functionalMenuController.createFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void createFunctionalMenuItemBadPermisssionsTest(){ + FieldsValidator actualFieldsValidator = null; + FieldsValidator expectedFieldsValidator = null; + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.createFunctionalMenuItem(menuItemJson)).thenReturn(expectedFieldsValidator); + actualFieldsValidator = functionalMenuController.createFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void getFavoritesForUserTest(){ + List<FavoritesFunctionalMenuItemJson> actualFavoritesFunctionalMenuItemsJson = null; + List<FavoritesFunctionalMenuItemJson> expectedFunctionalMenuItemsJson = new ArrayList<FavoritesFunctionalMenuItemJson>(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.getFavoriteItems(user.getId())).thenReturn(expectedFunctionalMenuItemsJson); + actualFavoritesFunctionalMenuItemsJson = functionalMenuController.getFavoritesForUser(mockedRequest, mockedResponse); + assertEquals(actualFavoritesFunctionalMenuItemsJson, expectedFunctionalMenuItemsJson); + } + + @Test + public void deleteFavoriteItemTest(){ + Long userId = (long)1; + Long menuId = (long)1; + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.removeFavoriteItem(user.getId(), menuId)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.deleteFavoriteItem(mockedRequest, menuId, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void addFavoriteItemTest(){ + FavoritesFunctionalMenuItem menuItemJson = new FavoritesFunctionalMenuItem(); + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.setFavoriteItem(menuItemJson)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.addFavoriteItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void getMenuItemsTest(){ + List<FunctionalMenuItem> actualFunctionalMenuItems = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> expectedFunctionalMenuItems = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> menuItems = new ArrayList<FunctionalMenuItem>(); + Mockito.when(functionalMenuService.getFunctionalMenuItems()).thenReturn(menuItems); + actualFunctionalMenuItems = functionalMenuController.getMenuItems(mockedRequest, mockedResponse); + assertEquals(actualFunctionalMenuItems, expectedFunctionalMenuItems); + } + + @Test + public void deleteFunctionalMenuItemTest(){ + Long menuId = (long)1; + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(functionalMenuService.deleteFunctionalMenuItem(menuId)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.deleteFunctionalMenuItem(mockedRequest, menuId, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void deleteFunctionalMenuItemBadPermissionsTest(){ + Long menuId = (long)1; + FieldsValidator actualFieldsValidator = null; + FieldsValidator expectedFieldsValidator = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.deleteFunctionalMenuItem(menuId)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.deleteFunctionalMenuItem(mockedRequest, menuId, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void editFunctionalMenuItemTest(){ + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(functionalMenuService.editFunctionalMenuItem(menuItemJson)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.editFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void editFunctionalMenuItemBadPermissionsTest(){ + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + FieldsValidator actualFieldsValidator = null; + FieldsValidator expectedFieldsValidator = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.editFunctionalMenuItem(menuItemJson)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.editFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void getECOMPTitleTest(){ + PortalRestResponse<String> actualportalRestResponse = null; + PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); + expectedportalRestResponse.setMessage("success"); + expectedportalRestResponse.setResponse("Portal"); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME)).thenReturn("Portal"); + actualportalRestResponse = functionalMenuController.getECOMPTitle(mockedRequest, mockedResponse); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + } diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java index 567446ee..765de291 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java @@ -80,8 +80,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("FAILURE"); expectedportalRestResponse.setResponse("MicroserviceData cannot be null or empty"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); MicroserviceData microserviceData = null; PortalRestResponse<String> actualportalRestResponse = microserviceController.createMicroservice(mockedRequest, mockedResponse, microserviceData); @@ -93,8 +92,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("SUCCESS"); expectedportalRestResponse.setResponse(""); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); PortalRestResponse<String> actualportalRestResponse = microserviceController.createMicroservice(mockedRequest, mockedResponse, microserviceData); assertEquals(actualportalRestResponse, expectedportalRestResponse); @@ -105,8 +103,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("FAILURE"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); Mockito.when(microserviceService.saveMicroservice(microserviceData)).thenReturn((long) 1); Mockito.when(microserviceData.getParameterList()).thenThrow(nullPointerException); PortalRestResponse<String> actualportalRestResponse = microserviceController.createMicroservice(mockedRequest, @@ -126,8 +123,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("FAILURE"); expectedportalRestResponse.setResponse("MicroserviceData cannot be null or empty"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); MicroserviceData microserviceData = null; PortalRestResponse<String> actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest, mockedResponse, 1, microserviceData); @@ -139,8 +135,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("SUCCESS"); expectedportalRestResponse.setResponse(""); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); PortalRestResponse<String> actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest, mockedResponse, 1, microserviceData); assertEquals(actualportalRestResponse, expectedportalRestResponse); @@ -151,8 +146,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("FAILURE"); expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); Mockito.when(microserviceController.updateMicroservice(mockedRequest, mockedResponse, 1, microserviceData)) .thenThrow(nullPointerException); PortalRestResponse<String> actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest, @@ -166,8 +160,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ expectedportalRestResponse.setMessage("FAILURE"); expectedportalRestResponse.setResponse( "I/O error on GET request for \"" + EcompPortalUtils.widgetMsProtocol() + "://null/widget/microservices/widgetCatalog/service/1\":null; nested exception is java.net.UnknownHostException: null"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); PowerMockito.mockStatic(WidgetServiceHeaders.class); PortalRestResponse<String> actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest, mockedResponse, 1); @@ -181,8 +174,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("SOME WIDGETS ASSOICATE WITH THIS SERVICE"); expectedportalRestResponse.setResponse("'null' ,'null' "); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.WARN); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.WARN); List<WidgetCatalog> List = new ArrayList<WidgetCatalog>(); WidgetCatalog widgetCatalog = new WidgetCatalog(); widgetCatalog.setId(1); @@ -212,8 +204,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("SUCCESS"); expectedportalRestResponse.setResponse(""); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); List<WidgetCatalog> List = new ArrayList<WidgetCatalog>(); PowerMockito.mockStatic(WidgetServiceHeaders.class); String whatService = "widgets-service"; diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RoleManageControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RoleManageControllerTest.java new file mode 100644 index 00000000..faa9b1f7 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RoleManageControllerTest.java @@ -0,0 +1,189 @@ +package org.openecomp.portalapp.portal.test.controller; + +import static org.junit.Assert.assertEquals; + +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.controller.core.RoleController; +import org.openecomp.portalapp.controller.core.RoleFunctionListController; +import org.openecomp.portalapp.controller.core.RoleListController; +import org.openecomp.portalapp.portal.controller.RoleManageController; +import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.openecomp.portalapp.portal.service.ExternalAccessRolesService; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.springframework.web.servlet.ModelAndView; + +public class RoleManageControllerTest { + + + + @Mock + RoleController roleController; + + @Mock + RoleListController roleListController; + + @Mock + RoleFunctionListController roleFunctionListController; + + + @Mock + ExternalAccessRolesService externalAccessRolesService; + + @Mock + ExternalAccessRolesService externalAccessRolesService1 = null; + + @InjectMocks + RoleManageController roleManageController = new RoleManageController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + @Test + public void toggleRoleTest() + { + PortalRestResponse<String> portalRestResponse = new PortalRestResponse<String>(); + portalRestResponse.setMessage("success"); + portalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + portalRestResponse.setStatus(portalRestStatusEnum.OK); + + PortalRestResponse<String> expectedpPortalRestResponse=roleManageController.toggleRole(mockedRequest, mockedResponse); + assertEquals(portalRestResponse,expectedpPortalRestResponse); + + } + +// @Test +// public void toggleRoleExceptionTest() +// { +// PortalRestResponse<String> portalRestResponse = new PortalRestResponse<String>(); +// portalRestResponse.setMessage("success"); +// portalRestResponse.setResponse(null); +// PortalRestStatusEnum portalRestStatusEnum = null; +// portalRestResponse.setStatus(portalRestStatusEnum.OK); +// Mockito.doNothing().when(roleListController).toggleRole(mockedRequest, mockedResponse))).th +// getRoleListController().toggleRole(request, response) +// +// PortalRestResponse<String> expectedpPortalRestResponse=roleManageController.toggleRole(mockedRequest, mockedResponse); +// assertEquals(portalRestResponse,expectedpPortalRestResponse); +// +// } + @Test + public void removeRoleTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleListController.removeRole(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.removeRole(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + @Test + public void saveRoleTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.saveRole(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.saveRole(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + @Test + public void removeRoleRoleFunctionTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.removeRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.removeRoleRoleFunction(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + @Test + public void addRoleRoRoleFunctionTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.addRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.addRoleRoRoleFunction(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + @Test + public void removeChildRoleTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.removeChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.removeChildRole(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + + @Test + public void getRoleTest() throws Exception + { + Mockito.doNothing().when(roleController).getRole(mockedRequest, mockedResponse); + roleManageController.getRole(mockedRequest, mockedResponse); + } + + @Test + public void getRolesTest() throws Exception + { + Mockito.doNothing().when(roleListController).getRoles(mockedRequest, mockedResponse); + roleManageController.getRoles(mockedRequest, mockedResponse); + } + + @Test + public void getRoleFunctionListTest() throws Exception + { + Mockito.doNothing().when(roleFunctionListController).getRoleFunctionList(mockedRequest, mockedResponse); + roleManageController.getRoleFunctionList(mockedRequest, mockedResponse); + } + + @Test + public void saveRoleFunctionTest() throws Exception + { + Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test"); + roleManageController.saveRoleFunction(mockedRequest, mockedResponse, "test"); + } + + @Test + public void removeRoleFunctionTest() throws Exception + { + Mockito.doNothing().when(roleFunctionListController).removeRoleFunction(mockedRequest, mockedResponse, "test"); + roleManageController.removeRoleFunction(mockedRequest, mockedResponse, "test"); + } + + @Test + public void syncRolesTest() throws Exception + { + EPApp app = new EPApp(); + Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app); + roleManageController.syncRoles(app); + } + + + @Test + public void addeChildRoleTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.addChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.addChildRole(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java index 6286245f..79ae0276 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java @@ -47,8 +47,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Request has no roles"); expectedportalRestResponse.setResponse("save user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -66,8 +65,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Saved Successfully"); expectedportalRestResponse.setResponse("Success"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -91,8 +89,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Received Bad String"); expectedportalRestResponse.setResponse("save user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -116,8 +113,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage(null); expectedportalRestResponse.setResponse("save user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -137,8 +133,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Request has no login ID"); expectedportalRestResponse.setResponse("save user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId(null); @@ -155,8 +150,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Updated Successfully"); expectedportalRestResponse.setResponse("Success"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -180,8 +174,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Received Bad String"); expectedportalRestResponse.setResponse("save user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -206,8 +199,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage(null); expectedportalRestResponse.setResponse("save user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -228,8 +220,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Request has no application name"); expectedportalRestResponse.setResponse("delete user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName(null); extSysUser.setLoginId("1"); @@ -247,8 +238,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Request has no request ID"); expectedportalRestResponse.setResponse("delete user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test"); extSysUser.setLoginId("1"); @@ -265,8 +255,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("Deleted Successfully"); expectedportalRestResponse.setResponse("Success"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -291,8 +280,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage("failed"); expectedportalRestResponse.setResponse("delete user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); @@ -317,8 +305,7 @@ public class RolesApprovalSystemControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>(); expectedportalRestResponse.setMessage(null); expectedportalRestResponse.setResponse("delete user profile failed"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); ExternalSystemUser extSysUser = new ExternalSystemUser(); extSysUser.setApplicationName("Test_App"); extSysUser.setLoginId("1"); diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/SchedulerControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/SchedulerControllerTest.java new file mode 100644 index 00000000..c5280814 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/SchedulerControllerTest.java @@ -0,0 +1,75 @@ +package org.openecomp.portalapp.portal.test.controller; + +import java.sql.DriverManager; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.simple.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.controller.SchedulerController; +import org.openecomp.portalapp.portal.scheduler.SchedulerProperties; +import org.openecomp.portalapp.portal.scheduler.SchedulerRestInterface; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({UserUtils.class,SystemProperties.class}) + +public class SchedulerControllerTest { + + @Mock + SchedulerRestInterface schedulerRestInterface; + + + + @InjectMocks + SchedulerController schedulerController = new SchedulerController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockEPUser mockUser = new MockEPUser(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void getTimeSlotsTest() throws Exception{ + schedulerController.getTimeSlots(mockedRequest, "12"); + + } + + @Test + public void postCreateNewVNFChangeTest() throws Exception{ + //String testJsonData="{\"domain\":\"ChangeManagement\",\"scheduleName\":\"VnfUpgrade/DWF\",\"userId\":\"su7376\",\"domainData\":[{\"WorkflowName\":\"HEAT Stack Software Update for vNFs\",\"CallbackUrl\":\"http://127.0.0.1:8989/scheduler/v1/loopbacktest/vid\",\"CallbackData\":\"testing\"}],\"schedulingInfo\":{\"normalDurationInSeconds\":60,\"additionalDurationInSeconds\":60,\"concurrencyLimit\":60,\"policyId\":\"SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_zone_localTime.1.xml\",\"vnfDetails\":[{\"groupId\":\"group1\",\"node\":[\"satmo415vbc\",\"satmo455vbc\"]}]}}"; + JSONObject jsonObject =Mockito.mock(JSONObject.class); + + schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject); + } + + @Test + public void postSubmitVnfChangeTimeslotsTest() throws Exception{ + JSONObject jsonObject =Mockito.mock(JSONObject.class); + Mockito.when(jsonObject.get("scheduleId")).thenReturn("12"); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals"); + schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject); + } + +}
\ No newline at end of file diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/SessionCommunicationControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/SessionCommunicationControllerTest.java new file mode 100644 index 00000000..cc7bf040 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/SessionCommunicationControllerTest.java @@ -0,0 +1,59 @@ +package org.openecomp.portalapp.portal.test.controller; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.drools.core.command.assertion.AssertEquals; +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.controller.sessionmgt.SessionCommunicationController; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.service.sessionmgt.ManageService; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; + +public class SessionCommunicationControllerTest { + + + @Mock + ManageService manageService; + + @InjectMocks + SessionCommunicationController SessionCommunicationController = new SessionCommunicationController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + + @Test + public void getSessionSlotCheckIntervalTest() throws Exception + { + Mockito.when(manageService.fetchSessionSlotCheckInterval()).thenReturn(1); + int result = SessionCommunicationController.getSessionSlotCheckInterval(mockedRequest, mockedResponse); + assertEquals(result, 1); + + } + + @Test + public void extendSessionTimeOutsTest() throws Exception + { + Mockito.doNothing().when(manageService).extendSessionTimeOuts("test"); + Boolean result = SessionCommunicationController.extendSessionTimeOuts(mockedRequest, mockedResponse, "test"); + assertEquals(result, true); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java index 492a39d6..19f309b4 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java @@ -60,8 +60,7 @@ public class UserControllerTest extends MockitoTestSuite { PortalRestResponse<ProfileDetail> expectedResponse = new PortalRestResponse<ProfileDetail>(); expectedResponse.setMessage(null); expectedResponse.setResponse(null); - PortalRestStatusEnum enu = null; - expectedResponse.setStatus(enu.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); PortalRestResponse<ProfileDetail> response = userController.getLoggedinUser(mockedRequest); assertEquals(response, expectedResponse); } @@ -74,8 +73,7 @@ public class UserControllerTest extends MockitoTestSuite { expectedResponse.setMessage("success"); ProfileDetail profileDetail = new ProfileDetail(); expectedResponse.setResponse(profileDetail); - PortalRestStatusEnum enu = null; - expectedResponse.setStatus(enu.OK); + expectedResponse.setStatus(PortalRestStatusEnum.OK); PowerMockito.mockStatic(CipherUtil.class); Mockito.when(CipherUtil.decrypt(epUser.getLoginPwd())).thenReturn("Password"); PortalRestResponse<ProfileDetail> response = userController.getLoggedinUser(mockedRequest); @@ -88,8 +86,7 @@ public class UserControllerTest extends MockitoTestSuite { PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>(); expectedResponse.setMessage("java.lang.NullPointerException"); expectedResponse.setResponse(null); - PortalRestStatusEnum enu = null; - expectedResponse.setStatus(enu.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); ProfileDetail profileDetail = null; PortalRestResponse<String> actualResponse = userController.modifyLoggedinUser(mockedRequest, profileDetail); assertEquals(actualResponse, expectedResponse); @@ -104,8 +101,7 @@ public class UserControllerTest extends MockitoTestSuite { expectedResponse.setMessage( "java.lang.ClassCastException: com.sun.crypto.provider.AESCipher$General cannot be cast to javax.crypto.CipherSpi"); expectedResponse.setResponse(null); - PortalRestStatusEnum enu = null; - expectedResponse.setStatus(enu.ERROR); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); ProfileDetail profileDetail = new ProfileDetail(); profileDetail.setFirstName("Test_FirstName"); profileDetail.setLastName("Test_LastName"); diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java index 1459caa4..4014f441 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java @@ -30,29 +30,50 @@ import javax.servlet.http.HttpSession; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.portalapp.portal.controller.UserRolesController; import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.domain.EcompAuditLog; +import org.openecomp.portalapp.portal.service.AdminRolesService; +import org.openecomp.portalapp.portal.service.SearchService; import org.openecomp.portalapp.portal.service.UserRolesService; import org.openecomp.portalapp.portal.test.core.MockEPUser; import org.openecomp.portalapp.portal.transport.AppWithRolesForUser; +import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole; import org.openecomp.portalapp.portal.transport.FieldsValidator; import org.openecomp.portalapp.portal.transport.FieldsValidator.FieldName; import org.openecomp.portalapp.portal.transport.RoleInAppForUser; +import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; import org.openecomp.portalapp.test.framework.MockitoTestSuite; import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.service.AuditService; import org.openecomp.portalsdk.core.service.DataAccessService; import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +@RunWith(PowerMockRunner.class) +@PrepareForTest({EcompPortalUtils.class, EPCommonSystemProperties.class, EcompAuditLog.class, SystemProperties.class}) public class UserRolesControllerTest extends MockitoTestSuite { String userid = "ab1234"; @Mock UserRolesService userRolesService; + + @Mock + SearchService searchService; + + @Mock + AuditService auditService; + + @Mock + AdminRolesService adminRolesService; @Mock FieldsValidator fieldsValidator; @@ -127,4 +148,161 @@ public class UserRolesControllerTest extends MockitoTestSuite { assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields()); } + + @Test + public void getPhoneBookSearchResultBadPermissionsTest() { + String searchString = "test"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getPhoneBookSearchResultValidationTest() { + String searchString = " t"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getPhoneBookSearchResultTest() { + String searchString = "test"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getAppsWithAdminRoleStateForUserTest(){ + + String orgUserId = "hb123f"; + AppsListWithAdminRole actualResult = new AppsListWithAdminRole(); + AppsListWithAdminRole expectedResult = new AppsListWithAdminRole(); + EPUser user = mockUser.mockEPUser(); + // PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId)).thenReturn(actualResult); + + actualResult = userRolesController.getAppsWithAdminRoleStateForUser(mockedRequest, orgUserId, mockedResponse); + assertEquals(expectedResult, actualResult); + } + + /*@Test + public void getAppsWithAdminRoleStateForUserBadRequestTest(){ + + String orgUserId = "hb123f"; + AppsListWithAdminRole actualResult = null; + AppsListWithAdminRole expectedResult = null; + EPUser user = mockUser.mockEPUser(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.when(EcompPortalUtils.legitimateUserId(orgUserId)).thenReturn(false); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId)).thenReturn(actualResult); + + actualResult = userRolesController.getAppsWithAdminRoleStateForUser(mockedRequest, orgUserId, mockedResponse); + assertEquals(expectedResult, actualResult); + }*/ + + @Test + public void putAppsWithAdminRoleStateForUserBadStatusCodeTest(){ + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fieldNames = new ArrayList<FieldName>(); + expectedFieldsValidator.setErrorCode(null); + expectedFieldsValidator.setFields(fieldNames); + expectedFieldsValidator.setHttpStatusCode((long)200); + + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + assertEquals(expectedFieldsValidator, actualFieldsValidator); + } + + + /*@Test + public void putAppsWithAdminRoleStateForUserTest() { + + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompAuditLog.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(SystemProperties.MDC_TIMER)).thenReturn("1400"); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + + System.out.println(actualFieldsValidator); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + }*/ + + /*@Test + public void putAppsWithAdminRoleStateForUserTest(){ + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fieldNames = new ArrayList<FieldName>(); + expectedFieldsValidator.setErrorCode(null); + expectedFieldsValidator.setFields(fieldNames); + expectedFieldsValidator.setHttpStatusCode((long)200); + + EPUser user = mockUser.mockEPUser(); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompAuditLog.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.setAppsWithAdminRoleStateForUser(newAppsListWithAdminRoles)); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + // Mockito.call(auditService.logActivity(auditLog, null)); +// Mockito.when(SystemProperties.getProperty(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(SystemProperties.MDC_TIMER)).thenReturn("1400"); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + assertEquals(expectedFieldsValidator, actualFieldsValidator); + }*/ } diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WidgetsCatalogController.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WidgetsCatalogController.java new file mode 100644 index 00000000..f3255917 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WidgetsCatalogController.java @@ -0,0 +1,111 @@ +package org.openecomp.portalapp.portal.test.controller; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +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.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.controller.DashboardController; +import org.openecomp.portalapp.portal.domain.WidgetCatalog; +import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse; +import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.openecomp.portalapp.portal.service.ConsulHealthService; +import org.openecomp.portalapp.portal.service.ConsulHealthServiceImpl; +import org.openecomp.portalapp.portal.service.DashboardSearchService; +import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl; +import org.openecomp.portalapp.portal.service.MicroserviceService; +import org.openecomp.portalapp.portal.service.MicroserviceServiceImpl; +import org.openecomp.portalapp.portal.service.WidgetParameterService; +import org.openecomp.portalapp.portal.service.WidgetParameterServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.portal.transport.CommonWidgetMeta; +import org.openecomp.portalapp.portal.utils.CustomLoggingFilter; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.client.RestClientException; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EPUserUtils.class}) +public class WidgetsCatalogController { + + @Mock + ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + + @Mock + MicroserviceService microserviceService = new MicroserviceServiceImpl(); + + @Mock + WidgetParameterService widgetParameterService = new WidgetParameterServiceImpl(); + + @InjectMocks + WidgetsCatalogController widgetsCatalogController = new WidgetsCatalogController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + /*public List<WidgetCatalog> getUserWidgetCatalog(HttpServletRequest request, HttpServletResponse response, + @PathVariable("loginName") String loginName) throws RestClientException, Exception { + List<WidgetCatalog> widgets = new ArrayList<>(); + try { + CustomLoggingFilter d; + ResponseEntity<ArrayList> ans = template.exchange( + EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, + SystemProperties.getProperty("microservices.widget.local.port")) + + "/widget/microservices/widgetCatalog/" + loginName, + HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), ArrayList.class); + widgets = ans.getBody(); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getUserWidgetCatalog failed", e); + // returning null because null help check on the UI if there was a + // communication problem with Microservice. + return null; + } + return widgets; + } + + @Test + public void getWidgetDataTest(){ + + String resourceType = null; + List<WidgetCatalog> expectedData = new ArrayList<WidgetCatalog>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Unexpected resource type null"); + expectedData.setResponse(null); + + PortalRestResponse<CommonWidgetMeta> actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType); + assertEquals(expectedData,actualResponse); + + + }*/ +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AdminUserAppTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AdminUserAppTest.java new file mode 100644 index 00000000..ed13c2df --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AdminUserAppTest.java @@ -0,0 +1,36 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.AdminUserApp; + +public class AdminUserAppTest { + + public AdminUserApp mockAdminUserApp(){ + + AdminUserApp adminUserApp = new AdminUserApp(); + + adminUserApp.setUserId((long)1); + adminUserApp.setFirstName("test"); + adminUserApp.setLastName("test"); + adminUserApp.setOrgUserId("test"); + adminUserApp.setAppId((long)1); + adminUserApp.setAppName("test"); + + return adminUserApp; + } + + @Test + public void adminUserAppTest(){ + AdminUserApp adminUserApp = mockAdminUserApp(); + + assertEquals(adminUserApp.getUser_Id(), new Long(1)); + assertEquals(adminUserApp.getFirstName(), "test"); + assertEquals(adminUserApp.getLastName(), "test"); + assertEquals(adminUserApp.getOrgUserId(), "test"); + assertEquals(adminUserApp.getAppName(), "test"); + assertEquals(adminUserApp.getAppId(), new Long(1)); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AdminUserApplicationsTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AdminUserApplicationsTest.java new file mode 100644 index 00000000..6faf44a8 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AdminUserApplicationsTest.java @@ -0,0 +1,57 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import javax.persistence.Column; +import javax.persistence.Id; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.AdminUserApp; +import org.openecomp.portalapp.portal.domain.AdminUserApplications; + +public class AdminUserApplicationsTest { + + public AdminUserApplications mockAdminUserApplications(){ + + AdminUserApp adminUserApp = new AdminUserApp(); + + adminUserApp.setUserId((long)1); + adminUserApp.setFirstName("test"); + adminUserApp.setLastName("test"); + adminUserApp.setOrgUserId("test"); + adminUserApp.setAppId((long)1); + adminUserApp.setAppName("test"); + + AdminUserApplications adminUserApplications = new AdminUserApplications(adminUserApp); + + adminUserApplications.setUser_Id((long)1); + adminUserApplications.setFirstName("test"); + adminUserApplications.setLastName("test"); + adminUserApplications.setOrgUserId("test"); + return adminUserApplications; + } + + @Test + public void adminUserAppTest(){ + AdminUserApplications adminUserApplications = mockAdminUserApplications(); + AdminUserApp adminUserApp = new AdminUserApp(); + + adminUserApp.setUserId((long)1); + adminUserApp.setFirstName("test"); + adminUserApp.setLastName("test"); + adminUserApp.setOrgUserId("test"); + adminUserApp.setAppId((long)1); + adminUserApp.setAppName("test"); + AdminUserApplications adminUserApplications1 = new AdminUserApplications(adminUserApp); + + assertEquals(adminUserApplications.getUser_Id(), new Long(1)); + assertEquals(adminUserApplications.getFirstName(), "test"); + assertEquals(adminUserApplications.getLastName(), "test"); + assertEquals(adminUserApplications.getOrgUserId(), "test"); + + + assertEquals(adminUserApplications1.getApps().get(0).getAppId(),adminUserApp.getAppId()); + assertEquals(adminUserApplications1.getApps().get(0).getAppName(),adminUserApp.getAppName()); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AppContactUsTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AppContactUsTest.java new file mode 100644 index 00000000..f4368616 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/AppContactUsTest.java @@ -0,0 +1,32 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.AppContactUs; + +public class AppContactUsTest { + + public AppContactUs mockAppContactUs(){ + AppContactUs appContactUs = new AppContactUs(); + appContactUs.setDescription("test"); + appContactUs.setContactEmail("test"); + appContactUs.setContactName("test"); + appContactUs.setUrl("test"); + appContactUs.setActiveYN("test"); + + return appContactUs; + } + + @Test + public void mockAppContactUsTest(){ + AppContactUs appContactUs = mockAppContactUs(); + + assertEquals(appContactUs.getDescription(), "test"); + assertEquals(appContactUs.getContactEmail(), "test"); + assertEquals(appContactUs.getContactName(), "test"); + assertEquals(appContactUs.getUrl(), "test"); + assertEquals(appContactUs.getActiveYN(), "test"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/CentralRoleFunctionTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/CentralRoleFunctionTest.java new file mode 100644 index 00000000..83bdc591 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/CentralRoleFunctionTest.java @@ -0,0 +1,31 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.CentralRoleFunction; + +public class CentralRoleFunctionTest { + + public CentralRoleFunction mockCentralRoleFunction(){ + + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + + centralRoleFunction.setCode("test"); + centralRoleFunction.setName("test"); + centralRoleFunction.setAppId((long)1); + centralRoleFunction.setEditUrl("test"); + + return centralRoleFunction; + } + + @Test + public void centralRoleFunctionTest(){ + CentralRoleFunction centralRoleFunction = mockCentralRoleFunction(); + + assertEquals(centralRoleFunction.getAppId(), new Long(1)); + assertEquals(centralRoleFunction.getCode(), "test"); + assertEquals(centralRoleFunction.getName(), "test"); + assertEquals(centralRoleFunction.getEditUrl(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPAppRoleFunctionTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPAppRoleFunctionTest.java new file mode 100644 index 00000000..a3f24631 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPAppRoleFunctionTest.java @@ -0,0 +1,27 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPAppRoleFunction; + +public class EPAppRoleFunctionTest { + + public EPAppRoleFunction mockEPAppRoleFunction(){ + EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction(); + epAppRoleFunction.setRoleId((long)1); + epAppRoleFunction.setAppId((long)1); + epAppRoleFunction.setCode("test"); + + return epAppRoleFunction; + } + + @Test + public void epAppRoleFunctionTest(){ + EPAppRoleFunction epAppRoleFunction = mockEPAppRoleFunction(); + + assertEquals(epAppRoleFunction.getRoleId(), new Long(1)); + assertEquals(epAppRoleFunction.getAppId(), new Long(1)); + assertEquals(epAppRoleFunction.getCode(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPAppTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPAppTest.java new file mode 100644 index 00000000..9a60e7d7 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPAppTest.java @@ -0,0 +1,61 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPApp; + +public class EPAppTest { + + public EPApp mockEPApp(){ + EPApp epApp = new EPApp(); + + epApp.setName("test"); + epApp.setImageUrl("test"); + epApp.setDescription("test"); + epApp.setNotes("test"); + epApp.setUrl("test"); + epApp.setAlternateUrl("test"); + epApp.setAppRestEndpoint("test"); + epApp.setMlAppName("test"); + epApp.setMlAppAdminId("test"); + epApp.setMotsId((long)1); + epApp.setUsername("test"); + epApp.setAppPassword("test"); + epApp.setOpen(false); + epApp.setEnabled(false); + epApp.setUebTopicName("test"); + epApp.setUebSecret("test"); + epApp.setAppType(1); + epApp.setCentralAuth(false); + epApp.setNameSpace("test"); + + return epApp; + } + + @Test + public void epAppTest(){ + EPApp epApp = mockEPApp(); + + assertEquals(epApp.getName(), "test"); + assertEquals(epApp.getImageUrl(), "test"); + assertEquals(epApp.getDescription(), "test"); + assertEquals(epApp.getNotes(), "test"); + assertEquals(epApp.getUrl(), "test"); + assertEquals(epApp.getAlternateUrl(), "test"); + assertEquals(epApp.getAppRestEndpoint(), "test"); + assertEquals(epApp.getMlAppName(), "test"); + assertEquals(epApp.getMlAppAdminId(), "test"); + assertEquals(epApp.getMotsId(), new Long(1)); + assertEquals(epApp.getUsername(), "test"); + assertEquals(epApp.getAppPassword(), "test"); + assertEquals(epApp.getOpen(), false); + assertEquals(epApp.getEnabled(), false); + assertEquals(epApp.getUebTopicName(), "test"); + assertEquals(epApp.getUebSecret(), "test"); + assertEquals(epApp.getAppType(), Integer.valueOf(1)); + assertEquals(epApp.getCentralAuth(), false); + assertEquals(epApp.getNameSpace(), "test"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPEndpointAccountTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPEndpointAccountTest.java new file mode 100644 index 00000000..07206244 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPEndpointAccountTest.java @@ -0,0 +1,29 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPEndpointAccount; + +public class EPEndpointAccountTest { + + public EPEndpointAccount mockEPEndpointAccount(){ + EPEndpointAccount epEndpointAccount = new EPEndpointAccount(); + + epEndpointAccount.setEp_id((long)1); + epEndpointAccount.setAccount_id((long)1); + epEndpointAccount.setId((long)1); + + return epEndpointAccount; + } + + @Test + public void epEndpointAccount(){ + EPEndpointAccount epEndpointAccount = mockEPEndpointAccount(); + assertEquals(epEndpointAccount.getEp_id(), new Long(1)); + assertEquals(epEndpointAccount.getAccount_id(), new Long(1)); + assertEquals(epEndpointAccount.getId(), new Long(1)); + + assertEquals(epEndpointAccount.toString(), "EPEndpointAccount [id=1, ep_id=1, account_id=1]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPEndpointTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPEndpointTest.java new file mode 100644 index 00000000..8fbee988 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPEndpointTest.java @@ -0,0 +1,27 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPEndpoint; + +public class EPEndpointTest { + + public EPEndpoint mockEPEndpoint(){ + EPEndpoint epEndpoint = new EPEndpoint(); + + epEndpoint.setId((long)1); + epEndpoint.setName("test"); + + return epEndpoint; + } + + @Test + public void epEndpointTest(){ + EPEndpoint epEndpoint = mockEPEndpoint(); + + assertEquals(epEndpoint.getId(), new Long(1)); + assertEquals(epEndpoint.getName(), "test"); + assertEquals("EPEndpoint [id=1, name=test]", epEndpoint.toString()); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPRoleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPRoleTest.java new file mode 100644 index 00000000..05453bfa --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPRoleTest.java @@ -0,0 +1,36 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPRole; + +public class EPRoleTest { + + public EPRole mockEPRole(){ + EPRole epRole = new EPRole(); + + epRole.setName("test"); + epRole.setActive(false); + epRole.setPriority(1); + epRole.setAppId((long)1); + epRole.setAppRoleId((long)1); + + return epRole; + } + + @Test + public void epRoleTest(){ + EPRole epRole = mockEPRole(); + + assertEquals(epRole.getName(), "test"); + assertEquals(epRole.getActive(), false); + assertEquals(epRole.getPriority().toString(),"1"); + assertEquals(epRole.getAppId(), new Long(1)); + assertEquals(epRole.getAppRoleId(), new Long(1)); + + assertEquals(epRole.toString(), "[Id = null, name = test]"); + + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppCatalogRolesTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppCatalogRolesTest.java new file mode 100644 index 00000000..a21eec76 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppCatalogRolesTest.java @@ -0,0 +1,32 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPUserAppCatalogRoles; + +public class EPUserAppCatalogRolesTest { + + public EPUserAppCatalogRoles mockEPUserAppCatalogRoles(){ + EPUserAppCatalogRoles epUserAppCatalogRoles = new EPUserAppCatalogRoles(); + + epUserAppCatalogRoles.setRequestedRoleId((long)1); + epUserAppCatalogRoles.setRolename("test"); + epUserAppCatalogRoles.setRequestStatus("status"); + epUserAppCatalogRoles.setAppId((long)1); + + return epUserAppCatalogRoles; + } + + @Test + public void epUserAppCatalogRolesTest(){ + EPUserAppCatalogRoles epUserAppCatalogRoles = mockEPUserAppCatalogRoles(); + + assertEquals(epUserAppCatalogRoles.getRequestedRoleId(), new Long(1)); + assertEquals(epUserAppCatalogRoles.getRolename(), "test"); + assertEquals(epUserAppCatalogRoles.getRequestStatus(), "status"); + assertEquals(epUserAppCatalogRoles.getAppId(), new Long(1)); + + assertEquals("EPUserAppCatalogRoles [requestedRoleId=1, rolename=test, requestStatus=status, appId=1]", epUserAppCatalogRoles.toString()); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppRolesRequestDetailTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppRolesRequestDetailTest.java new file mode 100644 index 00000000..c9147bbe --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppRolesRequestDetailTest.java @@ -0,0 +1,54 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPUserAppRolesRequest; +import org.openecomp.portalapp.portal.domain.EPUserAppRolesRequestDetail; + +public class EPUserAppRolesRequestDetailTest { + + public EPUserAppRolesRequestDetail mockEPUserAppRolesRequestDetail(){ + + EPUserAppRolesRequest epUserAppRolesRequest = new EPUserAppRolesRequest(); + epUserAppRolesRequest.setUserId((long)1); + epUserAppRolesRequest.setAppId((long)1); + epUserAppRolesRequest.setCreated(new Date()); + epUserAppRolesRequest.setUpdatedDate(new Date()); + epUserAppRolesRequest.setRequestStatus("test"); + + EPUserAppRolesRequestDetail epUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail(); + epUserAppRolesRequestDetail.setReqRoleId((long)1); + epUserAppRolesRequestDetail.setReqType("test"); + epUserAppRolesRequestDetail.setEpRequestIdData(epUserAppRolesRequest); + + return epUserAppRolesRequestDetail; + } + + @Test + public void epUserAppRolesRequestDetailTest(){ + + EPUserAppRolesRequest epUserAppRolesRequest = new EPUserAppRolesRequest(); + epUserAppRolesRequest.setUserId((long)1); + epUserAppRolesRequest.setAppId((long)1); + epUserAppRolesRequest.setCreated(new Date()); + epUserAppRolesRequest.setUpdatedDate(new Date()); + epUserAppRolesRequest.setRequestStatus("test"); + + EPUserAppRolesRequestDetail epUserAppRolesRequestDetail = mockEPUserAppRolesRequestDetail(); + + EPUserAppRolesRequestDetail epUserAppRolesRequestDetail1 = new EPUserAppRolesRequestDetail(); + epUserAppRolesRequestDetail1.setReqRoleId((long)1); + epUserAppRolesRequestDetail1.setReqType("test"); + epUserAppRolesRequestDetail1.setEpRequestIdData(epUserAppRolesRequest); + + assertEquals(epUserAppRolesRequestDetail.getReqRoleId(), new Long(1)); + assertEquals(epUserAppRolesRequestDetail.getReqType(), "test"); + assertEquals(epUserAppRolesRequestDetail.getEpRequestIdData(), epUserAppRolesRequest); + assertEquals(epUserAppRolesRequestDetail.hashCode(), epUserAppRolesRequestDetail1.hashCode()); + + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppRolesTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppRolesTest.java new file mode 100644 index 00000000..540c63e9 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppRolesTest.java @@ -0,0 +1,28 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPUserAppRoles; + +public class EPUserAppRolesTest { + + public EPUserAppRoles mockEPUserAppRoles(){ + EPUserAppRoles epUserAppRoles = new EPUserAppRoles(); + + epUserAppRoles.setRoleId((long)1); + epUserAppRoles.setAppId((long)1); + + return epUserAppRoles; + } + + @Test + public void epUserAppRolesTest(){ + EPUserAppRoles epUserAppRoles = mockEPUserAppRoles(); + + assertEquals(epUserAppRoles.getRoleId(), new Long(1)); + assertEquals(epUserAppRoles.getAppId(), new Long(1)); + assertEquals("EpUserAppRoles [roleId=1, appId=1]", epUserAppRoles.toString()); + } +} + diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppTest.java new file mode 100644 index 00000000..0c450ebb --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppTest.java @@ -0,0 +1,85 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.domain.EPRole; +import org.openecomp.portalapp.portal.domain.EPUserApp; + +public class EPUserAppTest { + + public EPUserApp mockEPUserApp(){ + + EPApp epApp = new EPApp(); + epApp.setName("test"); + epApp.setImageUrl("test"); + epApp.setDescription("test"); + epApp.setNotes("test"); + epApp.setUrl("test"); + epApp.setAlternateUrl("test"); + epApp.setAppRestEndpoint("test"); + epApp.setMlAppName("test"); + epApp.setMlAppAdminId("test"); + epApp.setMotsId((long)1); + epApp.setUsername("test"); + epApp.setAppPassword("test"); + + + //Role + EPRole epRole = new EPRole(); + epRole.setName("test"); + epRole.setActive(false); + epRole.setPriority(1); + epRole.setAppId((long)1); + epRole.setAppRoleId((long)1); + + EPUserApp user = new EPUserApp(); + user.setUserId((long)1); + user.setApp(epApp); + user.setRole(epRole); + user.setPriority((short)32767); + + + return user; + } + + @Test + public void userTest(){ + EPUserApp user = mockEPUserApp(); + + EPApp epApp = new EPApp(); + epApp.setName("test"); + epApp.setImageUrl("test"); + epApp.setDescription("test"); + epApp.setNotes("test"); + epApp.setUrl("test"); + epApp.setAlternateUrl("test"); + epApp.setAppRestEndpoint("test"); + epApp.setMlAppName("test"); + epApp.setMlAppAdminId("test"); + epApp.setMotsId((long)1); + epApp.setUsername("test"); + epApp.setAppPassword("test"); + user.setApp(epApp); + + //Role + EPRole epRole = new EPRole(); + epRole.setName("test"); + epRole.setActive(false); + epRole.setPriority(1); + epRole.setAppId((long)1); + epRole.setAppRoleId((long)1); + + + assertEquals(user.getUserId(),Long.valueOf(1)); + assertEquals(user.getApp(), epApp); + assertEquals(user.getPriority().getClass(), Short.class); + + assertEquals(user.toString(), "[u: 1; a: null, r: null; appRoleId: 1]"); + + assertEquals(user.hashCode(), user.hashCode()); + + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppsManualSortPreferenceTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppsManualSortPreferenceTest.java new file mode 100644 index 00000000..afad6f63 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppsManualSortPreferenceTest.java @@ -0,0 +1,29 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPUserAppsManualSortPreference; + +public class EPUserAppsManualSortPreferenceTest { + + public EPUserAppsManualSortPreference mockEPUserAppsManualSortPreference(){ + + EPUserAppsManualSortPreference epUserAppsManualSortPreference = new EPUserAppsManualSortPreference(); + epUserAppsManualSortPreference.setUserId(1); + epUserAppsManualSortPreference.setAppId((long)1); + epUserAppsManualSortPreference.setAppManualSortOrder(1); + + return epUserAppsManualSortPreference; + } + + @Test + public void epUserAppsManualSortPreferenceTest(){ + + EPUserAppsManualSortPreference epUserAppsManualSortPreference = mockEPUserAppsManualSortPreference(); + + assertEquals(epUserAppsManualSortPreference.getUserId(), 1); + assertEquals(epUserAppsManualSortPreference.getAppId(), new Long(1)); + assertEquals(epUserAppsManualSortPreference.getAppManualSortOrder(), 1); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppsSortPreferenceTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppsSortPreferenceTest.java new file mode 100644 index 00000000..545c16d5 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserAppsSortPreferenceTest.java @@ -0,0 +1,43 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPUserAppsSortPreference; + +public class EPUserAppsSortPreferenceTest { + + public EPUserAppsSortPreference mockEPUserAppsSortPreferenceTest(){ + + EPUserAppsSortPreference epUserAppsSortPreference = new EPUserAppsSortPreference(); + epUserAppsSortPreference.setUserId(1); + epUserAppsSortPreference.setSortPref("test"); + epUserAppsSortPreference.setId((long)1); + epUserAppsSortPreference.setCreated(new Date()); + epUserAppsSortPreference.setModified(new Date()); + epUserAppsSortPreference.setModifiedId((long)1); + epUserAppsSortPreference.setRowNum((long)1); + epUserAppsSortPreference.setAuditTrail(null); + + return epUserAppsSortPreference; + } + + @Test + public void epUserAppsSortPreferenceTest() { + EPUserAppsSortPreference epUserAppsSortPreference = mockEPUserAppsSortPreferenceTest(); + + assertEquals(epUserAppsSortPreference.getUserId(), 1); + assertEquals(epUserAppsSortPreference.getSortPref(), "test"); + assertEquals(epUserAppsSortPreference.getId(), new Long(1)); + assertEquals(epUserAppsSortPreference.getCreated(), new Date()); + assertEquals(epUserAppsSortPreference.getModified(), new Date()); + assertEquals(epUserAppsSortPreference.getModifiedId(), new Long(1)); + assertEquals(epUserAppsSortPreference.getRowNum(), new Long(1)); + assertEquals(epUserAppsSortPreference.getAuditTrail(), null); + + + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserNotificationTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserNotificationTest.java new file mode 100644 index 00000000..64313e52 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserNotificationTest.java @@ -0,0 +1,34 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPUserNotification; + +public class EPUserNotificationTest { + + public EPUserNotification mockEPUserNotification(){ + + EPUserNotification epUserNotification = new EPUserNotification(); + + epUserNotification.setUserId((long)1); + epUserNotification.setNotificationId((long)1); + epUserNotification.setViewed("test"); + epUserNotification.setUpdateTime(new Date()); + + return epUserNotification; + } + + @Test + public void epUserNotificationTest(){ + EPUserNotification epUserNotification = mockEPUserNotification(); + + assertEquals(epUserNotification.getUserId(), new Long(1)); + assertEquals(epUserNotification.getNotificationId(), new Long(1)); + assertEquals(epUserNotification.getViewed(), "test"); + // assertEquals(epUserNotification.getUpdateTime(), new Date()); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserTest.java new file mode 100644 index 00000000..54e6193d --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPUserTest.java @@ -0,0 +1,114 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPUser; + +public class EPUserTest { + + public EPUser mockEPUser(){ + + EPUser epUser = new EPUser(); + + epUser.setId((long)1); + epUser.setManagerId((long) 1234); + epUser.setFirstName("test"); + epUser.setLastName("test"); + epUser.setMiddleInitial("test"); + epUser.setPhone("test"); + epUser.setFax("test"); + epUser.setCellular("test"); + epUser.setEmail("test"); + epUser.setAddressId((long) 123); + epUser.setAlertMethodCd("test"); + epUser.setHrid("test"); + epUser.setOrgUserId("test"); + epUser.setOrgCode("test"); + epUser.setAddress1("test"); + epUser.setAddress2("test"); + epUser.setCity("test"); + epUser.setState("test"); + epUser.setZipCode("test"); + epUser.setCountry("test"); + epUser.setOrgManagerUserId("test"); + epUser.setLocationClli("test"); + epUser.setBusinessCountryCode("test"); + epUser.setBusinessCountryName("test"); + epUser.setBusinessUnit("test"); + epUser.setBusinessUnitName("test"); + epUser.setDepartment("test"); + epUser.setDepartmentName("test"); + epUser.setCompanyCode("test"); + epUser.setCompany("test"); + epUser.setZipCodeSuffix("test"); + epUser.setJobTitle("test"); + epUser.setCommandChain("test"); + epUser.setSiloStatus("test"); + epUser.setCostCenter("test"); + epUser.setFinancialLocCode("test"); + epUser.setLoginId("test"); + epUser.setLoginPwd("test"); + epUser.setLastLoginDate(new Date()); + epUser.setActive(false); + epUser.setInternal(false); + epUser.setSelectedProfileId((long) 12345); + epUser.setTimeZoneId((long) 12345); + epUser.setOnline(false); + epUser.setChatId("test"); + return epUser; + + } + + @Test + public void userTest(){ + EPUser user = mockEPUser(); + + assertEquals(user.getId(), new Long(1)); + assertEquals(user.getManagerId(), new Long(1234)); + assertEquals(user.getFirstName(), "test"); + assertEquals(user.getLastName(), "test"); + assertEquals(user.getMiddleInitial(), "test"); + assertEquals(user.getPhone(), "test"); + assertEquals(user.getFax(), "test"); + assertEquals(user.getCellular(), "test"); + assertEquals(user.getEmail(), "test"); + assertEquals(user.getAddressId(), new Long(123) ); + assertEquals(user.getAlertMethodCd(), "test"); + assertEquals(user.getHrid(), "test"); + assertEquals(user.getOrgUserId(), "test"); + assertEquals(user.getOrgCode(), "test"); + assertEquals(user.getAddress1(), "test"); + assertEquals(user.getAddress2(), "test"); + assertEquals(user.getState(), "test"); + assertEquals(user.getZipCode(), "test"); + assertEquals(user.getCountry(), "test"); + assertEquals(user.getOrgManagerUserId(), "test"); + assertEquals(user.getLocationClli(), "test"); + assertEquals(user.getBusinessCountryCode(), "test"); + assertEquals(user.getBusinessCountryName(), "test"); + assertEquals(user.getBusinessUnit(), "test"); + assertEquals(user.getBusinessUnitName(), "test"); + assertEquals(user.getDepartment(), "test"); + assertEquals(user.getDepartmentName(), "test"); + assertEquals(user.getCompanyCode(), "test"); + assertEquals(user.getCompany(), "test"); + assertEquals(user.getZipCodeSuffix(), "test"); + assertEquals(user.getJobTitle(), "test"); + assertEquals(user.getCommandChain(), "test"); + assertEquals(user.getSiloStatus(), "test"); + assertEquals(user.getFinancialLocCode(), "test"); + assertEquals(user.getLoginId(), "test"); + assertEquals(user.getLoginPwd(), "test"); + assertEquals(user.getActive(), false); + assertEquals(user.getInternal(), false); + assertEquals(user.getSelectedProfileId(), new Long (12345)); + assertEquals(user.getTimeZoneId(), new Long (12345)); + assertEquals(user.getChatId(), "test"); + + //assertEquals(user.toString(), "EPUser [orgId=null, managerId=1234, firstName=test, middleInitial=test, lastName=test, phone=test, fax=test, cellular=test, email=test, addressId=123, alertMethodCd=test, hrid=test, orgUserId=test, orgCode=test, address1=test, address2=test, city=test, state=test, zipCode=test, country=test, orgManagerUserId=test, locationClli=test, businessCountryCode=test, businessCountryName=test, businessUnit=test, businessUnitName=test, department=test, departmentName=test, companyCode=test, company=test, zipCodeSuffix=test, jobTitle=test, commandChain=test, siloStatus=test, costCenter=test, financialLocCode=test, loginId=test, loginPwd=test, lastLoginDate=Tue Sep 05 11:04:49 EDT 2017, active=false, internal=false, selectedProfileId=12345, timeZoneId=12345, online=false, chatId=test, isGuest=false, userApps=[], pseudoRoles=[]]"); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPWidgetsManualSortPreferenceTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPWidgetsManualSortPreferenceTest.java new file mode 100644 index 00000000..69aa3db0 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EPWidgetsManualSortPreferenceTest.java @@ -0,0 +1,36 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPWidgetsManualSortPreference; + +public class EPWidgetsManualSortPreferenceTest { + + public EPWidgetsManualSortPreference mockEPWidgetsManualSortPreference(){ + EPWidgetsManualSortPreference epWidgetsManualSortPreference = new EPWidgetsManualSortPreference(); + + epWidgetsManualSortPreference.setUserId(1); + epWidgetsManualSortPreference.setWidgetId((long)1); + epWidgetsManualSortPreference.setWidgetRow(1); + epWidgetsManualSortPreference.setWidgetCol(1); + epWidgetsManualSortPreference.setWidgetWidth(1); + epWidgetsManualSortPreference.setWidgetHeight(1); + + return epWidgetsManualSortPreference; + } + + @Test + public void epWidgetsManualSortPreferenceTest(){ + EPWidgetsManualSortPreference epWidgetsManualSortPreference = mockEPWidgetsManualSortPreference(); + + assertEquals(epWidgetsManualSortPreference.getWidgetId(), new Long(1)); + assertEquals(epWidgetsManualSortPreference.getUserId(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetRow(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetCol(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetHeight(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetWidth(), 1); + + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EcompAppRoleIdTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EcompAppRoleIdTest.java new file mode 100644 index 00000000..ca2bdfb3 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EcompAppRoleIdTest.java @@ -0,0 +1,33 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EcompAppRoleId; + +public class EcompAppRoleIdTest { + + public EcompAppRoleId mockEcompAppRoleId(){ + + EcompAppRoleId ecompAppRoleId = new EcompAppRoleId(); + + ecompAppRoleId.setAppId((long)1); + ecompAppRoleId.setAppName("test"); + ecompAppRoleId.setRoleId(1); + ecompAppRoleId.setRoleName("test"); + + return ecompAppRoleId; + } + + @Test + public void ecompAppRoleIdTest(){ + + EcompAppRoleId ecompAppRoleId = mockEcompAppRoleId(); + + assertEquals(ecompAppRoleId.getAppId(), new Long(1)); + assertEquals(ecompAppRoleId.getAppName(), "test"); + assertEquals(ecompAppRoleId.getRoleId().toString(), "1"); + assertEquals(ecompAppRoleId.getRoleName(), "test"); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EcompAppRoleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EcompAppRoleTest.java new file mode 100644 index 00000000..4ba244b7 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/EcompAppRoleTest.java @@ -0,0 +1,31 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EcompAppRole; + +public class EcompAppRoleTest { + + public EcompAppRole mockEcompAppRole(){ + EcompAppRole ecompAppRole = new EcompAppRole(); + + ecompAppRole.setAppId((long)1); + ecompAppRole.setAppName("test"); + ecompAppRole.setRoleId(1); + ecompAppRole.setRoleName("test"); + + return ecompAppRole; + } + + @Test + public void ecompAppRoleTest(){ + EcompAppRole ecompAppRole = mockEcompAppRole(); + + assertEquals(ecompAppRole.getAppId(), new Long(1)); + assertEquals(ecompAppRole.getAppName(), "test"); + assertEquals(ecompAppRole.getRoleId().toString(), "1"); + assertEquals(ecompAppRole.getRoleName(), "test"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalRoleDetailsTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalRoleDetailsTest.java new file mode 100644 index 00000000..e007102c --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalRoleDetailsTest.java @@ -0,0 +1,59 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.EPAppRoleFunction; +import org.openecomp.portalapp.portal.domain.ExternalRoleDetails; + +public class ExternalRoleDetailsTest { + + public ExternalRoleDetails mockExternalRoleDetails(){ + + List<EPAppRoleFunction> epAppRoleFunctionList = new ArrayList<EPAppRoleFunction>(); + + EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction(); + epAppRoleFunction.setRoleId((long)1); + epAppRoleFunction.setAppId((long)1); + epAppRoleFunction.setCode("test"); + + epAppRoleFunctionList.add(epAppRoleFunction); + + ExternalRoleDetails externalRoleDetails = new ExternalRoleDetails(); + + externalRoleDetails.setName("test"); + externalRoleDetails.setActive(false); + externalRoleDetails.setPriority(1); + externalRoleDetails.setAppId((long)1); + externalRoleDetails.setAppRoleId((long)1); + externalRoleDetails.setPerms(epAppRoleFunctionList); + + return externalRoleDetails; + } + + @Test + public void externalRoleDetailsTest(){ + + List<EPAppRoleFunction> epAppRoleFunctionList = new ArrayList<EPAppRoleFunction>(); + + EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction(); + epAppRoleFunction.setRoleId((long)1); + epAppRoleFunction.setAppId((long)1); + epAppRoleFunction.setCode("test"); + + epAppRoleFunctionList.add(epAppRoleFunction); + + ExternalRoleDetails externalRoleDetails = mockExternalRoleDetails(); + + assertEquals(externalRoleDetails.getAppId(), new Long(1)); + assertEquals(externalRoleDetails.getAppRoleId(), new Long(1)); + assertEquals(externalRoleDetails.getPriority().toString(), "1"); + assertEquals(externalRoleDetails.getName(), "test"); + assertEquals(externalRoleDetails.getPriority().toString(), "1"); + assertEquals(externalRoleDetails.getPerms().size(), epAppRoleFunctionList.size()); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalSystemAccessTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalSystemAccessTest.java new file mode 100644 index 00000000..ea884578 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalSystemAccessTest.java @@ -0,0 +1,27 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.ExternalSystemAccess; + +public class ExternalSystemAccessTest { + + public ExternalSystemAccess mockExternalSystemAccess(){ + ExternalSystemAccess externalSystemAccess = new ExternalSystemAccess("test", false); + + externalSystemAccess.setKey("test"); + externalSystemAccess.setAccessValue(false); + + return externalSystemAccess; + } + + @Test + public void externalSystemAccessTest(){ + ExternalSystemAccess externalSystemAccess = mockExternalSystemAccess(); + + assertEquals(externalSystemAccess.getKey(), "test"); + assertEquals(externalSystemAccess.getAccessValue(), false); + } +} + diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalSystemRoleApprovalTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalSystemRoleApprovalTest.java new file mode 100644 index 00000000..2c47ed5a --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ExternalSystemRoleApprovalTest.java @@ -0,0 +1,23 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.externalsystemapproval.model.ExternalSystemRoleApproval; + +public class ExternalSystemRoleApprovalTest { + + public ExternalSystemRoleApproval mockExternalSystemRoleApproval(){ + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApproval.setRoleName("test"); + + return externalSystemRoleApproval; + } + + @Test + public void externalSystemRoleApprovalTest(){ + ExternalSystemRoleApproval externalSystemRoleApproval = mockExternalSystemRoleApproval(); + + assertEquals(externalSystemRoleApproval.getRoleName(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/FunctionalMenuItemWithAppIDTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/FunctionalMenuItemWithAppIDTest.java new file mode 100644 index 00000000..abec873b --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/FunctionalMenuItemWithAppIDTest.java @@ -0,0 +1,28 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.FunctionalMenuItemWithAppID; + +public class FunctionalMenuItemWithAppIDTest { + + public FunctionalMenuItemWithAppID mockFunctionalMenuItemWithAppID(){ + FunctionalMenuItemWithAppID functionalMenuItemWithAppID = new FunctionalMenuItemWithAppID(); + + functionalMenuItemWithAppID.setRestrictedApp(false); + functionalMenuItemWithAppID.setUrl("test"); + + + return functionalMenuItemWithAppID; + } + + @Test + public void functionalMenuItemWithAppIDTest(){ + FunctionalMenuItemWithAppID functionalMenuItemWithAppID = mockFunctionalMenuItemWithAppID(); + + assertEquals(functionalMenuItemWithAppID.toString(), "FunctionalMenuItem [menuId=null, column=null, text=null, parentMenuId=null, url=test, active_yn=null, appid=null, roles=null, restrictedApp=false]"); + + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/GetAccessResultIdTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/GetAccessResultIdTest.java new file mode 100644 index 00000000..90a65eb8 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/GetAccessResultIdTest.java @@ -0,0 +1,29 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.GetAccessResultId; + +public class GetAccessResultIdTest { + + public GetAccessResultId mockGetAccessResultId(){ + + GetAccessResultId getAccessResultIdObj = new GetAccessResultId(); + getAccessResultIdObj.setEcompFunction("test"); + getAccessResultIdObj.setAppName("test"); + getAccessResultIdObj.setRoleName("test"); + + return getAccessResultIdObj; + } + + @Test + public void getAccessResultIdObjTest(){ + GetAccessResultId getAccessResultIdObj = mockGetAccessResultId(); + + assertEquals(getAccessResultIdObj.getEcompFunction(), "test"); + assertEquals(getAccessResultIdObj.getAppName(), "test"); + assertEquals(getAccessResultIdObj.getRoleName(), "test"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/MicroserviceDataTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/MicroserviceDataTest.java new file mode 100644 index 00000000..d7e4ca29 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/MicroserviceDataTest.java @@ -0,0 +1,57 @@ +package org.openecomp.portalapp.portal.test.domain; + +import java.util.ArrayList; +import java.util.List; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.MicroserviceData; +import org.openecomp.portalapp.portal.domain.MicroserviceParameter; + +public class MicroserviceDataTest { + + public MicroserviceData mockMicroserviceData(){ + + MicroserviceData microserviceData= new MicroserviceData(); + + List<MicroserviceParameter> parameterList = new ArrayList<MicroserviceParameter>(); + + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId((long)1); + microserviceParameter.setServiceId((long)1); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + parameterList.add(microserviceParameter); + + microserviceData.setId((long)1); + microserviceData.setName("test"); + microserviceData.setActive("test"); + microserviceData.setDesc("test"); + microserviceData.setAppId((long)1); + microserviceData.setUrl("test"); + microserviceData.setSecurityType("test"); + microserviceData.setUsername("test"); + microserviceData.setPassword("test"); + + + return microserviceData; + } + + @Test + public void microserviceDataTest(){ + MicroserviceData microserviceData= mockMicroserviceData(); + + assertEquals(microserviceData.getId(), new Long(1)); + assertEquals(microserviceData.getName(), "test"); + assertEquals(microserviceData.getActive(), "test"); + assertEquals(microserviceData.getDesc(), "test"); + // assertEquals(microserviceData.getAppId(), new long(1)); + assertEquals(microserviceData.getUrl(), "test"); + assertEquals(microserviceData.getSecurityType(), "test"); + assertEquals(microserviceData.getUsername(), "test"); + assertEquals(microserviceData.getPassword(), "test"); + + assertEquals(microserviceData.toString(), "MicroserviceData [id=1, name=test, desc=test, appId=1, " + + "url=test, securityType=test, username=test, password=test, parameterList=null]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/MicroserviceParameterTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/MicroserviceParameterTest.java new file mode 100644 index 00000000..e15f2267 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/MicroserviceParameterTest.java @@ -0,0 +1,31 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.MicroserviceParameter; + +public class MicroserviceParameterTest { + + public MicroserviceParameter mockMicroserviceParameter(){ + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + + microserviceParameter.setId((long)1); + microserviceParameter.setServiceId((long)1); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + + return microserviceParameter; + } + + @Test + public void microserviceParameterTest(){ + MicroserviceParameter microserviceParameter = mockMicroserviceParameter(); + assertEquals(microserviceParameter.getId(), new Long(1)); + assertEquals(microserviceParameter.getServiceId(),(long)1); + assertEquals(microserviceParameter.getPara_key(), "test"); + assertEquals(microserviceParameter.getPara_value(), "test"); + + assertEquals(microserviceParameter.toString(), "MicroserviceParameter [id=1, serviceId=1, para_key=test, para_value=test]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/PersUserAppSelectionTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/PersUserAppSelectionTest.java new file mode 100644 index 00000000..7f4bdc1b --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/PersUserAppSelectionTest.java @@ -0,0 +1,35 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.PersUserAppSelection; + +public class PersUserAppSelectionTest { + + public PersUserAppSelection mockPersUserAppSelection(){ + + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setUserId((long)1); + persUserAppSelection.setAppId((long)1); + persUserAppSelection.setStatusCode("test"); + + return persUserAppSelection; + } + + @Test + public void persUserAppSelectionTest(){ + + PersUserAppSelection persUserAppSelection1 = new PersUserAppSelection((long)1, (long)1, (long)1,"test"); + + PersUserAppSelection persUserAppSelection = mockPersUserAppSelection(); + + assertEquals(persUserAppSelection.getUserId(), new Long(1)); + assertEquals(persUserAppSelection.getAppId(), new Long(1)); + assertEquals(persUserAppSelection.getStatusCode(), "test"); + assertEquals(persUserAppSelection1.hashCode(), new PersUserAppSelection((long)1, (long)1, (long)1,"test").hashCode()); + assertEquals(persUserAppSelection1, new PersUserAppSelection((long)1, (long)1, (long)1,"test")); + assertTrue(persUserAppSelection1.equals(new PersUserAppSelection((long)1, (long)1, (long)1,"test"))); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/PersUserWidgetSelectionTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/PersUserWidgetSelectionTest.java new file mode 100644 index 00000000..55e1bd64 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/PersUserWidgetSelectionTest.java @@ -0,0 +1,36 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.PersUserWidgetSelection; + +public class PersUserWidgetSelectionTest { + + public PersUserWidgetSelection mockPersUserWidgetSelection(){ + + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + + persUserWidgetSelection.setUserId((long)1); + persUserWidgetSelection.setWidgetId((long)1); + persUserWidgetSelection.setStatusCode("test"); + + return persUserWidgetSelection; + } + + @Test + public void persUserWidgetSelectionTest(){ + PersUserWidgetSelection persUserWidgetSelection = mockPersUserWidgetSelection(); + + PersUserWidgetSelection persUserWidgetSelection1 = new PersUserWidgetSelection((long)1, (long)1, (long)1, "test"); + + assertEquals(persUserWidgetSelection.getUserId(), new Long(1)); + assertEquals(persUserWidgetSelection.getWidgetId(), new Long(1)); + assertEquals(persUserWidgetSelection.getStatusCode(), "test"); + assertEquals(persUserWidgetSelection1, new PersUserWidgetSelection((long)1, (long)1, (long)1, "test")); + assertTrue(persUserWidgetSelection1.equals(new PersUserWidgetSelection((long)1, (long)1, (long)1,"test"))); + assertEquals(persUserWidgetSelection.hashCode(), persUserWidgetSelection1.hashCode()); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ResultTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ResultTest.java new file mode 100644 index 00000000..6763cc0b --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/ResultTest.java @@ -0,0 +1,29 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.model.Result; + +public class ResultTest { + + public Result mockResult(){ + + Result result= new Result("test"); + + result.setResult("test"); + return result; + } + + @Test + public void resultTest(){ + + Result result = mockResult(); + result.setResult("test"); + + assertEquals(result.getResult(), "test"); + + } + + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/SharedContextTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/SharedContextTest.java new file mode 100644 index 00000000..239080d2 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/SharedContextTest.java @@ -0,0 +1,36 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.SharedContext; + +public class SharedContextTest { + + public SharedContext mockSharedContext(){ + + SharedContext sharedContext = new SharedContext(); + sharedContext.setId((long)1); + sharedContext.setCreate_time(new Date()); + sharedContext.setContext_id("test"); + sharedContext.setCkey("test"); + sharedContext.setCvalue("test"); + + return sharedContext; + } + + @Test + public void sharedContextTest(){ + SharedContext sharedContext = mockSharedContext(); + + assertEquals(sharedContext.getId(), new Long(1)); + // assertEquals(sharedContext.getCreate_time(), new Date()); + assertEquals(sharedContext.getContext_id(), "test"); + assertEquals(sharedContext.getCkey(), "test"); + assertEquals(sharedContext.getCvalue(), "test"); + + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/UserIdRoleIdTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/UserIdRoleIdTest.java new file mode 100644 index 00000000..169d8798 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/UserIdRoleIdTest.java @@ -0,0 +1,29 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.UserIdRoleId; + +public class UserIdRoleIdTest { + + public UserIdRoleId mockUserIdRoleId(){ + UserIdRoleId userIdRoleId = new UserIdRoleId(); + userIdRoleId.setUser_Id("test"); + userIdRoleId.setRoleId("test"); + userIdRoleId.setOrgUserId("test"); + userIdRoleId.setAppId("test"); + + return userIdRoleId; + } + + @Test + public void userIdRoleIdTest(){ + UserIdRoleId userIdRoleId = mockUserIdRoleId(); + + assertEquals(userIdRoleId.getUser_Id(), "test"); + assertEquals(userIdRoleId.getRoleId(), "test"); + assertEquals(userIdRoleId.getOrgUserId(), "test"); + assertEquals(userIdRoleId.getAppId(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetCatalogParameterTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetCatalogParameterTest.java new file mode 100644 index 00000000..fe525d7b --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetCatalogParameterTest.java @@ -0,0 +1,33 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.WidgetCatalogParameter; + +public class WidgetCatalogParameterTest { + + public WidgetCatalogParameter mockWidgetCatalogParameter(){ + WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter(); + + widgetCatalogParameter.setId((long)1); + widgetCatalogParameter.setWidgetId((long)1); + widgetCatalogParameter.setUserId((long)1); + widgetCatalogParameter.setParamId((long)1); + widgetCatalogParameter.setUser_value("test"); + + return widgetCatalogParameter; + } + + @Test + public void widgetCatalogParameterTest(){ + WidgetCatalogParameter widgetCatalogParameter = mockWidgetCatalogParameter(); + + assertEquals(widgetCatalogParameter.getId(), new Long(1)); + assertEquals(widgetCatalogParameter.getWidgetId(), new Long(1)); + assertEquals(widgetCatalogParameter.getUserId(), new Long(1)); + assertEquals(widgetCatalogParameter.getParamId(), new Long(1)); + assertEquals(widgetCatalogParameter.getUser_value(), "test"); + assertEquals(widgetCatalogParameter.toString(), "WidgetCatalogParameter [id=1, widgetId=1, userId=1, paramId=1, user_value=test]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetCatalogTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetCatalogTest.java new file mode 100644 index 00000000..3b7aa764 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetCatalogTest.java @@ -0,0 +1,84 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.App; +import org.openecomp.portalapp.portal.domain.RoleApp; +import org.openecomp.portalapp.portal.domain.WidgetCatalog; + +public class WidgetCatalogTest { + + public WidgetCatalog mockWidgetCatalog() { + + WidgetCatalog widgetCatalog = new WidgetCatalog(); + + Set<RoleApp> roleAppSet = new HashSet<RoleApp>(); + // App + App app = new App(); + app.setAppId((long) 1); + app.setAppName("test"); + + // RoleApp + RoleApp roleApp = new RoleApp(); + roleApp.setRoleId((long) 1); + roleApp.setRoleName("test"); + roleApp.setApp(app); + roleApp.setWidgets(null); + + roleAppSet.add(roleApp); + + widgetCatalog.setId((long) 1); + widgetCatalog.setName("test"); + widgetCatalog.setDesc("test"); + widgetCatalog.setFileLocation("test"); + widgetCatalog.setAllowAllUser("test"); + widgetCatalog.setServiceId((long) 1); + widgetCatalog.setSortOrder("test"); + widgetCatalog.setStatusCode("test"); + + widgetCatalog.setWidgetRoles(roleAppSet); + + return widgetCatalog; + + } + + @Test + public void widgetCatalogTest() { + + // App + App app = new App(); + app.setAppId((long) 1); + app.setAppName("test"); + + Set<RoleApp> roleAppSet = new HashSet<RoleApp>(); + // RoleApp + RoleApp roleApp = new RoleApp(); + roleApp.setRoleId((long) 1); + roleApp.setRoleName("test"); + roleApp.setApp(app); + roleApp.setWidgets(null); + + roleAppSet.add(roleApp); + + WidgetCatalog widgetCatalog = mockWidgetCatalog(); + + + assertEquals(widgetCatalog.getId(), (long)1); + assertEquals(widgetCatalog.getName(), "test"); + assertEquals(widgetCatalog.getDesc(), "test"); + assertEquals(widgetCatalog.getFileLocation(), "test"); + assertEquals(widgetCatalog.getAllowAllUser(), "test"); + assertEquals(widgetCatalog.getServiceId(), new Long (1)); + assertEquals(widgetCatalog.getSortOrder(), "test"); + assertEquals(widgetCatalog.getStatusCode(), "test"); + assertEquals(widgetCatalog.getWidgetRoles().size(),1); + + assertEquals("WidgetCatalog [id=1, name=test, desc=test, fileLocation=test, allowAllUser=test]", widgetCatalog.toString()); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetParameterResultTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetParameterResultTest.java new file mode 100644 index 00000000..75b3d606 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetParameterResultTest.java @@ -0,0 +1,33 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.WidgetParameterResult; + +public class WidgetParameterResultTest { + + public WidgetParameterResult mockWidgetParameterResult(){ + + WidgetParameterResult widgetParameterResult = new WidgetParameterResult(); + widgetParameterResult.setParam_id((long)1); + widgetParameterResult.setParam_key("test"); + widgetParameterResult.setUser_value("test"); + widgetParameterResult.setDefault_value("test"); + + return widgetParameterResult; + } + + @Test + public void widgetParameterResultTest(){ + + WidgetParameterResult widgetParameterResult = mockWidgetParameterResult(); + + assertEquals(widgetParameterResult.getParam_key(), "test"); + assertEquals(widgetParameterResult.getParam_id(), new Long(1)); + assertEquals(widgetParameterResult.getUser_value(), "test"); + assertEquals(widgetParameterResult.getDefault_value(), "test"); + + assertEquals("WidgetParameterResult [param_id=1, param_key=test, user_value=test, default_value=test]", widgetParameterResult.toString()); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetTest.java new file mode 100644 index 00000000..a7597982 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/domain/WidgetTest.java @@ -0,0 +1,34 @@ +package org.openecomp.portalapp.portal.test.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.Widget; + +public class WidgetTest { + + public Widget mockWidget(){ + + Widget widget = new Widget(); + widget.setName("test"); + widget.setWidth(100); + widget.setHeight(100); + widget.setUrl("test"); + widget.setAppId((long)1); + + return widget; + } + + @Test + public void widgetTest(){ + Widget widget = mockWidget(); + + assertEquals(widget.getName(), "test"); + assertTrue(widget.getWidth() == 100); + assertTrue(widget.getHeight() == 100); + assertEquals(widget.getUrl(), "test"); + assertEquals(widget.getAppId(), new Long(1)); + + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/AppContactUsServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/AppContactUsServiceImplTest.java new file mode 100644 index 00000000..bb74cc6a --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/AppContactUsServiceImplTest.java @@ -0,0 +1,147 @@ +package org.openecomp.portalapp.portal.test.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.test.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); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/DashboardSearchServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/DashboardSearchServiceImplTest.java new file mode 100644 index 00000000..ab380ba5 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/DashboardSearchServiceImplTest.java @@ -0,0 +1,114 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +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.ecomp.model.SearchResultItem; +import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.portal.transport.CommonWidget; +import org.openecomp.portalapp.portal.transport.CommonWidgetMeta; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.service.DataAccessService; + +public class DashboardSearchServiceImplTest { + + @Mock + DataAccessService dataAccessService; + + @InjectMocks + DashboardSearchServiceImpl dashboardSearchServiceImpl = new DashboardSearchServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void searchResultsTest() + { + Map<String, String> params = new HashMap<>(); + params.put("userId", "guestT"); + params.put("searchQuery", "test"); + + List<SearchResultItem> list = new ArrayList<>(); + SearchResultItem searchResultItem= new SearchResultItem(); + searchResultItem.setCategory("test"); + list.add(searchResultItem); + Mockito.when(dataAccessService.executeNamedQuery("searchPortal", params, null)).thenReturn(list); + Map<String, List<SearchResultItem>> result = dashboardSearchServiceImpl.searchResults("guestT", "test"); + assertTrue(result.keySet().contains("test")); + } + + @Test + public void getRelatedUsersTest() + { + List<String> activeUsers = new ArrayList<>(); + Map<String, String> params = new HashMap<>(); + params.put("userId", "guestT"); + Mockito.when(dataAccessService.executeNamedQuery("relatedUsers", params, null)).thenReturn(activeUsers); + List<String> expectedActiveUsers = dashboardSearchServiceImpl.getRelatedUsers("guestT"); + assertEquals(expectedActiveUsers,activeUsers); + } + @Test + public void getWidgetDataTest() + { + CommonWidgetMeta CommonWidgetMeta = null; + Map<String, String> params = new HashMap<>(); + params.put("cat", "test"); + @SuppressWarnings("unchecked") + List<CommonWidget> widgetItems = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + widgetItems.add(commonWidget); + Mockito.when(dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null)).thenReturn(widgetItems); + CommonWidgetMeta expectedCommonWidgetMeta =dashboardSearchServiceImpl.getWidgetData("test"); + assertEquals(expectedCommonWidgetMeta.getCategory(), "test"); + } + + @Test + public void saveWidgetDataBulkTest() + { + CommonWidgetMeta CommonWidgetMeta = new CommonWidgetMeta(); + List<CommonWidget> widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + widgetList.add(commonWidget); + CommonWidgetMeta.setItems(widgetList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(commonWidget, null); + assertEquals(dashboardSearchServiceImpl.saveWidgetDataBulk(CommonWidgetMeta), "success"); + } + + @Test + public void saveWidgetDataTest() + { + CommonWidget commonWidget = new CommonWidget(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(commonWidget, null); + assertEquals(dashboardSearchServiceImpl.saveWidgetData(commonWidget), "success"); + } + + @Test + public void deleteWidgetDataTest() + { + CommonWidget commonWidget = new CommonWidget(); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(commonWidget, null); + assertEquals(dashboardSearchServiceImpl.deleteWidgetData(commonWidget), "success"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleFunctionServiceCentralizedImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleFunctionServiceCentralizedImplTest.java new file mode 100644 index 00000000..7db06a52 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleFunctionServiceCentralizedImplTest.java @@ -0,0 +1,89 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.hibernate.SessionFactory; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.domain.CentralRoleFunction; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.service.EPRoleFunctionServiceCentralizedImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(SystemProperties.class) +public class EPRoleFunctionServiceCentralizedImplTest { + + + @Mock + DataAccessService dataAccessService; + + @Mock + SessionFactory sessionFactory; + + @InjectMocks + EPRoleFunctionServiceCentralizedImpl ePRoleFunctionServiceCentralizedImpl = new EPRoleFunctionServiceCentralizedImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void getRoleFunctions() + { + List<CentralRoleFunction> getRoleFuncList = new ArrayList<>(); + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + getRoleFuncList.add(centralRoleFunction); + List<RoleFunction> getRoleFuncListOfPortal = new ArrayList<>(); + RoleFunction roleFunction = new RoleFunction(); + getRoleFuncListOfPortal.add(roleFunction); + final Map<String, Long> params = new HashMap<>(); + params.put("appId", (long) 1); + Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(getRoleFuncList); + List<RoleFunction> expectedGetRoleFuncListOfPortal = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions(); + assertEquals(expectedGetRoleFuncListOfPortal.size(),getRoleFuncListOfPortal.size()); + } + + @Test + public void getRoleFunctionsNewTest() + { + HttpSession session = mockedRequest.getSession(); + EPUser user = mockUser.mockEPUser(); + user.setId((long) 1); + String userId = user.getId().toString(); + final Map<String, String> params = new HashMap<>(); + params.put("userId", userId); + @SuppressWarnings("unused") + List getRoleFuncListOfPortal = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getRoleFunctionsOfUser", params, null)).thenReturn(getRoleFuncListOfPortal); + Set<String> getRoleFuncListOfPortalSet = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions(mockedRequest, user); + assertTrue(getRoleFuncListOfPortalSet.size() == 0); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleFunctionServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleFunctionServiceImplTest.java new file mode 100644 index 00000000..c8cd8d28 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleFunctionServiceImplTest.java @@ -0,0 +1,98 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.domain.EPRole; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.service.EPRoleFunctionServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, EPUserUtils.class }) +public class EPRoleFunctionServiceImplTest { + + @Mock + DataAccessService dataAccessService; + + @InjectMocks + EPRoleFunctionServiceImpl ePRoleFunctionServiceImpl = new EPRoleFunctionServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void getRoleFunctionsTest() { + List<RoleFunction> functions = new ArrayList<>(); + Mockito.when(dataAccessService.getList(RoleFunction.class, null)).thenReturn(functions); + List<RoleFunction> expectedFunctions = ePRoleFunctionServiceImpl.getRoleFunctions(); + assertEquals(expectedFunctions, functions); + } + + @Test + public void getRoleFunctionsRequestTest() { + EPUser user = mockUser.mockEPUser(); + HashSet roleFunctions = new HashSet<>(); + PowerMockito.mockStatic(SystemProperties.class); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))) + .thenReturn(roleFunctions); + HashSet expectedRoleFunctions = (HashSet) ePRoleFunctionServiceImpl.getRoleFunctions(mockedRequest, user); + assertEquals(expectedRoleFunctions, roleFunctions); + } + + @SuppressWarnings("unchecked") + @Test + public void getRoleFunctionsRequestIfNullTest() { + EPUser user = mockUser.mockEPUser(); + HashSet roleFunctions = null; + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPUserUtils.class); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))) + .thenReturn(roleFunctions); + HashMap roles = new HashMap<>(); + EPRole role = new EPRole(); + SortedSet<RoleFunction> roleFunctionSet = new TreeSet<RoleFunction>(); + RoleFunction rolefun = new RoleFunction(); + roleFunctionSet.add(rolefun); + role.setRoleFunctions(roleFunctionSet); + roles.put((long) 1, role); + Mockito.when(EPUserUtils.getRoles(mockedRequest)).thenReturn(roles); + HashSet expectedRoleFunctions = (HashSet) ePRoleFunctionServiceImpl.getRoleFunctions(mockedRequest, user); + assertTrue(expectedRoleFunctions.size() == 1); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleServiceImplTest.java new file mode 100644 index 00000000..10060350 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/EPRoleServiceImplTest.java @@ -0,0 +1,208 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +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.EPRole; +import org.openecomp.portalapp.portal.service.EPRoleServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.service.DataAccessService; + +public class EPRoleServiceImplTest { + + @Mock + DataAccessService dataAccessService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + EPRoleServiceImpl ePRoleServiceImpl = new EPRoleServiceImpl(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getRoleFunctionsTest() { + List<RoleFunction> roleFunctionList = new ArrayList<>(); + Mockito.when(dataAccessService.getList(RoleFunction.class, null)).thenReturn(roleFunctionList); + List<RoleFunction> expectedRoleFunctionList = ePRoleServiceImpl.getRoleFunctions(); + assertEquals(roleFunctionList, expectedRoleFunctionList); + } + + @Test + public void getAvailableChildRolesIfRoleIdIsNullTest() { + List<EPRole> roleList = new ArrayList<>(); + EPRole role = new EPRole(); + EPRole role1 = new EPRole(); + role.addChildRole(role1); + roleList.add(role); + Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList); + List<EPRole> expectedRoleList = ePRoleServiceImpl.getAvailableChildRoles(null); + assertEquals(roleList, expectedRoleList); + } + + // @Test + // public void getAvailableChildRolesIfRoleIdNotNullTest() + // { + // List<EPRole> roleList = new ArrayList<>(); + // EPRole role = new EPRole(); + // EPRole role1= new EPRole(); + // role.addChildRole(role1); + // roleList.add(role); + // Mockito.when(dataAccessService.getDomainObject(EPRole.class, 1, + // null)).thenReturn(role); + // Mockito.when(dataAccessService.getList(EPRole.class, + // null)).thenReturn(roleList); + // + // List<EPRole> expectedRoleList = + // ePRoleServiceImpl.getAvailableChildRoles((long) 1); + // System.out.println(expectedRoleList); + // assertEquals(roleList,expectedRoleList); + // } + // + @Test + public void getRoleFunctionTest() { + RoleFunction roleFunction = new RoleFunction(); + Mockito.when(dataAccessService.getDomainObject(RoleFunction.class, "test", null)).thenReturn(roleFunction); + RoleFunction expectedRoleFunction = ePRoleServiceImpl.getRoleFunction("test"); + assertEquals(expectedRoleFunction, roleFunction); + } + + @Test + public void saveRoleFunctionTest() { + EPRole role = new EPRole(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(role, null); + ePRoleServiceImpl.saveRole(role); + } + + @Test + public void deleteRoleFunctionTest() { + RoleFunction roleFunction = new RoleFunction(); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(roleFunction, null); + ePRoleServiceImpl.deleteRoleFunction(roleFunction); + } + + @Test + public void getRoleTest() { + EPRole role = null; + Mockito.when(dataAccessService.getDomainObject(EPRole.class, 1, null)).thenReturn(role); + EPRole expectedRole = ePRoleServiceImpl.getRole((long) 1); + assertEquals(expectedRole, role); + } + + @Test + public void getRoleIfappIdNullTest() { + assertNull(ePRoleServiceImpl.getRole(null, null)); + + } + + @Test + public void getRoleIfappIdNotNullTest() { + List<EPRole> roles = new ArrayList<>(); + EPRole role = new EPRole(); + roles.add(role); + String sql = "SELECT * FROM fn_role where APP_ID = 1 AND APP_ROLE_ID = 1"; + Mockito.when(dataAccessService.executeSQLQuery(sql, EPRole.class, null)).thenReturn(roles); + EPRole expectedRole = ePRoleServiceImpl.getRole((long) 1, (long) 1); + assertEquals(expectedRole, role); + + } + + @Test + public void getRoleIfListSizeIsMoreThan1Test() { + List<EPRole> roles = new ArrayList<>(); + EPRole role = new EPRole(); + EPRole role1 = new EPRole(); + roles.add(role); + roles.add(role1); + String sql = "SELECT * FROM fn_role where APP_ID = 1 AND APP_ROLE_ID = 1"; + Mockito.when(dataAccessService.executeSQLQuery(sql, EPRole.class, null)).thenReturn(roles); + EPRole expectedRole = ePRoleServiceImpl.getRole((long) 1, (long) 1); + assertEquals(expectedRole, role); + + } + + @Test + public void getRoleIfListSizeIsEmptyTest() { + List<EPRole> roles = new ArrayList<>(); + String sql = "SELECT * FROM fn_role where APP_ID = 1 AND APP_ROLE_ID = 1"; + Mockito.when(dataAccessService.executeSQLQuery(sql, EPRole.class, null)).thenReturn(roles); + assertNull(ePRoleServiceImpl.getRole((long) 1, (long) 1)); + + } + + @Test + public void saveRoleTest() { + EPRole role = new EPRole(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(role, null); + ePRoleServiceImpl.saveRole(role); + } + + @Test + public void deleteRoleTest() { + EPRole role = new EPRole(); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(role, null); + ePRoleServiceImpl.deleteRole(role); + } + + @Test + public void getAvailableRolesTest() { + List<EPRole> roleList = new ArrayList<>(); + Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList); + List<EPRole> expectedRoleList = ePRoleServiceImpl.getAvailableRoles(); + assertEquals(expectedRoleList, roleList); + } + + @Test + public void getAppRolesTest() { + final Map<String, String> portalParams = null; + List<EPRole> roleList = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoles", portalParams, null)).thenReturn(roleList); + assertNull(ePRoleServiceImpl.getAppRole("test", (long) 1)); + + } + + @SuppressWarnings("unchecked") + @Test + public void getAppRolesIfNotPortalTest() { + final Map<String, String> params = null; + List<EPRole> roleList = new ArrayList<>(); + EPRole role = new EPRole(); + EPRole role1 = new EPRole(); + roleList.add(role); + roleList.add(role1); + Mockito.when((List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", params, null)) + .thenReturn(roleList); + List<EPRole> expectedRoleList = (List<EPRole>) ePRoleServiceImpl.getAppRole("test", (long) 10); + System.out.println(expectedRoleList); + + } + + @Test + public void saveRoleFunction() { + RoleFunction domainRoleFunction = new RoleFunction(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(domainRoleFunction, null); + ePRoleServiceImpl.saveRoleFunction(domainRoleFunction); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/ExternalAccessRolesServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/ExternalAccessRolesServiceImplTest.java new file mode 100644 index 00000000..d8cd6425 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/ExternalAccessRolesServiceImplTest.java @@ -0,0 +1,346 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.domain.CentralRoleFunction; +import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.domain.EPAppRoleFunction; +import org.openecomp.portalapp.portal.domain.EPRole; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.service.ExternalAccessRolesServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.portal.transport.ExternalAccessPerms; +import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.service.DataAccessServiceImpl; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EcompPortalUtils.class, SystemProperties.class, EPCommonSystemProperties.class }) +public class ExternalAccessRolesServiceImplTest { + @Mock + DataAccessService dataAccessService1 = new DataAccessServiceImpl(); + + @Mock + RestTemplate template = new RestTemplate(); + + @InjectMocks + ExternalAccessRolesServiceImpl externalAccessRolesServiceImpl = new ExternalAccessRolesServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + public EPApp mockApp() { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 10); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + + @Test + public void getAppRolesIfAppIsPortalTest() throws Exception { + List<EPRole> applicationRoles = new ArrayList<>(); + Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles); + List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 1); + assertEquals(expectedApplicationRoles, applicationRoles); + } + + @Test + public void getAppRolesTest() throws Exception { + List<EPRole> applicationRoles = new ArrayList<>(); + Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles); + List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 10); + assertEquals(expectedApplicationRoles, applicationRoles); + } + + // @SuppressWarnings("null") + // @Test(expected = java.lang.Exception.class) + // public void getAppRolesExceptionTest() throws Exception{ + // List<EPRole> applicationRoles = new ArrayList<>(); + // DataAccessService dataAccessService = null ; + // Mockito.when(dataAccessService.getList(EPRole.class, "where app_id = 10", + // null, null)).thenThrow(nullPointerException); + // List<EPRole> expectedApplicationRoles = + // externalAccessRolesServiceImpl.getAppRoles((long) 10); + // assertEquals(expectedApplicationRoles,applicationRoles); + // } + + @Test(expected = java.lang.Exception.class) + public void getAppExceptionTest() throws Exception { + List<EPApp> app = new ArrayList<>(); + String uebKey = "test-ueb-key"; + Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)) + .thenReturn(app); + List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey); + assertEquals(app, expectedapp); + } + + @Test(expected = java.lang.Exception.class) + public void getAppTest() throws Exception { + List<EPApp> appList = new ArrayList<>(); + EPApp app = mockApp(); + appList.add(app); + String uebKey = "test-ueb-key"; + Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)) + .thenReturn(appList); + List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey); + } + + @Test + public void getAppErrorTest() throws Exception { + List<EPApp> appList = new ArrayList<>(); + EPApp app = mockApp(); + app.setId((long) 1); + appList.add(app); + String uebKey = "test-ueb-key"; + Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)) + .thenReturn(appList); + List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey); + assertEquals(appList, expectedapp); + } + + @Test + public void addRoleTest() throws Exception { + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + String uebKey = "test-ueb-key"; + Role role = new Role(); + role.setId((long) 25); + EPApp app = mockApp(); + app.setEnabled(true); + app.setId((long) 10); + app.setNameSpace("test_namesapce"); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + List<EPApp> appList = new ArrayList<>(); + appList.add(app); + List<EPRole> roleList = new ArrayList<>(); + EPRole ePRole = new EPRole(); + role.setName("Test Role"); + roleList.add(ePRole); + Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)) + .thenReturn(appList); + Mockito.when(dataAccessService1.getList(EPRole.class, " where app_role_id = " + role.getId(), null, null)) + .thenReturn(roleList); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL)) + .thenReturn("Testurl"); + ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse); + + assertTrue(externalAccessRolesServiceImpl.addRole(role, uebKey)); + } + + @Test + public void addRoleMethodNotAllowedTest() throws Exception { + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + String uebKey = "test-ueb-key"; + Role role = new Role(); + role.setId((long) 25); + EPApp app = mockApp(); + app.setEnabled(true); + app.setId((long) 10); + app.setNameSpace("test_namesapce"); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + List<EPApp> appList = new ArrayList<>(); + appList.add(app); + List<EPRole> roleList = new ArrayList<>(); + EPRole ePRole = new EPRole(); + role.setName("Test Role"); + roleList.add(ePRole); + Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)) + .thenReturn(appList); + Mockito.when(dataAccessService1.getList(EPRole.class, " where app_role_id = " + role.getId(), null, null)) + .thenReturn(roleList); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL)) + .thenReturn("Testurl"); + ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse); + + assertFalse(externalAccessRolesServiceImpl.addRole(role, uebKey)); + } + + 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 deleteCentralRoleFunctionTest() throws Exception { + final Map<String, String> params = new HashMap<>(); + EPApp app = mockApp(); + params.put("functionCd", "menu_fun_code"); + params.put("appId", String.valueOf(10)); + List<CentralRoleFunction> centralRoleFunctionList = new ArrayList<>(); + CentralRoleFunction domainCentralRoleFunction = new CentralRoleFunction(); + domainCentralRoleFunction.setCode("menu_fun_code"); + centralRoleFunctionList.add(domainCentralRoleFunction); + Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params, null)) + .thenReturn(centralRoleFunctionList); + ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse); + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + + Mockito.doNothing().when(dataAccessService1).deleteDomainObjects(EPAppRoleFunction.class, + "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null); + + assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app)); + } + + @Test + public void deleteCentralRoleFunctionFailTest() throws Exception { + final Map<String, String> params = new HashMap<>(); + EPApp app = mockApp(); + params.put("functionCd", "menu_fun_code"); + params.put("appId", String.valueOf(10)); + List<CentralRoleFunction> centralRoleFunctionList = new ArrayList<>(); + CentralRoleFunction domainCentralRoleFunction = new CentralRoleFunction(); + domainCentralRoleFunction.setCode("menu_fun_code"); + centralRoleFunctionList.add(domainCentralRoleFunction); + HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.NOT_FOUND); + Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params, null)) + .thenReturn(centralRoleFunctionList); + ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.NOT_FOUND); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(httpClientErrorException); + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + + Mockito.doNothing().when(dataAccessService1).deleteDomainObjects(EPAppRoleFunction.class, + "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null); + + assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app)); + } + + @Test + public void deleteCentralRoleFunctionExceptionTest() { + final Map<String, String> params = new HashMap<>(); + EPApp app = mockApp(); + params.put("functionCd", "menu_fun_code"); + params.put("appId", String.valueOf(10)); + List<CentralRoleFunction> centralRoleFunctionList = new ArrayList<>(); + CentralRoleFunction domainCentralRoleFunction = new CentralRoleFunction(); + domainCentralRoleFunction.setCode("menu_fun_code"); + centralRoleFunctionList.add(domainCentralRoleFunction); + Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params, null)) + .thenThrow(nullPointerException); + assertFalse(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app)); + } + + @Test + public void getUserTest() { + List<EPUser> userList = new ArrayList<>(); + EPUser user = mockUser.mockEPUser(); + userList.add(user); + Mockito.when(dataAccessService1.getList(EPUser.class, " where org_user_id = '" + "guestT" + "'", null, null)) + .thenReturn(userList); + List<EPUser> expectedUserList = externalAccessRolesServiceImpl.getUser("guestT"); + assertEquals(expectedUserList, userList); + } + + public void saveCentralRoleFunctionTest() throws Exception { + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + centralRoleFunction.setCode("menu_test"); + EPApp app = mockApp(); + app.setId((long) 1); + final Map<String, String> params = new HashMap<>(); + params.put("functionCd", "menu_test"); + params.put("appId", String.valueOf(1)); + ExternalAccessPerms extPerms = new ExternalAccessPerms(); + PowerMockito.mockStatic(EcompPortalUtils.class); + HttpHeaders headers = new HttpHeaders(); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + List<CentralRoleFunction> appRoleFunc = new ArrayList<>(); + appRoleFunc.add(centralRoleFunction); + Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params, + null)).thenReturn(appRoleFunc); + ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuMockServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuMockServiceImplTest.java new file mode 100644 index 00000000..51802c13 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuMockServiceImplTest.java @@ -0,0 +1,205 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * 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. + * ================================================================================ + */ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.portal.domain.FunctionalMenuItemWithAppID; +import org.openecomp.portalapp.portal.service.FunctionalMenuService; +import org.openecomp.portalapp.portal.service.FunctionalMenuServiceImpl; +import org.openecomp.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; +import org.openecomp.portalapp.portal.transport.FunctionalMenuItem; +import org.openecomp.portalapp.portal.transport.FunctionalMenuRole; +import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; +import org.openecomp.portalapp.test.framework.ApplicationCommonContextTestSuite; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class, EPCommonSystemProperties.class}) +public class FunctionalMenuMockServiceImplTest extends ApplicationCommonContextTestSuite { + + @Mock + FunctionalMenuService functionalMenuService; + + @Mock + DataAccessService dataAccessService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + FunctionalMenuServiceImpl functionalMenuServiceImpl= new FunctionalMenuServiceImpl(); + + @Test + public void assignHelpURLsTest(){ + List<FunctionalMenuItem> menuItems = new ArrayList<FunctionalMenuItem>(); + FunctionalMenuItem functionalMenuItem1 = new FunctionalMenuItem(); + functionalMenuItem1.text = "Contact Us"; + FunctionalMenuItem functionalMenuItem2 = new FunctionalMenuItem(); + functionalMenuItem2.text = "Get Access"; + FunctionalMenuItem functionalMenuItem3 = new FunctionalMenuItem(); + functionalMenuItem3.text = "User Guide"; + menuItems.add(functionalMenuItem1); + menuItems.add(functionalMenuItem2); + menuItems.add(functionalMenuItem3); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.USER_GUIDE_URL)).thenReturn("http://todo_enter_user_guide_link"); +// Mockito.doNothing().when(functionalMenuServiceImpl).assignHelpURLs(menuItems); + functionalMenuServiceImpl.assignHelpURLs(menuItems); + } + + @Test + public void getFunctionalMenuItemsTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, " + + "fn_menu_functional_roles r WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' " + + "UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id FROM fn_menu_functional m " + + "WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItems(true); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsNegativeTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, " + + "fn_menu_functional_roles r WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' " + + "UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id FROM fn_menu_functional m " + + "WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItems(false); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsForNotificationTreeTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, fn_menu_functional_roles r " + + "WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id," + + " m.url, m.active_yn,-1 app_id FROM fn_menu_functional m WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForNotificationTree(true); + assertEquals(actualResult, expectedResult); + + } + + @Test + public void getFunctionalMenuItemsForNotificationNegativeTreeTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, fn_menu_functional_roles r " + + "WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id," + + " m.url, m.active_yn,-1 app_id FROM fn_menu_functional m WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForNotificationTree(false); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsForAppTest(){ + String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn " + + "FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr " + + "WHERE mr.app_id='1' AND mr.menu_id = m.menu_id AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' AND a.menu_id = m.menu_id " + + "AND a.ancestor_menu_id = m1.menu_id"; + Integer appId = 1; + List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForApp(appId); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsForUserTest(){ + String orgUserId = "test"; + String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn " + + "FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr, fn_user u , fn_user_role ur " + + "WHERE u.org_user_id='test' AND u.user_id = ur.user_id AND ur.app_id = mr.app_id AND (ur.role_id = mr.role_id OR ur.role_id = '999') " + + "AND m.menu_id = mr.menu_id AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' AND a.menu_id = m.menu_id " + + "AND a.ancestor_menu_id = m1.menu_id UNION select m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m1.active_yn " + + "FROM fn_menu_functional m, fn_menu_functional_roles mr, fn_menu_functional m1, fn_menu_functional_ancestors a where a.menu_id = m.menu_id AND a.ancestor_menu_id = m1.menu_id AND m.menu_id != m1.menu_id AND m.menu_id = mr.menu_id AND mr.role_id = '900' AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn FROM fn_menu_functional m WHERE m.text in ('Favorites','Get Access','Contact Us','Support','User Guide','Help')"; + List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>(); + List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForUser(orgUserId); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemDetailsTest(){ + Integer menuid = 1; + String sql = "SELECT * FROM fn_menu_functional_roles WHERE menu_id = '1'"; + FunctionalMenuItem actualResult = null; + FunctionalMenuItem expectedResult = null; + List<FunctionalMenuRole> roleItems = new ArrayList<FunctionalMenuRole>(); + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(roleItems); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemDetails(menuid); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFavoriteItemsTest(){ + Long userId = (long)1; + String sql = "SELECT DISTINCT f.user_id,f.menu_id,m.text,m.url " + + "FROM fn_menu_favorites f, fn_menu_functional m, fn_menu_functional_roles mr " + + "WHERE f.user_id='1' AND f.menu_id = m.menu_id AND f.menu_id = mr.menu_id AND mr.role_id != '900' "; + List<FavoritesFunctionalMenuItemJson> actualResult = new ArrayList<FavoritesFunctionalMenuItemJson>(); + List<FavoritesFunctionalMenuItemJson> expectedResult = new ArrayList<FavoritesFunctionalMenuItemJson>(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFavoriteItems(userId); + assertEquals(actualResult, expectedResult); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/GetAccessServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/GetAccessServiceImplTest.java new file mode 100644 index 00000000..e689fab7 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/GetAccessServiceImplTest.java @@ -0,0 +1,50 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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.EPUser; +import org.openecomp.portalapp.portal.domain.GetAccessResult; +import org.openecomp.portalapp.portal.service.GetAccessServiceImpl; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.service.DataAccessServiceImpl; + +public class GetAccessServiceImplTest { + + + @Mock + DataAccessService dataAccessService = new DataAccessServiceImpl(); + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + GetAccessServiceImpl getAccessServiceImpl = new GetAccessServiceImpl(); + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getAppAccessListTest() + { + EPUser user = mockUser.mockEPUser(); + Map<String, Long> params = new HashMap<>(); + params.put("userId", user.getId()); + List<GetAccessResult> appAccessList = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getAppAccessFunctionRole", params, null)).thenReturn(appAccessList); + + List<GetAccessResult> expectedAppAccessList = getAccessServiceImpl.getAppAccessList(user); + assertEquals(expectedAppAccessList, appAccessList); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/LicenseableClassImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/LicenseableClassImplTest.java new file mode 100644 index 00000000..5c4cb5b4 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/LicenseableClassImplTest.java @@ -0,0 +1,61 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.openecomp.portalapp.lm.LicenseableClassImpl; + +public class LicenseableClassImplTest { + + @InjectMocks + LicenseableClassImpl licenseableClassImpl= new LicenseableClassImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getApplicationNameTest() + { + assertEquals(licenseableClassImpl.getApplicationName(), ""); + } + @Test + public void getPublicKeystoreAsInputStreamTest() throws IOException + { + assertNull(licenseableClassImpl.getPublicKeystoreAsInputStream()); + } + @Test + public void getAliasTest() + { + assertEquals(licenseableClassImpl.getAlias(), ""); + } + @Test + public void getKeyPasswdTest() + { + assertEquals(licenseableClassImpl.getKeyPasswd(), ""); + } + @Test + public void getPublicKeystorePasswordTest() + { + assertEquals(licenseableClassImpl.getPublicKeystorePassword(), ""); + } + @Test + public void getCipherParamPasswordTest() + { + assertEquals(licenseableClassImpl.getPublicKeystorePassword(), ""); + } + @Test + public void getClassToLicenseTest() + { + assertEquals(licenseableClassImpl.getClassToLicense(), LicenseableClassImpl.class); + } + + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/ManifestServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/ManifestServiceImplTest.java new file mode 100644 index 00000000..f2b6036e --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/ManifestServiceImplTest.java @@ -0,0 +1,55 @@ +package org.openecomp.portalapp.portal.test.service; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.jar.Attributes; + +import javax.servlet.ServletContext; + +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.service.ManifestServiceImpl; + +public class ManifestServiceImplTest { + + @Mock + ServletContext context; + + @Mock + ServletContext context1 = null; + + @InjectMocks + ManifestServiceImpl manifestServiceImpl = new ManifestServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void getWebappManifestTest() throws IOException { + final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF"; + InputStream inputStream = new ByteArrayInputStream("test data".getBytes()); + Mockito.when(context.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenReturn(inputStream); + Attributes attributes = manifestServiceImpl.getWebappManifest(); + assertTrue(attributes.size() == 0); + } + + @Test(expected = java.lang.NullPointerException.class) + public void getWebappManifestExceptionTest() throws IOException { + final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF"; + InputStream inputStream = new ByteArrayInputStream("test data".getBytes()); + Mockito.when(context1.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenThrow(nullPointerException); + Attributes attributes = manifestServiceImpl.getWebappManifest(); + assertTrue(attributes.size() == 0); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/PersUserAppServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/PersUserAppServiceImplTest.java new file mode 100644 index 00000000..bdd6cbd1 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/PersUserAppServiceImplTest.java @@ -0,0 +1,181 @@ +package org.openecomp.portalapp.portal.test.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.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.domain.EPUserApp; +import org.openecomp.portalapp.portal.domain.PersUserAppSelection; +import org.openecomp.portalapp.portal.service.AdminRolesService; +import org.openecomp.portalapp.portal.service.PersUserAppServiceImpl; +import org.openecomp.portalapp.portal.service.UserRolesService; +import org.openecomp.portalapp.portal.test.core.MockEPUser; +import org.openecomp.portalapp.test.framework.MockitoTestSuite; +import org.openecomp.portalsdk.core.service.DataAccessService; + +public class PersUserAppServiceImplTest { + + @Mock + DataAccessService dataAccessService; + @Mock + AdminRolesService adminRolesService; + @Mock + UserRolesService userRolesService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + PersUserAppServiceImpl persUserAppServiceImpl = new PersUserAppServiceImpl(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + 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(expected = IllegalArgumentException.class) + public void setPersUserAppValueIfUserNull() { + persUserAppServiceImpl.setPersUserAppValue(null, null, false, false); + } + + @Test + public void setPersUserAppValueTest() { + EPApp app = getApp(); + EPUser user = mockUser.mockEPUser(); + List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserAppSelection, null); + persUserAppServiceImpl.setPersUserAppValue(user, app, false, true); + } + + @Test + public void setPersUserAppValueIfSelectTest() { + EPApp app = getApp(); + EPUser user = mockUser.mockEPUser(); + List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, true); + } + + @Test + public void setPersUserAppValueIfOpenTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, true); + } + + @Test + public void setPersUserAppValueIfAppNotOpenTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + List<EPUserApp> roles = new ArrayList<>(); + EPUserApp epUserApp = new EPUserApp(); + roles.add(epUserApp); + Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, false); + } + + @Test + public void setPersUserAppValueIfNotPortalAdminTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserAppSelection, null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + List<EPUserApp> roles = new ArrayList<>(); + EPUserApp epUserApp = new EPUserApp(); + roles.add(epUserApp); + Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, false); + } + + @Test + public void setPersUserAppValueNewTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + List<EPUserApp> roles = new ArrayList<>(); + EPUserApp epUserApp = new EPUserApp(); + roles.add(epUserApp); + Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles); + persUserAppServiceImpl.setPersUserAppValue(user, app, false, false); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AnalyticsTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AnalyticsTest.java new file mode 100644 index 00000000..7fd3c03f --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AnalyticsTest.java @@ -0,0 +1,33 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.Analytics; + +public class AnalyticsTest { + + public Analytics mockAnalytics(){ + Analytics analytics = new Analytics(); + + analytics.setAction("test"); + analytics.setPage("test"); + analytics.setFunction("test"); + analytics.setUserid("test"); + analytics.setType("test"); + + return analytics; + } + + @Test + public void analyticsTest(){ + Analytics analytics = mockAnalytics(); + + assertEquals(analytics.getAction(), "test"); + assertEquals(analytics.getPage(), "test"); + assertEquals(analytics.getFunction(), "test"); + assertEquals(analytics.getUserid(), "test"); + assertEquals(analytics.getType(), "test"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppCatalogPersonalizationTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppCatalogPersonalizationTest.java new file mode 100644 index 00000000..c583c9cd --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppCatalogPersonalizationTest.java @@ -0,0 +1,25 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class AppCatalogPersonalizationTest { + + public AppCatalogPersonalization mockAppCatalogPersonalization(){ + AppCatalogPersonalization appCatalogPersonalization = new AppCatalogPersonalization(); + + return appCatalogPersonalization; + } + + @Test + public void appCatalogPersonalizationTest(){ + AppCatalogPersonalization appCatalogPersonalization = mockAppCatalogPersonalization(); + + AppCatalogPersonalization appCatalogPersonalization1 = new AppCatalogPersonalization(); + + assertEquals(appCatalogPersonalization.hashCode(), appCatalogPersonalization1.hashCode()); + assertTrue(appCatalogPersonalization.equals(appCatalogPersonalization1)); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppNameIdIsAdminTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppNameIdIsAdminTest.java new file mode 100644 index 00000000..a1dffd28 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppNameIdIsAdminTest.java @@ -0,0 +1,38 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.AppNameIdIsAdmin; + +public class AppNameIdIsAdminTest { + + public AppNameIdIsAdmin mockAppNameIdIsAdmin(){ + AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin(); + appNameIdIsAdmin.setId((long)1); + appNameIdIsAdmin.setAppName("test"); + appNameIdIsAdmin.setRestrictedApp(false); + appNameIdIsAdmin.setIsAdmin(false); + return appNameIdIsAdmin; + } + + @Test + public void appNameIdIsAdminTest(){ + AppNameIdIsAdmin appNameIdIsAdmin = mockAppNameIdIsAdmin(); + + AppNameIdIsAdmin appNameIdIsAdmin1 = new AppNameIdIsAdmin(); + appNameIdIsAdmin1.setId((long)1); + appNameIdIsAdmin1.setAppName("test"); + appNameIdIsAdmin1.setRestrictedApp(false); + appNameIdIsAdmin1.setIsAdmin(false); + + assertEquals(appNameIdIsAdmin.getId(), new Long(1)); + assertEquals(appNameIdIsAdmin.getAppName(), "test"); + assertEquals(appNameIdIsAdmin.getRestrictedApp(), false); + assertEquals(appNameIdIsAdmin.getIsAdmin(), false); + + assertEquals(appNameIdIsAdmin.toString(), "AppNameIdIsAdmin [id=1, appName=test, isAdmin=false, restrictedApp=false]"); + assertEquals(appNameIdIsAdmin.hashCode(), appNameIdIsAdmin1.hashCode()); + assertTrue(appNameIdIsAdmin.equals(appNameIdIsAdmin1)); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppWithRolesForUserTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppWithRolesForUserTest.java new file mode 100644 index 00000000..2a7c343c --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppWithRolesForUserTest.java @@ -0,0 +1,32 @@ +package org.openecomp.portalapp.portal.transport; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import org.openecomp.portalapp.portal.transport.AppWithRolesForUser; + +public class AppWithRolesForUserTest { + + public AppWithRolesForUser mockAppWithRolesForUser(){ + AppWithRolesForUser appWithRolesForUser = new AppWithRolesForUser(); + + // List<RoleInAppForUser> appRoles = new ArrayList<RoleInAppForUser>(); + + appWithRolesForUser.setOrgUserId("test"); + appWithRolesForUser.setAppId((long)1); + appWithRolesForUser.setAppName("test"); + appWithRolesForUser.setAppRoles(null); + + return appWithRolesForUser; + } + + @Test + public void roleInAppForUserTest(){ + AppWithRolesForUser appWithRolesForUser = mockAppWithRolesForUser(); + + assertEquals(appWithRolesForUser.getOrgUserId(), "test"); + assertEquals(appWithRolesForUser.getAppId(), new Long(1)); + assertEquals(appWithRolesForUser.getAppName(), "test"); + assertEquals(appWithRolesForUser.getAppRoles(), null); + assertEquals(appWithRolesForUser.toString(), "AppWithRolesForUser [orgUserId=test, appId=1, appName=test, appRoles=null]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppsListWithAdminRoleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppsListWithAdminRoleTest.java new file mode 100644 index 00000000..2c601d3c --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/AppsListWithAdminRoleTest.java @@ -0,0 +1,46 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.AppNameIdIsAdmin; +import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole; + +public class AppsListWithAdminRoleTest { + + public AppsListWithAdminRole mockAppsListWithAdminRole(){ + AppsListWithAdminRole appsListWithAdminRole = new AppsListWithAdminRole(); + + ArrayList<AppNameIdIsAdmin> appsRoles = new ArrayList<AppNameIdIsAdmin>(); + AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin(); + appsRoles.add(appNameIdIsAdmin); + + appsListWithAdminRole.setOrgUserId("test"); + appsListWithAdminRole.setAppsRoles(appsRoles); + + return appsListWithAdminRole; + } + + @Test + public void appsListWithAdminRoleTest(){ + AppsListWithAdminRole appsListWithAdminRole = mockAppsListWithAdminRole(); + + AppsListWithAdminRole appsListWithAdminRole1 = new AppsListWithAdminRole(); + + ArrayList<AppNameIdIsAdmin> appsRoles = new ArrayList<AppNameIdIsAdmin>(); + AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin(); + appsRoles.add(appNameIdIsAdmin); + + appsListWithAdminRole1.setOrgUserId("test"); + appsListWithAdminRole1.setAppsRoles(appsRoles); + + assertEquals(appsListWithAdminRole.getOrgUserId(), "test"); + assertEquals(appsListWithAdminRole.getAppsRoles(), appsRoles); + + assertTrue(appsListWithAdminRole.equals(appsListWithAdminRole1)); + assertEquals(appsListWithAdminRole.hashCode(), appsListWithAdminRole1.hashCode()); + assertEquals(appsListWithAdminRole.toString(), "AppsListWithAdminRole [orgUserId=test, appsRoles=[AppNameIdIsAdmin [id=null, appName=null, isAdmin=null, restrictedApp=null]]]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BulkUploadRoleFunctionTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BulkUploadRoleFunctionTest.java new file mode 100644 index 00000000..854afccc --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BulkUploadRoleFunctionTest.java @@ -0,0 +1,35 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.BulkUploadRoleFunction; + +public class BulkUploadRoleFunctionTest { + + public BulkUploadRoleFunction mockBulkUploadRoleFunction(){ + + BulkUploadRoleFunction bulkUploadRoleFunction = new BulkUploadRoleFunction(); + + bulkUploadRoleFunction.setFunctionName("test"); + bulkUploadRoleFunction.setFunctionCd("test"); + + return bulkUploadRoleFunction; + } + + @Test + public void bulkUploadRoleFunctionTest(){ + BulkUploadRoleFunction bulkUploadRoleFunction = mockBulkUploadRoleFunction(); + + BulkUploadRoleFunction bulkUploadRoleFunction1 = new BulkUploadRoleFunction(); + + bulkUploadRoleFunction1.setFunctionName("test"); + bulkUploadRoleFunction1.setFunctionCd("test"); + + assertEquals(bulkUploadRoleFunction.getFunctionCd(), "test"); + assertEquals(bulkUploadRoleFunction.getFunctionName(), "test"); + assertEquals(bulkUploadRoleFunction.hashCode(), bulkUploadRoleFunction1.hashCode()); + assertTrue(bulkUploadRoleFunction.equals(bulkUploadRoleFunction1)); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BulkUploadUserRolesTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BulkUploadUserRolesTest.java new file mode 100644 index 00000000..b2bbba68 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BulkUploadUserRolesTest.java @@ -0,0 +1,37 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.BulkUploadUserRoles; + +public class BulkUploadUserRolesTest { + + public BulkUploadUserRoles mockBulkUploadUserRoles(){ + BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles(); + + bulkUploadUserRoles.setRoleName("test"); + bulkUploadUserRoles.setOrgUserId("test"); + bulkUploadUserRoles.setAppNameSpace("test"); + + return bulkUploadUserRoles; + } + + @Test + public void bulkUploadUserRolesTest(){ + BulkUploadUserRoles bulkUploadUserRoles = mockBulkUploadUserRoles(); + + BulkUploadUserRoles bulkUploadUserRoles1 = new BulkUploadUserRoles(); + + bulkUploadUserRoles1.setRoleName("test"); + bulkUploadUserRoles1.setOrgUserId("test"); + bulkUploadUserRoles1.setAppNameSpace("test"); + + assertEquals(bulkUploadUserRoles.getRoleName(), "test"); + assertEquals(bulkUploadUserRoles.getOrgUserId(), "test"); + assertEquals(bulkUploadUserRoles.getAppNameSpace(), "test"); + + assertEquals(bulkUploadUserRoles.hashCode(), bulkUploadUserRoles1.hashCode()); + assertTrue(bulkUploadUserRoles.equals(bulkUploadUserRoles1)); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BusinessCardApplicationRoleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BusinessCardApplicationRoleTest.java new file mode 100644 index 00000000..0ed06b12 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BusinessCardApplicationRoleTest.java @@ -0,0 +1,26 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class BusinessCardApplicationRoleTest { + + public BusinessCardApplicationRole mockBusinessCardApplicationRole(){ + BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole(); + + return businessCardApplicationRole; + } + + @Test + public void businessCardApplicationRoleTest(){ + BusinessCardApplicationRole businessCardApplicationRole = mockBusinessCardApplicationRole(); + + BusinessCardApplicationRole businessCardApplicationRole1 = new BusinessCardApplicationRole(); + + assertEquals(businessCardApplicationRole.hashCode(), businessCardApplicationRole1.hashCode()); + assertTrue(businessCardApplicationRole.equals(businessCardApplicationRole1)); + assertEquals(businessCardApplicationRole.toString(), "BusinessCardUserApplicationRoles [appName=null, roleName=null]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BusinessCardApplicationRolesListTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BusinessCardApplicationRolesListTest.java new file mode 100644 index 00000000..9f5e6785 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/BusinessCardApplicationRolesListTest.java @@ -0,0 +1,26 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class BusinessCardApplicationRolesListTest { + + public BusinessCardApplicationRolesList mockBusinessCardApplicationRolesList(){ + BusinessCardApplicationRolesList businessCardApplicationRolesList = new BusinessCardApplicationRolesList(); + + return businessCardApplicationRolesList; + } + + @Test + public void businessCardApplicationRolesListTest(){ + BusinessCardApplicationRolesList businessCardApplicationRolesList = mockBusinessCardApplicationRolesList(); + + BusinessCardApplicationRolesList businessCardApplicationRolesList1 = new BusinessCardApplicationRolesList(); + + assertEquals(businessCardApplicationRolesList.hashCode(), businessCardApplicationRolesList1.hashCode()); + assertTrue(businessCardApplicationRolesList.equals(businessCardApplicationRolesList1)); + assertEquals(businessCardApplicationRolesList.toString(), "BusinessCardUserAppRoles [appName=null, roleNames=null]"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralAppTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralAppTest.java new file mode 100644 index 00000000..97c9c59f --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralAppTest.java @@ -0,0 +1,102 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.CentralApp; + +public class CentralAppTest { + + public CentralApp mockCentralApp(){ + CentralApp centralApp = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + + + /* public CentralApp(Long id, Date created, Date modified, Long createdId, Long modifiedId, Long rowNum, String name, + String imageUrl, String description, String notes, String url, String alternateUrl, String restEndpoint, + String mlAppName, String mlAppAdminId, String motsId, String appPassword, String open, String enabled, + byte[] thumbnail, String username, String uebKey, String uebSecret, String uebTopicName)*/ + + centralApp.setId((long)1); + centralApp.setCreatedId((long)1); + centralApp.setModifiedId((long)1); + centralApp.setRowNum((long)1); + centralApp.setName("test"); + centralApp.setImageUrl("test"); + centralApp.setDescription("test"); + centralApp.setNotes("test"); + centralApp.setUrl("test"); + centralApp.setAlternateUrl("test"); + centralApp.setRestEndpoint("test"); + centralApp.setMlAppName("test"); + centralApp.setMlAppAdminId("test"); + centralApp.setMotsId("test"); + centralApp.setAppPassword("test"); + centralApp.setOpen("test"); + centralApp.setEnabled("test"); + centralApp.setUsername("test"); + centralApp.setUebKey("test"); + centralApp.setUebSecret("test"); + centralApp.setUebTopicName("test"); + + return centralApp; + } + + @Test + public void centralAppTest(){ + CentralApp centralApp = mockCentralApp(); + + CentralApp centralApp1 = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + + /*centralApp1.setId((long)1); + centralApp1.setCreatedId((long)1); + centralApp1.setModifiedId((long)1); + centralApp1.setRowNum((long)1); + centralApp1.setName("test"); + centralApp1.setImageUrl("test"); + centralApp1.setDescription("test"); + centralApp1.setNotes("test"); + centralApp1.setUrl("test"); + centralApp1.setAlternateUrl("test"); + centralApp1.setRestEndpoint("test"); + centralApp1.setMlAppName("test"); + centralApp1.setMlAppAdminId("test"); + centralApp1.setMotsId("test"); + centralApp1.setAppPassword("test"); + centralApp1.setOpen("test"); + centralApp1.setEnabled("test"); + centralApp1.setUsername("test"); + centralApp1.setUebKey("test"); + centralApp1.setUebSecret("test"); + centralApp1.setUebTopicName("test");*/ + + assertEquals(centralApp.getId(), new Long(1)); + assertEquals(centralApp.getCreatedId(), new Long(1)); + assertEquals(centralApp.getModifiedId(), new Long(1)); + assertEquals(centralApp.getRowNum(), new Long(1)); + assertEquals(centralApp.getName(), "test"); + assertEquals(centralApp.getImageUrl(), "test"); + assertEquals(centralApp.getDescription(), "test"); + assertEquals(centralApp.getNotes(), "test"); + assertEquals(centralApp.getUrl(), "test"); + assertEquals(centralApp.getAlternateUrl(), "test"); + assertEquals(centralApp.getRestEndpoint(), "test"); + assertEquals(centralApp.getMlAppName(), "test"); + assertEquals(centralApp.getMlAppAdminId(), "test"); + assertEquals(centralApp.getMotsId(), "test"); + assertEquals(centralApp.getAppPassword(), "test"); + assertEquals(centralApp.getOpen(), "test"); + assertEquals(centralApp.getEnabled(), "test"); + assertEquals(centralApp.getUsername(), "test"); + assertEquals(centralApp.getUebKey(), "test"); + assertEquals(centralApp.getUebSecret(), "test"); + assertEquals(centralApp.getUebTopicName(), "test"); + + assertTrue(centralApp.equals(centralApp1)); + assertEquals(centralApp.hashCode(), centralApp1.hashCode()); + /* assertTrue(centralApp.equals(new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test")));*/ + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralRoleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralRoleTest.java new file mode 100644 index 00000000..6ba0a444 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralRoleTest.java @@ -0,0 +1,63 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import java.util.Date; +import java.util.SortedSet; + +import org.junit.Test; +import org.openecomp.portalapp.portal.domain.CentralRoleFunction; +import org.openecomp.portalapp.portal.transport.CentralRole; + +public class CentralRoleTest { + + public CentralRole mockCentralRole(){ + CentralRole centralRole = new CentralRole((long)1, null, null, (long)1, (long)1, (long)1, + "test", false, 1, null, null, null); + + centralRole.setId((long)1); + centralRole.setCreatedId((long)1); + centralRole.setModifiedId((long)1); + centralRole.setRowNum((long)1); + centralRole.setName("test"); + centralRole.setActive(false); + centralRole.setPriority(1); + + centralRole.setCreated(null); + centralRole.setModified(null); + centralRole.setRoleFunctions(null); + centralRole.setChildRoles(null); + centralRole.setParentRoles(null); + + return centralRole; + } + + @Test + public void centralRoleTest(){ + CentralRole centralRole = mockCentralRole(); + + CentralRole centralRole1 = new CentralRole((long)1, null, null, (long)1, (long)1, (long)1, + "test", false, 1, null, null, null); + + CentralRole centralRole2 = new CentralRole((long)1, "test"); + + assertEquals(centralRole.getId(), new Long(1)); + assertEquals(centralRole.getCreatedId(), new Long(1)); + assertEquals(centralRole.getModifiedId(), new Long(1)); + assertEquals(centralRole.getRowNum(), new Long(1)); + assertEquals(centralRole.getName(), "test"); + assertEquals(centralRole.isActive(), false); + assertEquals(centralRole.getCreated(), null); + assertEquals(centralRole.getModified(), null); + assertEquals(centralRole.getRoleFunctions(), null); + assertEquals(centralRole.getChildRoles(), null); + assertEquals(centralRole.getParentRoles(), null); + assertEquals(centralRole.getPriority().toString(), "1"); + assertEquals(centralRole.hashCode(), centralRole1.hashCode()); + assertTrue(centralRole.equals(centralRole1)); + assertEquals(centralRole, centralRole1); + assertEquals(centralRole2, new CentralRole((long)1, "test")); + } + + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralUserAppTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralUserAppTest.java new file mode 100644 index 00000000..f3582647 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralUserAppTest.java @@ -0,0 +1,41 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.CentralApp; +import org.openecomp.portalapp.portal.transport.CentralRole; +import org.openecomp.portalapp.portal.transport.CentralUserApp; + +public class CentralUserAppTest { + + public CentralUserApp mockCentralUserApp(){ + CentralUserApp centralUserApp = new CentralUserApp(); + + CentralApp app = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + + CentralRole role = new CentralRole(); + + centralUserApp.setUserId((long)1); + centralUserApp.setApp(app); + centralUserApp.setRole(role); + centralUserApp.setPriority((short) 123); + + return centralUserApp; + } + + @Test + public void centralUserAppTest(){ + CentralUserApp centralUserApp = mockCentralUserApp(); + + CentralApp app1 = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + + CentralRole role1 = new CentralRole(); + + assertEquals(centralUserApp.getUserId(), new Long(1)); + assertEquals(centralUserApp.getPriority(), new Short((short) 123)); + assertEquals(centralUserApp.getApp(), app1); + assertEquals(centralUserApp.getRole(), role1); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralUserTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralUserTest.java new file mode 100644 index 00000000..9df86bc9 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/CentralUserTest.java @@ -0,0 +1,52 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.CentralRole; +import org.openecomp.portalapp.portal.transport.CentralUser; +import org.openecomp.portalapp.portal.transport.CentralUserApp; + +public class CentralUserTest { + + public CentralUser mockCentralUser(){ + Set<CentralUserApp> userApps = new HashSet<CentralUserApp>(); + Set<CentralRole> pseudoRoles = new HashSet<CentralRole>(); + CentralUser centralUser = new CentralUser((long)1, null, null, (long)1, (long)1, (long)1, (long)1, + (long)1, "test", "test", "test", "test", "test", + "test", "test", (long)1, "test", "test", "test", + "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, + false, false, (long)1, (long)1, false, "test", userApps, pseudoRoles); + + return centralUser; + } + + @Test + public void centralRoleTest(){ + CentralUser centralUser = mockCentralUser(); + + Set<CentralUserApp> userApps = new HashSet<CentralUserApp>(); + Set<CentralRole> pseudoRoles = new HashSet<CentralRole>(); + CentralUser centralUser1 = new CentralUser((long)1, null, null, (long)1, (long)1, (long)1, (long)1, + (long)1, "test", "test", "test", "test", "test", + "test", "test", (long)1, "test", "test", "test", + "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, + false, false, (long)1, (long)1, false, "test", userApps, pseudoRoles); + + + assertEquals(centralUser, centralUser1); + assertEquals(centralUser.hashCode(), centralUser1.hashCode()); + assertTrue(centralUser.equals(centralUser1)); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPAppsManualPreferenceTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPAppsManualPreferenceTest.java new file mode 100644 index 00000000..6e8b4018 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPAppsManualPreferenceTest.java @@ -0,0 +1,47 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EPAppsManualPreference; + +public class EPAppsManualPreferenceTest { + + public EPAppsManualPreference mockEPAppsManualPreference(){ + EPAppsManualPreference epAppsManualPreference = new EPAppsManualPreference(); + + epAppsManualPreference.setAppid((long)1); + epAppsManualPreference.setCol(1); + epAppsManualPreference.setHeaderText("test"); + epAppsManualPreference.setImageLink("test"); + epAppsManualPreference.setOrder(1); + epAppsManualPreference.setRestrictedApp(false); + epAppsManualPreference.setRow(1); + epAppsManualPreference.setSizeX(1); + epAppsManualPreference.setSizeY(1); + epAppsManualPreference.setSubHeaderText("test"); + epAppsManualPreference.setUrl("test"); + epAppsManualPreference.setAddRemoveApps(false); + + return epAppsManualPreference; + } + + @Test + public void epAppsManualPreferenceTest(){ + + EPAppsManualPreference epAppsManualPreference = mockEPAppsManualPreference(); + + assertEquals(epAppsManualPreference.getAppid(), new Long(1)); + assertEquals(epAppsManualPreference.getCol(), 1); + assertEquals(epAppsManualPreference.getHeaderText(), "test"); + assertEquals(epAppsManualPreference.getImageLink(), "test"); + assertEquals(epAppsManualPreference.getOrder(), 1); + assertEquals(epAppsManualPreference.isRestrictedApp(), false); + assertEquals(epAppsManualPreference.getRow(), 1); + assertEquals(epAppsManualPreference.getSizeX(), 1); + assertEquals(epAppsManualPreference.getSizeY(), 1); + assertEquals(epAppsManualPreference.getSubHeaderText(), "test"); + assertEquals(epAppsManualPreference.getUrl(), "test"); + assertEquals(epAppsManualPreference.isAddRemoveApps(), false); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPAppsSortPreferenceTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPAppsSortPreferenceTest.java new file mode 100644 index 00000000..6c67424a --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPAppsSortPreferenceTest.java @@ -0,0 +1,29 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EPAppsSortPreference; + +public class EPAppsSortPreferenceTest { + + public EPAppsSortPreference mockEPAppsSortPreference(){ + EPAppsSortPreference epAppsSortPreference = new EPAppsSortPreference(); + + epAppsSortPreference.setIndex(1); + epAppsSortPreference.setValue("test"); + epAppsSortPreference.setTitle("test"); + + return epAppsSortPreference; + } + + @Test + public void epAppsSortPreferenceTest(){ + EPAppsSortPreference epAppsSortPreference = mockEPAppsSortPreference(); + + assertEquals(epAppsSortPreference.getIndex(), 1); + assertEquals(epAppsSortPreference.getValue(), "test"); + assertEquals(epAppsSortPreference.getTitle(), "test"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPDeleteAppsManualSortPrefTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPDeleteAppsManualSortPrefTest.java new file mode 100644 index 00000000..78bb8474 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPDeleteAppsManualSortPrefTest.java @@ -0,0 +1,29 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EPDeleteAppsManualSortPref; + +public class EPDeleteAppsManualSortPrefTest { + + public EPDeleteAppsManualSortPref mockEPDeleteAppsManualSortPref(){ + EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = new EPDeleteAppsManualSortPref(); + + epDeleteAppsManualSortPref.setAppId((long)1); + epDeleteAppsManualSortPref.setSelect(false); + epDeleteAppsManualSortPref.setPending(false); + + return epDeleteAppsManualSortPref; + } + + @Test + public void epDeleteAppsManualSortPrefTest(){ + EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = mockEPDeleteAppsManualSortPref(); + + assertEquals(epDeleteAppsManualSortPref.getAppId(), new Long(1)); + assertEquals(epDeleteAppsManualSortPref.isSelect(), false); + assertEquals(epDeleteAppsManualSortPref.isPending(), false); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPUserAppCurrentRolesTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPUserAppCurrentRolesTest.java new file mode 100644 index 00000000..9c82ad37 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPUserAppCurrentRolesTest.java @@ -0,0 +1,41 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EPUserAppCurrentRoles; + +public class EPUserAppCurrentRolesTest { + + public EPUserAppCurrentRoles mockEPUserAppCurrentRoles(){ + EPUserAppCurrentRoles epUserAppCurrentRoles = new EPUserAppCurrentRoles(); + + epUserAppCurrentRoles.setRoleName("test"); + epUserAppCurrentRoles.setUserId((long)1); + epUserAppCurrentRoles.setPriority("test"); + epUserAppCurrentRoles.setRoleId((long)1); + + return epUserAppCurrentRoles; + } + + @Test + public void epUserAppCurrentRolesTest(){ + EPUserAppCurrentRoles epUserAppCurrentRoles = mockEPUserAppCurrentRoles(); + + EPUserAppCurrentRoles epUserAppCurrentRoles1 = new EPUserAppCurrentRoles(); + + epUserAppCurrentRoles1.setRoleName("test"); + epUserAppCurrentRoles1.setUserId((long)1); + epUserAppCurrentRoles1.setPriority("test"); + epUserAppCurrentRoles1.setRoleId((long)1); + + assertEquals(epUserAppCurrentRoles.getRoleName(), "test"); + assertEquals(epUserAppCurrentRoles.getUserId(), new Long(1)); + assertEquals(epUserAppCurrentRoles.getRoleId(), new Long(1)); + assertEquals(epUserAppCurrentRoles.getPriority(), "test"); + assertEquals(epUserAppCurrentRoles.hashCode(), epUserAppCurrentRoles1.hashCode()); + assertTrue(epUserAppCurrentRoles.equals(epUserAppCurrentRoles1)); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPWidgetsSortPreferenceTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPWidgetsSortPreferenceTest.java new file mode 100644 index 00000000..d466d91c --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EPWidgetsSortPreferenceTest.java @@ -0,0 +1,41 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EPWidgetsSortPreference; + +public class EPWidgetsSortPreferenceTest { + + public EPWidgetsSortPreference mockEPWidgetsSortPreference(){ + EPWidgetsSortPreference epWidgetsSortPreference = new EPWidgetsSortPreference(); + + epWidgetsSortPreference.setSizeX(1); + epWidgetsSortPreference.setSizeY(1); + epWidgetsSortPreference.setHeaderText("test"); + epWidgetsSortPreference.setUrl("test"); + epWidgetsSortPreference.setWidgetid((long)1); + epWidgetsSortPreference.setWidgetIdentifier("test"); + epWidgetsSortPreference.setRow(1); + epWidgetsSortPreference.setCol(1); + + return epWidgetsSortPreference; + } + + @Test + public void epWidgetsSortPreferenceTest(){ + EPWidgetsSortPreference epWidgetsSortPreference = mockEPWidgetsSortPreference(); + + assertEquals(epWidgetsSortPreference.getSizeX(), 1); + assertEquals(epWidgetsSortPreference.getSizeY(), 1); + assertEquals(epWidgetsSortPreference.getHeaderText(), "test"); + assertEquals(epWidgetsSortPreference.getUrl(), "test"); + assertEquals(epWidgetsSortPreference.getWidgetid(), new Long(1)); + assertEquals(epWidgetsSortPreference.getWidgetIdentifier(), "test"); + assertEquals(epWidgetsSortPreference.getRow(), 1); + assertEquals(epWidgetsSortPreference.getRow(), 1); + + } + + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EcompUserAppRolesTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EcompUserAppRolesTest.java new file mode 100644 index 00000000..928c3737 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EcompUserAppRolesTest.java @@ -0,0 +1,33 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EcompUserAppRoles; + +public class EcompUserAppRolesTest { + + public EcompUserAppRoles mockEcompUserAppRoles(){ + EcompUserAppRoles ecompUserAppRoles = new EcompUserAppRoles(); + + ecompUserAppRoles.setAppId("test"); + ecompUserAppRoles.setUserId((long)1); + ecompUserAppRoles.setPriority("test"); + ecompUserAppRoles.setRoleId((long)1); + ecompUserAppRoles.setRoleName("test"); + + return ecompUserAppRoles; + } + + @Test + public void ecompUserAppRolesTest(){ + + EcompUserAppRoles ecompUserAppRoles = mockEcompUserAppRoles(); + + assertEquals(ecompUserAppRoles.getAppId(), "test"); + assertEquals(ecompUserAppRoles.getPriority(), "test"); + assertEquals(ecompUserAppRoles.getRoleName(), "test"); + assertEquals(ecompUserAppRoles.getUserId(), new Long(1)); + assertEquals(ecompUserAppRoles.getRoleId(), new Long(1)); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemExtVOTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemExtVOTest.java new file mode 100644 index 00000000..11fe2cf7 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemExtVOTest.java @@ -0,0 +1,33 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EpNotificationItemExtVO; + +public class EpNotificationItemExtVOTest { + + public EpNotificationItemExtVO mockEpNotificationItemExtVO(){ + EpNotificationItemExtVO epNotificationItemExtVO = new EpNotificationItemExtVO(); + + //epNotificationItemExtVO.setActiveYn("abc"); + epNotificationItemExtVO.setMsgHeader("test"); + epNotificationItemExtVO.setMsgDescription("test"); + epNotificationItemExtVO.setPriority(1); + epNotificationItemExtVO.setCreatorId(1); + epNotificationItemExtVO.setLoginId("test"); + + return epNotificationItemExtVO; + } + + @Test + public void epNotificationItemExtVOTest(){ + EpNotificationItemExtVO epNotificationItemExtVO = mockEpNotificationItemExtVO(); + + assertEquals(epNotificationItemExtVO.getMsgHeader(), "test"); + assertEquals(epNotificationItemExtVO.getMsgDescription(), "test"); + assertEquals(epNotificationItemExtVO.getPriority().toString(), "1"); + assertEquals(epNotificationItemExtVO.getCreatorId().toString(), "1"); + assertEquals(epNotificationItemExtVO.getLoginId(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemTest.java new file mode 100644 index 00000000..6e1e48c6 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemTest.java @@ -0,0 +1,64 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EpNotificationItem; + +public class EpNotificationItemTest { + + public EpNotificationItem mockEpNotificationItem(){ + EpNotificationItem epNotificationItem = new EpNotificationItem(); + + epNotificationItem.setNotificationId((long)1); + epNotificationItem.setIsForOnlineUsers("test"); + epNotificationItem.setIsForAllRoles("test"); + epNotificationItem.setActiveYn("test"); + epNotificationItem.setMsgHeader("test"); + epNotificationItem.setMsgDescription("test"); + epNotificationItem.setMsgSource("test"); + + epNotificationItem.setPriority((long)1); + epNotificationItem.setCreatedId((long)1); + epNotificationItem.setNotificationHyperlink("test"); + + return epNotificationItem; + } + + @Test + public void epNotificationItemTest(){ + EpNotificationItem epNotificationItem = mockEpNotificationItem(); + + EpNotificationItem epNotificationItem1 = new EpNotificationItem(); + epNotificationItem1.setNotificationId((long)1); + epNotificationItem1.setIsForOnlineUsers("test"); + epNotificationItem1.setIsForAllRoles("test"); + epNotificationItem1.setActiveYn("test"); + epNotificationItem1.setMsgHeader("test"); + epNotificationItem1.setMsgDescription("test"); + epNotificationItem1.setMsgSource("test"); + + epNotificationItem1.setPriority((long)1); + epNotificationItem1.setCreatedId((long)1); + epNotificationItem1.setNotificationHyperlink("test"); + + assertEquals(epNotificationItem.getNotificationId(), new Long(1)); + assertEquals(epNotificationItem.getIsForOnlineUsers(), "test"); + assertEquals(epNotificationItem.getIsForAllRoles(), "test"); + assertEquals(epNotificationItem.getActiveYn(), "test"); + assertEquals(epNotificationItem.getMsgHeader(), "test"); + assertEquals(epNotificationItem.getMsgDescription(), "test"); + assertEquals(epNotificationItem.getMsgSource(), "test"); + assertEquals(epNotificationItem.getPriority(), new Long(1)); + assertEquals(epNotificationItem.getCreatedId(), new Long(1)); + assertEquals(epNotificationItem.getNotificationHyperlink(), "test"); + + assertEquals(epNotificationItem.toString(), "EpNotificationItem [notificationId=1, isForOnlineUsers=test, isForAllRoles=test, activeYn=test, msgHeader=test, msgDescription=test, msgSource=test, startTime=null, endTime=null, priority=1, creatorId=null, createdDate=null, roles=null, roleIds=null]"); + assertEquals(epNotificationItem.hashCode(), epNotificationItem1.hashCode()); + assertTrue(epNotificationItem.equals(epNotificationItem1)); + + } + +} + + diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemVOTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemVOTest.java new file mode 100644 index 00000000..35a11833 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpNotificationItemVOTest.java @@ -0,0 +1,46 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EpNotificationItemVO; + +public class EpNotificationItemVOTest { + + public EpNotificationItemVO mockEpNotificationItemVO(){ + EpNotificationItemVO epNotificationItemVO = new EpNotificationItemVO(); + + epNotificationItemVO.setNotificationId(1); + epNotificationItemVO.setIsForOnlineUsers('a'); + epNotificationItemVO.setIsForAllRoles('a'); + epNotificationItemVO.setActiveYn('a'); + epNotificationItemVO.setMsgHeader("test"); + epNotificationItemVO.setMsgDescription("test"); + epNotificationItemVO.setMsgSource("test"); + epNotificationItemVO.setPriority(1); + epNotificationItemVO.setCreatorId(1); + epNotificationItemVO.setLoginId("test"); + epNotificationItemVO.setNotificationHyperlink("test"); + + return epNotificationItemVO; + } + + @Test + public void epNotificationItemVOTest(){ + EpNotificationItemVO epNotificationItemVO = mockEpNotificationItemVO(); + + assertEquals(epNotificationItemVO.getNotificationId().toString(), "1"); + /*assertEquals(epNotificationItemVO.getIsForOnlineUsers(), 'a'); + assertEquals(epNotificationItemVO.getIsForAllRoles(), 'a'); + assertEquals(epNotificationItemVO.getActiveYn(), 'a');*/ + assertEquals(epNotificationItemVO.getMsgHeader(), "test"); + assertEquals(epNotificationItemVO.getMsgDescription(), "test"); + assertEquals(epNotificationItemVO.getMsgSource(), "test"); + assertEquals(epNotificationItemVO.getPriority().toString(), "1"); + assertEquals(epNotificationItemVO.getCreatorId().toString(), "1"); + assertEquals(epNotificationItemVO.getLoginId(), "test"); + assertEquals(epNotificationItemVO.getNotificationHyperlink(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpRoleNotificationItemTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpRoleNotificationItemTest.java new file mode 100644 index 00000000..beb67ba9 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/EpRoleNotificationItemTest.java @@ -0,0 +1,31 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem; + +public class EpRoleNotificationItemTest { + + public EpRoleNotificationItem mockEpRoleNotificationItem(){ + EpRoleNotificationItem epRoleNotificationItem = new EpRoleNotificationItem(); + + epRoleNotificationItem.setId((long)1); + epRoleNotificationItem.setNotificationId((long)1); + epRoleNotificationItem.setRoleId(1); + epRoleNotificationItem.setRecvUserId(1); + + return epRoleNotificationItem; + } + + @Test + public void epRoleNotificationItemTest(){ + EpRoleNotificationItem epRoleNotificationItem = mockEpRoleNotificationItem(); + + assertEquals(epRoleNotificationItem.getId(), new Long(1)); + assertEquals(epRoleNotificationItem.getNotificationId(), new Long(1)); + assertEquals(epRoleNotificationItem.getRoleId().toString(), "1"); + assertEquals(epRoleNotificationItem.getRecvUserId().toString(), "1"); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessPermsDetailTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessPermsDetailTest.java new file mode 100644 index 00000000..f490973a --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessPermsDetailTest.java @@ -0,0 +1,39 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.ExternalAccessPermsDetail; + +public class ExternalAccessPermsDetailTest { + + public ExternalAccessPermsDetail mockExternalAccessPermsDetail(){ + ExternalAccessPermsDetail externalAccessPermsDetail = new ExternalAccessPermsDetail(); + + List<String> roles = new ArrayList<String>(); + + externalAccessPermsDetail.setType("test"); + externalAccessPermsDetail.setInstance("test"); + externalAccessPermsDetail.setAction("test"); + externalAccessPermsDetail.setDescription("test"); + externalAccessPermsDetail.setRoles(roles); + + return externalAccessPermsDetail; + } + + @Test + public void externalAccessPermsDetailTest(){ + ExternalAccessPermsDetail externalAccessPermsDetail = mockExternalAccessPermsDetail(); + + List<String> roles = new ArrayList<String>(); + + assertEquals(externalAccessPermsDetail.getType(), "test"); + assertEquals(externalAccessPermsDetail.getInstance(), "test"); + assertEquals(externalAccessPermsDetail.getAction(), "test"); + assertEquals(externalAccessPermsDetail.getDescription(), "test"); + assertEquals(externalAccessPermsDetail.getRoles(), roles); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessPermsTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessPermsTest.java new file mode 100644 index 00000000..dfae6042 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessPermsTest.java @@ -0,0 +1,42 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.ExternalAccessPerms; + +public class ExternalAccessPermsTest { + + public ExternalAccessPerms mockExternalAccessPerms(){ + ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms(); + + externalAccessPerms.setType("test"); + externalAccessPerms.setInstance("test"); + externalAccessPerms.setAction("test"); + externalAccessPerms.setDescription("test"); + + return externalAccessPerms; + } + + @Test + public void externalAccessPermsTest(){ + ExternalAccessPerms externalAccessPerms = mockExternalAccessPerms(); + + ExternalAccessPerms externalAccessPerms1 = new ExternalAccessPerms("test", "test", "test"); + ExternalAccessPerms externalAccessPerms2 = new ExternalAccessPerms("test", "test", "test", "test"); + ExternalAccessPerms externalAccessPerms3 = new ExternalAccessPerms(); + externalAccessPerms3.setType("test"); + externalAccessPerms3.setInstance("test"); + externalAccessPerms3.setAction("test"); + externalAccessPerms3.setDescription("test"); + + assertEquals(externalAccessPerms.getType(), "test"); + assertEquals(externalAccessPerms.getInstance(), "test"); + assertEquals(externalAccessPerms.getAction(), "test"); + assertEquals(externalAccessPerms.getDescription(), "test"); + assertEquals(externalAccessPerms.hashCode(), externalAccessPerms3.hashCode()); + + assertTrue(externalAccessPerms1.equals(new ExternalAccessPerms("test", "test", "test"))); + assertTrue(externalAccessPerms2.equals(new ExternalAccessPerms("test", "test", "test", "test"))); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessRolePermsTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessRolePermsTest.java new file mode 100644 index 00000000..4e736eba --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessRolePermsTest.java @@ -0,0 +1,35 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.ExternalAccessPerms; +import org.openecomp.portalapp.portal.transport.ExternalAccessRolePerms; + +public class ExternalAccessRolePermsTest { + + public ExternalAccessRolePerms mockExternalAccessRolePerms(){ + ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms(); + externalAccessPerms.setAction("test"); + externalAccessPerms.setDescription("test"); + externalAccessPerms.setInstance("test"); + externalAccessPerms.setType("test"); + ExternalAccessRolePerms ExternalAccessRolePerms = new ExternalAccessRolePerms(externalAccessPerms, "test"); + + return ExternalAccessRolePerms; + } + + @Test + public void externalAccessRolePermsTest(){ + ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms(); + externalAccessPerms.setAction("test"); + externalAccessPerms.setDescription("test"); + externalAccessPerms.setInstance("test"); + externalAccessPerms.setType("test"); + + ExternalAccessRolePerms ExternalAccessRolePerms = mockExternalAccessRolePerms(); + + assertEquals(ExternalAccessRolePerms.getRole(), "test"); + assertEquals(ExternalAccessRolePerms.getPerm(), externalAccessPerms); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessRoleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessRoleTest.java new file mode 100644 index 00000000..19dee193 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessRoleTest.java @@ -0,0 +1,26 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.ExternalAccessRole; + +public class ExternalAccessRoleTest { + + public ExternalAccessRole mockExternalAccessRole(){ + ExternalAccessRole externalAccessRole = new ExternalAccessRole(); + + externalAccessRole.setName("test"); + externalAccessRole.setDescription("test"); + + return externalAccessRole; + } + + @Test + public void externalAccessRoleTest(){ + ExternalAccessRole externalAccessRole = mockExternalAccessRole(); + + assertEquals(externalAccessRole.getName(), "test"); + assertEquals(externalAccessRole.getDescription(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java new file mode 100644 index 00000000..6ffab981 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java @@ -0,0 +1,47 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.ExternalAccessUserRoleDetail; +import org.openecomp.portalapp.portal.transport.ExternalRoleDescription; + +public class ExternalAccessUserRoleDetailTest { + + public ExternalAccessUserRoleDetail mockExternalAccessUserRoleDetail(){ + + ExternalRoleDescription externalRoleDescription = new ExternalRoleDescription(); + externalRoleDescription.setId("test"); + externalRoleDescription.setName("test"); + externalRoleDescription.setActive("test"); + externalRoleDescription.setPriority("test"); + externalRoleDescription.setAppId("test"); + externalRoleDescription.setAppRoleId("test"); + + ExternalAccessUserRoleDetail externalAccessUserRoleDetail = new ExternalAccessUserRoleDetail("test", externalRoleDescription); + + externalAccessUserRoleDetail.setName("test"); + externalAccessUserRoleDetail.setDescription(externalRoleDescription); + return externalAccessUserRoleDetail; + } + + @Test + public void externalAccessUserRoleDetailTest(){ + ExternalAccessUserRoleDetail externalAccessUserRoleDetail = mockExternalAccessUserRoleDetail(); + + ExternalRoleDescription externalRoleDescription1 = new ExternalRoleDescription(); + externalRoleDescription1.setId("test"); + externalRoleDescription1.setName("test"); + externalRoleDescription1.setActive("test"); + externalRoleDescription1.setPriority("test"); + externalRoleDescription1.setAppId("test"); + externalRoleDescription1.setAppRoleId("test"); + + ExternalAccessUserRoleDetail externalAccessUserRoleDetail1 = new ExternalAccessUserRoleDetail("test", externalRoleDescription1); + + assertEquals(externalAccessUserRoleDetail.getName(), externalAccessUserRoleDetail1.getName()); + assertEquals(externalAccessUserRoleDetail.getDescription(), externalAccessUserRoleDetail1.getDescription()); + assertEquals(externalAccessUserRoleDetail.hashCode(), externalAccessUserRoleDetail1.hashCode()); + assertTrue(externalAccessUserRoleDetail.equals(externalAccessUserRoleDetail1)); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessUserTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessUserTest.java new file mode 100644 index 00000000..d2be97b1 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalAccessUserTest.java @@ -0,0 +1,24 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.ExternalAccessUser; + +public class ExternalAccessUserTest { + + public ExternalAccessUser mockExternalAccessUser(){ + ExternalAccessUser externalAccessUser = new ExternalAccessUser("test", "test"); + + return externalAccessUser; + } + + @Test + public void externalAccessUserTest(){ + ExternalAccessUser externalAccessUser = mockExternalAccessUser(); + + assertEquals(externalAccessUser.getRole(), "test"); + assertEquals(externalAccessUser.getUser(), "test"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalRoleDescriptionTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalRoleDescriptionTest.java new file mode 100644 index 00000000..5b6fe825 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/ExternalRoleDescriptionTest.java @@ -0,0 +1,35 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.ExternalRoleDescription; + +public class ExternalRoleDescriptionTest { + + public ExternalRoleDescription mockExternalRoleDescription(){ + + ExternalRoleDescription externalRoleDescription = new ExternalRoleDescription(); + + externalRoleDescription.setId("test"); + externalRoleDescription.setName("test"); + externalRoleDescription.setActive("test"); + externalRoleDescription.setPriority("test"); + externalRoleDescription.setAppId("test"); + externalRoleDescription.setAppRoleId("test"); + + return externalRoleDescription; + } + + @Test + public void externalRoleDescriptionTest(){ + ExternalRoleDescription externalRoleDescription = mockExternalRoleDescription(); + + assertEquals(externalRoleDescription.getId(), "test"); + assertEquals(externalRoleDescription.getName(), "test"); + assertEquals(externalRoleDescription.getActive(), "test"); + assertEquals(externalRoleDescription.getPriority(), "test"); + assertEquals(externalRoleDescription.getAppId(), "test"); + assertEquals(externalRoleDescription.getAppRoleId(), "test"); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/FunctionalMenuItemTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/FunctionalMenuItemTest.java new file mode 100644 index 00000000..7d4b96e5 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/FunctionalMenuItemTest.java @@ -0,0 +1,42 @@ +package org.openecomp.portalapp.portal.transport; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.FunctionalMenuItem; + +public class FunctionalMenuItemTest { + + public FunctionalMenuItem mockFunctionalMenuItem(){ + FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem(); + + List<Integer> roles = new ArrayList<Integer>(); + + functionalMenuItem.setRestrictedApp(false); + functionalMenuItem.setUrl("test"); + functionalMenuItem.setRoles(roles); + + return functionalMenuItem; + } + + @Test + public void functionalMenuItemTest(){ + FunctionalMenuItem functionalMenuItem = mockFunctionalMenuItem(); + + FunctionalMenuItem functionalMenuItem1 = mockFunctionalMenuItem(); + + List<Integer> roles = new ArrayList<Integer>(); + + functionalMenuItem1.setRestrictedApp(false); + functionalMenuItem1.setUrl("test"); + functionalMenuItem1.setRoles(roles); + + assertEquals(functionalMenuItem.getRoles(), functionalMenuItem1.getRoles()); + assertEquals(functionalMenuItem.toString(), "FunctionalMenuItem [menuId=null, column=null, text=null, parentMenuId=null, url=test, active_yn=null, appid=null, roles=[], restrictedApp=false]"); + // assertTrue(functionalMenuItem.normalize(), functionalMenuItem1.normalize()); + } + +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/FunctionalMenuRoleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/FunctionalMenuRoleTest.java new file mode 100644 index 00000000..09f4bc67 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/FunctionalMenuRoleTest.java @@ -0,0 +1,40 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.FunctionalMenuRole; + +public class FunctionalMenuRoleTest { + + public FunctionalMenuRole mockFunctionalMenuRole(){ + FunctionalMenuRole functionalMenuRole = new FunctionalMenuRole(); + + functionalMenuRole.setId(1); + functionalMenuRole.setMenuId((long)1); + functionalMenuRole.setAppId(1); + functionalMenuRole.setRoleId(1); + + return functionalMenuRole; + } + + @Test + public void functionalMenuRoleTest(){ + FunctionalMenuRole functionalMenuRole = mockFunctionalMenuRole(); + + FunctionalMenuRole functionalMenuRole1 = new FunctionalMenuRole(); + functionalMenuRole1.setId(1); + functionalMenuRole1.setMenuId((long)1); + functionalMenuRole1.setAppId(1); + functionalMenuRole1.setRoleId(1); + + assertEquals(functionalMenuRole.getId().toString(), "1"); + assertEquals(functionalMenuRole.getMenuId(), new Long(1)); + assertEquals(functionalMenuRole.getAppId().toString(), "1"); + assertEquals(functionalMenuRole.getRoleId().toString(), "1"); + assertEquals(functionalMenuRole.toString(), "FunctionalMenuRole [id=1, menuId=1, appId=1, roleId=1]"); + assertTrue(functionalMenuRole.equals(functionalMenuRole1)); + assertEquals(functionalMenuRole.hashCode(), functionalMenuRole1.hashCode()); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/RemoteUserWithRolesTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/RemoteUserWithRolesTest.java new file mode 100644 index 00000000..ef926f6a --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/RemoteUserWithRolesTest.java @@ -0,0 +1,65 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.RemoteRole; +import org.openecomp.portalapp.portal.transport.RemoteUserWithRoles; + +public class RemoteUserWithRolesTest { + + public RemoteUserWithRoles mockRemoteUserWithRoles(){ + RemoteUserWithRoles remoteUserWithRoles = new RemoteUserWithRoles(); + + List<RemoteRole> roles = new ArrayList<RemoteRole>(); + RemoteRole remoteRole = new RemoteRole(); + remoteRole.setId((long)1); + remoteRole.setName("test"); + roles.add(remoteRole); + + remoteUserWithRoles.setOrgId((long)1); + remoteUserWithRoles.setManagerId((long)1); + remoteUserWithRoles.setFirstName("test"); + remoteUserWithRoles.setMiddleInitial("test"); + remoteUserWithRoles.setLastName("test"); + remoteUserWithRoles.setPhone("test"); + remoteUserWithRoles.setEmail("test"); + remoteUserWithRoles.setHrid("test"); + remoteUserWithRoles.setOrgUserId("test"); + remoteUserWithRoles.setOrgCode("test"); + remoteUserWithRoles.setOrgManagerUserId("test"); + remoteUserWithRoles.setJobTitle("test"); + remoteUserWithRoles.setLoginId("test"); + remoteUserWithRoles.setActive(false); + remoteUserWithRoles.setRoles(roles); + + return remoteUserWithRoles; + } + + @Test + public void remoteUserWithRolesTest(){ + RemoteUserWithRoles remoteUserWithRoles = mockRemoteUserWithRoles(); + + assertEquals(remoteUserWithRoles.getOrgId(), new Long(1)); + assertEquals(remoteUserWithRoles.getManagerId(), new Long(1)); + assertEquals(remoteUserWithRoles.getFirstName(), "test"); + assertEquals(remoteUserWithRoles.getMiddleInitial(), "test"); + assertEquals(remoteUserWithRoles.getLastName(), "test"); + assertEquals(remoteUserWithRoles.getPhone(), "test"); + assertEquals(remoteUserWithRoles.getEmail(), "test"); + assertEquals(remoteUserWithRoles.getHrid(), "test"); + assertEquals(remoteUserWithRoles.getOrgUserId(), "test"); + assertEquals(remoteUserWithRoles.getOrgCode(), "test"); + assertEquals(remoteUserWithRoles.getOrgManagerUserId(), "test"); + assertEquals(remoteUserWithRoles.getJobTitle(), "test"); + assertEquals(remoteUserWithRoles.getLoginId(), "test"); + assertEquals(remoteUserWithRoles.getActive(), false); + assertEquals(remoteUserWithRoles.getRoles().size(), 1); + assertEquals(remoteUserWithRoles.toString(), "RemoteUserWithRoles [orgId=1, managerId=1, firstName=test, middleInitial=test, lastName=test, phone=test, " + + "email=test, hrid=test, orgUserId=test, orgCode=test, orgManagerUserId=test, jobTitle=test, loginId=test, active=false, roles=[RemoteRole [id=1, name=test]]]"); + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/RoleInAppForUserTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/RoleInAppForUserTest.java new file mode 100644 index 00000000..66624c2a --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/RoleInAppForUserTest.java @@ -0,0 +1,37 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.RoleInAppForUser; + +public class RoleInAppForUserTest { + + public RoleInAppForUser mockRoleInAppForUser(){ + RoleInAppForUser roleInAppForUser = new RoleInAppForUser((long)1 , "test"); + roleInAppForUser.setRoleId((long)1); + roleInAppForUser.setRoleName("test"); + roleInAppForUser.setIsApplied(false); + + return roleInAppForUser; + } + + @Test + public void roleInAppForUserTest(){ + RoleInAppForUser roleInAppForUser = mockRoleInAppForUser(); + + RoleInAppForUser roleInAppForUser1 = new RoleInAppForUser((long)1 , "test"); + roleInAppForUser1.setRoleId((long)1); + roleInAppForUser1.setRoleName("test"); + roleInAppForUser1.setIsApplied(false); + + assertEquals(roleInAppForUser.getRoleId(), new Long(1)); + assertEquals(roleInAppForUser.getRoleName(), "test"); + assertEquals(roleInAppForUser.getIsApplied(), false); + + assertEquals(roleInAppForUser.toString(), "RoleInAppForUser [roleId=1, roleName=test, isApplied=false]"); + assertTrue(roleInAppForUser.equals(roleInAppForUser1)); + assertEquals(roleInAppForUser.hashCode(), roleInAppForUser1.hashCode()); + //constructor + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/UserApplicationRolesTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/UserApplicationRolesTest.java new file mode 100644 index 00000000..632eeb4f --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/UserApplicationRolesTest.java @@ -0,0 +1,58 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.RemoteRole; +import org.openecomp.portalapp.portal.transport.UserApplicationRoles; + +public class UserApplicationRolesTest { + + public UserApplicationRoles mockUserApplicationRoles(){ + UserApplicationRoles userApplicationRoles = new UserApplicationRoles(); + + List<RemoteRole> roles = new ArrayList<RemoteRole>(); + RemoteRole remoteRole = new RemoteRole(); + remoteRole.setId((long)1); + remoteRole.setName("test"); + roles.add(remoteRole); + + userApplicationRoles.setAppId((long)1); + userApplicationRoles.setOrgUserId("test"); + userApplicationRoles.setFirstName("test"); + userApplicationRoles.setLastName("test"); + userApplicationRoles.setRoles(roles); + + return userApplicationRoles; + } + + @Test + public void userApplicationRolesTest(){ + UserApplicationRoles userApplicationRoles = mockUserApplicationRoles(); + + UserApplicationRoles userApplicationRoles1 = new UserApplicationRoles(); + + List<RemoteRole> roles = new ArrayList<RemoteRole>(); + RemoteRole remoteRole = new RemoteRole(); + remoteRole.setId((long)1); + remoteRole.setName("test"); + roles.add(remoteRole); + + userApplicationRoles1.setAppId((long)1); + userApplicationRoles1.setOrgUserId("test"); + userApplicationRoles1.setFirstName("test"); + userApplicationRoles1.setLastName("test"); + userApplicationRoles1.setRoles(roles); + + assertEquals(userApplicationRoles.getAppId(), userApplicationRoles1.getAppId()); + assertEquals(userApplicationRoles.getOrgUserId(), userApplicationRoles1.getOrgUserId()); + assertEquals(userApplicationRoles.getFirstName(), userApplicationRoles1.getFirstName()); + assertEquals(userApplicationRoles.getLastName(), userApplicationRoles1.getLastName()); + assertEquals(userApplicationRoles.getRoles(), userApplicationRoles1.getRoles()); + + + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/UserWithNameSurnameTitleTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/UserWithNameSurnameTitleTest.java new file mode 100644 index 00000000..7267dcde --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/UserWithNameSurnameTitleTest.java @@ -0,0 +1,19 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.UserWithNameSurnameTitle; + +public class UserWithNameSurnameTitleTest { + + @Test + public void userWithNameSurnameTitleTest(){ + + UserWithNameSurnameTitle userWithNameSurnameTitle = new UserWithNameSurnameTitle("test", "test", "test", "test"); + + assertEquals(userWithNameSurnameTitle, new UserWithNameSurnameTitle("test", "test", "test", "test")); + assertEquals(userWithNameSurnameTitle.hashCode(), new UserWithNameSurnameTitle("test", "test", "test", "test").hashCode()); + assertTrue(userWithNameSurnameTitle.equals(new UserWithNameSurnameTitle("test", "test", "test", "test"))); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/WidgetCatalogPersonalizationTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/WidgetCatalogPersonalizationTest.java new file mode 100644 index 00000000..6681d0a4 --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/transport/WidgetCatalogPersonalizationTest.java @@ -0,0 +1,25 @@ +package org.openecomp.portalapp.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.transport.WidgetCatalogPersonalization; + +public class WidgetCatalogPersonalizationTest { + + public WidgetCatalogPersonalization mockWidgetCatalogPersonalization(){ + WidgetCatalogPersonalization widgetCatalogPersonalization = new WidgetCatalogPersonalization(); + + widgetCatalogPersonalization.setWidgetId((long)1); + widgetCatalogPersonalization.setSelect(false); + return widgetCatalogPersonalization; + } + + @Test + public void widgetCatalogPersonalizationTest(){ + WidgetCatalogPersonalization widgetCatalogPersonalization = mockWidgetCatalogPersonalization(); + + assertEquals(widgetCatalogPersonalization.getWidgetId(), new Long(1)); + assertEquals(widgetCatalogPersonalization.getSelect(), false); + } +} diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/exceptions/NoHealthyServiceExceptionTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/exceptions/NoHealthyServiceExceptionTest.java new file mode 100644 index 00000000..33389fbc --- /dev/null +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/exceptions/NoHealthyServiceExceptionTest.java @@ -0,0 +1,23 @@ +package org.openecomp.portalapp.test.exceptions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.portalapp.portal.exceptions.NoHealthyServiceException; + +public class NoHealthyServiceExceptionTest { + + public NoHealthyServiceException mockNoHealthyServiceException(){ + NoHealthyServiceException noHealthyServiceException = new NoHealthyServiceException("test"); + + return noHealthyServiceException; + } + + @Test + public void noHealthyServiceExceptionTest(){ + NoHealthyServiceException noHealthyServiceException = mockNoHealthyServiceException(); + + // assertEquals(noHealthyServiceException, new NoHealthyServiceException("test")); + assertEquals(noHealthyServiceException.toString(), "NoHealthyServiceException [] test"); + } +} |