summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src
diff options
context:
space:
mode:
authorSunder Tattavarada <statta@research.att.com>2018-07-18 18:15:52 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-18 18:15:52 +0000
commitfe3a67c11b65d7989a6ef648c3f34eee8abe7394 (patch)
tree9695510ab78ec68678be2d2168723a58b46513fc /ecomp-portal-BE-common/src
parentf7c38545270c8c2dda31466dffd40b21f17ecf28 (diff)
parent6f03ccd5a4ad90296f4dc3567531848fce1d8ad5 (diff)
Merge "JUnits for coverage"
Diffstat (limited to 'ecomp-portal-BE-common/src')
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java49
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java57
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java336
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java53
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperControllerTest.java13
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java173
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EncryptAdminControllerTest.java123
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java541
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java125
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/HealthCheckControllerTest.java19
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java50
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java102
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java75
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java217
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsControllerTest.java317
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java77
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptorTest.java155
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/logging/logic/EPLogUtilTest.java107
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java207
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/EPRoleTest.java108
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/scheduler/policy/rest/RequestDetailsTest.java60
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java15
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImplTest.java243
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppsCacheServiceImpleTest.java89
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImplTest.java111
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java632
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLdapServiceImplTest.java1343
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java10
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java37
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java222
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java885
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java41
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java35
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java253
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java114
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java20
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java376
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAuthUserRoleTest.java62
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidatorTest.java94
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleTest.java82
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleV1Test.java94
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/CustomLoggingFilterTest.java81
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/CoreTimeoutHandlerTest.java93
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationVersionControllerTest.java96
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/FunctionalMenuHandlerTest.java131
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/InitUebHandlerTest.java111
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java425
48 files changed, 8330 insertions, 333 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java
index d861cc85..a94d1955 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java
@@ -39,6 +39,7 @@ package org.onap.portalapp.command;
import static org.junit.Assert.*;
+import org.apache.bcel.generic.AASTORE;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.onap.portalapp.command.PostSearchBean;
@@ -55,8 +56,11 @@ public class PostSearchBeanTest {
PostSearchBean postSearchBean = new PostSearchBean();
EPUser user = mockUser.mockEPUser();
+ EPUser userOrig=mockUser.mockEPUser();
+ postSearchBean.setUserOrig(userOrig);
+
postSearchBean.setUser(user);
- postSearchBean.setUserOrig(null);
+ //postSearchBean.setUserOrig(null);
postSearchBean.setSelected(null);
postSearchBean.setHrid(null);
postSearchBean.setPostUserId(null);
@@ -85,6 +89,19 @@ public class PostSearchBeanTest {
postSearchBean.setPostSiloStatus(null);
postSearchBean.setPostFinancialLocCode(null);
postSearchBean.setPostManagerUserId(null);
+ postSearchBean.setPostHrid(null);
+ postSearchBean.setPostCompany(null);
+ postSearchBean.setFirstName(null);
+ postSearchBean.setLastName(null);
+ postSearchBean.setOrgUserId(null);
+ postSearchBean.setEmail(null);
+ postSearchBean.setFirstNameOrig(null);
+ postSearchBean.setLastNameOrig(null);
+ postSearchBean.setHridOrig(null);
+ postSearchBean.setOrgUserIdOrig(null);
+ postSearchBean.setOrgCodeOrig(null);
+ postSearchBean.setEmailOrig(null);
+ postSearchBean.setOrgManagerUserIdOrig(null);
return postSearchBean;
}
@@ -94,7 +111,7 @@ public class PostSearchBeanTest {
PostSearchBean postSearchBean = mockPostSearchBean();
EPUser user = mockUser.mockEPUser();
assertEquals(postSearchBean.getUser().getActive(), user.getActive());
- assertNull(postSearchBean.getUserOrig());
+ assertNotNull(postSearchBean.getUserOrig());
assertNull(postSearchBean.getSelected());
assertNull(postSearchBean.getHrid());
assertNull(postSearchBean.getPostOrgUserId());
@@ -123,6 +140,20 @@ public class PostSearchBeanTest {
assertNull(postSearchBean.getPostSiloStatus());
assertNull(postSearchBean.getPostFinancialLocCode());
assertNull(postSearchBean.getPostManagerUserId());
+ assertNull(postSearchBean.getPostHrid());
+ assertNull(postSearchBean.getPostCompany());
+ assertNull(postSearchBean.getFirstName());
+ assertNull(postSearchBean.getLastName());
+
+ assertNull(postSearchBean.getOrgUserId());
+ assertNull(postSearchBean.getEmail());
+ assertNull(postSearchBean.getFirstNameOrig());
+ assertNull(postSearchBean.getLastNameOrig());
+ assertNull(postSearchBean.getHridOrig());
+ assertNull(postSearchBean.getOrgUserIdOrig());
+ assertNull(postSearchBean.getOrgCodeOrig());
+ assertNull(postSearchBean.getEmailOrig());
+ assertNull(postSearchBean.getOrgManagerUserIdOrig());
}
@Test
@@ -146,5 +177,19 @@ public class PostSearchBeanTest {
mockPostSearchBean.setUserOrig(null);
assertFalse(mockPostSearchBean.isCriteriaUpdated());
}
+
+ @Test
+ public void isCriteriaUpdatedIfUserOrgigTest()
+ {
+ // mockPostSearchBean.setUser(null);
+ mockPostSearchBean.setUserOrig(null);
+ assertTrue(mockPostSearchBean.isCriteriaUpdated());
+ }
+
+ @Test
+ public void isCriteriaUpdatedIfUserTest1()
+ {
+ assertFalse(mockPostSearchBean.isCriteriaUpdated());
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java
index 52870983..1c1d7bc0 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java
@@ -277,5 +277,62 @@ public class AppCatalogControllerTest extends MockitoTestSuite {
assertEquals(expectedFieldValidator, actualFieldValidator);
}
+
+ @Test
+ public void putAppCatalogSelectionTestWithException() throws IOException {
+
+ AppCatalogPersonalization persRequest = new AppCatalogPersonalization();
+ persRequest.setAppId((long) 1);
+ persRequest.setPending(false);
+ persRequest.setSelect(false);
+
+ EPUser user = mockUser.mockEPUser();
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ ;
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+
+ 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);
+
+ Mockito.when(appService.getApp(persRequest.getAppId())).thenReturn(app);
+
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.doNothing().when(persUserAppService).setPersUserAppValue(user, null, persRequest.getSelect(),
+ persRequest.getPending());
+
+ actualFieldValidator = appCatalogController.putAppCatalogSelection(mockedRequest, persRequest, mockedResponse);
+
+ assertEquals(expectedFieldValidator, actualFieldValidator);
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java
index 5e99b44b..847d4744 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java
@@ -173,7 +173,7 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite {
.postPortalAdmin(mockedRequest, mockedResponse, user);
assertEquals(actualPortalRestResponse, expectedportalRestResponse);
}
-
+/*reference*/
@Test
public void postPortalAdminCreateUserIfNotSuperAdminTest() throws Exception {
PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
@@ -307,4 +307,338 @@ public class AppsControllerExternalRequestTest extends MockitoTestSuite {
.putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
assertEquals(actualPortalRestResponse, expectedportalRestResponse);
}
+
+ @Test
+ public void putOnboardAppExternalIfOnboardingAppDetailsTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Failed to find user: testUser");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Long appId = (long) 1;
+
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = (long) 1;
+ expectedOnboardingApp.name = "test";
+ expectedOnboardingApp.url="test.com";
+ expectedOnboardingApp.restUrl="test1.com";
+ expectedOnboardingApp.myLoginsAppOwner="testUser";
+ expectedOnboardingApp.restrictedApp=false;
+ expectedOnboardingApp.isOpen=true;
+ expectedOnboardingApp.isEnabled=true;
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalIfOnboardingAppDetailsTest2() throws Exception {
+
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+
+ Long appId = (long) 1;
+
+ OnboardingApp oldOnboardApp = new OnboardingApp();
+ oldOnboardApp.id = (long) 1;
+ oldOnboardApp.name = "test";
+ oldOnboardApp.url="test.com";
+ oldOnboardApp.restUrl="test1.com";
+ oldOnboardApp.myLoginsAppOwner="12";
+ oldOnboardApp.restrictedApp=false;
+ oldOnboardApp.isOpen=true;
+ oldOnboardApp.isEnabled=true;
+
+
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(oldOnboardApp.myLoginsAppOwner)).thenReturn(expectedList);
+ //Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(appService.modifyOnboardingApp(oldOnboardApp, user)).thenReturn(expectedFieldValidator);
+ //Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest.putOnboardAppExternal(mockedRequest, mockedResponse, appId, oldOnboardApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+
+ @Test
+ public void putOnboardAppExternalTest() throws Exception {
+
+ 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);
+
+ Long appId = (long) 1;
+
+ OnboardingApp oldOnboardApp = new OnboardingApp();
+ oldOnboardApp.id = (long) 1;
+ oldOnboardApp.name = "test";
+ oldOnboardApp.url="test.com";
+ oldOnboardApp.restUrl="test1.com";
+ oldOnboardApp.myLoginsAppOwner="12";
+ oldOnboardApp.restrictedApp=false;
+ oldOnboardApp.isOpen=true;
+ oldOnboardApp.isEnabled=true;
+
+
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(oldOnboardApp.myLoginsAppOwner)).thenReturn(expectedList);
+ //Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 500);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(appService.modifyOnboardingApp(oldOnboardApp, user)).thenReturn(expectedFieldValidator);
+ //Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest.putOnboardAppExternal(mockedRequest, mockedResponse, appId, oldOnboardApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalIsNotSuperAdminTest() throws Exception {
+
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("User lacks Portal admin role: Test");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ Long appId = (long) 1;
+
+ OnboardingApp oldOnboardApp = new OnboardingApp();
+ oldOnboardApp.id = (long) 1;
+ oldOnboardApp.name = "test";
+ oldOnboardApp.url="test.com";
+ oldOnboardApp.restUrl="test1.com";
+ oldOnboardApp.myLoginsAppOwner="12";
+ oldOnboardApp.restrictedApp=false;
+ oldOnboardApp.isOpen=true;
+ oldOnboardApp.isEnabled=true;
+
+
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(oldOnboardApp.myLoginsAppOwner)).thenReturn(expectedList);
+ //Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ //Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest.putOnboardAppExternal(mockedRequest, mockedResponse, appId, oldOnboardApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalWithExceptionTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("java.lang.NullPointerException");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ Long appId = (long) 1;
+
+ OnboardingApp oldOnboardApp = new OnboardingApp();
+ oldOnboardApp.id = (long) 1;
+ oldOnboardApp.name = "test";
+ oldOnboardApp.url="test.com";
+ oldOnboardApp.restUrl="test1.com";
+ oldOnboardApp.myLoginsAppOwner="12";
+ oldOnboardApp.restrictedApp=false;
+ oldOnboardApp.isOpen=true;
+ oldOnboardApp.isEnabled=true;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(oldOnboardApp.myLoginsAppOwner)).thenThrow(nullPointerException);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId,oldOnboardApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postOnboardAppExternalwithExceptionTest() throws Exception {
+
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("User lacks Portal admin role: Test");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ Long appId = (long) 1;
+
+
+
+ OnboardingApp newOnboardApp = new OnboardingApp();
+ //newOnboardApp.id = (long) 1;
+ newOnboardApp.name = "test";
+ newOnboardApp.url="test.com";
+ newOnboardApp.restUrl="test1.com";
+ newOnboardApp.myLoginsAppOwner="12";
+ newOnboardApp.restrictedApp=false;
+ newOnboardApp.isOpen=true;
+ newOnboardApp.isEnabled=true;
+
+
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(newOnboardApp.myLoginsAppOwner)).thenReturn(expectedList);
+ //Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ //Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest.postOnboardAppExternal(mockedRequest, mockedResponse,newOnboardApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postOnboardAppExternalIsNotSuperAdminTest() throws Exception {
+
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("java.lang.NullPointerException");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ Long appId = (long) 1;
+
+
+
+ OnboardingApp newOnboardApp = new OnboardingApp();
+ //newOnboardApp.id = (long) 1;
+ newOnboardApp.name = "test";
+ newOnboardApp.url="test.com";
+ newOnboardApp.restUrl="test1.com";
+ newOnboardApp.myLoginsAppOwner="12";
+ newOnboardApp.restrictedApp=false;
+ newOnboardApp.isOpen=true;
+ newOnboardApp.isEnabled=true;
+
+
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(newOnboardApp.myLoginsAppOwner)).thenReturn(expectedList);
+ //Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ //Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest.postOnboardAppExternal(mockedRequest, mockedResponse,newOnboardApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postOnboardAppExternalIsSuperAdminTest() throws Exception {
+
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+
+ Long appId = (long) 1;
+
+
+
+ OnboardingApp newOnboardApp = new OnboardingApp();
+ //newOnboardApp.id = (long) 1;
+ newOnboardApp.name = "test";
+ newOnboardApp.url="test.com";
+ newOnboardApp.restUrl="test1.com";
+ newOnboardApp.myLoginsAppOwner="12";
+ newOnboardApp.restrictedApp=false;
+ newOnboardApp.isOpen=true;
+ newOnboardApp.isEnabled=true;
+
+
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@test.portal.onap.org");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(newOnboardApp.myLoginsAppOwner)).thenReturn(expectedList);
+ //Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(appService.addOnboardingApp(newOnboardApp, user)).thenReturn(expectedFieldValidator);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest.postOnboardAppExternal(mockedRequest, mockedResponse,newOnboardApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
index 222bfd26..ff37fd50 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
@@ -80,6 +80,7 @@ import org.onap.portalapp.portal.transport.EPWidgetsSortPreference;
import org.onap.portalapp.portal.transport.FieldsValidator;
import org.onap.portalapp.portal.transport.LocalRole;
import org.onap.portalapp.portal.transport.OnboardingApp;
+import org.onap.portalapp.portal.utils.EcompPortalUtils;
import org.onap.portalapp.util.EPUserUtils;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.portalsdk.core.web.support.AppUtils;
@@ -952,4 +953,56 @@ public class AppsControllerTest extends MockitoTestSuite{
assertEquals(listOfActualApps.size(), 1);
}
+ @Test
+ public void getSingleAppInfoWithExceptionTest (){
+ EPApp epApp=new EPApp();
+ epApp.setName("test");
+ epApp.setId(1L);
+ //EPApp listOfApps = new ArrayList<EcompApp>();
+
+ //EcompApp app = new EcompApp();
+ //listOfApps.add(app);
+ EPUser user = mockUser.mockEPUser();
+ String appName="test";
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("mparams")).thenReturn("M");
+ Mockito.when(appService.getAppDetailByAppName(appName)).thenReturn(epApp);
+ EPApp listOfActualApps = appsController.getSingleAppInfo(mockedRequest, mockedResponse);
+ //assertEquals(listOfActualApps,epApp);
+ assertNull(listOfActualApps);
+ }
+
+ @Test
+ public void getSingleAppInfoTest (){
+ EPApp epApp=new EPApp();
+ epApp.setName("test");
+ epApp.setId(1L);
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(mockedRequest.getParameter("appParam")).thenReturn("test");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("mparams")).thenReturn("M");
+ Mockito.when(appService.getAppDetailByAppName("test")).thenReturn(epApp);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+
+ EPApp listOfActualApps = appsController.getSingleAppInfo(mockedRequest, mockedResponse);
+ //assertEquals(listOfActualApps,epApp);
+ assertEquals(listOfActualApps,epApp);
+ }
+
+
+ @Test
+ public void getSingleAppInfoByIdTest(){
+ EPApp epApp=new EPApp();
+ epApp.setName("test");
+ epApp.setId(1L);
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(mockedRequest.getParameter("appParam")).thenReturn("123");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("mparams")).thenReturn("M");
+ Mockito.when(appService.getApp(123L)).thenReturn(epApp);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ EPApp listOfActualApps = appsController.getSingleAppInfoById(mockedRequest, mockedResponse);
+ assertEquals(listOfActualApps,epApp);
+ }
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperControllerTest.java
index 62e93727..38510d9a 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuxApiRequestMapperControllerTest.java
@@ -113,6 +113,19 @@ public class AuxApiRequestMapperControllerTest {
Mockito.when(mockedRequest.getMethod()).thenReturn("GET");
assertNull(auxApiRequestMapperController.getUser(mockedRequest, mockedResponse, "test12"));
}
+
+ @Test
+ public void getUserTestWithException() throws Exception {
+ Mockito.when(mockedRequest.getRequestURI()).thenReturn("/auxapi/v3/roles");
+ Mockito.when(mockedRequest.getHeader("MinorVersion")).thenReturn("0");
+ Map<String, Object> beans = new HashMap<>();
+ beans.put("bean1", rolesController);
+ Mockito.when(context.getBeansWithAnnotation(ApiVersion.class)).thenReturn(beans);
+ PowerMockito.mockStatic(AopUtils.class);
+ Mockito.when(AopUtils.isAopProxy(Matchers.anyObject())).thenReturn(false);
+ Mockito.when(mockedRequest.getMethod()).thenReturn("GET");
+ assertNull(auxApiRequestMapperController.getUser(mockedRequest, mockedResponse, "test12"));
+ }
@Test
public void getRolesTest() throws Exception {
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java
index db81dcd2..417568da 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java
@@ -41,6 +41,7 @@ import static org.junit.Assert.*;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,6 +49,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -58,8 +60,10 @@ import org.mockito.MockitoAnnotations;
import org.onap.portalapp.portal.controller.DashboardController;
import org.onap.portalapp.portal.core.MockEPUser;
import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.EcompAuditLog;
import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.onap.portalapp.portal.ecomp.model.SearchResultItem;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalapp.portal.service.AdminRolesService;
import org.onap.portalapp.portal.service.AdminRolesServiceImpl;
@@ -68,12 +72,18 @@ import org.onap.portalapp.portal.service.DashboardSearchServiceImpl;
import org.onap.portalapp.portal.transport.CommonWidget;
import org.onap.portalapp.portal.transport.CommonWidgetMeta;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalapp.portal.utils.PortalConstants;
import org.onap.portalapp.util.EPUserUtils;
+import org.onap.portalsdk.core.domain.AuditLog;
import org.onap.portalsdk.core.domain.support.CollaborateList;
+import org.onap.portalsdk.core.service.AuditService;
+import org.onap.portalsdk.core.service.AuditServiceImpl;
import org.onap.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.beans.factory.annotation.Autowired;
@RunWith(PowerMockRunner.class)
@@ -83,11 +93,19 @@ public class DashboardControllerTest {
@Mock
DashboardSearchService searchService = new DashboardSearchServiceImpl();
+ /*@Mock
+ AuditService auditService = new AuditServiceImpl();*/
+
@InjectMocks
DashboardController dashboardController = new DashboardController();
@Mock
AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Autowired
+ AuditService auditService;
+
+
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
@@ -213,13 +231,8 @@ public class DashboardControllerTest {
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");*/
-
+ commonWidgetMeta.setItems(widgetList);
+ commonWidgetMeta.setCategory("EVENTS");
PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
expectedData.setStatus(PortalRestStatusEnum.OK);
expectedData.setMessage("success");
@@ -250,6 +263,21 @@ public class DashboardControllerTest {
}
@Test
+ public void saveWidgetDataTitleTest() throws IOException {
+ CommonWidget commonWidget = mockCommonWidget();
+ commonWidget.setId((long)1);
+ commonWidget.setContent("test");
+ commonWidget.setTitle("test");
+ PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
+ expectedData.setStatus(PortalRestStatusEnum.ERROR);
+ expectedData.setMessage("Invalid category: test");
+ expectedData.setResponse(null);
+ Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
+ PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse);
+ assertEquals(expectedData.getMessage(),actualResponse.getMessage());
+ }
+
+ @Test
public void saveWidgetDataErrorTest() throws IOException {
CommonWidget commonWidget = mockCommonWidget();
@@ -464,4 +492,135 @@ public class DashboardControllerTest {
PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest);
assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
}
+ @Test
+ public void searchPortalTestWhenSearchStringIsNull(){
+ EPUser user = mockUser.mockEPUser();
+ user.setLoginId("test");
+ user.setId(1L);
+ String searchString = null;
+ //user.setLoginId("test");
+ PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>();
+ expectedData.setStatus(PortalRestStatusEnum.ERROR);
+ expectedData.setMessage("null - check logs.");
+ expectedData.setResponse(Matchers.any());
+
+ PowerMockito.mockStatic(EPUserUtils.class);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedResult.setMessage("null - check logs.");
+ expectedResult.setResponse(null);
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+ //Mockito.doNothing().when(auditService).logActivity(auditLog, null);
+
+ //Mockito.when(auditService.logActivity(auditLog, null).;
+ //Mockito.when(searchService.searchResults(user.getLoginId(), searchString )).thenReturn((Map<String, List<SearchResultItem>>) expectedResult);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualResponse = dashboardController.searchPortal(mockedRequest, null);
+ assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+ }
+
+ @Test
+ public void searchPortalTest(){
+ EPUser user = null;
+ String searchString = null;
+ //user.setLoginId("test");
+ PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>();
+ expectedData.setStatus(PortalRestStatusEnum.ERROR);
+ expectedData.setMessage("null - check logs.");
+ expectedData.setResponse(Matchers.any());
+
+ PowerMockito.mockStatic(EPUserUtils.class);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedResult.setMessage("null - check logs.");
+ expectedResult.setResponse(null);
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+ //Mockito.doNothing().when(auditService).logActivity(auditLog, null);
+
+ //Mockito.when(auditService.logActivity(auditLog, null).;
+ //Mockito.when(searchService.searchResults(user.getLoginId(), searchString )).thenReturn((Map<String, List<SearchResultItem>>) expectedResult);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualResponse = dashboardController.searchPortal(mockedRequest, null);
+ assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+ }
+ @Test
+ public void searchPortalTestWithException(){
+ EPUser user = mockUser.mockEPUser();
+ user.setLoginId("test");
+ user.setId(1L);
+
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String searchString = "test";
+ List<SearchResultItem> searchResultItemList = new ArrayList<SearchResultItem>();
+ SearchResultItem searchResultItem = new SearchResultItem();
+
+ searchResultItem.setId((long) 1);
+ searchResultItem.setCategory("test");
+ searchResultItem.setName("test_name");
+ searchResultItem.setTarget("test_target");
+ searchResultItem.setUuid("test_UUId");
+ searchResultItemList.add(searchResultItem);
+ Map<String, List<SearchResultItem>> expectedResultMap = new HashMap<String, List<SearchResultItem>>();
+ expectedResultMap.put(searchString, searchResultItemList);
+
+ AuditLog auditLog = new AuditLog();
+ auditLog.setUserId(1L);
+ auditLog.setActivityCode("test");
+ auditLog.setComments("test");
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedResult.setMessage("null - check logs.");
+ expectedResult.setResponse(null);
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+ //Mockito.doNothing().when(auditService).logActivity(auditLog, null);
+
+ //Mockito.when(auditService.logActivity(auditLog, null).;
+ Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenReturn(expectedResultMap);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualResult = dashboardController.searchPortal(mockedRequest, searchString);
+
+ assertTrue(expectedResult.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+
+ }
+
+ @Test
+ public void searchPortalUserNullTest(){
+ EPUser user = null;
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedData.setMessage("searchPortal: User object is null? - check logs");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualData = dashboardController.searchPortal(mockedRequest, null);
+ assertEquals(actualData.getMessage(), expectedData.getMessage());
+ }
+
+ @Test
+ public void searchPortalsearchStringNullTest(){
+ EPUser user = mockUser.mockEPUser();
+ String searchString = null;
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedData.setMessage("searchPortal: String string is null");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualData = dashboardController.searchPortal(mockedRequest, searchString);
+ assertEquals(actualData.getMessage(), expectedData.getMessage());
+ }
+ @Ignore
+ @Test
+ public void searchPortalsearchStringTest(){
+ EPUser user = mockUser.mockEPUser();
+ String searchString = "test";
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedData.setMessage("success");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.doNothing().when(auditService).logActivity(null, null);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualData = dashboardController.searchPortal(mockedRequest, searchString);
+ assertEquals(actualData.getMessage(), expectedData.getMessage());
+ }
+ //@Ignore
+ @Test
+ public void searchPortalsearchStringExceptionTest(){
+ EPUser user = mockUser.mockEPUser();
+ String searchString = "test";
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedData.setMessage("searchPortal: String string is null");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(dashboardController.searchPortal(mockedRequest, searchString)).thenThrow(nullPointerException);
+ }
+
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EncryptAdminControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EncryptAdminControllerTest.java
new file mode 100644
index 00000000..b2c80308
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EncryptAdminControllerTest.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portalapp.portal.controller;
+
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.hibernate.Query;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+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.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ CipherUtil.class})
+public class EncryptAdminControllerTest {
+
+ @InjectMocks
+ EncryptAdminController encryptAdminController=new EncryptAdminController();
+
+ @Mock
+ HttpServletRequest request;
+ @Mock
+ HttpServletResponse response;
+ @Mock
+ Session session;
+ @Mock
+ SessionFactory sessionFactory;
+ @Mock
+ Transaction transaction;
+ @Mock
+ SQLQuery query;
+ @Mock
+ SQLQuery basicQuery;
+
+ @Mock
+ SQLQuery microQuery;
+ @Mock
+ DataAccessService dataAccessService;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ PowerMockito.mockStatic(CipherUtil.class);
+ }
+
+ @Test
+ public void testExecuteEncrypt()throws Exception {
+ List appPassword=new ArrayList<>();
+ Object[] array= new Object[2];
+ array[0]=new Long(3l);
+ array[1]="test";
+ appPassword.add(array);
+
+ when(sessionFactory.openSession()).thenReturn(session);
+ when(dataAccessService.executeNamedQuery("getAppPassword", null, null)).thenReturn(appPassword);
+ when(CipherUtil.decrypt("test")).thenReturn("testDecrypt");
+ when(CipherUtil.encrypt("testDecrypt")).thenReturn("test");
+ when(session.getTransaction()).thenReturn(transaction);
+ when(session.createSQLQuery("UPDATE fn_app m SET m.app_password= :pass " + " where m.app_id = :app_id")).thenReturn(query);
+ when(dataAccessService.executeNamedQuery("getBasicauthAccount", null, null)).thenReturn(appPassword);
+ when(dataAccessService.executeNamedQuery("getMicroserviceInfo", null, null)).thenReturn(appPassword);
+ when(session.createSQLQuery("UPDATE ep_basic_auth_account m SET m.password= :pass" + " where m.id = :app_id")).thenReturn(basicQuery);
+ when(session.createSQLQuery("UPDATE ep_microservice m SET m.password= :pass" + " where m.id = :app_id")).thenReturn(microQuery);
+
+ encryptAdminController.executeEncrypt(request, response);
+
+ }
+
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java
index 6518320a..556e215c 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java
@@ -71,6 +71,7 @@ import org.onap.portalapp.portal.service.ExternalAccessRolesService;
import org.onap.portalapp.portal.service.ExternalAccessRolesServiceImpl;
import org.onap.portalapp.portal.transport.CentralRole;
import org.onap.portalapp.portal.transport.CentralRoleFunction;
+import org.onap.portalapp.portal.transport.CentralUser;
import org.onap.portalapp.portal.transport.CentralV2Role;
import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
@@ -131,30 +132,6 @@ public class ExternalAccessRolesControllerTest {
String loginId = "guestT";
String uebKey = "testUebKey";
- @Test
- public void getUserTest() throws Exception {
- String reason = getInvalidKeyJson();
- StringWriter sw = new StringWriter();
- PrintWriter writer = new PrintWriter(sw);
- Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
- List<EPUser> userList = new ArrayList<>();
- Mockito.when(externalAccessRolesService.getUser(loginId)).thenReturn(userList);
- externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId);
- String result = sw.getBuffer().toString().trim();
- assertEquals(reason, result);
- }
-
- @Test
- public void getUserExceptionTest() throws Exception {
- String reason = getInvalidKeyJson();
- StringWriter sw = new StringWriter();
- PrintWriter writer = new PrintWriter(sw);
- Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
- externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId);
- String result = sw.getBuffer().toString().trim();
- assertEquals(reason, result);
- }
-
public EPApp mockApp()
{
EPApp app = new EPApp();
@@ -180,6 +157,146 @@ public class ExternalAccessRolesControllerTest {
return app;
}
+ @Test
+ public void getUserTest() throws Exception {
+ CentralUser expectedCentralUser = new CentralUser(null, null, null, null, null, null, null, null, loginId, loginId, loginId, loginId, loginId, loginId, loginId, null, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, loginId, null, false, false, null, null, false, loginId, null);
+ String loginId = "test";
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ Mockito.when(externalAccessRolesService.getUserRoles(loginId, mockedRequest.getHeader("uebkey"))).thenReturn(expectedCentralUser);
+ CentralUser actualCentralUser = externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId);
+ assertEquals(actualCentralUser.isActive(), expectedCentralUser.isActive());
+ }
+
+ @Test
+ public void getUserExceptionTest() throws Exception {
+ String reason = getInvalidKeyJson();
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId);
+ String result = sw.getBuffer().toString().trim();
+ assertEquals(reason, result);
+ }
+
+ @Test
+ public void getV2UserListTest() throws Exception {
+ String expectedCentralUser = "test";
+ String loginId = "test";
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ Mockito.when(externalAccessRolesService.getV2UserWithRoles(loginId, mockedRequest.getHeader("uebkey"))).thenReturn(expectedCentralUser);
+ String actualString = externalAccessRolesController.getV2UserList(mockedRequest, mockedResponse, loginId);
+ assertEquals(actualString, expectedCentralUser);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getV2UserListExceptionTest() throws Exception {
+ String expectedCentralUser = null;
+ String loginId = "test";
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ ResponseEntity<String> response = null;
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ Mockito.when(externalAccessRolesService.getV2UserWithRoles(loginId, mockedRequest.getHeader("uebkey"))).thenReturn(expectedCentralUser);
+ String actualString = externalAccessRolesController.getV2UserList(mockedRequest, mockedResponse, loginId);
+ assertEquals(actualString, expectedCentralUser);
+ }
+
+ @Test
+ public void getRolesForAppCentralRoleTest() throws Exception {
+ List<CentralRole> expectedCentralRoleList = new ArrayList<CentralRole>();
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ List<CentralV2Role> centralV2RoleList = new ArrayList<>();
+ List<CentralRole> centralRoleList = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ Mockito.when(externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey))).thenReturn(centralV2RoleList);
+ Mockito.when(externalAccessRolesService.convertV2CentralRoleListToOldVerisonCentralRoleList(centralV2RoleList)).thenReturn(centralRoleList);
+ List<CentralRole> actualCentralRoleList = externalAccessRolesController.getRolesForApp(mockedRequest, mockedResponse);
+ assertEquals(actualCentralRoleList.size(), expectedCentralRoleList.size());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getRolesForAppCentralRoleExceptionTest() throws Exception {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ List<CentralV2Role> centralV2RoleList = new ArrayList<>();
+ List<CentralRole> centralRoleList = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ ResponseEntity<String> response = null;
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ Mockito.when(externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey))).thenReturn(centralV2RoleList);
+ Mockito.when(externalAccessRolesService.convertV2CentralRoleListToOldVerisonCentralRoleList(centralV2RoleList)).thenReturn(centralRoleList);
+ List<CentralRole> actualCentralRoleList = externalAccessRolesController.getRolesForApp(mockedRequest, mockedResponse);
+ assertEquals(null,actualCentralRoleList);
+ }
+
+ @Test
+ public void getV2RolesForAppTest() throws Exception {
+ List<CentralRole> expectedCentralRoleList = new ArrayList<CentralRole>();
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ List<CentralV2Role> centralV2Role = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ Mockito.when(externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey))).thenReturn(centralV2Role);
+ List<CentralV2Role> actualCentralV2Role = externalAccessRolesController.getV2RolesForApp(mockedRequest, mockedResponse);
+ assertEquals(actualCentralV2Role.size(), expectedCentralRoleList.size());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getV2RolesForAppExceptionTest() throws Exception {
+ List<CentralRole> expectedCentralRoleList = new ArrayList<CentralRole>();
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ List<CentralV2Role> centralV2Role = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ ResponseEntity<String> response = null;
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ Mockito.when(externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey))).thenReturn(centralV2Role);
+ List<CentralV2Role> actualCentralV2Role = externalAccessRolesController.getV2RolesForApp(mockedRequest, mockedResponse);
+ assertEquals(actualCentralV2Role.size(), expectedCentralRoleList.size());
+ }
+
@Test(expected = NullPointerException.class)
public void getRolesForAppTest() throws Exception {
List<EPApp> applicationList = new ArrayList<EPApp>();
@@ -206,28 +323,82 @@ public class ExternalAccessRolesControllerTest {
@Test
public void getRoleFunctionsListTest() throws Exception {
+ List<CentralRole> expectedCentralRoleList = new ArrayList<CentralRole>();
+ List<CentralRoleFunction> roleFuncList = new ArrayList<CentralRoleFunction>();
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ List<CentralV2RoleFunction> centralV2RoleFunction = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ Mockito.when(externalAccessRolesService.getRoleFuncList(mockedRequest.getHeader("uebkey"))).thenReturn(centralV2RoleFunction);
+ Mockito.when(externalAccessRolesService.convertCentralRoleFunctionToRoleFunctionObject(centralV2RoleFunction)).thenReturn(roleFuncList);
+ List<CentralRoleFunction> actualCentralRoleFunction = externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse);
+ assertEquals(actualCentralRoleFunction.size(), expectedCentralRoleList.size());
+ }
+
+ @Test
+ public void getRoleFunctionsListExceptionTest() throws Exception {
String reason = getInvalidKeyJson();
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
- Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
- List<CentralV2RoleFunction> answer = null;
- Mockito.when(externalAccessRolesService.getRoleFuncList(mockedRequest.getHeader(uebKey))).thenReturn(null);
- assertEquals(externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse), answer);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse);
String result = sw.getBuffer().toString().trim();
assertEquals(reason, result);
}
@Test
- public void getRoleFunctionsListExceptionTest() throws Exception {
+ public void getV2RoleFunctionsListTest() throws Exception {
+ List<CentralV2RoleFunction> expectedCentralV2RoleFunctionList = new ArrayList<CentralV2RoleFunction>();
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ List<CentralV2RoleFunction> centralV2RoleFunction = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ Mockito.when(externalAccessRolesService.getRoleFuncList(mockedRequest.getHeader("uebkey"))).thenReturn(centralV2RoleFunction);
+ List<CentralV2RoleFunction> actualCentralV2RoleFunctionList = externalAccessRolesController.getV2RoleFunctionsList(mockedRequest, mockedResponse);
+ assertEquals(actualCentralV2RoleFunctionList.size(), expectedCentralV2RoleFunctionList.size());
+ }
+
+ @Test
+ public void getV2RoleFunctionsListExceptionTest() throws Exception {
String reason = getInvalidKeyJson();
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
- externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse);
+ externalAccessRolesController.getV2RoleFunctionsList(mockedRequest, mockedResponse);
String result = sw.getBuffer().toString().trim();
assertEquals(reason, result);
}
-
+
+ @Test
+ public void getRoleInfoValidationTest() throws Exception {
+ CentralRole expectedCentralRole = null;
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ long roleId = 1;
+ CentralV2Role centralV2Role = new CentralV2Role();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.when(externalAccessRolesService.getRoleInfo(roleId, mockedRequest.getHeader("uebkey"))).thenReturn(centralV2Role);
+ CentralRole actualCentralRole = externalAccessRolesController.getRoleInfo(mockedRequest, mockedResponse, roleId);
+ assertEquals(actualCentralRole, expectedCentralRole);
+ }
+
@Test
public void getRoleInfoTest() throws Exception {
String reason = getInvalidKeyJson();
@@ -254,8 +425,104 @@ public class ExternalAccessRolesControllerTest {
String result = sw.getBuffer().toString().trim();
assertEquals(reason, result);
}
+
+ @Test
+ public void getV2RoleInfoValidationTest() throws Exception {
+ CentralV2Role expectedCentralRole = new CentralV2Role();
+ expectedCentralRole.setActive(false);
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ long roleId = 1;
+ CentralV2Role centralV2Role = new CentralV2Role();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.when(externalAccessRolesService.getRoleInfo(roleId, mockedRequest.getHeader("uebkey"))).thenReturn(centralV2Role);
+ CentralV2Role actualCentralRole = externalAccessRolesController.getV2RoleInfo(mockedRequest, mockedResponse, roleId);
+ assertEquals(actualCentralRole.getActive(), expectedCentralRole.getActive());
+ }
+
+ @Test
+ public void getV2RoleInfoTest() throws Exception {
+ String reason = getInvalidKeyJson();
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ CentralV2Role answer = new CentralV2Role();
+ long roleId = 1;
+ Mockito.when(externalAccessRolesService.getRoleInfo(roleId, mockedRequest.getHeader(uebKey)))
+ .thenReturn(answer);
+ externalAccessRolesController.getV2RoleInfo(mockedRequest, mockedResponse, roleId);
+ String result = sw.getBuffer().toString().trim();
+ assertEquals(reason, result);
+ }
@Test
+ public void getV2RoleInfoExceptionTest() throws Exception {
+ String reason = getInvalidKeyJson();
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ long roleId = 1;
+ assertNull(externalAccessRolesController.getV2RoleInfo(mockedRequest, mockedResponse, roleId));
+ String result = sw.getBuffer().toString().trim();
+ assertEquals(reason, result);
+ }
+
+ @Test
+ public void getV2RoleFunctionTest() throws HttpClientErrorException, Exception{
+ CentralV2RoleFunction expectedCentralV2RoleFunction = new CentralV2RoleFunction();
+ expectedCentralV2RoleFunction.setCode("test");
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ String code = "test";
+ CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
+ centralV2RoleFunction.setCode("test");
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader("uebkey"))).thenReturn(centralV2RoleFunction);
+ CentralV2RoleFunction actualCentralV2RoleFunction = externalAccessRolesController.getV2RoleFunction(mockedRequest, mockedResponse, code);
+ assertEquals(actualCentralV2RoleFunction.getCode(), expectedCentralV2RoleFunction.getCode());
+ }
+
+ @Test
+ public void getV2RoleFunctionNullCheckTest() throws HttpClientErrorException, Exception{
+ CentralV2RoleFunction expectedCentralV2RoleFunction = new CentralV2RoleFunction();
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ String code = "test";
+ CentralV2RoleFunction centralV2RoleFunction = null;
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(applicationList);
+ Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader("uebkey"))).thenReturn(centralV2RoleFunction);
+ CentralV2RoleFunction actualCentralV2RoleFunction = externalAccessRolesController.getV2RoleFunction(mockedRequest, mockedResponse, code);
+ assertEquals(actualCentralV2RoleFunction.getAction(), expectedCentralV2RoleFunction.getAction());
+ }
+
+ @Test
+ public void getV2RoleFunctionExceptionTest() throws Exception {
+ String reason = getInvalidKeyJson();
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ String code = "test";
+ assertNull(externalAccessRolesController.getV2RoleFunction(mockedRequest, mockedResponse, code));
+ String result = sw.getBuffer().toString().trim();
+ assertEquals(reason, result);
+ }
+
+ @Test
public void getRoleFunctionTest() throws Exception {
EPApp mockApp = mockApp();
mockApp.setCentralAuth(true);
@@ -423,6 +690,24 @@ public class ExternalAccessRolesControllerTest {
}
@Test
+ public void getActiveRolesValidationTest() throws Exception {
+ List<CentralRole> expectedRolesList = null;
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<EPApp>();
+ appList.add(app);
+ List<CentralV2Role> cenRoles = new ArrayList<CentralV2Role>();
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader("uebkey"))).thenReturn(cenRoles);
+ Mockito.when(externalAccessRolesService.convertV2CentralRoleListToOldVerisonCentralRoleList(cenRoles)).thenReturn(expectedRolesList);
+ List<CentralRole> actualRolesList = externalAccessRolesController.getActiveRoles(mockedRequest, mockedResponse);
+ assertEquals(actualRolesList, expectedRolesList);
+ }
+
+ @Test
public void getActiveRolesExceptionTest() throws Exception {
String reason = getInvalidKeyJson();
StringWriter sw = new StringWriter();
@@ -892,4 +1177,198 @@ public class ExternalAccessRolesControllerTest {
assertNull(externalAccessRolesController.getEcompRolesOfApplication(mockedRequest, mockedResponse));
}
+
+ @Test
+ public void saveRoleTest() throws Exception{
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ PortalRestResponse<String> actualPortalRestResponse = null;
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Successfully Saved");
+ expectedportalRestResponse.setResponse("Success");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ EPUser user = mockUser.mockEPUser();
+ List<EPUser> userList = new ArrayList<>();
+ userList.add(user);
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ Role role = new Role();
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, "Success");
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LoginId"))).thenReturn(userList);
+ Mockito.when(externalAccessRolesService.saveRoleForApplication(role, mockedRequest.getHeader("uebkey"))).thenReturn(externalRequestFieldsValidator);
+ actualPortalRestResponse = externalAccessRolesController.saveRole(mockedRequest, mockedResponse, role);
+ assertEquals(actualPortalRestResponse.getStatus(), expectedportalRestResponse.getStatus());
+ }
+
+ @Test
+ public void saveRoleNegativeTest() throws Exception{
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ PortalRestResponse<String> actualPortalRestResponse = null;
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Successfully Saved");
+ expectedportalRestResponse.setResponse("Success");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ EPUser user = mockUser.mockEPUser();
+ List<EPUser> userList = new ArrayList<>();
+ userList.add(user);
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Role role = new Role();
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, "Failed");
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LoginId"))).thenReturn(userList);
+ Mockito.when(externalAccessRolesService.saveRoleForApplication(role, mockedRequest.getHeader("uebkey"))).thenReturn(externalRequestFieldsValidator);
+ actualPortalRestResponse = externalAccessRolesController.saveRole(mockedRequest, mockedResponse, role);
+ assertEquals(actualPortalRestResponse.getStatus(), expectedportalRestResponse.getStatus());
+ }
+
+ @Test
+ public void saveRole406Test() throws Exception{
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ PortalRestResponse<String> actualPortalRestResponse = null;
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Successfully Saved");
+ expectedportalRestResponse.setResponse("Failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ EPUser user = mockUser.mockEPUser();
+ List<EPUser> userList = new ArrayList<>();
+ userList.add(user);
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Role role = new Role();
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, "406");
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LoginId"))).thenReturn(userList);
+ Mockito.when(externalAccessRolesService.saveRoleForApplication(role, mockedRequest.getHeader("uebkey"))).thenReturn(externalRequestFieldsValidator);
+ actualPortalRestResponse = externalAccessRolesController.saveRole(mockedRequest, mockedResponse, role);
+ assertEquals(actualPortalRestResponse.getStatus(), expectedportalRestResponse.getStatus());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void saveRoleNullExceptionTest() throws Exception
+ {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ applicationList.add(app);
+ Role role = new Role();
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, "failed");
+ Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(Matchers.anyLong(),Matchers.anyString(),Matchers.anyString())).thenReturn(externalRequestFieldsValidator);
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Failed to deleteRole");
+ expectedportalRestResponse.setResponse("Failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ PortalRestResponse<String> actualResponse = externalAccessRolesController.saveRole(mockedRequest, mockedResponse, role);
+ assertEquals(actualResponse, null);
+ }
+
+ @Test
+ public void deleteRoleTest() throws Exception{
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ PortalRestResponse<String> actualPortalRestResponse = null;
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Successfully Deleted");
+ expectedportalRestResponse.setResponse("Success");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ EPUser user = mockUser.mockEPUser();
+ List<EPUser> userList = new ArrayList<>();
+ userList.add(user);
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ String code ="test";
+ boolean deleteResponse = true;
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LoginId"))).thenReturn(userList);
+ Mockito.when(externalAccessRolesService.deleteRoleForApplication(code, mockedRequest.getHeader("uebkey"))).thenReturn(deleteResponse);
+ actualPortalRestResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse, code);
+ assertEquals(actualPortalRestResponse.getStatus(), expectedportalRestResponse.getStatus());
+ }
+
+ @Test
+ public void deleteRoleNegativeTest() throws Exception{
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ PortalRestResponse<String> actualPortalRestResponse = null;
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Failed to delete Role for 'test");
+ expectedportalRestResponse.setResponse("Failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ EPUser user = mockUser.mockEPUser();
+ List<EPUser> userList = new ArrayList<>();
+ userList.add(user);
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(app);
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ String code ="test";
+ boolean deleteResponse = false;
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(appList.get(0))).thenReturn(response);
+ Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LoginId"))).thenReturn(userList);
+ Mockito.when(externalAccessRolesService.deleteRoleForApplication(code, mockedRequest.getHeader("uebkey"))).thenReturn(deleteResponse);
+ actualPortalRestResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse, code);
+ assertEquals(actualPortalRestResponse.getStatus(), expectedportalRestResponse.getStatus());
+ }
+
+ @Test
+ public void deleteDependcyRoleRecordTest() throws Exception {
+ ExternalRequestFieldsValidator removeResult = new ExternalRequestFieldsValidator(true, "success");
+ PortalRestResponse<String> portalRestResponse = null;
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Invalid uebkey!");
+ expectedportalRestResponse.setResponse("Failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ long roleId = 123;
+ String LoginId = "loginId";
+ List<EPApp> appList = new ArrayList<EPApp>();
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
+ Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn(LoginId);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("uebkey"))).thenReturn(appList);
+ Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(roleId, mockedRequest.getHeader("uebkey"), mockedRequest.getHeader("LoginId"))).thenReturn(removeResult);
+ portalRestResponse = externalAccessRolesController.deleteDependencyRoleRecord(mockedRequest, mockedResponse, roleId);
+ assertEquals(expectedportalRestResponse, portalRestResponse);
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java
index 7f3170b7..73978a33 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java
@@ -39,9 +39,14 @@ package org.onap.portalapp.portal.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -50,12 +55,17 @@ 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.onap.portalapp.portal.controller.ExternalAppsRestfulController;
import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPApp;
import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.UserRole;
+import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalapp.portal.service.AdminRolesService;
import org.onap.portalapp.portal.service.AdminRolesServiceImpl;
@@ -67,10 +77,13 @@ import org.onap.portalapp.portal.service.FunctionalMenuService;
import org.onap.portalapp.portal.service.FunctionalMenuServiceImpl;
import org.onap.portalapp.portal.service.UserNotificationService;
import org.onap.portalapp.portal.service.UserNotificationServiceImpl;
+import org.onap.portalapp.portal.transport.EpNotificationItem;
import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
import org.onap.portalapp.portal.transport.FunctionalMenuItem;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalsdk.core.menu.MenuBuilder;
+import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.service.DataAccessServiceImpl;
import org.powermock.api.mockito.PowerMockito;
@@ -79,7 +92,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.MDC;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ MDC.class, EPCommonSystemProperties.class })
+@PrepareForTest({ MDC.class, EPCommonSystemProperties.class ,EPApp.class})
public class ExternalAppsRestfulControllerTest {
@InjectMocks
@@ -117,6 +130,32 @@ public class ExternalAppsRestfulControllerTest {
NullPointerException nullPointerException = new NullPointerException();
MockEPUser mockUser = new MockEPUser();
+
+ public EPApp mockApp() {
+ EPApp app = new EPApp();
+ app.setName("Test");
+ app.setImageUrl("test");
+ app.setNameSpace("com.test.app");
+ app.setCentralAuth(true);
+ 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(true);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.setAppType(1);
+ return app;
+ }
@Test(expected = Exception.class)
public void getFunctionalMenuItemsForUserIfUSerNullTest() throws
@@ -208,4 +247,88 @@ public class ExternalAppsRestfulControllerTest {
.getFavoritesForUser(mockedRequest, mockedResponse);
assertEquals(actaulFavorites.size(), 1);
}
+
+ @Test(expected=NullPointerException.class)
+ public void publishNotificationTest() throws Exception{
+ EPApp appTest=new EPApp();
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn("RxH3983AHiyBOQmj");
+ appTest.setUebKey("123456");
+ String appKey="123456";
+ EpNotificationItem notificationItem=new EpNotificationItem();
+ List<Long> roleList = new ArrayList<Long>();
+ Long role1 = (long) 1;
+ roleList.add(role1);
+ notificationItem.setRoleIds(roleList);
+ notificationItem.setIsForAllRoles("N");
+ notificationItem.setIsForOnlineUsers("N");
+ notificationItem.setActiveYn("Y");
+ notificationItem.setPriority(1L);
+ notificationItem.setMsgHeader("testHeader");
+ notificationItem.setMsgDescription("Test Description");
+ Date currentDate = new Date();
+ Calendar c = Calendar.getInstance();
+ c.setTime(currentDate);
+ c.add(Calendar.DATE, 1);
+ Date currentDatePlusOne = c.getTime();
+ notificationItem.setStartTime(currentDate);
+ notificationItem.setEndTime(currentDatePlusOne);
+ notificationItem.setCreatedDate(c.getTime());
+
+ PortalAPIResponse actualPortalRestResponse = new PortalAPIResponse(true, appKey);
+ PortalAPIResponse expectedPortalRestResponse = new PortalAPIResponse(true, appKey);
+ expectedPortalRestResponse.setMessage("SUCCESS");
+ expectedPortalRestResponse.setStatus("ok");
+ Map<String, String> params = new HashMap<>();
+ params.put("appKey", "1234567");
+
+ Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", params, null)).thenReturn(null);
+
+ Mockito.when(userNotificationService.saveNotification(notificationItem)).thenReturn("Test");
+ actualPortalRestResponse = externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+ assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse));
+
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void publishNotificationTest1() throws Exception{
+ EpNotificationItem notificationItem=new EpNotificationItem();
+ List<Long> roleList = new ArrayList<Long>();
+ Long role1 = (long) 1;
+ roleList.add(role1);
+ notificationItem.setRoleIds(roleList);
+ notificationItem.setIsForAllRoles("N");
+ notificationItem.setIsForOnlineUsers("N");
+ notificationItem.setActiveYn("Y");
+ notificationItem.setPriority(1L);
+ notificationItem.setMsgHeader("testHeader");
+ notificationItem.setMsgDescription("Test Description");
+ Date currentDate = new Date();
+ Calendar c = Calendar.getInstance();
+ c.setTime(currentDate);
+ c.add(Calendar.DATE, 1);
+ Date currentDatePlusOne = c.getTime();
+ notificationItem.setStartTime(currentDate);
+ notificationItem.setEndTime(currentDatePlusOne);
+ notificationItem.setCreatedDate(c.getTime());
+
+ //PowerMockito.mockStatic(EPApp.class);
+
+
+ List<EPApp> appList = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setId((long) 1);
+ appList.add(app);
+
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appUebkeyParams.put("appKey", "test-ueb-key");
+
+ Mockito.when(DataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ //EPApp epApp=new EPApp();
+
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn("RxH3983AHiyBOQmj");
+
+ externalAppsRestfulController.publishNotification(mockedRequest, notificationItem);
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/HealthCheckControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/HealthCheckControllerTest.java
index 0f3bb49c..fb41bc02 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/HealthCheckControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/HealthCheckControllerTest.java
@@ -74,4 +74,23 @@ public class HealthCheckControllerTest {
PowerMockito.mockStatic(EcompPortalUtils.class);
healthCheckController.healthCheck(mockedRequest, mockedResponse);
}
+
+ @Test
+ public void healthCheckFailTest1() {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ healthCheckController.healthCheckSuspend(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void healthCheckResumeTest() {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ healthCheckController.healthCheckResume(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void healthCheckPingTest() {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ healthCheckController.ping(mockedRequest, mockedResponse);
+ }
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java
index bddcde65..98292c66 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java
@@ -143,6 +143,56 @@ public class PolicyControllerTest {
}
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getPolicyInfoTestException() throws Exception {
+
+ JSONObject jsonObject = Mockito.mock(JSONObject.class);
+ PowerMockito.mockStatic(SchedulerAuxRestInterfaceFactory.class);
+ PowerMockito.mockStatic(SchedulerProperties.class);
+ SchedulerAuxRestInterfaceIfc policyRestInterface = Mockito.mock(SchedulerAuxRestInterfaceIfc.class);
+ PowerMockito.mockStatic(SchedulerAuxUtil.class);
+ // RestObject restObj=Mockito.mock(RestObject.class);
+ SchedulerAuxResponseWrapper policyWrapper = Mockito.mock(SchedulerAuxResponseWrapper.class);
+ PowerMockito.when(SchedulerAuxUtil.wrapResponse(Matchers.any(RestObject.class))).thenReturn(policyWrapper);
+ Mockito.when(policyWrapper.getResponse()).thenReturn("Success");
+ Mockito.when(policyWrapper.getStatus()).thenReturn(200);
+
+ PowerMockito.when(SchedulerAuxRestInterfaceFactory.getInstance()).thenReturn(policyRestInterface);
+ /*Mockito.doNothing().when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(),
+ Matchers.anyString(), Matchers.anyString(), Matchers.anyObject());*/
+ Mockito.doThrow(new NullPointerException()).when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(),
+ Matchers.anyString(), Matchers.anyString(), Matchers.anyObject());
+
+
+ ResponseEntity<String> responsePolicy = policyController.getPolicyInfo(mockedRequest);
+ Assert.assertEquals(responsePolicy.getStatusCode(), HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getPolicyInfoTestException1() throws Exception {
+
+ JSONObject jsonObject = Mockito.mock(JSONObject.class);
+ PowerMockito.mockStatic(SchedulerAuxRestInterfaceFactory.class);
+ PowerMockito.mockStatic(SchedulerProperties.class);
+ SchedulerAuxRestInterfaceIfc policyRestInterface = Mockito.mock(SchedulerAuxRestInterfaceIfc.class);
+ PowerMockito.mockStatic(SchedulerAuxUtil.class);
+ // RestObject restObj=Mockito.mock(RestObject.class);
+ SchedulerAuxResponseWrapper policyWrapper = Mockito.mock(SchedulerAuxResponseWrapper.class);
+ PowerMockito.when(SchedulerAuxUtil.wrapResponse(Matchers.any(RestObject.class))).thenReturn(policyWrapper);
+ Mockito.when(policyWrapper.getResponse()).thenReturn("Bad Request");
+ Mockito.when(policyWrapper.getStatus()).thenReturn(400);
+
+ PowerMockito.when(SchedulerAuxRestInterfaceFactory.getInstance()).thenReturn(policyRestInterface);
+ Mockito.doNothing().when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(),
+ Matchers.anyString(), Matchers.anyString(), Matchers.anyObject());
+ /*Mockito.doThrow(new NullPointerException()).when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(),
+ Matchers.anyString(), Matchers.anyString(), Matchers.anyObject());*/
+
+ ResponseEntity<String> responsePolicy = policyController.getPolicyInfo(mockedRequest);
+ Assert.assertEquals(responsePolicy.getStatusCode(), HttpStatus.BAD_REQUEST);
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java
index 94e55af9..20bb3e8b 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java
@@ -49,6 +49,7 @@ import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
+import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -167,16 +168,18 @@ public class PortalAdminControllerTest extends MockitoTestSuite{
assertEquals(actualFieldValidator,expectedFieldValidator);
}
+
+
-// @Test
-// public void createPortalAdminIfUserIsNullTest()
-// {
-// //EPUser user = null;
-// Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
-// String sbcid = "null";
-// assertNull(portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse));
-//
-// }
+ @Test
+ public void createPortalAdminIfUserIsNullTest()
+ {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
+ String sbcid = "null";
+ assertNull(portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse));
+
+ }
@Test
public void createPortalAdminIfUserIsSuperAdminTest()
@@ -188,5 +191,86 @@ public class PortalAdminControllerTest extends MockitoTestSuite{
assertNull(portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse));
}
+
+ @Test
+ public void deletePortalAdminTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<PortalAdmin> expectedPortalAdminsList = new ArrayList<PortalAdmin>();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(portalAdminService.deletePortalAdmin(12L)).thenReturn(null);
+ FieldsValidator actualPortalAdminsList = portalAdminController.deletePortalAdmin(mockedRequest, "test", mockedResponse);
+ assertNull(actualPortalAdminsList);
+
+ }
+
+ @Test
+ public void deletePortalAdminTest1()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String sbcid = "Test";
+ List<PortalAdmin> expectedPortalAdminsList = new ArrayList<PortalAdmin>();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(portalAdminService.deletePortalAdmin(112L)).thenReturn(null);
+ FieldsValidator actualPortalAdminsList = portalAdminController.deletePortalAdmin(mockedRequest, "112-1", mockedResponse);
+ assertNull(actualPortalAdminsList);
+
+ }
+
+ @Test
+ public void deletePortalAdminTest2()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ //String sbcid = "Test";
+ Long userId=123L;
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(portalAdminService.deletePortalAdmin(userId)).thenReturn(expectedFieldValidator);
+ actualFieldValidator = portalAdminController.deletePortalAdmin(mockedRequest,"123-Test" , mockedResponse);
+ assertEquals(actualFieldValidator,expectedFieldValidator);
+
+ }
+
+ @Test
+ public void getRolesByAppsTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPRole> expectedgetAppsList = new ArrayList<EPRole>();
+ EPRole epRole= new EPRole();
+ epRole.setName("Test");
+ epRole.setActive(true);
+ epRole.setPriority(1);
+ epRole.setAppId(12L);
+ epRole.setId(1111L);
+ expectedgetAppsList.add(epRole);
+ Mockito.when(adminRolesService.getRolesByApp(user,12L)).thenReturn(expectedgetAppsList);
+ //Mockito.when(portalAdminService.deletePortalAdmin(userId)).thenReturn(expectedFieldValidator);
+ List<EPRole> actualgetAppsList = portalAdminController.getRolesByApp(mockedRequest,12L , mockedResponse);
+ assertEquals(actualgetAppsList,expectedgetAppsList);
+
+ }
+
+ @Test
+ public void getRolesByAppsWhenUserIsNullTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
+ List<EPRole> expectedgetAppsList = new ArrayList<EPRole>();
+ EPRole epRole= new EPRole();
+ expectedgetAppsList.add(epRole);
+ Mockito.when(adminRolesService.getRolesByApp(user,12L)).thenReturn(expectedgetAppsList);
+ List<EPRole> actualgetAppsList = portalAdminController.getRolesByApp(mockedRequest,12L , mockedResponse);
+ assertNull(actualgetAppsList);
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java
index dffd561e..8216510b 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java
@@ -40,11 +40,13 @@ package org.onap.portalapp.portal.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.poi.ss.formula.functions.T;
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.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -53,6 +55,7 @@ import org.onap.portalapp.portal.core.MockEPUser;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalapp.portal.scheduler.SchedulerProperties;
import org.onap.portalapp.portal.scheduler.SchedulerRestInterface;
+import org.onap.portalapp.portal.scheduler.restobjects.RestObject;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.portalsdk.core.web.support.UserUtils;
import org.powermock.api.mockito.PowerMockito;
@@ -60,7 +63,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UserUtils.class,SystemProperties.class})
+@PrepareForTest({UserUtils.class,SystemProperties.class,SchedulerProperties.class})
public class SchedulerControllerTest {
@@ -91,6 +94,22 @@ public class SchedulerControllerTest {
}
@Test
+ public void getTimeSlotsTestWithException1() throws Exception{
+ JSONObject jsonObject =Mockito.mock(JSONObject.class);
+ RestObject<T> restObject=new RestObject<>();
+ Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Get(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
+ schedulerController.getTimeSlots(mockedRequest, "12");
+
+ }
+
+
+ @Test
+ public void getTimeSlotsTestWithexception() throws Exception{
+ schedulerController.getTimeSlots(mockedRequest, null);
+
+ }
+
+ @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);
@@ -99,6 +118,24 @@ public class SchedulerControllerTest {
}
@Test
+ public void postCreateNewVNFChangeTestWithException1() throws Exception{
+ JSONObject jsonObject =Mockito.mock(JSONObject.class);
+ RestObject<T> restObject=new RestObject<>();
+ Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Post(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
+ schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject);
+
+ }
+
+
+ @Test
+ public void postCreateNewVNFChangeTestWithException() 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, null);
+ }
+
+ @Test
public void postSubmitVnfChangeTimeslotsTest() throws Exception{
JSONObject jsonObject =Mockito.mock(JSONObject.class);
Mockito.when(jsonObject.get("scheduleId")).thenReturn("12");
@@ -107,4 +144,40 @@ public class SchedulerControllerTest {
schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject);
}
+ @Test
+ public void postSubmitVnfChangeTimeslotsTestWithException1() throws Exception{
+ JSONObject jsonObject =Mockito.mock(JSONObject.class);
+ RestObject<T> restObject=new RestObject<>();
+ Mockito.doThrow(new NullPointerException()).when(schedulerRestInterface).Post(Matchers.any(),Matchers.any(),Matchers.any(),Matchers.any());
+ schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject);
+
+ }
+
+ @Test
+ public void postSubmitVnfChangeTimeslotsTestWithException() 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, null);
+ }
+
+ @Test
+ public void getSchedulerConstantTestWithException() 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_CALLBACK_URL)).thenReturn("mockedRequest");
+ schedulerController.getSchedulerConstant(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void getSchedulerConstantTest() 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_CALLBACK_URL)).thenReturn("callbackUrl");
+ schedulerController.getSchedulerConstant(mockedRequest, mockedResponse);
+ }
+
} \ No newline at end of file
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java
index 3bede966..1607f423 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java
@@ -38,27 +38,81 @@ package org.onap.portalapp.portal.controller;
*/
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.drools.core.command.assertion.AssertEquals;
+import org.json.JSONObject;
import org.junit.Assert;
+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.onap.portalapp.portal.controller.SharedContextRestClient;
import org.onap.portalapp.portal.controller.SharedContextTestProperties;
+import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
+import org.onap.portalapp.portal.domain.SharedContext;
+import org.onap.portalapp.portal.framework.MockitoTestSuite;
+import org.onap.portalapp.portal.scheduler.SchedulerProperties;
+import org.onap.portalapp.portal.service.SharedContextService;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.beans.factory.annotation.Autowired;
+import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Tests the endpoints exposed by the Shared Context controller in Portal.
*/
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({SharedContext.class,EPCommonSystemProperties.class})
+
public class SharedContextRestControllerTest {
+
+ @Mock
+ SharedContextService contextService;
+
+ @InjectMocks
+ SharedContextRestController sharedContextRestController=new SharedContextRestController();
+
+ @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();
+
private final Log logger = LogFactory.getLog(getClass());
- private final SharedContextTestProperties properties;
+ //private final SharedContextTestProperties properties;
private final String ckey = "ckey";
private final String cvalue = "cvalue";
@@ -70,13 +124,13 @@ public class SharedContextRestControllerTest {
private final String value1 = "first value";
private final String value2 = "second value";
- public SharedContextRestControllerTest() throws IOException {
+ /*public SharedContextRestControllerTest() throws IOException {
properties = new SharedContextTestProperties();
- }
+ }*/
@SuppressWarnings("unchecked")
//@Test
- public void test() throws Exception {
+ /*public void test() throws Exception {
String response = null, val = null;
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> responseMap, jsonMap;
@@ -140,5 +194,160 @@ public class SharedContextRestControllerTest {
String json = mapper.writeValueAsString(stringMap);
String response = SharedContextRestClient.postJson(properties, "set", json);
return response;
+ }*/
+
+ @Test
+ public void getContextTest() throws Exception{
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(), Matchers.any())).thenReturn(sharedContext);
+ String result = sharedContextRestController.getContext(mockedRequest, "12","test");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void getContextTestWithContextNull() throws Exception{
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(), Matchers.any())).thenReturn(null);
+ String result = sharedContextRestController.getContext(mockedRequest, "12","test");
+ assertNotNull(result);
+ }
+
+ @Test(expected=Exception.class)
+ public void getContextTestWithException() throws Exception{
+ sharedContextRestController.getContext(mockedRequest, null,null);
+ }
+
+ @Test(expected=Exception.class)
+ public void getUserContextTest() throws Exception{
+ sharedContextRestController.getUserContext(mockedRequest, null);
+ }
+
+ @Test
+ public void getUserContextTestWithContext() throws Exception{
+ PowerMockito.mock(SharedContext.class);
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ List<SharedContext> listSharedContext = new ArrayList<SharedContext>();
+ listSharedContext.add(sharedContext);
+ Mockito.when(contextService.getSharedContext(Matchers.any(),Matchers.any())).thenReturn(sharedContext);
+ String response=sharedContextRestController.getUserContext(mockedRequest, "12");
+ assertNotNull(response);
+ }
+
+ @Test
+ public void checkContextTest() throws Exception{
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(),Matchers.any())).thenReturn(sharedContext);
+ String response=sharedContextRestController.checkContext(mockedRequest, "12","test");
+ assertNotNull(response);
+ }
+
+ @Test(expected=Exception.class)
+ public void checkContextTestWithContextIdNull() throws Exception{
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(),Matchers.any())).thenReturn(sharedContext);
+ sharedContextRestController.checkContext(mockedRequest, null,null);
+ }
+
+ @Test
+ public void removeContextTest() throws Exception{
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(),Matchers.any())).thenReturn(sharedContext);
+
+ //Mockito.when(contextService.deleteSharedContext(sharedContext));
+ String actual=sharedContextRestController.removeContext(mockedRequest, "12","test");
+ assertNotNull(actual);
+
+ }
+
+ @Test(expected=Exception.class)
+ public void removeContextTestWithContextNull() throws Exception{
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(),Matchers.any())).thenReturn(sharedContext);
+
+ //Mockito.when(contextService.deleteSharedContext(sharedContext));
+ String actual=sharedContextRestController.removeContext(mockedRequest, null,null);
+ assertNotNull(actual);
+
+ }
+
+ @Test(expected=Exception.class)
+ public void clearContextTestwithContextIdNull() throws Exception{
+
+ Mockito.when(contextService.deleteSharedContexts(Matchers.any())).thenReturn(12);
+
+ String actual=sharedContextRestController.clearContext(mockedRequest,null);
+ assertNotNull(actual);
+
+ }
+
+ @Test
+ public void clearContextTest() throws Exception{
+
+ Mockito.when(contextService.deleteSharedContexts(Matchers.any())).thenReturn(12);
+
+ String actual=sharedContextRestController.clearContext(mockedRequest,"12");
+ assertNotNull(actual);
+
+ }
+
+ @Test
+ public void setContextTest() throws Exception{
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, Object> userData = new HashMap<String, Object>();
+ userData.put("context_id", "test_contextId");
+ userData.put("ckey", "test_ckey");
+ userData.put("cvalue", "test_cvalue");
+ //String testUserJson=Matchers.anyString();
+ JSONObject testUserJson = new JSONObject();
+ testUserJson.put("context_id", "test1ContextId");
+ testUserJson.put("ckey", "testCkey");
+ testUserJson.put("cvalue", "testCValue");
+ Map<String, Object> userData1 = mapper.readValue(testUserJson.toString(), Map.class);
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(),Matchers.any())).thenReturn(sharedContext);
+ // Mockito.when(mapper.readValue("true", Map.class)).thenReturn(userData);
+ String actual=sharedContextRestController.setContext(mockedRequest,testUserJson.toString());
+
+ }
+
+ @Test(expected=Exception.class)
+ public void setContextTestWithContextNull() throws Exception{
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, Object> userData = new HashMap<String, Object>();
+ userData.put("context_id", "test_contextId");
+ userData.put("ckey", "test_ckey");
+ userData.put("cvalue", "test_cvalue");
+ //String testUserJson=Matchers.anyString();
+ JSONObject testUserJson = new JSONObject();
+ testUserJson.put("context_id", "test1ContextId");
+ testUserJson.put("ckey", "testCkey");
+ testUserJson.put("cvalue", "testCValue");
+ Map<String, Object> userData1 = mapper.readValue(testUserJson.toString(), Map.class);
+ SharedContext sharedContext=new SharedContext();
+ sharedContext.setContext_id("test_contextid");
+ sharedContext.setCkey("test_ckey");
+ Mockito.when(contextService.getSharedContext(Matchers.any(),Matchers.any())).thenReturn(null);
+ Mockito.when(userData1.get(ckey)).thenReturn(null);
+ Mockito.when(userData1.get(cxid)).thenReturn(null);
+
+ // Mockito.when(mapper.readValue("true", Map.class)).thenReturn(userData);
+ String actual=sharedContextRestController.setContext(mockedRequest,testUserJson.toString());
+
}
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsControllerTest.java
new file mode 100644
index 00000000..c6bd8001
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsControllerTest.java
@@ -0,0 +1,317 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.controller;
+
+import static org.junit.Assert.assertEquals;
+
+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.mockito.stubbing.Answer;
+import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.framework.MockitoTestSuite;
+import org.onap.portalapp.portal.service.AdminRolesService;
+import org.onap.portalapp.portal.service.PersUserWidgetService;
+import org.onap.portalapp.portal.service.WidgetService;
+import org.onap.portalapp.portal.transport.FieldsValidator;
+import org.onap.portalapp.portal.transport.FieldsValidator.FieldName;
+import org.onap.portalapp.portal.transport.OnboardingWidget;
+import org.onap.portalapp.portal.transport.WidgetCatalogPersonalization;
+import org.onap.portalapp.util.EPUserUtils;
+import org.springframework.web.client.RestClientException;
+
+public class WidgetsControllerTest extends MockitoTestSuite{
+
+ @InjectMocks
+ WidgetsController widgetsController = new WidgetsController();
+
+ @Mock
+ private AdminRolesService rolesService;
+
+ @Mock
+ private WidgetService widgetService ;
+
+ @Mock
+ private PersUserWidgetService persUserWidgetService;
+
+ @Mock
+ EPUser epuser;
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ @Test
+ public void getOnboardingWidgetsTest() throws RestClientException, Exception{
+ EPUser user = mockUser.mockEPUser();
+ String getType="test";
+ List<OnboardingWidget> actualResult = null;
+ String expectedResult = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<OnboardingWidget> onboardingWidgets = null;
+ //Mockito.when(StringUtils.isEmpty("")).thenReturn(true);
+ Mockito.when(widgetService.getOnboardingWidgets(user, getType.equals("managed"))).thenReturn(onboardingWidgets);
+ actualResult = widgetsController.getOnboardingWidgets(mockedRequest, mockedResponse);
+ assertEquals(expectedResult, actualResult);
+
+ }
+
+ @Test
+ public void getOnboardingWidgetsTest1(){
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(mockedRequest.getHeader("X-Widgets-Type")).thenReturn("managed");
+ //String getType=Matchers.any(String.class);
+ List<OnboardingWidget> actualResult = null;
+ String expectedResult = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<OnboardingWidget> onboardingWidgets = new ArrayList<>();
+ OnboardingWidget widget = new OnboardingWidget();
+ onboardingWidgets.add(widget); //Mockito.when(StringUtils.isEmpty("")).thenReturn(true);
+ Mockito.when(widgetService.getOnboardingWidgets(user, true)).thenReturn(onboardingWidgets);
+ actualResult = widgetsController.getOnboardingWidgets(mockedRequest, mockedResponse);
+ // assertEquals(expectedResult, actualResult);
+
+ }
+
+ @Test
+ public void getOnboardingWidgetswithUserNullTest(){
+ EPUser user = null;
+ Mockito.when(mockedRequest.getHeader("X-Widgets-Type")).thenReturn("managed");
+ //String getType=Matchers.any(String.class);
+ List<OnboardingWidget> actualResult = null;
+ String expectedResult = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<OnboardingWidget> onboardingWidgets = new ArrayList<>();
+ OnboardingWidget widget = new OnboardingWidget();
+ onboardingWidgets.add(widget); //Mockito.when(StringUtils.isEmpty("")).thenReturn(true);
+ Mockito.when(widgetService.getOnboardingWidgets(user, true)).thenReturn(onboardingWidgets);
+ actualResult = widgetsController.getOnboardingWidgets(mockedRequest, mockedResponse);
+
+ }
+
+ @Test
+ public void putOnboardingWidgetTest() {
+ FieldsValidator actualFieldsValidator = null;
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingWidget onboardingWidget=new OnboardingWidget();
+ onboardingWidget.id=12L;
+ onboardingWidget.normalize();
+ //Mockito.doNothing().when(onboardingWidget).normalize();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(widgetService.setOnboardingWidget(user, onboardingWidget)).thenReturn(expectedFieldValidator);
+ actualFieldsValidator = widgetsController.putOnboardingWidget(mockedRequest, 12L, onboardingWidget, mockedResponse);
+
+ }
+
+ @Test
+ public void putOnboardingWidgetWithUserPermissionTest() {
+ FieldsValidator actualFieldsValidator = null;
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(rolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(rolesService.isAccountAdmin(user)).thenReturn(true);
+ OnboardingWidget onboardingWidget=new OnboardingWidget();
+ onboardingWidget.id=12L;
+ onboardingWidget.normalize();
+ //Mockito.doNothing().when(onboardingWidget).normalize();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(widgetService.setOnboardingWidget(user, onboardingWidget)).thenReturn(expectedFieldValidator);
+ actualFieldsValidator = widgetsController.putOnboardingWidget(mockedRequest, 12L, onboardingWidget, mockedResponse);
+ assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldsValidator.getHttpStatusCode());
+ assertEquals(expectedFieldValidator.getErrorCode(), actualFieldsValidator.getErrorCode());
+ assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields());
+ }
+
+ @Test
+ public void postOnboardingWidgetTest(){
+ EPUser user=mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator actualFieldsValidator = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(rolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(rolesService.isAccountAdmin(user)).thenReturn(true);
+ OnboardingWidget onboardingWidget=new OnboardingWidget();
+ onboardingWidget.id=12L;
+ onboardingWidget.normalize();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(widgetService.setOnboardingWidget(user, onboardingWidget)).thenReturn(expectedFieldValidator);
+ actualFieldsValidator = widgetsController.postOnboardingWidget(mockedRequest, onboardingWidget, mockedResponse);
+ assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldsValidator.getHttpStatusCode());
+ assertEquals(expectedFieldValidator.getErrorCode(), actualFieldsValidator.getErrorCode());
+ assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields());
+ }
+
+ @Test
+ public void postOnboardingWidgetTestwiThoutUserPermission() {
+ FieldsValidator actualFieldsValidator = null;
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingWidget onboardingWidget=new OnboardingWidget();
+ onboardingWidget.id=12L;
+ onboardingWidget.normalize();
+ //Mockito.doNothing().when(onboardingWidget).normalize();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(widgetService.setOnboardingWidget(user, onboardingWidget)).thenReturn(expectedFieldValidator);
+ actualFieldsValidator = widgetsController.postOnboardingWidget(mockedRequest, onboardingWidget, mockedResponse);
+
+ }
+
+ @Test
+ public void deleteOnboardingWidgetTest(){
+ FieldsValidator actualFieldsValidator = null;
+ EPUser user=mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ Mockito.when(rolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(rolesService.isAccountAdmin(user)).thenReturn(true);
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(widgetService.deleteOnboardingWidget(user, 12L)).thenReturn(expectedFieldValidator);
+ actualFieldsValidator = widgetsController.deleteOnboardingWidget(mockedRequest, 12L, mockedResponse);
+ assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldsValidator.getHttpStatusCode());
+ assertEquals(expectedFieldValidator.getErrorCode(), actualFieldsValidator.getErrorCode());
+ assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields());
+ }
+ @Test
+ public void deleteOnboardingWidgetWithOutUserPermissionsTest(){
+ FieldsValidator actualFieldsValidator = null;
+ EPUser user=mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ Mockito.when(rolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(rolesService.isAccountAdmin(user)).thenReturn(false);
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(widgetService.deleteOnboardingWidget(user, 12L)).thenReturn(expectedFieldValidator);
+ actualFieldsValidator = widgetsController.deleteOnboardingWidget(mockedRequest, 12L, mockedResponse);
+
+ }
+
+ @Test
+ public void putWidgetCatalogSelectionTest1() throws Exception {
+
+ FieldsValidator actualFieldsValidator = new FieldsValidator();
+ EPUser user=mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ Mockito.when(rolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(rolesService.isAccountAdmin(user)).thenReturn(true);
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ WidgetCatalogPersonalization widgetCatalogPersonalization=new WidgetCatalogPersonalization();
+ widgetCatalogPersonalization.widgetId=12L;
+ //Mockito.doThrow(new Exception()).doNothing().when(persUserWidgetService).setPersUserAppValue(user, 12L, true);
+ //Mockito.doNothing().thenReturn();
+ actualFieldsValidator = widgetsController.putWidgetCatalogSelection(mockedRequest, widgetCatalogPersonalization, mockedResponse);
+ assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldsValidator.getHttpStatusCode());
+ assertEquals(expectedFieldValidator.getErrorCode(), actualFieldsValidator.getErrorCode());
+ assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields());
+
+
+ }
+
+ @Test(expected=ClassCastException.class)
+ public void putWidgetCatalogSelectionTest() throws Exception {
+
+ FieldsValidator actualFieldsValidator = new FieldsValidator();
+ EPUser user=null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ Mockito.when(rolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(rolesService.isAccountAdmin(user)).thenReturn(true);
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ WidgetCatalogPersonalization widgetCatalogPersonalization=new WidgetCatalogPersonalization();
+ Mockito.doAnswer((Answer) new Exception()).doNothing().when(persUserWidgetService).setPersUserAppValue(user, 12L, true);
+ //Mockito.doNothing().thenReturn();
+ actualFieldsValidator = widgetsController.putWidgetCatalogSelection(mockedRequest, widgetCatalogPersonalization, mockedResponse);
+ assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldsValidator.getHttpStatusCode());
+ assertEquals(expectedFieldValidator.getErrorCode(), actualFieldsValidator.getErrorCode());
+ assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields());
+
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java
index 37625895..d081b801 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java
@@ -35,39 +35,74 @@
*
*
*/
+
package org.onap.portalapp.portal.domain;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.junit.Test;
import org.onap.portalapp.portal.domain.EPRole;
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.restful.domain.EcompRoleFunction;
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();
+ public void testEpRole() {
+ EPRole role=new EPRole();
+ role.setActive(true);
+ role.setAppId(1l);
+ role.setAppRoleId(2l);
+ role.setId(3l);
+ role.setName("TEST_ADMIN");
+ SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
+ EPRole child=new EPRole();
+ child.setActive(true);
+ child.setAppId(1l);
+ child.setAppRoleId(3l);
+ child.setId(6l);
+ child.setName("TEST_USER");
+ childRoles.add(child);
+ role.setChildRoles(childRoles);
+ SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
+ EPRole parent=new EPRole();
+ parent.setActive(true);
+ parent.setAppId(1l);
+ parent.setAppRoleId(3l);
+ parent.setId(6l);
+ parent.setName("TEST_USER");
+ parentRoles.add(parent);
+ role.setParentRoles(parentRoles);
- 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]");
-
+ SortedSet<RoleFunction> rolefunction = new TreeSet<RoleFunction>();
+ RoleFunction function=new RoleFunction();
+ function.setAction("Test");;
+ function.setCode("code");
+ rolefunction.add(function);
+ role.setRoleFunctions(rolefunction);
+ role.setPriority(5);
+ role.setAppRoleId(3l);
+ assertEquals(3l, role.getAppRoleId().longValue());
+ assertNotNull(role.getChildRoles());
+ assertNotNull(role.getParentRoles());
+ assertNotNull(role.getRoleFunctions());
+ role.compareTo(role);
+ assertEquals(1l, role.getAppId().longValue());
+ assertEquals("TEST_ADMIN",role.getName());
+ role.removeChildRole(6l);
+ role.removeParentRole(6l);
+ assertEquals(role.toString(), "[Id = 3, name = TEST_ADMIN]");
+ role.removeRoleFunction("code");
+ role.addChildRole(child);
+ role.addParentRole(parent);
+ role.addRoleFunction(function);
}
+
}
+
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptorTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptorTest.java
new file mode 100644
index 00000000..93a08619
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptorTest.java
@@ -0,0 +1,155 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.interceptor;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.controller.BasicAuthenticationController;
+import org.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.service.ExternalAccessRolesService;
+import org.onap.portalsdk.core.controller.FusionBaseController;
+import org.springframework.web.method.HandlerMethod;
+
+public class PortalResourceInterceptorTest {
+
+ @InjectMocks
+ PortalResourceInterceptor portalResourceInterceptor;
+ @Mock
+ HttpServletRequest request;
+ @Mock
+ HttpServletResponse response;
+ @Mock
+ HandlerMethod handler;
+ @Mock
+ HttpSession session;
+ @Mock
+ FusionBaseController fusionBaseController;
+ @Mock
+ BasicAuthenticationController basicAuthenticationController;
+ @Mock
+ private ExternalAccessRolesService externalAccessRolesService;
+ @Mock
+ PrintWriter printWriter;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+
+ }
+
+ @Test
+ public void testPreHandle()throws Exception {
+ Set<String> data=new HashSet<>();
+ data.add("test");
+ when(request.getRequestURI()).thenReturn("test/portalApi/test");
+
+ when(session.getAttribute(anyString())).thenReturn(data);
+ when(request.getSession()).thenReturn(session);
+ when(fusionBaseController.isAccessible()).thenReturn(true);
+ when(handler.getBean()).thenReturn(fusionBaseController);
+
+
+ boolean result= portalResourceInterceptor.preHandle(request, response, handler);
+ assertEquals(true, result);
+
+
+ }
+
+ @Test
+ public void testPreHandlePass()throws Exception {
+ Set<String> data=new HashSet<>();
+ data.add("test/test");
+ when(request.getRequestURI()).thenReturn("test/portalApi/test/test");
+
+ when(session.getAttribute(anyString())).thenReturn(data);
+ when(request.getSession()).thenReturn(session);
+ when(fusionBaseController.isAccessible()).thenReturn(false);
+ when(handler.getBean()).thenReturn(fusionBaseController);
+
+
+ boolean result= portalResourceInterceptor.preHandle(request, response, handler);
+
+ assertEquals(true, result);
+
+ }
+
+
+
+ @Test
+ public void testPreHandleAuth()throws Exception {
+ Set<String> data=new HashSet<>();
+ data.add("test/test");
+ List<EPApp> apps=new ArrayList<>();
+ EPApp app=new EPApp();
+ app.setUsername("test");
+ apps.add(app);
+ when(request.getRequestURI()).thenReturn("test/portalApi/test/test");
+
+ when(request.getHeader("Authorization")).thenReturn("Basictest");
+ when(request.getHeader("uebkey")).thenReturn("test");
+ when(request.getSession()).thenReturn(session);
+ when(fusionBaseController.isAccessible()).thenReturn(false);
+ when(handler.getBean()).thenReturn(basicAuthenticationController);
+ when( externalAccessRolesService.getApp("test")).thenReturn(apps);
+ when(response.getWriter()).thenReturn(printWriter);
+
+ boolean result= portalResourceInterceptor.preHandle(request, response, handler);
+
+ assertEquals(false, result);
+
+ }
+
+
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/logging/logic/EPLogUtilTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/logging/logic/EPLogUtilTest.java
new file mode 100644
index 00000000..e4ec5e0f
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/logging/logic/EPLogUtilTest.java
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portalapp.portal.logging.logic;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.portalapp.portal.interceptor.PortalResourceInterceptor;
+import org.onap.portalapp.portal.logging.format.EPAppMessagesEnum;
+import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
+import org.onap.portalsdk.core.logging.format.ErrorSeverityEnum;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.http.HttpStatus;
+
+public class EPLogUtilTest {
+
+ @Mock
+ private EELFLoggerDelegate eelfLoggerDelegate;
+
+ EPAppMessagesEnum epAppMessagesEnum;
+
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPLogUtilTest.class);
+
+ @Test
+ public void testLogEcompError() {
+
+
+ EPAppMessagesEnum epAppMessagesEnum= EPAppMessagesEnum.BeHealthCheckRecovery;
+ AlarmSeverityEnum alarmSeverityEnum=AlarmSeverityEnum.INFORMATIONAL;
+ epAppMessagesEnum.setAlarmSeverity(alarmSeverityEnum);
+ epAppMessagesEnum.setErrorSeverity(ErrorSeverityEnum.INFO);
+
+ EPLogUtil.logEcompError( epAppMessagesEnum,"testError");
+
+
+ }
+
+ @Test
+ public void testLogEcompErrorWithDelegate() {
+
+ EPAppMessagesEnum epAppMessagesEnum= EPAppMessagesEnum.BeHttpConnectionError;
+ AlarmSeverityEnum alarmSeverityEnum=AlarmSeverityEnum.INFORMATIONAL;
+ epAppMessagesEnum.setAlarmSeverity(alarmSeverityEnum);
+ epAppMessagesEnum.setErrorSeverity(ErrorSeverityEnum.WARN);
+
+ EPLogUtil.logEcompError(logger, epAppMessagesEnum,"testError");
+
+
+ }
+ @Test
+ public void testFormatAuditLogMessage() {
+
+ EPLogUtil.formatAuditLogMessage("test", "operation", "test", "test", "testinfo");
+
+ }
+
+ @Test
+ public void formatStoreAnalyticsAuditLogMessage() {
+ EPLogUtil.formatStoreAnalyticsAuditLogMessage("test", "operation", "test", "test", "testinfo", "testPage", "testFunction", "testType");
+ }
+
+ @Test
+ public void logExternalAuthAccessAlarm() {
+ EPLogUtil.logExternalAuthAccessAlarm(logger, HttpStatus.BAD_REQUEST);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, HttpStatus.BANDWIDTH_LIMIT_EXCEEDED);
+ EPLogUtil.schedulerAccessAlarm(logger, 404);
+ EPLogUtil.schedulerAccessAlarm(logger, 403);
+ EPLogUtil.schedulerAccessAlarm(logger, 200);
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java
index c65671a0..605464cf 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -66,7 +66,208 @@ public class AppCatalogItemTest {
assertEquals(appCatalogItem.toString(), "AppCatalogItem [id=null, name=null, access=null, select=null, pending=null]");
assertEquals(appCatalogItem.hashCode(), appCatalogItem1.hashCode());
- assertTrue(appCatalogItem.equals(appCatalogItem1));
-
+ assertTrue(appCatalogItem.equals(appCatalogItem1));
+ }
+
+ @Test
+ public void hashCodeTest(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ appCatalogItem.setAccess(true);
+ appCatalogItem.setAlternateUrl("test");
+ appCatalogItem.setDescription("test");
+ appCatalogItem.setId(123L);
+ appCatalogItem.setImageUrl("test");
+ appCatalogItem.setName("test");
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.hashCode();
+ }
+
+ @Test
+ public void equalsTest(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest1(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setAccess(true);
+ appCatalogItem.setAlternateUrl("test");
+ appCatalogItem.setDescription("test");
+ appCatalogItem.setId(123L);
+ appCatalogItem.setImageUrl("test");
+ appCatalogItem.setName("test");
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest2(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setAlternateUrl("test");
+ appCatalogItem.setDescription("test");
+ appCatalogItem.setId(123L);
+ appCatalogItem.setImageUrl("test");
+ appCatalogItem.setName("test");
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest3(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setDescription("test");
+ appCatalogItem.setId(123L);
+ appCatalogItem.setImageUrl("test");
+ appCatalogItem.setName("test");
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest4(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setId(123L);
+ appCatalogItem.setImageUrl("test");
+ appCatalogItem.setName("test");
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest5(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setImageUrl("test");
+ appCatalogItem.setName("test");
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest6(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setName("test");
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest7(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setNotes("test");
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest8(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest9(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setPending(false);
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest10(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest11(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setSelect(false);
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest12(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest13(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.setUrl("test");
+ appCatalogItem.equals(appCatalogItem1);
+ }
+
+ @Test
+ public void equalsTest14(){
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ AppCatalogItem appCatalogItem1 = new AppCatalogItem();
+ appCatalogItem.equals(appCatalogItem1);
}
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/EPRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/EPRoleTest.java
new file mode 100644
index 00000000..dd1fcccf
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/EPRoleTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portalapp.portal.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.junit.Test;
+import org.onap.portalapp.portal.domain.EPRole;
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.restful.domain.EcompRoleFunction;
+
+public class EPRoleTest {
+
+
+ @Test
+ public void testEpRole() {
+ EPRole role=new EPRole();
+ role.setActive(true);
+ role.setAppId(1l);
+ role.setAppRoleId(2l);
+ role.setId(3l);
+ role.setName("TEST_ADMIN");
+ SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
+ EPRole child=new EPRole();
+ child.setActive(true);
+ child.setAppId(1l);
+ child.setAppRoleId(3l);
+ child.setId(6l);
+ child.setName("TEST_USER");
+ childRoles.add(child);
+ role.setChildRoles(childRoles);
+ SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
+ EPRole parent=new EPRole();
+ parent.setActive(true);
+ parent.setAppId(1l);
+ parent.setAppRoleId(3l);
+ parent.setId(6l);
+ parent.setName("TEST_USER");
+ parentRoles.add(parent);
+ role.setParentRoles(parentRoles);
+
+ SortedSet<RoleFunction> rolefunction = new TreeSet<RoleFunction>();
+ RoleFunction function=new RoleFunction();
+ function.setAction("Test");;
+ function.setCode("code");
+ rolefunction.add(function);
+ role.setRoleFunctions(rolefunction);
+ role.setPriority(5);
+ role.setAppRoleId(3l);
+ assertEquals(3l, role.getAppRoleId().longValue());
+ assertNotNull(role.getChildRoles());
+ assertNotNull(role.getParentRoles());
+ assertNotNull(role.getRoleFunctions());
+ role.compareTo(role);
+ assertEquals(1l, role.getAppId().longValue());
+ assertEquals("TEST_ADMIN",role.getName());
+ role.removeChildRole(6l);
+ role.removeParentRole(6l);
+ assertEquals(role.toString(), "[Id = 3, name = TEST_ADMIN]");
+ role.removeRoleFunction("code");
+ role.addChildRole(child);
+ role.addParentRole(parent);
+ role.addRoleFunction(function);
+
+ }
+
+}
+
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/scheduler/policy/rest/RequestDetailsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/scheduler/policy/rest/RequestDetailsTest.java
new file mode 100644
index 00000000..a79f3a9e
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/scheduler/policy/rest/RequestDetailsTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.scheduler.policy.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class RequestDetailsTest {
+
+ public RequestDetails mockRequestDetails(){
+ RequestDetails requestDetails = new RequestDetails();
+ requestDetails.setPolicyName("test");
+ return requestDetails;
+ }
+
+ @Test
+ public void getPolicyNameTest(){
+ RequestDetails requestDetails = mockRequestDetails();
+ RequestDetails requestDetails1 = new RequestDetails();
+ requestDetails1.setPolicyName("test");
+ assertEquals(requestDetails.getPolicyName(), requestDetails1.getPolicyName());
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java
index 04c8e32d..74fb5da7 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java
@@ -188,6 +188,21 @@ public class AdminRolesServiceImplTest {
AppsListWithAdminRole actual = adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId());
assertNotNull(actual);
}
+
+ @Test
+ public void getAppsWithAdminRoleStateForUserTestWithException() {
+ EPUser user = mockUser.mockEPUser();
+ EPApp app = mockApp();
+ app.setId(1l);
+ List<EPUser> users = new ArrayList<>();
+ users.add(user);
+ Map<String, String> userParams = new HashMap<>();
+ userParams.put("org_user_id", user.getOrgUserId());
+ Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null)).thenReturn(users);
+ AppsListWithAdminRole actual = adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId());
+
+
+ }
@SuppressWarnings({ "deprecation", "unchecked" })
@Test
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImplTest.java
new file mode 100644
index 00000000..a9747335
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImplTest.java
@@ -0,0 +1,243 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.transport.http.HTTPException;
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+/*import org.junit.Assert;
+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.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.service.ApplicationsRestClientServiceImpl;
+import org.onap.portalapp.portal.service.AppsCacheService;
+import org.onap.portalapp.util.SystemType;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.apache.cxf.jaxrs.impl.ResponseImpl;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({WebClient.class,Object.class,CipherUtil.class})
+public class ApplicationsRestClientServiceImplTest {
+
+ @Mock
+ private AppsCacheService appsCacheService;
+
+ @InjectMocks
+ private ApplicationsRestClientServiceImpl serviceImpl= new ApplicationsRestClientServiceImpl();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void unt_get_failure() throws HTTPException{
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.get(ApplicationsRestClientServiceImpl.class, 12L,"/path" );
+ Assert.assertNull(appservice);
+
+ }
+
+ @Test(expected=ClassCastException.class)
+ public void unt_get_successwithException() throws HTTPException{
+ PowerMockito.mockStatic(WebClient.class);
+ WebClient client=Mockito.mock(WebClient.class);
+ PowerMockito.when(WebClient.create(Matchers.anyString())).thenReturn(client);
+ Response response=Mockito.mock(Response.class);
+ Mockito.when(client.get()).thenReturn(response);
+ Mockito.when(client.type(MediaType.APPLICATION_JSON)).thenReturn(client);
+ Mockito.when(response.getStatus()).thenReturn(HttpStatus.SC_OK);
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.get(ApplicationsRestClientServiceImpl.class, 12L,"/path" );
+ Assert.assertNull(appservice);
+
+ }
+
+ @Test(expected=ClassCastException.class)
+ public void unt_get_successwithException1() throws HTTPException{
+ PowerMockito.mockStatic(WebClient.class);
+ WebClient client=Mockito.mock(WebClient.class);
+ PowerMockito.when(WebClient.create(Matchers.anyString())).thenReturn(client);
+ Response response=Mockito.mock(Response.class);
+ Mockito.when(client.get()).thenReturn(response);
+ Mockito.when(client.type(MediaType.APPLICATION_JSON)).thenReturn(client);
+ Mockito.when(response.getStatus()).thenReturn(1);
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.get(ApplicationsRestClientServiceImpl.class, 12L,"/path" );
+ Assert.assertNull(appservice);
+
+ }
+
+ @Test
+ public void unt_post_failure() throws HTTPException{
+ PowerMockito.mockStatic(Object.class);
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.post(ApplicationsRestClientServiceImpl.class, 12L, Matchers.any() , "/path",Matchers.any());
+ Assert.assertNull(appservice);
+
+ }
+
+ @Test
+ public void unt_post_successwithException() throws HTTPException, CipherUtilException{
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(WebClient.class);
+ WebClient client=Mockito.mock(WebClient.class);
+ PowerMockito.when(WebClient.create(Matchers.anyString())).thenReturn(client);
+ PowerMockito.when(CipherUtil.decryptPKC(Matchers.anyString())).thenReturn("password1234");
+ /*Map<String, String> payload = new HashMap<String, String>();
+ payload.put("payload1", Long.toString(1));*/
+ List payload=new ArrayList<>();
+ payload.add("test");
+ Response response=Mockito.mock(Response.class);
+ Mockito.when(client.get()).thenReturn(response);
+ Mockito.when(client.type(MediaType.APPLICATION_JSON)).thenReturn(client);
+ Mockito.when(response.getStatus()).thenReturn(HttpStatus.SC_OK);
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.post(ApplicationsRestClientServiceImpl.class, 12L,payload,"/path",SystemType.APPLICATION);
+ Assert.assertNull(appservice);
+
+ }
+
+
+ @Test(expected=ClassCastException.class)
+ public void unt_post_successwithException2() throws HTTPException, CipherUtilException{
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(WebClient.class);
+ WebClient client=Mockito.mock(WebClient.class);
+ PowerMockito.when(WebClient.create(Matchers.anyString())).thenReturn(client);
+ PowerMockito.when(CipherUtil.decryptPKC(Matchers.anyString())).thenReturn("password1234");
+ /*Map<String, String> payload = new HashMap<String, String>();
+ payload.put("payload1", Long.toString(1));*/
+ List payload=new ArrayList<>();
+ payload.add("test");
+ Response response=Mockito.mock(Response.class);
+ Mockito.when(client.post(Matchers.any())).thenReturn(response);
+ Mockito.when(client.type(MediaType.APPLICATION_JSON)).thenReturn(client);
+ Mockito.when(response.getStatus()).thenReturn(HttpStatus.SC_OK);
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.post(ApplicationsRestClientServiceImpl.class, 12L,payload,"/path",SystemType.APPLICATION);
+ Assert.assertNull(appservice);
+
+ }
+
+
+ @Test(expected=ClassCastException.class)
+ public void unt_post_successwithException3() throws HTTPException, CipherUtilException{
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(WebClient.class);
+ WebClient client=Mockito.mock(WebClient.class);
+ PowerMockito.when(WebClient.create(Matchers.anyString())).thenReturn(client);
+ PowerMockito.when(CipherUtil.decryptPKC(Matchers.anyString())).thenReturn("password1234");
+ /*Map<String, String> payload = new HashMap<String, String>();
+ payload.put("payload1", Long.toString(1));*/
+ List payload=new ArrayList<>();
+ payload.add("test");
+ Response response=Mockito.mock(Response.class);
+ Mockito.when(client.post(Matchers.any())).thenReturn(response);
+ Mockito.when(client.type(MediaType.APPLICATION_JSON)).thenReturn(client);
+ Mockito.when(response.getStatus()).thenReturn(1);
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.post(ApplicationsRestClientServiceImpl.class, 12L,payload,"/path",SystemType.APPLICATION);
+ Assert.assertNull(appservice);
+
+ }
+
+
+ @Test(expected=ClassCastException.class)
+ public void unt_get_successwithException3() throws HTTPException{
+ PowerMockito.mockStatic(WebClient.class);
+ WebClient client=Mockito.mock(WebClient.class);
+ PowerMockito.when(WebClient.create(Matchers.anyString())).thenReturn(client);
+ Response response=Mockito.mock(Response.class);
+ Mockito.when(client.get()).thenReturn(response);
+ Mockito.when(client.type(MediaType.APPLICATION_JSON)).thenReturn(client);
+ Mockito.when(response.getStatus()).thenReturn(1);
+ EPApp appTest=new EPApp();
+ appTest.setAppRestEndpoint("https");
+ appTest.setAppPassword("testPassword");
+ Mockito.when(appsCacheService.getApp(Matchers.anyLong())).thenReturn(appTest);
+ ApplicationsRestClientServiceImpl appservice=serviceImpl.get(ApplicationsRestClientServiceImpl.class, 12L,"/path" , Matchers.anyBoolean());
+ Assert.assertNull(appservice);
+
+ }
+
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppsCacheServiceImpleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppsCacheServiceImpleTest.java
new file mode 100644
index 00000000..77492f74
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppsCacheServiceImpleTest.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+
+
+/*package org.onap.portalapp.portal.service;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.transport.http.HTTPException;
+import org.junit.Assert;
+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.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.service.AppsCacheServiceImple.CacheConfiguration;
+import org.onap.portalapp.util.SystemType;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({CacheConfiguration.class})
+public class AppsCacheServiceImpleTest {
+ private long updateTime = 2;
+ private int updateInterval = 10;
+
+ @Mock
+ EPAppService appsService;
+
+ @InjectMocks
+ private AppsCacheServiceImple cacheServiceImple= new AppsCacheServiceImple();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void initTest() {
+
+ }
+
+
+}
+*/
+
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImplTest.java
new file mode 100644
index 00000000..472cc4d2
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImplTest.java
@@ -0,0 +1,111 @@
+
+
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ */
+package org.onap.portalapp.portal.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.ProjectionList;
+import org.junit.Assert;
+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.onap.portalapp.portal.domain.BasicAuthCredentials;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({CipherUtil.class})
+
+public class BasicAuthenticationCredentialServiceImplTest {
+
+ @Mock
+ private DataAccessService dataAccessService;
+
+ @InjectMocks
+ private BasicAuthenticationCredentialServiceImpl serviceImpl = new BasicAuthenticationCredentialServiceImpl();
+
+ @Before
+ public void setup() throws CipherUtilException {
+ MockitoAnnotations.initMocks(this);
+
+ }
+
+ @Test
+ public void unt_getBasicAuthCredentialByUsernameAndPassword() throws CipherUtilException {
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.when(CipherUtil.decryptPKC(Matchers.anyString())).thenReturn("password1234");
+ List credList=new ArrayList<>();
+ BasicAuthCredentials basicAuthCredentials=new BasicAuthCredentials();
+ basicAuthCredentials.setPassword("password");
+ //basicAuthCredentials.setId(123L);
+ credList.add(basicAuthCredentials);
+ Mockito.when(dataAccessService.getList(Matchers.any(),(ProjectionList)Matchers.isNull() , Matchers.anyListOf(Criterion.class),(List)Matchers.isNull())).thenReturn(credList);
+ BasicAuthCredentials credentials = serviceImpl.getBasicAuthCredentialByUsernameAndPassword("abc1234",
+ "password1234");
+ Assert.assertNotNull(credentials);
+
+ }
+
+ @Test
+ public void unt_getBasicAuthCredentialByUsernameAndPassword_withException() {
+ List credList=new ArrayList<>();
+ BasicAuthCredentials basicAuthCredentials=new BasicAuthCredentials();
+ basicAuthCredentials.setPassword("password");
+ credList.add(basicAuthCredentials);
+ Mockito.when(dataAccessService.getList(Matchers.any(),(ProjectionList)Matchers.isNull() , Matchers.anyListOf(Criterion.class),(List)Matchers.isNull())).thenReturn(credList);
+ BasicAuthCredentials credentials = serviceImpl.getBasicAuthCredentialByUsernameAndPassword("abc1234",
+ "password1234");
+ Assert.assertNull(credentials);
+
+ }
+
+}
+
+
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
index b8743145..63b94f23 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -57,20 +57,26 @@ import org.junit.Ignore;
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.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.AdminUserApp;
+import org.onap.portalapp.portal.domain.AdminUserApplications;
import org.onap.portalapp.portal.domain.AppIdAndNameTransportModel;
import org.onap.portalapp.portal.domain.AppsResponse;
import org.onap.portalapp.portal.domain.EPApp;
import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.EPUserAppRolesRequest;
import org.onap.portalapp.portal.domain.EPUserAppsManualSortPreference;
import org.onap.portalapp.portal.domain.EPUserAppsSortPreference;
import org.onap.portalapp.portal.domain.EPWidgetsManualSortPreference;
import org.onap.portalapp.portal.domain.EcompApp;
import org.onap.portalapp.portal.domain.UserRole;
import org.onap.portalapp.portal.domain.UserRoles;
+import org.onap.portalapp.portal.ecomp.model.AppCatalogItem;
+import org.onap.portalapp.portal.transport.EPAppsManualPreference;
import org.onap.portalapp.portal.transport.EPAppsSortPreference;
import org.onap.portalapp.portal.transport.EPDeleteAppsManualSortPref;
import org.onap.portalapp.portal.transport.EPWidgetsSortPreference;
@@ -107,6 +113,9 @@ public class EPAppCommonServiceImplTest {
@Mock
AdminRolesServiceImpl adminRolesServiceImpl = new AdminRolesServiceImpl();
+ /*@Mock
+ EPAppServiceImpl epAppServiceImpl = new EPAppServiceImpl();*/
+
@Mock
SessionFactory sessionFactory;
@@ -115,6 +124,8 @@ public class EPAppCommonServiceImplTest {
@Mock
Transaction transaction;
+
+ NullPointerException nullPointerException = new NullPointerException();
@Before
public void setup() {
@@ -157,7 +168,7 @@ public class EPAppCommonServiceImplTest {
app.setAppType(1);
return app;
}
-
+
@Test
public void getUserAsAdminAppsTest() {
EPApp mockApp = mockApp();
@@ -178,14 +189,15 @@ public class EPAppCommonServiceImplTest {
@Test
public void getUserAsAdminAppsTestException() {
+ List<EPApp> expected = new ArrayList<>();
EPUser user = mockUser.mockEPUser();
String sql = "SELECT * FROM FN_APP join FN_USER_ROLE ON FN_USER_ROLE.APP_ID=FN_APP.APP_ID where "
+ "FN_USER_ROLE.USER_ID=" + user.getId() + " AND FN_USER_ROLE.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ " AND FN_APP.ENABLED = 'Y'";
Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeSQLQuery(sql, EPApp.class, null);
- Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(true);
+ Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(false);
List<EPApp> actual = epAppCommonServiceImpl.getUserAsAdminApps(user);
- assertNull(actual);
+ assertEquals(expected, actual);
}
@Test
@@ -206,6 +218,25 @@ public class EPAppCommonServiceImplTest {
List<EPApp> actual = epAppCommonServiceImpl.getUserByOrgUserIdAsAdminApps(user.getOrgUserId());
assertEquals(expected, actual);
}
+
+ @Test
+ public void getUserByOrgUserIdAsAdminAppsTest1() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> expected = new ArrayList<>();
+ expected.add(mockApp);
+ expected.add(mockApp2);
+ String format = "SELECT * FROM FN_APP app INNER JOIN FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID "
+ + "INNER JOIN FN_USER user on user.USER_ID = userrole.USER_ID "
+ + "WHERE user.org_user_id = '%s' AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ + " AND FN_APP.ENABLED = 'Y'";
+ String sql = String.format(format, user.getOrgUserId());
+ Mockito.when(dataAccessService.executeSQLQuery(sql, EPApp.class, null)).thenReturn(expected);
+ List<EPApp> actual = epAppCommonServiceImpl.getUserByOrgUserIdAsAdminApps(user.getOrgUserId());
+ assertEquals(expected, actual);
+ }
@Test
public void getUserByOrgUserIdAsAdminAppsTestException() {
@@ -727,6 +758,23 @@ public class EPAppCommonServiceImplTest {
}
@Test
+ public void saveAppsSortPreferenceExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", user.getId());
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap());
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ //expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ EPAppsSortPreference mockEPAppsSortPreference = new EPAppsSortPreference();
+ mockEPAppsSortPreference.setIndex(1);
+ mockEPAppsSortPreference.setTitle("Last Used");
+ mockEPAppsSortPreference.setValue("L");
+ FieldsValidator actual = epAppCommonServiceImpl.saveAppsSortPreference(mockEPAppsSortPreference, user);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
public void getUserAppsSortTypePreferenceTest() {
EPUser user = mockUser.mockEPUser();
final Map<String, Long> params = new HashMap<>();
@@ -809,4 +857,580 @@ public class EPAppCommonServiceImplTest {
expected.setHttpStatusCode(500l);
assertEquals(expected, actual);
}
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppDetailByAppNameTest(){
+ String appName = "test";
+ EPApp expectedResult = mockApp();
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(expectedResult);
+ final Map<String, String> params = new HashMap<String, String>();
+ params.put("appName", expectedResult.getName());
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAppDetailsByAppName", params, null))
+ .thenReturn(appList);
+ EPApp actualResult = epAppCommonServiceImpl.getAppDetailByAppName(appName);
+ assertEquals(expectedResult, actualResult);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppDetailByAppNameExceptionTest(){
+ String appName = null;
+ EPApp expectedResult = null;
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(expectedResult);
+ final Map<String, String> params = new HashMap<String, String>();
+ params.put("appName", null);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAppDetailsByAppName", params, null))
+ .thenReturn(appList);
+ EPApp actualResult = epAppCommonServiceImpl.getAppDetailByAppName(appName);
+ assertEquals(expectedResult, actualResult);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsForSuperAdminAndAccountAdminTest(){
+ String sql = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app "
+ + "where app.ENABLED = 'Y' AND app.app_type = 1";
+ EPUser user = mockUser.mockEPUser();
+ List<AppIdAndNameTransportModel> expected = null;
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(true);
+ List<AppIdAndNameTransportModel> actual = null;
+ Mockito.when((List<AppIdAndNameTransportModel>) dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null))
+ .thenReturn(actual);
+ actual = epAppCommonServiceImpl.getAppsForSuperAdminAndAccountAdmin(user);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsForSuperAdminAndNotAccountAdminTest(){
+ String sql = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app "
+ + "where app.ENABLED = 'Y' AND app.app_type = 1";
+ EPUser user = mockUser.mockEPUser();
+ List<AppIdAndNameTransportModel> expected = new ArrayList<AppIdAndNameTransportModel>();
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(true);
+ List<AppIdAndNameTransportModel> actual = null;
+ Mockito.when((List<AppIdAndNameTransportModel>) dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null))
+ .thenReturn(actual);
+ actual = epAppCommonServiceImpl.getAppsForSuperAdminAndAccountAdmin(user);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsForAdminAndAccountAdminTest(){
+ String sql = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app "
+ + "where app.ENABLED = 'Y' AND app.app_type = 1";
+ EPUser user = mockUser.mockEPUser();
+ List<AppIdAndNameTransportModel> expected = null;
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(user)).thenReturn(true);
+ List<AppIdAndNameTransportModel> actual = null;
+ Mockito.when((List<AppIdAndNameTransportModel>) dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null))
+ .thenReturn(actual);
+ actual = epAppCommonServiceImpl.getAppsForSuperAdminAndAccountAdmin(user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAppsForSuperAdminAndAccountAdminExceptionTest(){
+ String sql = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app "
+ + "where app.ENABLED = 'Y' AND app.app_type = 1";
+ EPUser user = mockUser.mockEPUser();
+ List<AppIdAndNameTransportModel> expected = new ArrayList<AppIdAndNameTransportModel>();
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(user)).thenReturn(true);
+ List<AppIdAndNameTransportModel> actual = null;
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeSQLQuery(sql, AppIdAndNameTransportModel.class, null);
+ actual = epAppCommonServiceImpl.getAppsForSuperAdminAndAccountAdmin(user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getDataAccessServiceTest(){
+ assertEquals(epAppCommonServiceImpl.getDataAccessService(), epAppCommonServiceImpl.getDataAccessService());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsAdminsTest(){
+ List<AdminUserApplications> expected = new ArrayList<AdminUserApplications>();
+ List<AdminUserApplications> actual = null;
+ List<AdminUserApp> list = new ArrayList<AdminUserApp>();
+ Map<String, String> params = new HashMap<>();
+ params.put("accountAdminRoleId", ACCOUNT_ADMIN_ROLE_ID);
+ Mockito.when((List<AdminUserApp>) dataAccessService.executeNamedQuery("getAppsAdmins", params, null)).thenReturn(list);
+ actual = epAppCommonServiceImpl.getAppsAdmins();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAppsAdminsExceptionTest(){
+ List<AdminUserApplications> expected = null;
+ List<AdminUserApplications> actual = null;
+ Map<String, String> params = new HashMap<>();
+ params.put("accountAdminRoleId", ACCOUNT_ADMIN_ROLE_ID);
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery("getAppsAdmins", params, null);
+ actual = epAppCommonServiceImpl.getAppsAdmins();
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsAdminsAggregateResultsTest(){
+ List<AdminUserApplications> expected = new ArrayList<AdminUserApplications>();
+ AdminUserApp adminUserApp = new AdminUserApp();
+ AdminUserApplications adminUserApplications = new AdminUserApplications(adminUserApp);
+ expected.add(adminUserApplications);
+ List<AdminUserApplications> actual = null;
+ List<AdminUserApp> list = new ArrayList<AdminUserApp>();
+ AdminUserApp adminUserApp1 = new AdminUserApp();
+ list.add(adminUserApp1);
+ Map<String, String> params = new HashMap<>();
+ params.put("accountAdminRoleId", ACCOUNT_ADMIN_ROLE_ID);
+ Mockito.when((List<AdminUserApp>) dataAccessService.executeNamedQuery("getAppsAdmins", params, null)).thenReturn(list);
+ actual = epAppCommonServiceImpl.getAppsAdmins();
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getUserAppsTest(){
+ String sql ="";
+ EPApp epApp = new EPApp();
+ epApp.setOpen(false);
+ List<EPApp> expected = new ArrayList<EPApp>();
+ List<EPApp> list = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ list.add(epApp);
+ Mockito.when((List<EPApp>) dataAccessService.executeSQLQuery(sql, EPApp.class, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getUserApps(epUser);
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getUserAppsUserGuestTest(){
+ String sql ="";
+ List<EPApp> expected = new ArrayList<EPApp>();
+ List<EPApp> list = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ epUser.setGuest(true);
+ Mockito.when((List<EPApp>) dataAccessService.executeSQLQuery(sql, EPApp.class, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getUserApps(epUser);
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getPersAdminAppsTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getPersAdminApps", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getPersAdminApps(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getPersUserAppsTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ List<EPApp> list = new ArrayList<EPApp>();
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getPersUserApps", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getPersUserApps(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getUserAppCatalogTest(){
+ List<AppCatalogItem> expected = new ArrayList<AppCatalogItem>();
+ EPUser epUser = new EPUser();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ List<AppCatalogItem> list = new ArrayList<AppCatalogItem>();
+ Mockito.when((List<AppCatalogItem>) dataAccessService.executeNamedQuery("getUserAppCatalog", params, null)).thenReturn(list);
+ List<AppCatalogItem> actual = epAppCommonServiceImpl.getUserAppCatalog(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAdminAppCatalogTest(){
+ List<AppCatalogItem> expected = new ArrayList<AppCatalogItem>();
+ EPUser epUser = new EPUser();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ List<AppCatalogItem> list = new ArrayList<AppCatalogItem>();
+ Mockito.when((List<AppCatalogItem>) dataAccessService.executeNamedQuery("getAdminAppCatalog", params, null)).thenReturn(list);
+ List<AppCatalogItem> actual = epAppCommonServiceImpl.getAdminAppCatalog(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByNameTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getPersAdminAppsOrderByName", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByName(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByNameNotSuperAdminTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(false);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getPersAdminAppsOrderByName", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByName(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAppsOrderByNameExceptionTest(){
+ List<EPApp> expected = null;
+ EPUser epUser = new EPUser();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", null);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap());
+ //Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap())).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByName(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByLastUsedTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAdminAppsOrderByLastUsed", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByLastUsed(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByLastUsedNotSuperAdminTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(false);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAdminAppsOrderByLastUsed", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByLastUsed(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAppsOrderByLastUsedExceptionTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", null);
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap());
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByLastUsed(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByMostUsedTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAppsOrderByMostUsed", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByMostUsed(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByMostUsedNotSuperAdminTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(false);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAppsOrderByMostUsed", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByMostUsed(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAppsOrderByMostUsedExceptionTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", null);
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap());
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByMostUsed(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByManualTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAdminAppsOrderByManual", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByManual(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByManualSuperAdminTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(false);
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getAdminAppsOrderByManual", params, null)).thenReturn(list);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByManual(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppsOrderByManualExceptionTest(){
+ List<EPApp> expected = new ArrayList<EPApp>();
+ EPUser epUser = new EPUser();
+ List<EPApp> list = new ArrayList<EPApp>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", null);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap());
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsOrderByManual(epUser);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void getOnboardingAppsTest(){
+ List<EPApp> apps = new ArrayList<EPApp>();
+ List<OnboardingApp> expected = new ArrayList<OnboardingApp>();
+ Mockito.when(dataAccessService.getList(EPApp.class, " where id!=" + ECOMP_APP_ID, null, null)).thenReturn(apps);
+ List<OnboardingApp> actual = epAppCommonServiceImpl.getOnboardingApps();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getEnabledNonOpenOnboardingAppsTest(){
+ List<OnboardingApp> expected = new ArrayList<OnboardingApp>();
+ List<OnboardingApp> actual = epAppCommonServiceImpl.getEnabledNonOpenOnboardingApps();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void addOnboardingAppTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(400l);
+ EPUser epUser = new EPUser();
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.setRestrictedApp(true);
+ FieldsValidator actual = epAppCommonServiceImpl.addOnboardingApp(onboardingApp, epUser);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
+ public void deleteOnboardingAppTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(403l);
+ EPUser epUser = new EPUser();
+ Long appId = (long) 123;
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.setRestrictedApp(true);
+ FieldsValidator actual = epAppCommonServiceImpl.deleteOnboardingApp(epUser, appId);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void deleteOnboardingAppSuperAdminTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ EPUser epUser = new EPUser();
+ Long appId = (long) 123;
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.setRestrictedApp(true);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("app_id", (long)123);
+ EPUserAppRolesRequest epUserAppRolesRequest = new EPUserAppRolesRequest();
+ epUserAppRolesRequest.setUserId((long)123);
+ List<EPUserAppRolesRequest> list= new ArrayList<>();
+ list.add(epUserAppRolesRequest);
+ Mockito.when((List<EPUserAppRolesRequest>) dataAccessService.executeNamedQuery("getRequestIdsForApp", params, null)).thenReturn(list);
+ FieldsValidator actual = epAppCommonServiceImpl.deleteOnboardingApp(epUser, appId);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void deleteOnboardingAppExceptionTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ EPUser epUser = new EPUser();
+ //Long appId = (long) 123;
+ List<EPUserAppRolesRequest> epUserAppRolesRequestList= new ArrayList<>();
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.setRestrictedApp(true);
+ Mockito.when(adminRolesServiceImpl.isSuperAdmin(epUser)).thenReturn(true);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("app_id", null);
+ Mockito.when(dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap())).thenThrow(nullPointerException);
+ Mockito.when(dataAccessService.executeNamedQuery( "getRequestIdsForApp", params, null)).thenReturn(epUserAppRolesRequestList);
+ //Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap());
+ FieldsValidator actual = epAppCommonServiceImpl.deleteOnboardingApp(epUser, null);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void saveAppsSortManualAppIdNullTest(){
+ List<EPUserAppsManualSortPreference> epUserAppsManualSortPreferenceList = new ArrayList<EPUserAppsManualSortPreference>();
+ EPAppsManualPreference epAppsManualPreference = new EPAppsManualPreference();
+ epAppsManualPreference.setAddRemoveApps(true);
+ epAppsManualPreference.setAppid((long)123);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ EPUser epUser = new EPUser();
+ List<EPAppsManualPreference> list = new ArrayList<EPAppsManualPreference>();
+ list.add(epAppsManualPreference);
+ Mockito.when(dataAccessService.executeNamedQuery("userAppsManualSortPrfQuery", params, null)).thenReturn(epUserAppsManualSortPreferenceList);
+ FieldsValidator actual = epAppCommonServiceImpl.saveAppsSortManual(list, epUser);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
+ public void saveAppsSortManualExceptionTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", (long)123);
+ EPUser epUser = new EPUser();
+ List<EPAppsManualPreference> list = new ArrayList<EPAppsManualPreference>();
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap());
+ FieldsValidator actual = epAppCommonServiceImpl.saveAppsSortManual(list, epUser);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
+ public void getUserProfileForLeftMenuNullListTest(){
+ UserRole userRole =new UserRole();
+ userRole.setFirstName("test");
+ UserRoles expected = null;
+ UserRoles actual = epAppCommonServiceImpl.getUserProfileForLeftMenu("123");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserProfileForLeftMenuTest(){
+ final Map<String, String> params = new HashMap<>();
+ params.put("org_user_id", "test");
+ UserRole userRole =new UserRole();
+ userRole.setFirstName("test");
+ UserRoles expected = null;
+ List<UserRole> list = new ArrayList<UserRole>();
+ list.add(userRole);
+ Mockito.when(dataAccessService.executeNamedQuery( "getUserRolesForLeftMenu", params, null)).thenReturn(list);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfileForLeftMenu("123");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserProfileForRolesLeftMenuNullListTest(){
+ UserRoles expected = null;
+ List<UserRole> userRoleList = new ArrayList<UserRole>();
+ final Map<String, String> params = new HashMap<>();
+ params.put("org_user_id", "test");
+ Mockito.when(dataAccessService.executeNamedQuery( "getRolesForLeftMenu", params, null)).thenReturn(userRoleList);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfileForRolesLeftMenu("test");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserProfileForRolesLeftMenuTest(){
+ UserRole userRole = new UserRole();
+ userRole.setRoleId((long)123);
+ userRole.setOrgUserId("test");
+ userRole.setUser_Id((long)1);
+ List<UserRole> userRoleList = new ArrayList<UserRole>();
+ userRoleList.add(userRole);
+ UserRoles expected = new UserRoles(userRole);
+ final Map<String, String> params = new HashMap<>();
+ params.put("org_user_id", "test");
+ Mockito.when(dataAccessService.executeNamedQuery( "getRolesForLeftMenu", params, null)).thenReturn(userRoleList);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfileForRolesLeftMenu("test");
+ assertEquals(expected.getOrgUserId(), actual.getOrgUserId());
+ }
+
+ @Test
+ public void getUserProfileNormalizedForLeftMenuNullListTest(){
+ EPUser epUser = new EPUser();
+ List<String> list = new ArrayList<String>();
+ list.add("Guest");
+ UserRole userRole = new UserRole();
+ userRole.setFirstName("GuestT");
+ userRole.setLastName("GuestT");
+ userRole.setOrgUserId("guestT");
+ userRole.setRoleId(1l);
+ userRole.setRoleName("Test");
+ userRole.setUser_Id(-1l);
+ UserRoles expected = new UserRoles(userRole);
+ expected.setRoles(list);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfileNormalizedForLeftMenu(epUser);
+ assertEquals(expected.getRoles(), actual.getRoles());
+ }
+
+ @Test
+ public void getUserProfileNormalizedForRolesLeftMenuTest(){
+ EPUser epUser = new EPUser();
+ List<String> list = new ArrayList<String>();
+ list.add("Guest");
+ UserRole userRole = new UserRole();
+ userRole.setFirstName("GuestT");
+ userRole.setLastName("GuestT");
+ userRole.setOrgUserId("guestT");
+ userRole.setRoleId(1l);
+ userRole.setRoleName("Test");
+ userRole.setUser_Id(-1l);
+ UserRoles expected = new UserRoles(userRole);
+ expected.setRoles(list);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfileNormalizedForRolesLeftMenu(epUser);
+ assertEquals(expected.getRoles(), actual.getRoles());
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLdapServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLdapServiceImplTest.java
new file mode 100644
index 00000000..bacd2a9e
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLdapServiceImplTest.java
@@ -0,0 +1,1343 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.service;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+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.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalsdk.core.command.support.SearchResult;
+import org.onap.portalsdk.core.service.support.ServiceLocator;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.owasp.esapi.ESAPI;
+import org.owasp.esapi.Encoder;
+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, ESAPI.class})
+public class EPLdapServiceImplTest {
+
+ @Mock
+ SessionFactory sessionFactory;
+
+ @Mock
+ Session session;
+
+ @Mock
+ Transaction transaction;
+
+ @Mock
+ ServiceLocator serviceLocator;
+
+ @Mock
+ DirContext dirContext;
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Mockito.when(session.beginTransaction()).thenReturn(transaction);
+ }
+
+ EPUser epUser = mockEPUser();
+
+ @InjectMocks
+ EPLdapServiceImpl epLdapServiceImpl = new EPLdapServiceImpl();
+
+ 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.setCentralAuth(true);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.setAppType(1);
+ return app;
+ }
+
+ public EPUser mockEPUser() {
+
+ EPUser ePUser = new EPUser();
+ ePUser.setOrgId(null);
+ ePUser.setManagerId(null);
+ ePUser.setFirstName("test");
+ ePUser.setLastName("test");
+ ePUser.setMiddleInitial(null);
+ ePUser.setPhone(null);
+ ePUser.setFax(null);
+ ePUser.setCellular(null);
+ ePUser.setEmail(null);
+ ePUser.setAddressId(null);
+ ePUser.setAlertMethodCd(null);
+ ePUser.setHrid(null);
+ ePUser.setOrgUserId("guestT");
+ ePUser.setOrgCode(null);
+ ePUser.setAddress1(null);
+ ePUser.setAddress2(null);
+ ePUser.setCity(null);
+ ePUser.setState(null);
+ ePUser.setZipCode(null);
+ ePUser.setCountry(null);
+ ePUser.setOrgManagerUserId(null);
+ ePUser.setLocationClli(null);
+ ePUser.setBusinessCountryCode(null);
+ ePUser.setBusinessCountryName(null);
+ ePUser.setBusinessUnit(null);
+ ePUser.setBusinessUnitName(null);
+ ePUser.setDepartment(null);
+ ePUser.setDepartmentName(null);
+ ePUser.setCompanyCode(null);
+ ePUser.setCompany(null);
+ ePUser.setZipCodeSuffix(null);
+ ePUser.setJobTitle(null);
+ ePUser.setCommandChain(null);
+ ePUser.setSiloStatus(null);
+ ePUser.setCostCenter(null);
+ ePUser.setFinancialLocCode(null);
+ ePUser.setHrid("test");
+ ePUser.setOrgUserId("test");
+ ePUser.setOrgCode("test");
+
+ ePUser.setEmail("test.com");
+ ePUser.setLoginId(null);
+ ePUser.setLoginPwd(null);
+ Date date = new Date();
+ ePUser.setLastLoginDate(date);
+ ePUser.setActive(true);
+ ePUser.setInternal(false);
+ ePUser.setSelectedProfileId(null);
+ ePUser.setTimeZoneId(null);
+ ePUser.setOnline(true);
+ ePUser.setChatId(null);
+ ePUser.setUserApps(null);
+ ePUser.setPseudoRoles(null);
+
+ ePUser.setId((long) -1);
+ return ePUser;
+ }
+
+ @Test
+ public void searchPostTest() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ NamingEnumeration e = PowerMockito.mock(NamingEnumeration.class);
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void searchPostNamingExceptionTest() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ NamingEnumeration e = PowerMockito.mock(NamingEnumeration.class);
+ NamingException ne = new NamingException("test");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenThrow(ne);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void searchPostExceptionTest() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void searchPostWhileTest() throws Exception{
+ SearchResult expected = new SearchResult();
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void searchPostwhile2Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("givenName");
+
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile3Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("initials");
+
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile4Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("sn");
+
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile5Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("employeeNumber");
+
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile6Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("mail");
+
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile7Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("telephoneNumber");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile8Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("departmentNumber");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile9Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("a1");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile10Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("street");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile11Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("roomNumber");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile12Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("l");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile13Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("st");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile14Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("postalCode");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile15Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("zip4");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile16Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("physicalDeliveryOfficeName");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile17Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("bc");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile18Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("friendlyCountryName");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile19Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("bd");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile20Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("bdname");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile21Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("jtname");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile22Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("mgrid");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile23Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("a2");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile24Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("compcode");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile25Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("compdesc");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile26Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("bu");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile27Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("buname");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile28Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("silo");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile29Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("costcenter");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile30Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("b2");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostwhile31Test() throws Exception{
+ SearchResult expected = new SearchResult();
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ NamingException ne = new NamingException();
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenThrow(ne);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("b2");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void searchPostWhileCountTest() throws Exception{
+ SearchResult expected = new SearchResult();
+ expected.setDataSize(123);
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_PROVIDER_URL)).thenReturn("http://todo_enter_ush_ticket_url");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("POST_SECURITY_PRINCIPAL");
+ Mockito.when(SystemProperties.getProperty(SystemProperties.POST_MAX_RESULT_SIZE)).thenReturn("0");
+ PowerMockito.mockStatic(ESAPI.class);
+ Encoder encoder = PowerMockito.mock(Encoder.class);
+ PowerMockito.when(ESAPI.encoder()).thenReturn(encoder);
+ Mockito.when(serviceLocator.getDirContext(
+ SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL))).thenReturn(dirContext);
+ PowerMockito.when(encoder.encodeForDN(Matchers.anyString())).thenReturn("test");
+ Set<javax.naming.directory.SearchResult> set = new HashSet<>();
+ javax.naming.directory.SearchResult sr = Mockito.mock(javax.naming.directory.SearchResult.class);
+ NamingEnumeration e = Mockito.mock(NamingEnumeration.class);
+ Mockito.when(e.hasMore()).thenReturn(true);
+ Mockito.when(e.next()).thenReturn(sr);
+ Attributes attributes = Mockito.mock(Attributes.class);
+ Mockito.when(sr.getAttributes()).thenReturn(attributes);
+ NamingEnumeration ef = Mockito.mock(NamingEnumeration.class);
+ NamingException ne = new NamingException();
+ Mockito.when(ef.hasMore()).thenReturn(true);
+ Attribute attribute = Mockito.mock(Attribute.class);
+ Mockito.when(ef.next()).thenReturn(attribute);
+ Mockito.when(attribute.getAll()).thenThrow(ne);
+ Mockito.when(attributes.getAll()).thenReturn(ef);
+ Mockito.when(attribute.getID()).thenReturn("b2");
+ Mockito.when(dirContext.search(Matchers.anyString(),Matchers.anyString(),Matchers.anyObject())).thenReturn(e);
+ SearchResult actual = epLdapServiceImpl.searchPost(epUser, "test", "test", "test", 123, 123, 123);
+ assertEquals(actual.getDataSize(), expected.getDataSize());
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java
index 77089a8f..69536a89 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java
@@ -64,15 +64,18 @@ import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.exceptions.RoleFunctionException;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalapp.portal.service.EPRoleFunctionServiceCentralizedImpl;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalapp.util.EPUserUtils;
import org.onap.portalsdk.core.domain.RoleFunction;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.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)
-@Ignore
+@PrepareForTest({EcompPortalUtils.class})
public class EPRoleFunctionServiceCentralizedImplTest {
@@ -96,7 +99,7 @@ public class EPRoleFunctionServiceCentralizedImplTest {
HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
- @Test(expected = NullPointerException.class)
+ @Test
public void getRoleFunctions()
{
List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
@@ -107,6 +110,7 @@ public class EPRoleFunctionServiceCentralizedImplTest {
getRoleFuncListOfPortal.add(roleFunction);
final Map<String, Long> params = new HashMap<>();
params.put("appId", (long) 1);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(getRoleFuncList);
List<RoleFunction> expectedGetRoleFuncListOfPortal = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions();
assertEquals(expectedGetRoleFuncListOfPortal.size(),getRoleFuncListOfPortal.size());
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java
index 562a48a9..95986457 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java
@@ -89,35 +89,34 @@ public class EPRoleServiceImplTest {
@Test
public void getAvailableChildRolesIfRoleIdIsNullTest() {
+ Long roleId = (long)123;
List<EPRole> roleList = new ArrayList<>();
+ EPRole epRole = new EPRole();
EPRole role = new EPRole();
EPRole role1 = new EPRole();
role.addChildRole(role1);
roleList.add(role);
Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList);
+ Mockito.when(dataAccessService.getDomainObject(EPRole.class, roleId, null)).thenReturn(epRole);
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 getAvailableChildRolesIfRoleIdTest() {
+ Long roleId = (long)123;
+ List<EPRole> roleList = new ArrayList<>();
+ EPRole epRole = new EPRole();
+ EPRole role = new EPRole();
+ EPRole role1 = new EPRole();
+ role.addChildRole(role1);
+ roleList.add(role);
+ Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList);
+ Mockito.when(dataAccessService.getDomainObject(EPRole.class, roleId, null)).thenReturn(epRole);
+ List<EPRole> expectedRoleList = ePRoleServiceImpl.getAvailableChildRoles(roleId);
+ assertEquals(roleList, expectedRoleList);
+ }
+
@Test
public void getRoleFunctionTest() {
RoleFunction roleFunction = new RoleFunction();
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java
deleted file mode 100644
index ca196033..00000000
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*-
- * ============LICENSE_START==========================================
- * ONAP Portal
- * ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software 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.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END============================================
- *
- *
- */
-package org.onap.portalapp.portal.service;
-
-import 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.onap.portalapp.portal.domain.FunctionalMenuItemWithAppID;
-import org.onap.portalapp.portal.service.FunctionalMenuService;
-import org.onap.portalapp.portal.service.FunctionalMenuServiceImpl;
-import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
-import org.onap.portalapp.portal.transport.FunctionalMenuItem;
-import org.onap.portalapp.portal.transport.FunctionalMenuRole;
-import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
-import org.onap.portalsdk.core.service.DataAccessService;
-import org.onap.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 {
-
- @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(){
- Long menuid = 1L;
- 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/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java
new file mode 100644
index 00000000..520887fd
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java
@@ -0,0 +1,885 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.service;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+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.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.FunctionalMenuItemWithAppID;
+import org.onap.portalapp.portal.transport.BusinessCardApplicationRole;
+import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItem;
+import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
+import org.onap.portalapp.portal.transport.FieldsValidator;
+import org.onap.portalapp.portal.transport.FunctionalMenuItem;
+import org.onap.portalapp.portal.transport.FunctionalMenuItemWithRoles;
+import org.onap.portalapp.portal.transport.FunctionalMenuRole;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.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, StringUtils.class})
+public class FunctionalMenuServiceImplTest {
+
+ @Mock
+ FunctionalMenuService functionalMenuService;
+
+ @Mock
+ DataAccessService dataAccessService;
+
+ @Mock
+ Session session;
+
+ @Mock
+ private SessionFactory sessionFactory;
+
+ @Mock
+ Criteria criteria;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ FunctionalMenuServiceImpl functionalMenuServiceImpl= new FunctionalMenuServiceImpl();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @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(){
+ Long menuid = 1L;
+ String sql = "SELECT * FROM fn_menu_functional_roles WHERE menu_id = '1'";
+ FunctionalMenuItem actualResult = null;
+ FunctionalMenuItem expectedResult = null;
+ List<FunctionalMenuRole> roleItems = new ArrayList<FunctionalMenuRole>();
+ FunctionalMenuRole functionalMenuRole = new FunctionalMenuRole();
+ roleItems.add(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);
+ }
+
+ @Test
+ public void getFavoriteItemsExceptionTest(){
+ 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' ";
+ Mockito.when(dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null));
+ List<FavoritesFunctionalMenuItemJson> expectedResult = functionalMenuServiceImpl.getFavoriteItems(userId);
+ }
+
+ @Test
+ public void getFunctionalMenuItemsTest1(){
+ EPUser epUser = new EPUser();
+ List<FunctionalMenuItem> expected = new ArrayList<FunctionalMenuItem>();
+ List<FunctionalMenuItem> actual = functionalMenuServiceImpl.getFunctionalMenuItems(epUser);
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void getFunctionalMenuItemsTest2(){
+ List<FunctionalMenuItem> expected = new ArrayList<FunctionalMenuItem>();
+ List<FunctionalMenuItem> actual = functionalMenuServiceImpl.getFunctionalMenuItems();
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(){
+ FunctionalMenuItemWithAppID functionalMenuItemWithAppID = new FunctionalMenuItemWithAppID();
+ List<FunctionalMenuItemWithAppID> functionalMenuItemWithAppIDList = new ArrayList<FunctionalMenuItemWithAppID>();
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ functionalMenuItemWithAppIDList.add(functionalMenuItemWithAppID);
+ List<FunctionalMenuItem> expected = new ArrayList<FunctionalMenuItem>();
+ expected.add(functionalMenuItem);
+ List<FunctionalMenuItem> actual = functionalMenuServiceImpl.transformFunctionalMenuItemWithAppIDToFunctionalMenuItem(functionalMenuItemWithAppIDList);
+ assertEquals(actual.size(), expected.size());
+ }
+
+ @Test
+ public void addRolesTest(){
+ FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles();
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ menuItemJson.setRoles(list);
+ functionalMenuServiceImpl.addRoles(menuItemJson, session);
+ }
+
+ @Test
+ public void deleteRolesTest(){
+ Long id = (long)123;
+ Mockito.doNothing().when(dataAccessService).deleteDomainObjects(FavoritesFunctionalMenuItem.class, "menu_id='" + id + "'", null);
+ functionalMenuServiceImpl.deleteFavorites(id);
+ }
+
+ @Test
+ public void deleteFavoritesTest(){
+ Long id = (long)123;
+ Mockito.doNothing().when(dataAccessService).deleteDomainObjects(FavoritesFunctionalMenuItem.class, "menu_id='" + id + "'", null);
+ functionalMenuServiceImpl.deleteFavorites(id);
+ }
+
+ @Test
+ public void removeAppInfoTest(){
+ Long id = (long)123;
+ FunctionalMenuItem menuItem = new FunctionalMenuItem();
+ Mockito.when(session.get(FunctionalMenuItem.class, id)).thenReturn(menuItem);
+ functionalMenuServiceImpl.removeAppInfo(session, id);
+ }
+
+ @Test
+ public void editFunctionalMenuItem400Status(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(400l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(list);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItemMenuIdNullTest(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(400l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setUrl("test.com");
+ functionalMenuItem.setRoles(null);
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ //functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(null);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItemTest(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setUrl("test.com");
+ functionalMenuItem.setRoles(null);
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(null);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItem1Test(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setRoles(list1);
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ functionalMenuItemWithRoles.appid =1;
+ functionalMenuItemWithRoles.url = "test.com";
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(list);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(StringUtils.isEmpty(Matchers.anyString())).thenReturn(false);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItem2Test(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setRoles(list1);
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ functionalMenuItemWithRoles.appid =1;
+ functionalMenuItemWithRoles.column = 1;
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(list);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(StringUtils.isEmpty(Matchers.anyString())).thenReturn(false);
+ Mockito.when(session.createCriteria(FunctionalMenuItem.class)).thenReturn(criteria);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItem3Test(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setRoles(list1);
+ functionalMenuItem.parentMenuId = (Integer)123;
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ functionalMenuItemWithRoles.appid =1;
+ functionalMenuItemWithRoles.column = 1;
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(list);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(StringUtils.isEmpty(Matchers.anyString())).thenReturn(false);
+ Mockito.when(session.createCriteria(FunctionalMenuItem.class)).thenReturn(criteria);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItem4Test(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setRoles(list1);
+ functionalMenuItem.parentMenuId = (Integer)12;
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ functionalMenuItemWithRoles.appid =1;
+ functionalMenuItemWithRoles.column = 1;
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(list);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(StringUtils.isEmpty(Matchers.anyString())).thenReturn(false);
+ Mockito.when(session.createCriteria(FunctionalMenuItem.class)).thenReturn(criteria);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItem5Test(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setRoles(list1);
+ functionalMenuItem.parentMenuId = (Integer)123;
+ functionalMenuItem.setUrl("test.com");
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)12;
+ functionalMenuItemWithRoles.appid =1;
+ functionalMenuItemWithRoles.column = 1;
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(list);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(StringUtils.isEmpty(Matchers.anyString())).thenReturn(false);
+ Mockito.when((FunctionalMenuItem) session.get(FunctionalMenuItem.class, (long)12)).thenReturn(functionalMenuItem);
+ Mockito.when(session.createCriteria(FunctionalMenuItem.class)).thenReturn(criteria);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItem6Test(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setUrl("test.com");
+ functionalMenuItem.setRoles(null);
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(null);
+ EPApp app = new EPApp();
+ app.setId((long)123);
+ Mockito.when(session.get(EPApp.class, (long)123)).thenReturn(app);
+ Mockito.when((List<FunctionalMenuItem>)dataAccessService.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(functionalMenuItemList);
+ Mockito.when(session.get(FunctionalMenuItem.class, functionalMenuItemWithRoles.menuId)).thenReturn(functionalMenuItem);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void editFunctionalMenuItem7Test(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ List<Integer> list1 = new ArrayList<Integer>();
+ list1.add(123);
+ functionalMenuItem.setRoles(list1);
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.text = "test";
+ functionalMenuItemWithRoles.menuId = (long)123;
+ functionalMenuItemWithRoles.column = (Integer)123;
+ functionalMenuItemWithRoles.parentMenuId = (Integer)123;
+ functionalMenuItemWithRoles.appid =1;
+ functionalMenuItemWithRoles.url = "test.com";
+ List<Integer> list = new ArrayList<Integer>();
+ list.add(123);
+ functionalMenuItemWithRoles.setRoles(list);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(StringUtils.isEmpty(Matchers.anyString())).thenReturn(false);
+ EPApp app = new EPApp();
+ app.setEnabled(false);
+ PowerMockito.when((EPApp)session.get(EPApp.class,1)).thenReturn(app);
+ FieldsValidator actual = functionalMenuServiceImpl.editFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
+ public void deleteFunctionalMenuItemTest(){
+ String sql = "set FOREIGN_KEY_CHECKS=";
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ Long menuId = (long)123;
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ // SQLQuery query = PowerMockito.mock(Query.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ // Mockito.when(session.createSQLQuery(sql)).thenReturn(query);
+ FieldsValidator actual = functionalMenuServiceImpl.deleteFunctionalMenuItem(menuId);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
+ public void deleteFunctionalMenuItemExceptionTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ Long menuId = (long)123;
+ FieldsValidator actual = functionalMenuServiceImpl.deleteFunctionalMenuItem(menuId);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
+ public void getFunctionalMenuRoleTest(){
+ List<FunctionalMenuRole> expected = null;
+ String sql = "SELECT * from fn_menu_functional_roles";
+ Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuRole.class,
+ null)).thenReturn(expected);
+ List<FunctionalMenuRole> actual = functionalMenuServiceImpl.getFunctionalMenuRole();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserAppRolesListTest(){
+ String userId = "test";
+ Map<String, String> params = new HashMap<>();
+ params.put("userId", "test");
+ List<BusinessCardApplicationRole> userAppRoles = null;
+ List<BusinessCardApplicationRole> expected = null;
+ Mockito.when(dataAccessService.executeNamedQuery("getUserApproles", params, null)).thenReturn(userAppRoles);
+ List<BusinessCardApplicationRole> actual = functionalMenuServiceImpl.getUserAppRolesList(userId);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserAppRolesListExceptionTest(){
+ String userId = "test";
+ Map<String, String> params = new HashMap<>();
+ params.put("userId", "test");
+ Mockito.when(dataAccessService.executeNamedQuery("getUserApproles", params, null));
+ List<BusinessCardApplicationRole> actual = functionalMenuServiceImpl.getUserAppRolesList(userId);
+ }
+
+ @Test
+ public void createFunctionalMenuItem400StautusTest(){
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(400l);
+ FieldsValidator actual = functionalMenuServiceImpl.createFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void createFunctionalMenuItemTest(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ functionalMenuItem.setRestrictedApp(true);
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.menuId = (long) 123;
+ functionalMenuItemWithRoles.url = "test";
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(400l);
+ DataAccessService dao = PowerMockito.mock(DataAccessService.class);
+ PowerMockito.when((List<FunctionalMenuItem>)dao.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(null);
+ FieldsValidator actual = functionalMenuServiceImpl.createFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void createFunctionalMenuItemExceptionTest1(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ functionalMenuItem.setRestrictedApp(true);
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.menuId = (long) 123;
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ DataAccessService dao = PowerMockito.mock(DataAccessService.class);
+ PowerMockito.when((List<FunctionalMenuItem>)dao.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(null);
+ FieldsValidator actual = functionalMenuServiceImpl.createFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void createFunctionalMenuItemTest1(){
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ functionalMenuItem.setRestrictedApp(true);
+ Criterion textCriterion = Restrictions.eq("text",functionalMenuItem.text);
+ restrictionsList.add(textCriterion);
+ FunctionalMenuItemWithRoles functionalMenuItemWithRoles = new FunctionalMenuItemWithRoles();
+ functionalMenuItemWithRoles.menuId = (long) 123;
+ List<FunctionalMenuItem> functionalMenuItemList = new ArrayList<FunctionalMenuItem>();
+ functionalMenuItemList.add(functionalMenuItem);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ Criteria criteria = Mockito.mock(Criteria.class);
+ DataAccessService dao = PowerMockito.mock(DataAccessService.class);
+ Mockito.when(session.createCriteria(FunctionalMenuItem.class)).thenReturn(criteria);
+ PowerMockito.when((List<FunctionalMenuItem>)dao.getList(FunctionalMenuItem.class, null, restrictionsList, null)).thenReturn(null);
+ FieldsValidator actual = functionalMenuServiceImpl.createFunctionalMenuItem(functionalMenuItemWithRoles);
+ assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode());
+ }
+
+ @Test
+ public void regenerateAncestorTableTest(){
+ FieldsValidator expected = new FieldsValidator ();
+ expected.setHttpStatusCode(200l);
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ SQLQuery query = Mockito.mock(SQLQuery.class);
+ String sql = "DELETE FROM fn_menu_functional_ancestors";
+ Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(query);
+ FieldsValidator actual = functionalMenuServiceImpl.regenerateAncestorTable();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void regenerateAncestorTableExceptionTest(){
+ FieldsValidator expected = new FieldsValidator ();
+ expected.setHttpStatusCode(500l);
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ SQLQuery query = Mockito.mock(SQLQuery.class);
+ String sql = "DELETE FROM fn_menu_functional_ancestors";
+ Mockito.when(session.createSQLQuery(sql)).thenReturn(query);
+ FieldsValidator actual = functionalMenuServiceImpl.regenerateAncestorTable();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void setFavoriteItemTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ FavoritesFunctionalMenuItem favoritesFunctionalMenuItem = new FavoritesFunctionalMenuItem ();
+ Mockito.doNothing().when(tx).commit();
+ FieldsValidator actual = functionalMenuServiceImpl.setFavoriteItem(favoritesFunctionalMenuItem);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void setFavoriteItemExceptionTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ FavoritesFunctionalMenuItem favoritesFunctionalMenuItem = new FavoritesFunctionalMenuItem ();
+ Mockito.doNothing().when(tx).commit();
+ FieldsValidator actual = functionalMenuServiceImpl.setFavoriteItem(favoritesFunctionalMenuItem);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void removeFavoriteItemTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.when(session.beginTransaction()).thenReturn(tx);
+ Mockito.doNothing().when(tx).commit();
+ FieldsValidator actual = functionalMenuServiceImpl.removeFavoriteItem((long)123, (long)123);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void removeFavoriteItemExceptionTest(){
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ Session session = PowerMockito.mock(Session.class);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Transaction tx = PowerMockito.mock(Transaction.class);
+ Mockito.doNothing().when(tx).commit();
+ FieldsValidator actual = functionalMenuServiceImpl.removeFavoriteItem((long)123, (long)123);
+ assertEquals(expected, actual);
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java
index 4c906ea4..0806d15d 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java
@@ -39,6 +39,8 @@ package org.onap.portalapp.portal.transport;
import static org.junit.Assert.*;
+import java.util.Date;
+
import org.junit.Test;
import org.onap.portalapp.portal.transport.AppCatalogPersonalization;
@@ -59,5 +61,44 @@ public class AppCatalogPersonalizationTest {
assertEquals(appCatalogPersonalization.hashCode(), appCatalogPersonalization1.hashCode());
assertTrue(appCatalogPersonalization.equals(appCatalogPersonalization1));
}
+
+ @Test
+ public void unt_hashCodeTest(){
+ AppCatalogPersonalization appCatalogPersonalization=new AppCatalogPersonalization();
+ appCatalogPersonalization.setAppId(123L);
+ appCatalogPersonalization.setPending(true);
+ appCatalogPersonalization.setSelect(true);
+ AppCatalogPersonalization appCatalogPersonalization1 = new AppCatalogPersonalization();
+ appCatalogPersonalization1.setAppId(123L);
+ appCatalogPersonalization1.setPending(true);
+ appCatalogPersonalization1.setSelect(true);
+ assertEquals(appCatalogPersonalization.hashCode(), appCatalogPersonalization1.hashCode());
+ assertTrue(appCatalogPersonalization.equals(appCatalogPersonalization1));
+
+ }
+
+ @Test
+ public void appCatalogPersonalizationTestwithAppId(){
+ AppCatalogPersonalization appCatalogPersonalization = mockAppCatalogPersonalization();
+ AppCatalogPersonalization appCatalogPersonalization1 = new AppCatalogPersonalization();
+ appCatalogPersonalization1.setAppId(123L);
+ assertFalse(appCatalogPersonalization.equals(appCatalogPersonalization1));
+ }
+
+ @Test
+ public void appCatalogPersonalizationTestwithpending(){
+ AppCatalogPersonalization appCatalogPersonalization = mockAppCatalogPersonalization();
+ AppCatalogPersonalization appCatalogPersonalization1 = new AppCatalogPersonalization();
+ appCatalogPersonalization1.setPending(true);
+ assertFalse(appCatalogPersonalization.equals(appCatalogPersonalization1));
+ }
+
+ @Test
+ public void appCatalogPersonalizationTestwithSelect(){
+ AppCatalogPersonalization appCatalogPersonalization = mockAppCatalogPersonalization();
+ AppCatalogPersonalization appCatalogPersonalization1 = new AppCatalogPersonalization();
+ appCatalogPersonalization1.setSelect(true);
+ assertFalse(appCatalogPersonalization.equals(appCatalogPersonalization1));
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java
index 21c079e0..584c212e 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java
@@ -80,4 +80,39 @@ public class AppsListWithAdminRoleTest {
assertEquals(appsListWithAdminRole.hashCode(), appsListWithAdminRole1.hashCode());
assertEquals(appsListWithAdminRole.toString(), "AppsListWithAdminRole [orgUserId=test, appsRoles=[AppNameIdIsAdmin [id=null, appName=null, isAdmin=null, restrictedApp=null]]]");
}
+
+ @Test
+ public void appsListWithAdminRoleTest1(){
+ AppsListWithAdminRole appsListWithAdminRole = mockAppsListWithAdminRole();
+ AppsListWithAdminRole appsListWithAdminRole1 = new AppsListWithAdminRole();
+ ArrayList<AppNameIdIsAdmin> appsRoles = new ArrayList<AppNameIdIsAdmin>();
+ AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin();
+ appsRoles.add(appNameIdIsAdmin);
+ appsListWithAdminRole1.setOrgUserId(null);
+ appsListWithAdminRole1.setAppsRoles(null);
+ assertFalse(appsListWithAdminRole.equals(appsListWithAdminRole1));
+ }
+
+ @Test
+ public void appsListWithAdminRoleTest2(){
+ AppsListWithAdminRole appsListWithAdminRole = mockAppsListWithAdminRole();
+ appsListWithAdminRole.setOrgUserId(null);
+ appsListWithAdminRole.setAppsRoles(null);
+ AppsListWithAdminRole appsListWithAdminRole1 = new AppsListWithAdminRole();
+
+ ArrayList<AppNameIdIsAdmin> appsRoles = new ArrayList<AppNameIdIsAdmin>();
+ AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin();
+ appsRoles.add(appNameIdIsAdmin);
+
+ appsListWithAdminRole1.setOrgUserId(null);
+ appsListWithAdminRole1.setAppsRoles(null);
+
+ assertEquals(appsListWithAdminRole.getOrgUserId(), null);
+ assertEquals(appsListWithAdminRole.getAppsRoles(), null);
+
+ assertTrue(appsListWithAdminRole.equals(appsListWithAdminRole1));
+ assertEquals(appsListWithAdminRole.hashCode(), appsListWithAdminRole1.hashCode());
+ assertEquals(appsListWithAdminRole.toString(), "AppsListWithAdminRole [orgUserId=null, appsRoles=null]");
+ }
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java
index 1eba42dd..26b673f9 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java
@@ -68,5 +68,9 @@ public class BulkUploadRoleFunctionTest {
assertEquals(bulkUploadRoleFunction.hashCode(), bulkUploadRoleFunction1.hashCode());
assertTrue(bulkUploadRoleFunction.equals(bulkUploadRoleFunction1));
+ BulkUploadRoleFunction bulkUploadRoleFunction2=new BulkUploadRoleFunction();
+ assertFalse(bulkUploadRoleFunction2.equals(bulkUploadRoleFunction1));
+ assertNotEquals(bulkUploadRoleFunction2.hashCode(), bulkUploadRoleFunction1.hashCode());
+
}
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java
index 07d983b9..e1e75b59 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java
@@ -39,10 +39,14 @@ package org.onap.portalapp.portal.transport;
import static org.junit.Assert.*;
+import java.util.Date;
+
import org.junit.Test;
import org.onap.portalapp.portal.transport.CentralApp;
public class CentralAppTest {
+
+ CentralApp centralApp=new CentralApp();
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",
@@ -83,4 +87,253 @@ public class CentralAppTest {
assertEquals(centralApp.hashCode(), centralApp1.hashCode());
}
+
+ @Test
+ public void unt_IdTest(){
+ Long defaultValue=123L;
+ centralApp.setId(defaultValue);
+ assertEquals(defaultValue, centralApp.getId());
+ }
+
+ @Test
+ public void unt_createdTest(){
+ Date defaultValue=new Date();
+ centralApp.setCreated(defaultValue);
+ assertEquals(defaultValue, centralApp.getCreated());
+ }
+
+ @Test
+ public void unt_modifiedTest(){
+ Date defaultValue=new Date();
+ centralApp.setCreated(defaultValue);
+ assertEquals(defaultValue, centralApp.getCreated());
+ }
+
+ @Test
+ public void unt_craetedIdTest(){
+ Long defaultValue=123L;
+ centralApp.setCreatedId(defaultValue);
+ assertEquals(defaultValue, centralApp.getCreatedId());
+ }
+
+ @Test
+ public void unt_modifiedIdTest(){
+ Long defaultValue=123L;
+ centralApp.setModifiedId(defaultValue);
+ assertEquals(defaultValue, centralApp.getModifiedId());
+ }
+
+ @Test
+ public void unt_rowNumTest(){
+ Long defaultValue=123L;
+ centralApp.setRowNum(defaultValue);
+ assertEquals(defaultValue, centralApp.getRowNum());
+ }
+
+
+ @Test
+ public void unt_nameTest(){
+ String defaultValue="test";
+ centralApp.setName(defaultValue);
+ assertEquals(defaultValue, centralApp.getName());
+ }
+
+ @Test
+ public void unt_ImageUrlTest(){
+ String defaultValue="test";
+ centralApp.setImageUrl(defaultValue);
+ assertEquals(defaultValue, centralApp.getImageUrl());
+ }
+
+ @Test
+ public void unt_descriptionTest(){
+ String defaultValue="test";
+ centralApp.setDescription(defaultValue);
+ assertEquals(defaultValue, centralApp.getDescription());
+ }
+
+ @Test
+ public void unt_notesTest(){
+ String defaultValue="test";
+ centralApp.setNotes(defaultValue);
+ assertEquals(defaultValue, centralApp.getNotes());
+ }
+
+ @Test
+ public void unt_urlTest(){
+ String defaultValue="testUrl";
+ centralApp.setUrl(defaultValue);
+ assertEquals(defaultValue, centralApp.getUrl());
+ }
+
+ @Test
+ public void unt_alternateUrlTest(){
+ String defaultValue="testUrl";
+ centralApp.setAlternateUrl(defaultValue);
+ assertEquals(defaultValue, centralApp.getAlternateUrl());
+ }
+
+ @Test
+ public void unt_restendpointTest(){
+ String defaultValue="testUrl";
+ centralApp.setRestEndpoint(defaultValue);
+ assertEquals(defaultValue, centralApp.getRestEndpoint());
+ }
+
+ @Test
+ public void unt_mlAppNameTest(){
+ String defaultValue="testAppName";
+ centralApp.setMlAppName(defaultValue);
+ assertEquals(defaultValue, centralApp.getMlAppName());
+ }
+
+ @Test
+ public void unt_mlAppAdminIdTest(){
+ String defaultValue="testAppAdminId";
+ centralApp.setMlAppAdminId(defaultValue);
+ assertEquals(defaultValue, centralApp.getMlAppAdminId());
+ }
+
+ @Test
+ public void unt_motsIdIdTest(){
+ String defaultValue="testmotsid";
+ centralApp.setMotsId(defaultValue);
+ assertEquals(defaultValue, centralApp.getMotsId());
+ }
+
+ @Test
+ public void unt_appPasswordTest(){
+ String defaultValue="TestAppPassword";
+ centralApp.setAppPassword(defaultValue);
+ assertEquals(defaultValue, centralApp.getAppPassword());
+ }
+
+ @Test
+ public void unt_openTest(){
+ String defaultValue="Testopen";
+ centralApp.setOpen(defaultValue);
+ assertEquals(defaultValue, centralApp.getOpen());
+ }
+
+ @Test
+ public void unt_enabledTest(){
+ String defaultValue="Testenable";
+ centralApp.setEnabled(defaultValue);
+ assertEquals(defaultValue, centralApp.getEnabled());
+ }
+
+ @Test
+ public void unt_thumbnailTest(){
+ byte[] defaultValue={1,2,3};
+ centralApp.setThumbnail(defaultValue);
+ assertEquals(defaultValue, centralApp.getThumbnail());
+ }
+
+ @Test
+ public void unt_userNameTest(){
+ String defaultValue="Testusername";
+ centralApp.setUsername(defaultValue);
+ assertEquals(defaultValue, centralApp.getUsername());
+ }
+
+ @Test
+ public void unt_uebKeyTest(){
+ String defaultValue="Testuebkey";
+ centralApp.setUebKey(defaultValue);
+ assertEquals(defaultValue, centralApp.getUebKey());
+ }
+
+ @Test
+ public void unt_uebSecreteTest(){
+ String defaultValue="Testuebscrete";
+ centralApp.setUebSecret(defaultValue);
+ assertEquals(defaultValue, centralApp.getUebSecret());
+ }
+
+ @Test
+ public void unt_uebTopicNameTest(){
+ String defaultValue="Testuebtopicname";
+ centralApp.setUebTopicName(defaultValue);
+ assertEquals(defaultValue, centralApp.getUebTopicName());
+ }
+
+ @Test
+ public void unt_hashCodeWithNullTest(){
+ CentralApp centralApp=new CentralApp(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+
+ CentralApp centralApp1=new CentralApp(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+
+ assertEquals(centralApp.hashCode(), centralApp1.hashCode());
+ assertTrue(centralApp.equals(centralApp1));
+
+ }
+
+ @Test
+ public void unt_hashCodeTest(){
+ 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");
+
+ 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");
+
+ assertEquals(centralApp.hashCode(), centralApp1.hashCode());
+ assertTrue(centralApp.equals(centralApp1));
+
+ }
+
+ @Test
+ public void unt_hashCodeTestWithNull(){
+ 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");
+ 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");
+ assertEquals(centralApp.hashCode(), centralApp1.hashCode());
+ assertFalse(centralApp.equals(null));
+
+ }
+
+ @Test
+ public void unt_hashCodeTestWithNull1(){
+ CentralApp centralApp=new CentralApp(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+ 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");
+ assertFalse(centralApp.equals(centralApp1));
+
+ }
+
+ @Test
+ public void unt_hashCodeTestWithalternateURL(){
+ CentralApp centralApp=new CentralApp(null, null, null, null, null, null, null, null, null, null, null, "test1", null, null, null, null, null, null, null, null, null, null, null, null);
+ 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");
+ assertFalse(centralApp.equals(centralApp1));
+
+ }
+
+ @Test
+ public void unt_hashCodeTestWithpassword(){
+ CentralApp centralApp=new CentralApp(null, null, null, null, null, null, null, null, null, null, null, "test", null, null, null, null, "testPass", null, null, null, null, null, null, null);
+ 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");
+ assertFalse(centralApp.equals(centralApp1));
+
+ }
+
+ @Test
+ public void unt_hashCodeTestWithcreateId(){
+ CentralApp centralApp=new CentralApp(null, null, null, 123L, null, null, null, null, null, null, null, "test", null, null, null, null, "test", null, null, null, null, null, null, null);
+ 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");
+ assertFalse(centralApp.equals(centralApp1));
+
+ }
+
+ @Test
+ public void unt_hashCodeTestWithcreateId1(){
+ CentralApp centralApp=new CentralApp(12L, null, null, 123L, 123L, 123L, "test1", "test1", "test1", "test1", "test1", "test", "tests1", "test1", "test1", null, "test", null, null, null, null, null, null, null);
+ 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");
+ assertFalse(centralApp.equals(centralApp1));
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java
index e019ae2f..5ba983c4 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java
@@ -37,14 +37,20 @@
*/
package org.onap.portalapp.portal.transport;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
+
+import java.util.Date;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.junit.Test;
public class CentralRoleTest {
- public CentralV2Role mockCentralRole(){
+ CentralRole centralRole=new CentralRole();
+
+
+ /*public CentralV2Role mockCentralRole(){
CentralV2Role centralV2Role = new CentralV2Role((long)1, null, null, (long)1, (long)1, (long)1,
"test", false, 1, null, null, null);
@@ -90,7 +96,109 @@ public class CentralRoleTest {
assertTrue(centralV2Role.equals(centralRole1));
assertEquals(centralV2Role, centralRole1);
assertEquals(centralRole2, new CentralV2Role((long)1, "test"));
+ }*/
+
+ @Test
+ public void unt_centralRoleConstructorTest(){
+ centralRole=new CentralRole(null, null, null, null, null, null, null, false, null, null, null, null);
+ assertEquals(false, centralRole.isActive());
+ }
+
+ @Test
+ public void unt_centralRoleConstructor2Test(){
+ centralRole=new CentralRole(null, null, false, null, null);
+ assertEquals(false, centralRole.isActive());
+ }
+
+ @Test
+ public void unt_IdTest(){
+ Long defaultValue=123L;
+ centralRole.setId(defaultValue);
+ assertEquals(defaultValue, centralRole.getId());
}
+ @Test
+ public void unt_createdTest(){
+ Date defaultValue=new Date();
+ centralRole.setCreated(defaultValue);
+ assertEquals(defaultValue, centralRole.getCreated());
+ }
+
+ @Test
+ public void unt_modifiedTest(){
+ Date defaultValue=new Date();
+ centralRole.setModified(defaultValue);
+ assertEquals(defaultValue, centralRole.getModified());
+ }
+
+ @Test
+ public void unt_modifiedIdTest(){
+ Long defaultValue=123L;
+ centralRole.setModifiedId(defaultValue);
+ assertEquals(defaultValue, centralRole.getModifiedId());
+ }
+
+ @Test
+ public void unt_createdIdTest(){
+ Long defaultValue=123L;
+ centralRole.setCreatedId(defaultValue);
+ assertEquals(defaultValue, centralRole.getCreatedId());
+ }
+
+ @Test
+ public void unt_rowNumTest(){
+ Long defaultValue=123L;
+ centralRole.setRowNum(defaultValue);
+ assertEquals(defaultValue, centralRole.getRowNum());
+ }
+
+ @Test
+ public void unt_nameTest(){
+ String defaultValue="test";
+ centralRole.setName(defaultValue);
+ assertEquals(defaultValue, centralRole.getName());
+ }
+
+ @Test
+ public void unt_activeTest(){
+ Boolean defaultValue=false;
+ centralRole.setActive(defaultValue);
+ assertEquals(defaultValue, centralRole.isActive());
+ }
+
+ @Test
+ public void unt_priorityTest(){
+ Integer defaultValue=123;
+ centralRole.setPriority(defaultValue);
+ assertEquals(defaultValue, centralRole.getPriority());
+ }
+
+ @Test
+ public void unt_getRoleFunctionsTest(){
+ //Integer defaultValue=123;
+ SortedSet<CentralRoleFunction> roleFunctions = new TreeSet<>();
+ CentralRoleFunction centralRoleFunction=new CentralRoleFunction();
+ roleFunctions.add(centralRoleFunction);
+ centralRole.setRoleFunctions(roleFunctions);
+ assertNotNull(centralRole.getRoleFunctions());
+ }
+
+ @Test
+ public void unt_childRolesTest(){
+ //Integer defaultValue=123;
+ SortedSet<CentralRole> centralRoles=new TreeSet<>();
+ //CentralRole centralRole=new CentralRole();
+ //centralRoles.add(centralRole);
+ centralRole.setChildRoles(centralRoles);
+ assertNotNull(centralRole.getChildRoles());
+ }
+
+ @Test
+ public void unt_parentRolesTest(){
+ //Integer defaultValue=123;
+ SortedSet<CentralRole> centralRoles=new TreeSet<>();
+ centralRole.setParentRoles(centralRoles);
+ assertNotNull(centralRole.getParentRoles());
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java
index 30e2440b..5500b6a3 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -38,6 +38,8 @@
package org.onap.portalapp.portal.transport;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
import org.onap.portalapp.portal.transport.CentralApp;
import org.onap.portalapp.portal.transport.CentralV2Role;
@@ -68,6 +70,7 @@ public class CentralUserAppTest {
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");
+
CentralV2Role role1 = new CentralV2Role();
assertEquals(centralV2UserApp.getUserId(), new Long(1));
@@ -75,4 +78,19 @@ public class CentralUserAppTest {
assertEquals(centralV2UserApp.getApp(), app1);
assertEquals(centralV2UserApp.getRole(), role1);
}
+
+ @Test
+ public void unt_hashCodeTest(){
+ AppCatalogPersonalization appCatalogPersonalization=new AppCatalogPersonalization();
+ appCatalogPersonalization.setAppId(123L);
+ appCatalogPersonalization.setPending(true);
+ appCatalogPersonalization.setSelect(true);
+ AppCatalogPersonalization appCatalogPersonalization1 = new AppCatalogPersonalization();
+ appCatalogPersonalization1.setAppId(123L);
+ appCatalogPersonalization1.setPending(true);
+ appCatalogPersonalization1.setSelect(true);
+ assertEquals(appCatalogPersonalization.hashCode(), appCatalogPersonalization1.hashCode());
+ assertTrue(appCatalogPersonalization.equals(appCatalogPersonalization1));
+
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java
index 0b3a3e2b..b8c019b0 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -39,6 +39,7 @@ package org.onap.portalapp.portal.transport;
import static org.junit.Assert.*;
+import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@@ -49,6 +50,8 @@ import org.onap.portalapp.portal.transport.CentralV2UserApp;
public class CentralUserTest {
+ CentralUser centralUser=new CentralUser(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, false, null, null, false, null, null);
+
public CentralV2User mockCentralUser(){
Set<CentralV2UserApp> userApps = new HashSet<CentralV2UserApp>();
Set<CentralV2Role> pseudoRoles = new HashSet<CentralV2Role>();
@@ -86,4 +89,375 @@ public class CentralUserTest {
assertEquals(centralV2User.hashCode(), centralV2User1.hashCode());
assertTrue(centralV2User.equals(centralV2User1));
}
+
+ @Test
+ public void unt_IdTest(){
+ Long defaultValue=123L;
+ centralUser.setId(defaultValue);
+ assertEquals(defaultValue, centralUser.getId());
+ }
+
+ @Test
+ public void unt_createdTest(){
+ Date defaultValue=new Date();
+ centralUser.setCreated(defaultValue);
+ assertEquals(defaultValue, centralUser.getCreated());
+ }
+
+ @Test
+ public void unt_modifiedTest(){
+ Date defaultValue=new Date();
+ centralUser.setModified(defaultValue);
+ assertEquals(defaultValue, centralUser.getModified());
+ }
+
+ @Test
+ public void unt_createdIdTest(){
+ Long defaultValue=123L;
+ centralUser.setCreatedId(defaultValue);
+ assertEquals(defaultValue, centralUser.getCreatedId());
+ }
+
+ @Test
+ public void unt_modifiedIdTest(){
+ Long defaultValue=123L;
+ centralUser.setModifiedId(defaultValue);
+ assertEquals(defaultValue, centralUser.getModifiedId());
+ }
+
+ @Test
+ public void unt_rowNumTest(){
+ Long defaultValue=123L;
+ centralUser.setRowNum(defaultValue);
+ assertEquals(defaultValue, centralUser.getRowNum());
+ }
+
+ @Test
+ public void unt_orgIdTest(){
+ Long defaultValue=123L;
+ centralUser.setOrgId(defaultValue);
+ assertEquals(defaultValue, centralUser.getOrgId());
+ }
+
+ @Test
+ public void unt_managerIdTest(){
+ Long defaultValue=123L;
+ centralUser.setManagerId(defaultValue);
+ assertEquals(defaultValue, centralUser.getManagerId());
+ }
+
+ @Test
+ public void unt_firstNameTest(){
+ String defaultValue="test";
+ centralUser.setFirstName(defaultValue);
+ assertEquals(defaultValue, centralUser.getFirstName());
+ }
+
+ @Test
+ public void unt_middleInitialTest(){
+ String defaultValue="test";
+ centralUser.setMiddleInitial(defaultValue);
+ assertEquals(defaultValue, centralUser.getMiddleInitial());
+ }
+
+ @Test
+ public void unt_lastNameTest(){
+ String defaultValue="test";
+ centralUser.setLastName(defaultValue);
+ assertEquals(defaultValue, centralUser.getLastName());
+ }
+
+ @Test
+ public void unt_phoneTest(){
+ String defaultValue="test";
+ centralUser.setPhone(defaultValue);
+ assertEquals(defaultValue, centralUser.getPhone());
+ }
+
+ @Test
+ public void unt_faxTest(){
+ String defaultValue="test";
+ centralUser.setFax(defaultValue);
+ assertEquals(defaultValue, centralUser.getFax());
+ }
+
+ @Test
+ public void unt_cellularTest(){
+ String defaultValue="test";
+ centralUser.setCellular(defaultValue);
+ assertEquals(defaultValue, centralUser.getCellular());
+ }
+
+ @Test
+ public void unt_emailTest(){
+ String defaultValue="test";
+ centralUser.setEmail(defaultValue);
+ assertEquals(defaultValue, centralUser.getEmail());
+ }
+
+ @Test
+ public void unt_addressTest(){
+ Long defaultValue=123L;
+ centralUser.setAddressId(defaultValue);
+ assertEquals(defaultValue, centralUser.getAddressId());
+ }
+
+ @Test
+ public void unt_alertMethodCdTest(){
+ String defaultValue="testAlert";
+ centralUser.setAlertMethodCd(defaultValue);
+ assertEquals(defaultValue, centralUser.getAlertMethodCd());
+ }
+
+ @Test
+ public void unt_hridTest(){
+ String defaultValue="testHrid";
+ centralUser.setHrid(defaultValue);
+ assertEquals(defaultValue, centralUser.getHrid());
+ }
+
+ @Test
+ public void unt_orgUserIdTest(){
+ String defaultValue="testorgUseriD";
+ centralUser.setOrgUserId(defaultValue);
+ assertEquals(defaultValue, centralUser.getOrgUserId());
+ }
+
+ @Test
+ public void unt_orgCodeTest(){
+ String defaultValue="testorgcode";
+ centralUser.setOrgCode(defaultValue);
+ assertEquals(defaultValue, centralUser.getOrgCode());
+ }
+
+ @Test
+ public void unt_address1Test(){
+ String defaultValue="testaddress1";
+ centralUser.setAddress1(defaultValue);
+ assertEquals(defaultValue, centralUser.getAddress1());
+ }
+
+ @Test
+ public void unt_address2Test(){
+ String defaultValue="testaddress2";
+ centralUser.setAddress2(defaultValue);
+ assertEquals(defaultValue, centralUser.getAddress2());
+ }
+
+ @Test
+ public void unt_cityTest(){
+ String defaultValue="testcity";
+ centralUser.setCity(defaultValue);
+ assertEquals(defaultValue, centralUser.getCity());
+ }
+
+ @Test
+ public void unt_stateTest(){
+ String defaultValue="testcity";
+ centralUser.setState(defaultValue);
+ assertEquals(defaultValue, centralUser.getState());
+ }
+
+ @Test
+ public void unt_zipcodeTest(){
+ String defaultValue="testzipcode";
+ centralUser.setZipCode(defaultValue);
+ assertEquals(defaultValue, centralUser.getZipCode());
+ }
+
+ @Test
+ public void unt_countryTest(){
+ String defaultValue="testcountry";
+ centralUser.setCountry(defaultValue);
+ assertEquals(defaultValue, centralUser.getCountry());
+ }
+
+ @Test
+ public void unt_orgManagerUserIdTest(){
+ String defaultValue="testOrgManagerUserId";
+ centralUser.setOrgManagerUserId(defaultValue);
+ assertEquals(defaultValue, centralUser.getOrgManagerUserId());
+ }
+
+ @Test
+ public void unt_locationClliTest(){
+ String defaultValue="testLocationClli";
+ centralUser.setLocationClli(defaultValue);
+ assertEquals(defaultValue, centralUser.getLocationClli());
+ }
+
+ @Test
+ public void unt_businessCountryCodeTest(){
+ String defaultValue="testBusinessCountryCode";
+ centralUser.setBusinessCountryCode(defaultValue);
+ assertEquals(defaultValue, centralUser.getBusinessCountryCode());
+ }
+
+ @Test
+ public void unt_businessCountryNameTest(){
+ String defaultValue="testBusinessCountryName";
+ centralUser.setBusinessCountryName(defaultValue);
+ assertEquals(defaultValue, centralUser.getBusinessCountryName());
+ }
+
+ @Test
+ public void unt_businessUnitTest(){
+ String defaultValue="testBusinessUnit";
+ centralUser.setBusinessUnit(defaultValue);
+ assertEquals(defaultValue, centralUser.getBusinessUnit());
+ }
+
+ @Test
+ public void unt_businessUnitNameTest(){
+ String defaultValue="testBusinessUnitName";
+ centralUser.setBusinessUnitName(defaultValue);
+ assertEquals(defaultValue, centralUser.getBusinessUnitName());
+ }
+
+ @Test
+ public void unt_departmentTest(){
+ String defaultValue="testdepartment";
+ centralUser.setDepartment(defaultValue);
+ assertEquals(defaultValue, centralUser.getDepartment());
+ }
+
+ @Test
+ public void unt_departmentNameTest(){
+ String defaultValue="testdepartmentName";
+ centralUser.setDepartmentName(defaultValue);
+ assertEquals(defaultValue, centralUser.getDepartmentName());
+ }
+
+ @Test
+ public void unt_companyCodeTest(){
+ String defaultValue="testcompanyCode";
+ centralUser.setCompanyCode(defaultValue);
+ assertEquals(defaultValue, centralUser.getCompanyCode());
+ }
+
+ @Test
+ public void unt_companyTest(){
+ String defaultValue="testcompany";
+ centralUser.setCompany(defaultValue);
+ assertEquals(defaultValue, centralUser.getCompany());
+ }
+
+ @Test
+ public void unt_zipcodeSuffixTest(){
+ String defaultValue="testcompany";
+ centralUser.setZipCodeSuffix(defaultValue);
+ assertEquals(defaultValue, centralUser.getZipCodeSuffix());
+ }
+
+ @Test
+ public void unt_jobTitleTest(){
+ String defaultValue="testjobTitle";
+ centralUser.setJobTitle(defaultValue);
+ assertEquals(defaultValue, centralUser.getJobTitle());
+ }
+
+ @Test
+ public void unt_commandChainTest(){
+ String defaultValue="testcommandChain";
+ centralUser.setCommandChain(defaultValue);
+ assertEquals(defaultValue, centralUser.getCommandChain());
+ }
+
+ @Test
+ public void unt_siloStatusTest(){
+ String defaultValue="testcommandChain";
+ centralUser.setSiloStatus(defaultValue);
+ assertEquals(defaultValue, centralUser.getSiloStatus());
+ }
+
+ @Test
+ public void unt_costCenterTest(){
+ String defaultValue="testcommandChain";
+ centralUser.setCostCenter(defaultValue);
+ assertEquals(defaultValue, centralUser.getCostCenter());
+ }
+
+ @Test
+ public void unt_financialLocCodeTest(){
+ String defaultValue="testcommandChain";
+ centralUser.setFinancialLocCode(defaultValue);
+ assertEquals(defaultValue, centralUser.getFinancialLocCode());
+ }
+
+ @Test
+ public void unt_loginIdTest(){
+ String defaultValue="testcommandChain";
+ centralUser.setLoginId(defaultValue);
+ assertEquals(defaultValue, centralUser.getLoginId());
+ }
+
+ @Test
+ public void unt_loginPwdTest(){
+ String defaultValue="testcommandChain";
+ centralUser.setLoginPwd(defaultValue);
+ assertEquals(defaultValue, centralUser.getLoginPwd());
+ }
+
+ @Test
+ public void unt_lastLoginDateTest(){
+ Date defaultValue=new Date();
+ centralUser.setLastLoginDate(defaultValue);
+ assertEquals(defaultValue, centralUser.getLastLoginDate());
+ }
+
+ @Test
+ public void unt_activeTest(){
+ boolean defaultValue= false;
+ centralUser.setActive(defaultValue);
+ assertEquals(defaultValue, centralUser.isActive());
+ }
+
+ @Test
+ public void unt_internalTest(){
+ boolean defaultValue= false;
+ centralUser.setInternal(defaultValue);
+ assertEquals(defaultValue, centralUser.isInternal());
+ }
+
+ @Test
+ public void unt_selectedProfileIdTest(){
+ Long defaultValue= (long)123;
+ centralUser.setSelectedProfileId(defaultValue);
+ assertEquals(defaultValue, centralUser.getSelectedProfileId());
+ }
+
+ @Test
+ public void unt_timeZoneIdTest(){
+ Long defaultValue= (long)123;
+ centralUser.setTimeZoneId(defaultValue);
+ assertEquals(defaultValue, centralUser.getTimeZoneId());
+ }
+
+ @Test
+ public void unt_onlineTest(){
+ boolean defaultValue= false;
+ centralUser.setOnline(defaultValue);
+ assertEquals(defaultValue, centralUser.isOnline());
+ }
+
+ @Test
+ public void unt_chatIdTest(){
+ String defaultValue= "false";
+ centralUser.setChatId(defaultValue);
+ assertEquals(defaultValue, centralUser.getChatId());
+ }
+
+ @Test
+ public void unt_userAppsTest(){
+ Set<CentralUserApp> userApps= new HashSet<CentralUserApp>();
+ centralUser.setUserApps(userApps);
+ assertEquals(userApps, centralUser.getUserApps());
+ }
+
+ @Test
+ public void unt_getPseudoRolesTest(){
+ Set<CentralRole> centralRoles= new HashSet<CentralRole>();
+ centralUser.setPseudoRoles(centralRoles);
+ assertEquals(centralRoles, centralUser.getPseudoRoles());
+ }
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAuthUserRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAuthUserRoleTest.java
new file mode 100644
index 00000000..8a373b22
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAuthUserRoleTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.transport;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ExternalAuthUserRoleTest {
+
+ public ExternalAuthUserRole mockExternalAuthUserRole(){
+ ExternalAuthUserRole externalAuthUserRole = new ExternalAuthUserRole();
+ externalAuthUserRole.setRole("test");
+ externalAuthUserRole.setUser("test");
+ externalAuthUserRole.setExpiryDate("test");
+ return externalAuthUserRole;
+ }
+
+ @Test
+ public void externalAuthUserRoleTest(){
+ ExternalAuthUserRole externalAuthUserRole = mockExternalAuthUserRole();
+
+ assertEquals(externalAuthUserRole.getRole(), "test");
+ assertEquals(externalAuthUserRole.getUser(), "test");
+
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidatorTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidatorTest.java
new file mode 100644
index 00000000..999cbfc4
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidatorTest.java
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.transport;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+
+import javax.validation.constraints.AssertFalse;
+
+import org.junit.Test;
+
+public class ExternalRequestFieldsValidatorTest {
+
+
+ ExternalRequestFieldsValidator externalRequestFieldsValidator= new ExternalRequestFieldsValidator(false,"test");
+
+ @Test
+ public void unt_isResultTest(){
+ Boolean defaultValue=false;
+ externalRequestFieldsValidator.setResult(false);
+ assertEquals(defaultValue, externalRequestFieldsValidator.isResult());
+ }
+
+ @Test
+ public void unt_detailMessageTest(){
+ String defaultValue="test";
+ externalRequestFieldsValidator.setDetailMessage("test");
+ assertEquals(defaultValue, externalRequestFieldsValidator.getDetailMessage());
+ }
+
+ @Test
+ public void unt_hashCodeTest(){
+ ExternalRequestFieldsValidator externalRequestFieldsValidator= new ExternalRequestFieldsValidator(false,"test");
+ ExternalRequestFieldsValidator externalRequestFieldsValidator1= new ExternalRequestFieldsValidator(false,"test");
+ assertEquals(externalRequestFieldsValidator.hashCode(), externalRequestFieldsValidator1.hashCode());
+ assertTrue(externalRequestFieldsValidator.equals(externalRequestFieldsValidator1));
+
+ }
+
+ @Test
+ public void unt_hashCodeWithNullTest(){
+ ExternalRequestFieldsValidator externalRequestFieldsValidator= new ExternalRequestFieldsValidator(false,null);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator1= new ExternalRequestFieldsValidator(false,null);
+ assertEquals(externalRequestFieldsValidator.hashCode(), externalRequestFieldsValidator1.hashCode());
+ assertTrue(externalRequestFieldsValidator.equals(externalRequestFieldsValidator1));
+
+ }
+
+ @Test
+ public void unt_hashCodeWithNullTest1(){
+ ExternalRequestFieldsValidator externalRequestFieldsValidator= new ExternalRequestFieldsValidator(false,null);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator1= new ExternalRequestFieldsValidator(false,null);
+ assertEquals(externalRequestFieldsValidator.hashCode(), externalRequestFieldsValidator1.hashCode());
+ assertFalse(externalRequestFieldsValidator.equals(null));
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleTest.java
new file mode 100644
index 00000000..11b979f3
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleTest.java
@@ -0,0 +1,82 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.transport;
+
+//@RunWith(PowerMockRunner.class)
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class RemoteRoleTest {
+ RemoteRole remoteRole;
+ private String NAME = "test";
+ private Long ID = 12L;
+ private Set<String> ROLEFUNCTIONS = new HashSet<String>();
+
+ @Before
+ public void setUp() {
+ remoteRole = new RemoteRole();
+ remoteRole.setRoleFunctions(ROLEFUNCTIONS);
+ remoteRole.setName(NAME);
+ remoteRole.setId(ID);
+ }
+
+
+ @Test
+ public void testNotNull() {
+ assertNotNull(remoteRole);
+ }
+
+ @Test
+ public void testRemoteRoleProperties() {
+ assertEquals(ROLEFUNCTIONS, remoteRole.getRoleFunctions());
+ assertEquals(ID, remoteRole.getId());
+ assertEquals(NAME, remoteRole.getName());
+ }
+
+ @Test
+ public void testequals() {
+ assertEquals(true, remoteRole.equals(remoteRole));
+ }
+
+} \ No newline at end of file
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleV1Test.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleV1Test.java
new file mode 100644
index 00000000..27652d30
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteRoleV1Test.java
@@ -0,0 +1,94 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.transport;
+
+//@RunWith(PowerMockRunner.class)
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class RemoteRoleV1Test {
+ RemoteRoleV1 remoteRoleV1;
+ private String NAME = "test";
+ private Long ID = 12L;
+
+ @Before
+ public void setUp() {
+ remoteRoleV1 = new RemoteRoleV1();
+ remoteRoleV1.setName(NAME);
+ remoteRoleV1.setId(ID);
+ }
+
+
+ @Test
+ public void testNotNull() {
+ assertNotNull(remoteRoleV1);
+ }
+
+ @Test
+ public void testRemoteRoleV1Properties() {
+ assertEquals(ID, remoteRoleV1.getId());
+ assertEquals(NAME, remoteRoleV1.getName());
+ }
+
+ @Test
+ public void remoteRoleV1Test(){
+
+ RemoteRoleV1 remoteRoleV11 = new RemoteRoleV1();
+ RemoteRoleV1 remoteRoleV12 = new RemoteRoleV1();
+ RemoteRoleV1 remoteRoleV13 = new RemoteRoleV1();
+ remoteRoleV13.setId(12L);
+ remoteRoleV13.setName("test");
+
+ assertEquals(new Long(12), remoteRoleV1.getId());
+ assertEquals(remoteRoleV1.getName(), "test");
+ assertEquals(remoteRoleV1.hashCode(), remoteRoleV13.hashCode());
+
+ assertTrue(remoteRoleV11.equals(new RemoteRoleV1()));
+ assertTrue(remoteRoleV12.equals(new RemoteRoleV1()));
+ }
+
+ @Test
+ public void testcompareTo() {
+ assertEquals(0, remoteRoleV1.compareTo(remoteRoleV1));
+ }
+
+} \ No newline at end of file
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/CustomLoggingFilterTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/CustomLoggingFilterTest.java
new file mode 100644
index 00000000..1dba3167
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/CustomLoggingFilterTest.java
@@ -0,0 +1,81 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.portal.utils;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.spi.FilterReply;
+
+public class CustomLoggingFilterTest {
+
+ @Test
+ public void decideTest(){
+ ILoggingEvent event = Mockito.mock(ILoggingEvent.class);
+ Mockito.when(event.getLevel()).thenReturn(Level.ERROR);
+ Mockito.when(event.getThreadName()).thenReturn("UEBConsumerThread");
+ Mockito.when(event.getLoggerName()).thenReturn("org.onap.nsa");
+ CustomLoggingFilter customLoggingFilter = new CustomLoggingFilter();
+ FilterReply reply = customLoggingFilter.decide(event);
+ Assert.assertEquals( FilterReply.DENY, reply);
+ }
+
+ @Test
+ public void decideNEUTRALTest(){
+ ILoggingEvent event = Mockito.mock(ILoggingEvent.class);
+ Mockito.when(event.getLevel()).thenReturn(Level.ERROR);
+ Mockito.when(event.getThreadName()).thenReturn("UEBConsumerThread");
+ Mockito.when(event.getLoggerName()).thenReturn("test");
+ CustomLoggingFilter customLoggingFilter = new CustomLoggingFilter();
+ FilterReply reply = customLoggingFilter.decide(event);
+ Assert.assertEquals( FilterReply.NEUTRAL, reply);
+ }
+
+ @Test
+ public void decideExceptionTest(){
+ ILoggingEvent event = Mockito.mock(ILoggingEvent.class);
+ Mockito.when(event.getLevel()).thenReturn(Level.ERROR);
+ Mockito.when(event.getThreadName()).thenReturn("UEBConsumerThread");
+ CustomLoggingFilter customLoggingFilter = new CustomLoggingFilter();
+ FilterReply reply = customLoggingFilter.decide(event);
+ Assert.assertEquals( FilterReply.NEUTRAL, reply);
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/CoreTimeoutHandlerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/CoreTimeoutHandlerTest.java
new file mode 100644
index 00000000..1ad645b8
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/CoreTimeoutHandlerTest.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portalapp.service.sessionmgt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalsdk.core.domain.sessionmgt.TimeoutVO;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+
+public class CoreTimeoutHandlerTest {
+
+ @Mock
+ HttpSession session;
+ @InjectMocks
+ CoreTimeoutHandler coreTimeoutHandler;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+
+ }
+
+
+
+ @Test
+ public void testSessionCreated() {
+ Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("testPortal");
+ coreTimeoutHandler.sessionCreated("testPortal", "testSession", session);
+ }
+
+ @Test
+ public void testGatherSessionExtenstions()throws Exception {
+ Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("testPortal-testSession");
+ coreTimeoutHandler.sessionCreated("testPortal", "testSession", session);
+ coreTimeoutHandler.gatherSessionExtenstions();
+ TimeoutVO timeoutVO=new TimeoutVO("testSession", 1800l);
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, TimeoutVO> sessionTimeoutMap=new HashMap<>();
+ sessionTimeoutMap.put("testPortal", timeoutVO);
+ String sessionTimeoutMapStr= mapper.writeValueAsString(sessionTimeoutMap);
+ coreTimeoutHandler.updateSessionExtensions(sessionTimeoutMapStr);
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationVersionControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationVersionControllerTest.java
new file mode 100644
index 00000000..35ecec80
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationVersionControllerTest.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ */
+package org.onap.portalapp.service.sessionmgt;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+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.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.annotation.ApiVersion;
+import org.onap.portalapp.controller.sessionmgt.SessionCommunicationController;
+import org.onap.portalapp.controller.sessionmgt.SessionCommunicationVersionController;
+import org.onap.portalapp.portal.framework.MockitoTestSuite;
+import org.powermock.api.mockito.PowerMockito;
+import org.springframework.aop.support.AopUtils;
+
+public class SessionCommunicationVersionControllerTest {
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ SessionCommunicationVersionController sessionCommunicationVersionController;
+
+ @Mock
+ SessionCommunicationController sessionCommunicationController;
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void getSessionSlotCheckIntervalTest() throws Exception {
+ Mockito.when(sessionCommunicationController.getSessionSlotCheckInterval(mockedRequest, mockedResponse)).thenReturn(1);
+ int result = sessionCommunicationVersionController.getSessionSlotCheckInterval(mockedRequest, mockedResponse);
+ assertEquals(result, 1);
+
+ }
+
+ @Test
+ public void extendSessionTimeOutsTest() throws Exception {
+ Mockito.when(sessionCommunicationController.extendSessionTimeOuts(mockedRequest, mockedResponse,"testsession")).thenReturn(true);
+ boolean result = sessionCommunicationVersionController.extendSessionTimeOuts(mockedRequest, mockedResponse,"testsession");
+ assertEquals(result, true);
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/FunctionalMenuHandlerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/FunctionalMenuHandlerTest.java
new file mode 100644
index 00000000..4e7f5fe9
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/FunctionalMenuHandlerTest.java
@@ -0,0 +1,131 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portalapp.uebhandler;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+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.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.framework.MockitoTestSuite;
+import org.onap.portalapp.portal.service.AdminRolesService;
+import org.onap.portalapp.portal.service.FunctionalMenuService;
+import org.onap.portalapp.portal.service.SearchService;
+import org.onap.portalapp.portal.transport.FunctionalMenuItem;
+import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
+
+public class FunctionalMenuHandlerTest {
+
+ @InjectMocks
+ FunctionalMenuHandler functionalMenuHandler = new FunctionalMenuHandler();
+
+ @Mock
+ private AdminRolesService adminRolesService;
+
+ @Mock
+ private FunctionalMenuService functionalMenuService;
+
+ @Mock
+ private SearchService searchSvc;
+
+ @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();
+
+ //@Ignore
+ @Test
+ public void getFunctionalMenuTest() throws IOException {
+
+ UebMsg uebMsg=new UebMsg();
+ uebMsg.putMsgId("1");
+
+ uebMsg.putMsgType("testType");
+
+ Boolean actualResponse = functionalMenuHandler.getFunctionalMenu(null);
+
+ assertFalse(actualResponse);
+ uebMsg.putSourceTopicName("test");
+ actualResponse = functionalMenuHandler.getFunctionalMenu(uebMsg);
+ uebMsg.putUserId("123");
+
+ EPUser user = new EPUser();
+ user.setOrgUserId("123");
+ user.setFirstName("TestFirstName");
+ user.setLastName("TestLastName");
+ List<FunctionalMenuItem> menuItems=new ArrayList<>();
+ FunctionalMenuItem menu=new FunctionalMenuItem();
+ menu.setUrl("test");
+ menu.setRestrictedApp(true);
+ menuItems.add(menu);
+
+ Mockito.when(searchSvc.searchUserByUserId(uebMsg.getUserId())).thenReturn(user);
+ Mockito.when(functionalMenuService.getFunctionalMenuItems()).thenReturn(menuItems);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ actualResponse = functionalMenuHandler.getFunctionalMenu(uebMsg);
+ assertTrue(actualResponse);
+
+ uebMsg.putUserId("245");
+ Mockito.when(searchSvc.searchUserByUserId(uebMsg.getUserId())).thenReturn(null);
+ actualResponse = functionalMenuHandler.getFunctionalMenu(uebMsg);
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/InitUebHandlerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/InitUebHandlerTest.java
new file mode 100644
index 00000000..7e4eb3be
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/uebhandler/InitUebHandlerTest.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portalapp.uebhandler;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+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.onap.portalapp.portal.controller.ExternalAccessRolesController;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalapp.portal.utils.PortalConstants;
+import org.onap.portalsdk.core.onboarding.ueb.UebManager;
+import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.onap.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({ EcompPortalUtils.class, PortalConstants.class, SystemProperties.class,
+ EPCommonSystemProperties.class, PortalApiProperties.class,PortalApiConstants.class,UebManager.class })
+public class InitUebHandlerTest {
+
+ @Mock
+ MainUebHandler mainUebHandler;
+
+ @InjectMocks
+ InitUebHandler initUebHandler=new InitUebHandler();
+
+ @Mock
+ UebManager uebManager1;
+
+ @Test
+ public void initUebTestWithException() throws Exception {
+ PowerMockito.mockStatic(PortalApiProperties.class);
+ initUebHandler.initUeb();
+ }
+
+ @Test
+ public void initUebTest() throws Exception {
+ PowerMockito.mockStatic(PortalApiProperties.class);
+ PowerMockito.mockStatic(PortalApiConstants.class);
+ Mockito.when(PortalApiProperties.getProperty(Matchers.any())).thenReturn("test");
+ //Mockito.when(methodCall)
+ initUebHandler.initUeb();
+ }
+
+ @SuppressWarnings("static-access")
+ @Test
+ public void initUebTest1() throws Exception {
+ PowerMockito.mockStatic(PortalApiProperties.class);
+ PowerMockito.mockStatic(PortalApiConstants.class);
+ PowerMockito.mockStatic(UebManager.class);
+ UebMsg uebMsg=new UebMsg();
+ uebMsg.putMsgId("12");
+ uebMsg.putMsgType("test");
+ uebMsg.putPayload("samplePayload");
+ uebMsg.putUserId("13");
+ ConcurrentLinkedQueue<UebMsg> inboxQueue = new ConcurrentLinkedQueue<UebMsg>();
+ Mockito.when(PortalApiProperties.getProperty(Matchers.any())).thenReturn("TRUE");
+ Mockito.when(UebManager.getInstance()).thenReturn(uebManager1);
+ initUebHandler.initUeb();
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java
new file mode 100644
index 00000000..7383330d
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java
@@ -0,0 +1,425 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.Vector;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.codec.binary.Hex;
+import org.drools.core.command.assertion.AssertEquals;
+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.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPRole;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.EPUserApp;
+import org.onap.portalapp.portal.exceptions.RoleFunctionException;
+import org.onap.portalapp.portal.framework.MockitoTestSuite;
+import org.onap.portalapp.portal.service.EPRoleFunctionService;
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.exception.SessionExpiredException;
+import org.onap.portalsdk.core.menu.MenuBuilder;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.AppUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import org.apache.commons.codec.DecoderException;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({SystemProperties.class,AppUtils.class,Hex.class,MenuBuilder.class})
+public class EPUserUtilsTest {
+
+/* @Before
+ public void setup() {
+ //DataAccessService dataAccessService=Mockito.mock(DataAccessService.class);
+ }*/
+
+ @Mock
+ DataAccessService dataAccessService;
+
+ @Mock
+ EPRoleFunctionService epRoleFunctionService;
+
+ /*@Mock
+ DataAccessService dataAccessService;*/
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ MockEPUser mockUser = new MockEPUser();
+
+
+ @Test
+ public void getUserIdAsLongTest() {
+ Long expectedUserId=1L;
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1");
+ Long userId=EPUserUtils.getUserIdAsLong(mockedRequest);
+ assertEquals(userId,expectedUserId);
+ }
+
+ @Test
+ public void getUserIdAsLongTestWithRequestNull() {
+ Long expectedUserId=-1L;
+ EPUser user = mockUser.mockEPUser();
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Long userId=EPUserUtils.getUserIdAsLong(mockedRequest);
+ assertEquals(userId,expectedUserId);
+
+ }
+
+ @Test
+ public void setDataAccessServiceTest() throws RoleFunctionException{
+
+ }
+
+ @Test
+ public void getUserIdAsLongWithExceptionTest() {
+ Long expectedUserId=1L;
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1");
+ Long userId=EPUserUtils.getUserIdAsLong(mockedRequest);
+ assertEquals(userId,expectedUserId);
+ }
+
+ @Test
+ public void getRequestIdTestWithException() {
+ String expectedRequestId="c6f9542c-7378-4995-9ee3-cb498710e1ea";
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1");
+ String requestId=EPUserUtils.getRequestId(mockedRequest);
+ assertNotNull(requestId);
+ }
+
+
+
+ @Test
+ public void getRequestIdTest() {
+ String expectedRequestId=UUID.randomUUID().toString();
+ Enumeration<String> enums;
+ Vector<String> attrs = new Vector<String>();
+ attrs.add("ff_test");
+ enums = attrs.elements();
+ Mockito.when(mockedRequest.getHeaderNames()).thenReturn(enums);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1");
+ String requestId=EPUserUtils.getRequestId(mockedRequest);
+ assertNotNull(requestId);
+ }
+
+
+ @Test
+ public void getRequestIdTestWithSess() {
+ Enumeration<String> enums;
+ Vector<String> attrs = new Vector<String>();
+ attrs.add("X-ECOMP-RequestID");
+ enums = attrs.elements();
+ Mockito.when(mockedRequest.getHeaderNames()).thenReturn(enums);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1");
+ Mockito.when(mockedRequest.getHeader("X-ECOMP-RequestID")).thenReturn("test");
+ String requestId=EPUserUtils.getRequestId(mockedRequest);
+ assertNotNull(requestId);
+
+ }
+
+ @Test
+ public void getFullURLTest(){
+ String expected="test?testString";
+ StringBuffer stringBuffer = new StringBuffer("test");
+ Mockito.when(mockedRequest.getRequestURL()).thenReturn(stringBuffer);
+ Mockito.when(mockedRequest.getQueryString()).thenReturn("testString");
+ String actual=EPUserUtils.getFullURL(mockedRequest);
+ assertEquals(actual,expected);
+ }
+
+ @Test
+ public void getFullURLTestWithQueryStringNull(){
+ String expected="test";
+ StringBuffer stringBuffer = new StringBuffer("test");
+ Mockito.when(mockedRequest.getRequestURL()).thenReturn(stringBuffer);
+ Mockito.when(mockedRequest.getQueryString()).thenReturn(null);
+ String actual=EPUserUtils.getFullURL(mockedRequest);
+ assertEquals(actual,expected);
+
+ }
+
+
+
+ @Test
+ public void getFullURLTestWithRequestNull(){
+ String expected="";
+ StringBuffer stringBuffer = new StringBuffer("test");
+ Mockito.when(mockedRequest.getRequestURL()).thenReturn(stringBuffer);
+ Mockito.when(mockedRequest.getQueryString()).thenReturn(null);
+ String actual=EPUserUtils.getFullURL(null);
+ assertEquals(actual,expected);
+
+ }
+
+ @Test
+ public void getUserIdTest(){
+ int expected=1;
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1");
+ int actual=EPUserUtils.getUserId(mockedRequest);
+ assertEquals(actual,expected);
+
+ }
+
+ @Test
+ public void hasRoleTest(){
+ boolean expected=false;
+ EPUser user = mockUser.mockEPUser();
+ boolean actual=EPUserUtils.hasRole(user, "12");
+ assertEquals(actual,expected);
+
+ }
+
+ @Test
+ public void getRolesTest(){
+ HashMap roles=new HashMap<>();
+ roles.put((long) 1, "test");
+ HashMap expected=new HashMap<>();
+ expected.put((long) 1, "test");
+ Set menuSet = new HashSet<>();
+ menuSet.add(1);
+ HttpSession session = mock(HttpSession.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.when(AppUtils.getSession(mockedRequest)).thenReturn(session);
+ PowerMockito.when(SystemProperties.getProperty(Matchers.anyString())).thenReturn("12");
+ Mockito.when(session.getAttribute(Matchers.anyString())).thenReturn(roles);
+ roles=EPUserUtils.getRoles(mockedRequest);
+ assertEquals(roles,expected);
+
+
+ }
+
+ @Test
+ public void getRolesTestWithNoRoles(){
+ EPUser user=mock(EPUser.class);
+ HashMap roles=new HashMap<>();
+ HashMap expected=new HashMap<>();
+ SortedSet<EPRole> role= new TreeSet<>();
+ role.add(new EPRole());
+ //user.setEPRoles(role);
+ HttpSession session = mock(HttpSession.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.when(AppUtils.getSession(mockedRequest)).thenReturn(session);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME)).thenReturn("12");
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("attr_name");
+ Mockito.when(session.getAttribute("attr_name")).thenReturn(user);
+ Mockito.when(user.getEPRoles()).thenReturn(role);
+ Mockito.when(session.getAttribute("12")).thenReturn(null);
+ roles=EPUserUtils.getRoles(mockedRequest);
+ assertEquals(roles,expected);
+
+ }
+
+ @Test
+ public void getRolesTestWithNoRolesException(){
+ EPUser user=mock(EPUser.class);
+ EPRole epRole=mock(EPRole.class);
+ HashMap roles=new HashMap<>();
+
+ SortedSet<EPRole> role= new TreeSet<>();
+ role.add(epRole);
+
+ SortedSet<EPRole> childRoles=new TreeSet<>();
+ EPRole epRole2=new EPRole();
+ epRole2.setActive(true);
+ epRole2.setId(3L);
+ childRoles.add(epRole2);
+
+ SortedSet<EPUserApp> epUserApps= new TreeSet<>();
+ EPUserApp epUserApp=new EPUserApp();
+ EPRole epRole3=new EPRole();
+ epRole3.setActive(true);
+ epRole3.setId(999L);
+ epUserApp.setRole(epRole3);
+ epUserApps.add(epUserApp);
+
+ HttpSession session = mock(HttpSession.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.when(AppUtils.getSession(mockedRequest)).thenReturn(session);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.ROLES_ATTRIBUTE_NAME)).thenReturn("12");
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("attr_name");
+ Mockito.when(session.getAttribute("attr_name")).thenReturn(user);
+ Mockito.when(user.getEPRoles()).thenReturn(role);
+ Mockito.when(epRole.getActive()).thenReturn(true);
+ Mockito.when(epRole.getId()).thenReturn(2L);
+ Mockito.when(epRole.getChildRoles()).thenReturn(childRoles);
+ Mockito.when(user.getEPUserApps()).thenReturn(epUserApps);
+ Mockito.when(session.getAttribute("12")).thenReturn(null);
+ roles= EPUserUtils.getRoles(mockedRequest);
+ assertNotNull(roles);
+ }
+
+ @Test
+ public void decodeFunctionCodeTest() throws Exception{
+ String expected="test_instance";
+ String actual= EPUserUtils.decodeFunctionCode("test_instance");
+ assertEquals(expected, actual);
+ }
+
+ @Test(expected=RoleFunctionException.class)
+ public void decodeFunctionCodeTestWithException() throws DecoderException, RoleFunctionException {
+ PowerMockito.mockStatic(Hex.class);
+ PowerMockito.when(Hex.decodeHex(Matchers.any())).thenThrow(DecoderException.class);
+ EPUserUtils.decodeFunctionCode("n+");
+ }
+
+ @Test
+ public void setUserSessionTest() throws Exception{
+ EPUser user = mockUser.mockEPUser();
+ Set<String> applicationMenuData = new HashSet<String>();
+ applicationMenuData.add("test_application_menuData");
+ Set<String> businessDirectMenuData = new HashSet<String>();
+ businessDirectMenuData.add("test_businessDirect_menuData");
+ HttpSession session = mockedRequest.getSession();
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPRoleFunctionService.class);
+ PowerMockito.mockStatic(MenuBuilder.class);
+ List<RoleFunction> roleFunctions=new ArrayList<RoleFunction>();
+ RoleFunction roleFunction=new RoleFunction();
+ roleFunction.setId(1L);
+ roleFunction.setCode("test_code");
+ roleFunctions.add(roleFunction);
+
+ Mockito.when(epRoleFunctionService.getRoleFunctions()).thenReturn(roleFunctions);
+ Mockito.when(MenuBuilder.filterMenu(applicationMenuData, mockedRequest)).thenReturn(applicationMenuData);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("12");
+ EPUserUtils.setUserSession(mockedRequest, user, applicationMenuData, businessDirectMenuData, "login_method", epRoleFunctionService);
+ assertNotNull(session);
+
+
+ }
+
+ @Test
+ public void setUserSessionTestWithException() throws Exception{
+ EPUser user = mockUser.mockEPUser();
+ Set<String> applicationMenuData = new HashSet<String>();
+ applicationMenuData.add("test_application_menuData");
+ Set<String> businessDirectMenuData = new HashSet<String>();
+ businessDirectMenuData.add("test_businessDirect_menuData");
+ HttpSession session = mockedRequest.getSession();
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPRoleFunctionService.class);
+ PowerMockito.mockStatic(MenuBuilder.class);
+ List<RoleFunction> roleFunctions=new ArrayList<RoleFunction>();
+ RoleFunction roleFunction=new RoleFunction();
+ roleFunction.setId(1L);
+ roleFunction.setCode("test_code");
+ roleFunctions.add(roleFunction);
+ Mockito.when(epRoleFunctionService.getRoleFunctions()).thenReturn(null);
+ Mockito.when(MenuBuilder.filterMenu(applicationMenuData, mockedRequest)).thenReturn(applicationMenuData);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("12");
+ EPUserUtils.setUserSession(mockedRequest, user, applicationMenuData, businessDirectMenuData, "login_method", epRoleFunctionService);
+ assertNotNull(session);
+ }
+
+ @Test(expected=SessionExpiredException.class)
+ public void setUserSessionTestWithsessionException() throws Exception{
+ EPUser user = mockUser.mockEPUser();
+ Set<String> applicationMenuData = new HashSet<String>();
+ applicationMenuData.add("test_application_menuData");
+ Set<String> businessDirectMenuData = new HashSet<String>();
+ businessDirectMenuData.add("test_businessDirect_menuData");
+ HttpSession session = mockedRequest.getSession();
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPRoleFunctionService.class);
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.mockStatic(MenuBuilder.class);
+ List<RoleFunction> roleFunctions=new ArrayList<RoleFunction>();
+ RoleFunction roleFunction=new RoleFunction();
+ roleFunction.setId(1L);
+ roleFunction.setCode("test_code");
+ roleFunctions.add(roleFunction);
+ Mockito.when(AppUtils.getSession(mockedRequest)).thenReturn(null);
+ Mockito.when(epRoleFunctionService.getRoleFunctions()).thenReturn(null);
+ Mockito.when(MenuBuilder.filterMenu(applicationMenuData, mockedRequest)).thenReturn(applicationMenuData);
+ PowerMockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("12");
+ EPUserUtils.setUserSession(mockedRequest, user, applicationMenuData, businessDirectMenuData, "login_method", epRoleFunctionService);
+ assertNotNull(session);
+
+
+ }
+
+
+ @Test(expected=SessionExpiredException.class)
+ public void getUserSessionTest(){
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.when(AppUtils.getSession(mockedRequest)).thenReturn(null);
+ EPUserUtils.getUserSession(mockedRequest);
+ }
+
+}