summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-os/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-os/src/test/java/org')
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java118
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java55
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java134
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsControllerExternalRequestOSTest.java119
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java150
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java77
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java84
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java89
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java47
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java142
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java84
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockTestSuite.java68
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java75
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java148
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java189
-rw-r--r--ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/UserServiceImplTest.java63
16 files changed, 1574 insertions, 68 deletions
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java
new file mode 100644
index 00000000..4386ccd7
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java
@@ -0,0 +1,118 @@
+package org.openecomp.portalapp.portal.authentication;
+
+import static org.junit.Assert.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mitre.openid.connect.model.DefaultUserInfo;
+import org.mitre.openid.connect.model.UserInfo;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.authentication.OpenIdConnectLoginStrategy;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.utils.EPSystemProperties;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalapp.util.SessionCookieUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.util.StringUtils;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({StringUtils.class, EPUserUtils.class , SessionCookieUtil.class,SystemProperties.class})
+public class OpenIdConnectLoginStrategyTest {
+
+ @InjectMocks
+ OpenIdConnectLoginStrategy OpenIdConnectLoginStrategy = new OpenIdConnectLoginStrategy();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void loginTest()
+ {
+ PowerMockito.mockStatic(StringUtils.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ PowerMockito.mockStatic(SessionCookieUtil.class);
+
+ UserInfo userInfo = new DefaultUserInfo();
+ userInfo.setPreferredUsername("Test");
+ userInfo.setEmail("test@gmail.com");
+ userInfo.setName("first_name");
+ userInfo.setFamilyName("last_name");
+ Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo);
+ assertTrue(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginIfUserNullTest()
+ {
+ PowerMockito.mockStatic(SystemProperties.class);
+ UserInfo userInfo = null;
+ Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo);
+// Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("auth");
+ assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginIfUserIfAuthIsOIDCTest()
+ {
+ PowerMockito.mockStatic(SystemProperties.class);
+ UserInfo userInfo = null;
+ Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo);
+ Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("OIDC");
+ Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url");
+ assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginIfUserIfAuthNotNullTest()
+ {
+ PowerMockito.mockStatic(SystemProperties.class);
+ UserInfo userInfo = null;
+ Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo);
+ Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("test");
+ Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url");
+ assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginIfUserExceptionest()
+ {
+ PowerMockito.mockStatic(SystemProperties.class);
+ UserInfo userInfo = null;
+ Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo);
+ Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenThrow(nullPointerException);
+ Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url");
+ assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+ @Test(expected = Exception.class)
+ public void doLoginTest() throws Exception
+ {
+ OpenIdConnectLoginStrategy.doLogin(mockedRequest, mockedResponse);
+ }
+
+ @Test(expected = PortalAPIException.class)
+ public void getUserIdTest() throws Exception
+ {
+ OpenIdConnectLoginStrategy.getUserId(mockedRequest);
+ }
+
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java
new file mode 100644
index 00000000..fc827f78
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java
@@ -0,0 +1,55 @@
+package org.openecomp.portalapp.portal.authentication;
+
+import static org.junit.Assert.assertFalse;
+
+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.MockitoAnnotations;
+import org.openecomp.portalapp.authentication.LoginStrategy;
+import org.openecomp.portalapp.authentication.SimpleLoginStrategy;
+import org.openecomp.portalapp.controller.EPFusionBaseController;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.interceptor.SessionTimeoutInterceptor;
+import org.springframework.web.method.HandlerMethod;
+
+public class SessionTimeoutInterceptorTest {
+
+
+ @Mock
+ LoginStrategy loginStrategy = new SimpleLoginStrategy();
+
+ @Mock
+ EPFusionBaseController ePFusionBaseController = new EPFusionBaseController() {
+ };
+
+ @Mock
+ HandlerMethod handlerMethod;
+
+ @InjectMocks
+ SessionTimeoutInterceptor sessionTimeoutInterceptor = new SessionTimeoutInterceptor();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ @Test
+ public void preHandleTest() throws Exception{
+ assertFalse(sessionTimeoutInterceptor.preHandle(mockedRequest, mockedResponse, ePFusionBaseController));
+ }
+
+ @Test
+ public void preHandleTestIfMethodIsinstanceOfHandlerMethod() throws Exception{
+ assertFalse(sessionTimeoutInterceptor.preHandle(mockedRequest, mockedResponse, handlerMethod));
+ }
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java
new file mode 100644
index 00000000..5093fae0
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java
@@ -0,0 +1,134 @@
+package org.openecomp.portalapp.portal.authentication;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.authentication.SimpleLoginStrategy;
+import org.openecomp.portalapp.command.EPLoginBean;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.service.EPLoginService;
+import org.openecomp.portalapp.portal.service.EPRoleFunctionService;
+import org.openecomp.portalapp.portal.service.EPRoleService;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalapp.util.SessionCookieUtil;
+import org.openecomp.portalsdk.core.menu.MenuProperties;
+import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.util.StringUtils;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ StringUtils.class, EPUserUtils.class, SessionCookieUtil.class, SystemProperties.class,
+ SessionCookieUtil.class, MenuProperties.class })
+public class SimpleLoginStrategyTest {
+
+ @InjectMocks
+ SimpleLoginStrategy simpleLoginStrategy = new SimpleLoginStrategy();
+
+ @Mock
+ EPLoginService loginService;
+ @Mock
+ EPRoleService roleService;
+ @Mock
+ EPRoleFunctionService ePRoleFunctionService;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test(expected = Exception.class)
+ public void loginTest() throws Exception {
+ PowerMockito.mockStatic(MenuProperties.class);
+ PowerMockito.mockStatic(SessionCookieUtil.class);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT");
+ Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(false);
+ EPLoginBean commandBean = new EPLoginBean();
+ EPUser user = new EPUser();
+ commandBean.setUser(user);
+ commandBean.setOrgUserId("guestT");
+ Mockito.when(mockedRequest.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY))
+ .thenReturn("menu_properties_filename");
+ Mockito.when(loginService.findUser(commandBean, "menu_properties_filename", null)).thenReturn(commandBean);
+ assertTrue(simpleLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginIfUserEmptyTest() throws Exception {
+ PowerMockito.mockStatic(MenuProperties.class);
+ PowerMockito.mockStatic(SessionCookieUtil.class);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT");
+ Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true);
+ EPLoginBean commandBean = new EPLoginBean();
+ EPUser user = new EPUser();
+ commandBean.setUser(user);
+ commandBean.setOrgUserId("guestT");
+ assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginIfAuthIsBothTest() throws Exception {
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(SessionCookieUtil.class);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT");
+ Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("BOTH");
+ assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginIfAuthIsNotNullTest() throws Exception {
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(SessionCookieUtil.class);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT");
+ Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("Test");
+ assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void loginExceptionTest() throws Exception {
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(SessionCookieUtil.class);
+ PowerMockito.mockStatic(StringUtils.class);
+ Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT");
+ Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM))
+ .thenThrow(nullPointerException);
+ assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse));
+ }
+
+ @Test(expected = Exception.class)
+ public void doLoginTest() throws Exception {
+ simpleLoginStrategy.doLogin(mockedRequest, mockedResponse);
+ }
+
+ @Test(expected = PortalAPIException.class)
+ public void getUserIdTest() throws Exception {
+ simpleLoginStrategy.getUserId(mockedRequest);
+ }
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsControllerExternalRequestOSTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsControllerExternalRequestOSTest.java
new file mode 100644
index 00000000..049f7239
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsControllerExternalRequestOSTest.java
@@ -0,0 +1,119 @@
+/*package org.openecomp.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.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.AdminRolesService;
+import org.openecomp.portalapp.portal.service.EPAppService;
+import org.openecomp.portalapp.portal.service.PortalAdminService;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.OnboardingApp;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+public class AppsControllerExternalRequestOSTest {
+
+ @Mock
+ AdminRolesService adminRolesService;
+
+ @Mock
+ EPAppService appService;
+
+ @Mock
+ PortalAdminService portalAdminService;
+
+
+ @InjectMocks
+ AppsControllerExternalRequest appsControllerExternalRequest = new AppsControllerExternalRequest();
+
+ @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();
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ @Test
+ public void postOnboardAppExternalFieldValidatorTestTest() {
+ 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);
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 500);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.addOnboardingApp(expectedOnboardingApp, user)).thenReturn(expectedFieldValidator);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void postOnboardAppExternalIfSuperAdminTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.addOnboardingApp(expectedOnboardingApp, user)).thenReturn(expectedFieldValidator);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+}
+*/ \ No newline at end of file
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java
new file mode 100644
index 00000000..70e7a0ca
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java
@@ -0,0 +1,150 @@
+package org.openecomp.portalapp.portal.controller;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.drools.core.command.assertion.AssertEquals;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.AdminRolesService;
+import org.openecomp.portalapp.portal.service.EPAppService;
+import org.openecomp.portalapp.portal.service.PersUserAppService;
+import org.openecomp.portalapp.portal.service.UserService;
+import org.openecomp.portalapp.portal.framework.MockEPUser;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+public class AppsOSControllerTest {
+
+ @Mock
+ AdminRolesService adminRolesService;
+
+ @Mock
+ EPAppService appService;
+
+ @Mock
+ PersUserAppService persUserAppService;
+
+ @Mock
+ UserService userService;
+
+ @Mock
+ EPUserUtils ePUserUtils;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ AppsOSController appsOSController = new AppsOSController();
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void saveNewUserIfUserISNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("failure");
+ expectedportalRestResponse.setResponse("New User cannot be null or empty");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<String> actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, null);
+ assertEquals(expectedportalRestResponse, actualPortalRestResponse);
+ }
+
+ @Test
+ public void saveNewUserIfUserNOtNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("failure");
+ expectedportalRestResponse.setResponse("UnAuthorized");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ EPUser user1 = mockUser.mockEPUser();
+ user1.setLoginId("guest");
+ user.setLoginId("guestT");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user1);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false);
+ PortalRestResponse<String> actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user);
+ assertEquals(expectedportalRestResponse, actualPortalRestResponse);
+ }
+
+ @Test
+ public void saveNewUserAndLoggedInUserIdSameTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Success");
+ expectedportalRestResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ EPUser user = mockUser.mockEPUser();
+ user.setLoginId("guestT");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false);
+ Mockito.when(mockedRequest.getParameter("isCheck")).thenReturn("test");
+ Mockito.when(userService.saveNewUser(user, "test")).thenReturn("Success");
+ PortalRestResponse<String> actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user);
+ assertEquals(expectedportalRestResponse, actualPortalRestResponse);
+ }
+
+ @Test
+ public void saveNewUserexceptionest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("failure");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ user.setLoginId("guestT");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false);
+ Mockito.when(mockedRequest.getParameter("isCheck")).thenReturn("test");
+ Mockito.when(userService.saveNewUser(user, "test")).thenThrow(nullPointerException);
+ PortalRestResponse<String> actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user);
+ assertEquals(expectedportalRestResponse, actualPortalRestResponse);
+ }
+
+ @Test
+ public void getCurrentUserProfileTest() {
+ String loginId = "guestT";
+ EPUser user = mockUser.mockEPUser();
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(userService.getUserByUserId(loginId)).thenReturn(expectedList);
+ String expectedString = appsOSController.getCurrentUserProfile(mockedRequest, loginId);
+ assertEquals("{\"firstName\":\"test\",\"lastName\":\"test\"}", expectedString);
+ }
+
+ @Test
+ public void getCurrentUserProfileExceptionTest() {
+ String loginId = "guestT";
+ EPUser user = mockUser.mockEPUser();
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(userService.getUserByUserId(loginId)).thenThrow(nullPointerException);
+ String expectedString = appsOSController.getCurrentUserProfile(mockedRequest, loginId);
+ assertEquals("{}", expectedString);
+ }
+
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java
new file mode 100644
index 00000000..729debaa
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java
@@ -0,0 +1,77 @@
+package org.openecomp.portalapp.portal.controller;
+
+import static org.junit.Assert.*;
+
+import javax.servlet.ServletRequestWrapper;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.OngoingStubbing;
+import org.openecomp.portalapp.controller.ECOMPLogoutController;
+import org.openecomp.portalapp.portal.service.DashboardSearchService;
+import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl;
+import org.openecomp.portalapp.portal.framework.MockEPUser;
+import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.core.NamedThreadLocal;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.servlet.ModelAndView;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({EPUserUtils.class, EPCommonSystemProperties.class,RequestContextHolder.class,RequestAttributes.class})
+public class ECOMPLogoutControllerTest {
+
+ @Mock
+ DashboardSearchService searchService = new DashboardSearchServiceImpl();
+
+ @InjectMocks
+ ECOMPLogoutController ecompLogoutController = new ECOMPLogoutController();
+
+ @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();
+
+ @Mock
+ RequestContextHolder requestContextHolder;
+
+ @Mock
+ RequestAttributes requestAttributes;
+
+ @Test
+ public void logOutTest() throws Exception{
+ ModelAndView actualData = new ModelAndView("redirect:login.htm");
+ ModelAndView expedtedData = null;
+ ThreadLocal<RequestAttributes> requestAttributesHolder =
+ new NamedThreadLocal<RequestAttributes>("Request attributes");
+ RequestAttributes requestAttributes = new ServletRequestAttributes(mockedRequest);
+ PowerMockito.mockStatic(RequestContextHolder.class);
+ PowerMockito.mockStatic(RequestAttributes.class);
+ Mockito.when((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).thenReturn((ServletRequestAttributes) requestAttributes);
+ expedtedData = ecompLogoutController.logOut(mockedRequest, mockedResponse);
+ assertEquals(actualData.getViewName(),expedtedData.getViewName());
+ }
+
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java
new file mode 100644
index 00000000..968f5811
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java
@@ -0,0 +1,84 @@
+package org.openecomp.portalapp.portal.controller;
+
+import static org.junit.Assert.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.controller.LoginController;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.service.EPLoginService;
+import org.openecomp.portalapp.portal.service.EPRoleFunctionService;
+import org.openecomp.portalapp.portal.service.EPRoleService;
+import org.openecomp.portalapp.portal.service.SharedContextService;
+import org.openecomp.portalapp.service.EPProfileService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.web.servlet.ModelAndView;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(SystemProperties.class)
+public class LoginControllerTest {
+
+ @Mock
+ EPProfileService service;
+ @Mock
+ EPLoginService loginService;
+ @Mock
+ SharedContextService sharedContextService;
+ @Mock
+ EPRoleService roleService;
+ @Mock
+ EPRoleFunctionService ePRoleFunctionService;
+
+ @InjectMocks
+ LoginController loginController = new LoginController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void loginIfAuthNullTest()
+ {
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn(null);
+ ModelAndView result = loginController.login(mockedRequest);
+ assertEquals(result.getViewName(),"openIdLogin") ;
+ }
+
+ @Test
+ public void loginIfAuthOIDCTest()
+ {
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("OIDC");
+ ModelAndView result = loginController.login(mockedRequest);
+ assertEquals(result.getViewName(),"openIdLogin") ;
+ }
+
+ @Test
+ public void loginTest()
+ {
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("Test");
+ ModelAndView result = loginController.login(mockedRequest);
+ assertEquals(result.getViewName(),"login") ;
+ }
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java
new file mode 100644
index 00000000..06dfc902
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java
@@ -0,0 +1,89 @@
+package org.openecomp.portalapp.portal.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.controller.ONAPLoginController;
+import org.openecomp.portalapp.portal.framework.MockEPUser;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.auth.LoginStrategy;
+import org.openecomp.portalsdk.core.service.LoginService;
+import org.openecomp.portalsdk.core.service.ProfileService;
+import org.openecomp.portalsdk.core.service.ProfileServiceImpl;
+import org.springframework.web.servlet.ModelAndView;
+
+public class ONAPLoginControllerTest {
+
+ @Mock
+ ProfileService ProfileService = new ProfileServiceImpl();
+
+ @Mock
+ LoginService mockLoginService;
+
+ @Mock
+ LoginStrategy loginStrategy ;
+
+ @InjectMocks
+ ONAPLoginController oNAPLoginController = new ONAPLoginController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ MockEPUser mockUser = new MockEPUser();
+
+
+ @Test
+ public void doLogin() throws Exception
+ {
+ ModelAndView expectedModelandView = null;
+ ModelAndView actualModelandView = null;
+ Mockito.when(loginStrategy.doLogin(mockedRequest, mockedResponse)).thenReturn(expectedModelandView);
+ actualModelandView= oNAPLoginController.doLogin(mockedRequest, mockedResponse);
+ assertEquals(actualModelandView,expectedModelandView);
+ }
+
+
+ @Test
+ public void ViewTest() throws Exception
+ {
+ ModelAndView expectedModelandView = new ModelAndView();
+ expectedModelandView.setViewName("testView");
+ ModelAndView actualModelandView = null;
+ Mockito.when(loginStrategy.doLogin(mockedRequest, mockedResponse)).thenReturn(expectedModelandView);
+ actualModelandView= oNAPLoginController.doLogin(mockedRequest, mockedResponse);
+ assertEquals(actualModelandView.getViewName(),expectedModelandView.getViewName());
+ }
+ @Test
+ public void getJessionIdTest() throws Exception
+ {
+ assertNull(oNAPLoginController.getJessionId(mockedRequest));
+ }
+
+ @Test
+ public void getLoginServiceTest() throws Exception
+ {
+ LoginService expectedLoginService = oNAPLoginController.getLoginService();
+ assertEquals(mockLoginService,expectedLoginService);
+ }
+
+
+
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java
new file mode 100644
index 00000000..c15f366a
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java
@@ -0,0 +1,47 @@
+package org.openecomp.portalapp.portal.controller;
+
+import static org.junit.Assert.*;
+
+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.MockitoAnnotations;
+import org.openecomp.portalapp.controller.ONAPWelcomeController;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+
+public class ONAPWelcomeControllerTest {
+
+ @InjectMocks
+ ONAPWelcomeController oNAPWelcomeController = new ONAPWelcomeController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void getIndexPageTest()
+ {
+ assertEquals(oNAPWelcomeController.getIndexPage(mockedRequest), "/index");
+ }
+
+ @Test
+ public void getEcompSinglePageTest()
+ {
+ assertEquals(oNAPWelcomeController.getEcompSinglePage(mockedRequest, mockedResponse), "forward:/index.html");
+ }
+
+ @Test
+ public void userTest()
+ {
+ assertEquals(oNAPWelcomeController.user(null), "oid-user");
+ }
+
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java
new file mode 100644
index 00000000..65925977
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java
@@ -0,0 +1,142 @@
+/*package org.openecomp.portalapp.portal.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.domain.EPRole;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.service.AdminRolesService;
+import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl;
+import org.openecomp.portalapp.portal.service.PortalAdminService;
+import org.openecomp.portalapp.portal.service.PortalAdminServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.service.AuditService;
+import org.openecomp.portalsdk.core.service.AuditServiceImpl;
+
+public class PortalAdminControllerOSTest {
+
+ @InjectMocks
+ PortalAdminController portalAdminController = new PortalAdminController();
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Mock
+ PortalAdminService portalAdminService = new PortalAdminServiceImpl();
+
+ @Mock
+ AuditService auditService = new AuditServiceImpl();
+
+
+ @Mock
+ EcompPortalUtils ecompPortalUtils = new EcompPortalUtils();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void deletePortalAdminIfUserIsSuperAdminTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ String userInfo = "1-test";
+ assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse));
+
+ }
+
+ @Test
+ public void deletePortalAdminTest()
+ {
+ 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 userInfo = "1-test";
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(portalAdminService.deletePortalAdmin((long) 1)).thenReturn(expectedFieldValidator);
+ actualFieldValidator = portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse);
+ assertEquals(actualFieldValidator,expectedFieldValidator);
+
+ }
+
+ @Test
+ public void deletePortalAdminWithNoUserInfoTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ String userInfo = "";
+ assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse));
+ }
+
+ @Test
+ public void getRolesByAppExceptionTest()
+ {
+ EPUser user = mockUser.mockEPUser();;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPRole> expectedRoleList = new ArrayList<EPRole>();
+ EPRole ePRole = new EPRole();
+ expectedRoleList.add(ePRole);
+ Long appId = (long) 1;
+ Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenThrow(nullPointerException);
+ assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse));
+ }
+
+ @Test
+ public void getRolesByAppIfUserNullTest()
+ {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Long appId = (long) 1;
+ assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse));
+ }
+
+ @Test
+ public void getRolesByAppTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPRole> expectedRoleList = new ArrayList<EPRole>();
+ EPRole ePRole = new EPRole();
+ expectedRoleList.add(ePRole);
+ Long appId = (long) 1;
+ Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenReturn(expectedRoleList);
+ List<EPRole> actualRoleList = portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse);
+ assertEquals(actualRoleList,expectedRoleList);
+ }
+}
+*/ \ No newline at end of file
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java
new file mode 100644
index 00000000..d132ccf3
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java
@@ -0,0 +1,84 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.framework;
+
+import java.util.Date;
+
+import org.openecomp.portalapp.portal.domain.EPUser;
+
+public class MockEPUser {
+
+ 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.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;
+ }
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockTestSuite.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockTestSuite.java
deleted file mode 100644
index 492079f8..00000000
--- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockTestSuite.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package org.openecomp.portalapp.portal.framework;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.openecomp.portalapp.portal.test.controller.AppCatalogControllerTest;
-import org.openecomp.portalapp.portal.test.controller.AppContactUsControllerTest;
-import org.openecomp.portalapp.portal.test.controller.AppsControllerExternalRequestTest;
-import org.openecomp.portalapp.portal.test.controller.AppsControllerTest;
-import org.openecomp.portalapp.portal.test.controller.BEPropertyReaderControllerTest;
-import org.openecomp.portalapp.portal.test.controller.BasicAuthAccountControllerTest;
-import org.openecomp.portalapp.portal.test.controller.CommonWidgetControllerTest;
-import org.openecomp.portalapp.portal.test.controller.ConsulClientControllerTest;
-import org.openecomp.portalapp.portal.test.controller.DashboardSearchResultControllerTest;
-import org.openecomp.portalapp.portal.test.controller.ExternalAppsRestfulControllerTest;
-import org.openecomp.portalapp.portal.test.controller.FunctionalMenuControllerTest;
-import org.openecomp.portalapp.portal.test.controller.GetAccessControllerTest;
-import org.openecomp.portalapp.portal.test.controller.ManifestControllerTest;
-import org.openecomp.portalapp.portal.test.controller.MicroserviceControllerTest;
-import org.openecomp.portalapp.portal.test.controller.MicroserviceProxyControllerTest;
-import org.openecomp.portalapp.portal.test.controller.PortalAdminControllerTest;
-import org.openecomp.portalapp.portal.test.controller.RolesApprovalSystemControllerTest;
-import org.openecomp.portalapp.portal.test.controller.TicketEventControllerTest;
-import org.openecomp.portalapp.portal.test.controller.UserControllerTest;
-import org.openecomp.portalapp.portal.test.controller.UserNotificationControllerTest;
-import org.openecomp.portalapp.portal.test.controller.UserRolesControllerTest;
-import org.openecomp.portalapp.portal.test.controller.WebAnalyticsExtAppControllerTest;
-import org.openecomp.portalapp.portal.test.controller.WidgetsCatalogMarkupControllerTest;
-
-
-
-/**
- *
- *
- * Create the Test class in ecmop-portal-BE-common-test and extend from MockitoTestSuite
- * Add the class in Suite to test it
- *
- */
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
-UserRolesControllerTest.class,
-FunctionalMenuControllerTest.class,
-AppCatalogControllerTest.class,
-AppContactUsControllerTest.class,
-UserNotificationControllerTest.class,
-TicketEventControllerTest.class,
-CommonWidgetControllerTest.class,
-ConsulClientControllerTest.class,
-GetAccessControllerTest.class,
-AppsControllerTest.class,
-BasicAuthAccountControllerTest.class,
-DashboardSearchResultControllerTest.class,
-//PortalAdminControllerTest.class,
-ManifestControllerTest.class,
-BEPropertyReaderControllerTest.class,
-WebAnalyticsExtAppControllerTest.class,
-AppsControllerExternalRequestTest.class,
-WidgetsCatalogMarkupControllerTest.class,
-RolesApprovalSystemControllerTest.class,
-MicroserviceProxyControllerTest.class,
-MicroserviceControllerTest.class,
-ExternalAppsRestfulControllerTest.class,
-UserControllerTest.class
-})
-public class MockTestSuite {
-
-}
-
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java
new file mode 100644
index 00000000..3ff837dc
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java
@@ -0,0 +1,75 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.framework;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MockitoTestSuite {
+
+
+ public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper(
+ Mockito.mock(HttpServletRequest.class));
+ public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class);
+
+ public MockHttpServletRequestWrapper getMockedRequest() {
+ return mockedRequest;
+ }
+
+ public HttpServletResponse getMockedResponse() {
+ return mockedResponse;
+ }
+
+ public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper {
+
+ HttpSession session = Mockito.mock(HttpSession.class);
+
+ public MockHttpServletRequestWrapper(HttpServletRequest request) {
+ super(request);
+
+ }
+
+ @Override
+ public HttpSession getSession() {
+
+ return session;
+ }
+
+ @Override
+ public HttpSession getSession(boolean create) {
+
+ return session;
+ }
+
+ }
+ @Test
+ public void test()
+ {
+ assert(true);
+ }
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java
new file mode 100644
index 00000000..d38525b3
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java
@@ -0,0 +1,148 @@
+package org.openecomp.portalapp.portal.service;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.domain.EPApp;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.service.RemoteWebServiceCallServiceImpl;
+import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
+import org.openecomp.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 , SystemProperties.class})
+public class RemoteWebServiceCallServiceImplTest {
+
+
+ @InjectMocks
+ RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl();
+
+ @Mock
+ AppsCacheService appCacheService;
+
+ @Mock
+ DataAccessService dataAccessService;
+
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void verifyRESTCredentialTest() throws Exception
+ {
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ String criteria= " where ueb_key = 'requestUebKey'";
+ List<EPApp> appList = new ArrayList<>();
+ EPApp app = new EPApp();
+ app.setAppPassword("password");
+ appList.add(app);
+ Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
+ String secretKey = null;
+ Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
+ Mockito.when(CipherUtil.decrypt("password",
+ secretKey == null ? null : secretKey)).thenReturn("pwd");
+ assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword"));
+ }
+
+ @Test
+ public void verifyRESTCredentialExceptionTest() throws Exception
+ {
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ String criteria= " where ueb_key = 'requestUebKey'";
+ List<EPApp> appList = new ArrayList<>();
+ EPApp app = new EPApp();
+ app.setAppPassword("password");
+ app.setUsername("requestAppName");
+ appList.add(app);
+ Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
+ String secretKey = null;
+ Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
+ Mockito.when(CipherUtil.decrypt("password",
+ secretKey == null ? null : secretKey)).thenReturn("pwd");
+ assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
+ }
+
+ @Test
+ public void verifyRESTCredentialIfAppNullTest() throws Exception
+ {
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ String criteria= " where ueb_key = 'requestUebKey'";
+ List<EPApp> appList = new ArrayList<>();
+ EPApp app = new EPApp();
+ app.setAppPassword("password");
+ app.setUsername("requestAppName");
+ appList.add(app);
+ Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
+ String secretKey = null;
+ Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
+ Mockito.when(CipherUtil.decrypt("password",
+ secretKey == null ? null : secretKey)).thenReturn("pwd");
+ assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
+ }
+
+ @Test
+ public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception
+ {
+ assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null));
+ }
+
+ @Test
+ public void verifyAppKeyCredentialTest() throws Exception
+ {
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ StringBuffer criteria = new StringBuffer("where ueb_key = 'requestUebKey'");
+// String criteria= " where ueb_key = 'requestUebKey'";
+ List<EPApp> appList = new ArrayList<>();
+ EPApp app = new EPApp();
+ app.setAppPassword("password");
+ app.setUsername("requestAppName");
+ appList.add(app);
+ Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
+ assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));
+ }
+
+ @Test
+ public void verifyAppKeyCredentialSuccessTest() throws Exception
+ {
+ PowerMockito.mockStatic(CipherUtil.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ String criteria= " where ueb_key = 'test'";
+ List<EPApp> appList = new ArrayList<>();
+ EPApp app = new EPApp();
+ app.setAppPassword("password");
+ app.setUsername("requestAppName");
+ appList.add(app);
+ Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
+ assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));
+ }
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java
new file mode 100644
index 00000000..fd6578f8
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java
@@ -0,0 +1,189 @@
+package org.openecomp.portalapp.portal.service;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.framework.MockEPUser;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.transport.UserWithNameSurnameTitle;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+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})
+public class SearchServiceImplTest {
+
+ @InjectMocks
+ SearchServiceImpl searchServiceImpl = new SearchServiceImpl();
+
+ @Mock
+ UserService userService;
+
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ NullPointerException nullPointerException = new NullPointerException();
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void searchUsersInPhoneBookTest()
+ {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ List<String> list = new ArrayList<>();
+ String str = "Test";
+ list.add(str);
+ Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list);
+ assertEquals(searchServiceImpl.searchUsersInPhoneBook("Test"), "[]");
+ }
+
+ @Test
+ public void searchUsersInFnTableToFindUserIdTest()
+ {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ List<String> list = new ArrayList<>();
+ String str = "Test";
+ String str2 = "Test new";
+ String str1 = "Test new1";
+ list.add(str);
+ list.add(str1);
+ list.add(str2);
+ Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list);
+ List<EPUser> userList = new ArrayList();
+ EPUser user = mockUser.mockEPUser();
+ user.setLastName("Test new");
+ userList.add(user);
+ Mockito.when( this.userService.getUserByFirstLastName("Test","Test new")).thenReturn(userList);
+ String result = searchServiceImpl.searchUsersInPhoneBook("Test");
+ assertEquals("[{\"orgUserId\":\"guestT\",\"firstName\":\"test\",\"lastName\":\"Test new\",\"jobTitle\":null}]" , result);
+ }
+
+
+
+ @Test
+ public void searchUsersInFnTableFirstNameTest()
+ {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ List<String> list = new ArrayList<>();
+ String str = "TestTT";
+ String str2 = "Test new1";
+ String str1 = "Test new";
+ String str3 = "Test new2";
+ list.add(str);
+ list.add(str1);
+ list.add(str2);
+ list.add(str3);
+ Mockito.when(EcompPortalUtils.parsingByRegularExpression("TestTT", " ")).thenReturn(list);
+ List<EPUser> userList = new ArrayList();
+ EPUser user = mockUser.mockEPUser();
+ user.setLastName("Test new");
+ user.setFirstName(null);
+ userList.add(user);
+ Mockito.when( this.userService.getUserByFirstLastName("TestTT","Test new")).thenReturn(userList);
+ assertEquals(searchServiceImpl.searchUsersInPhoneBook("TestTT"), "[]"); }
+
+
+ @Test
+ public void searchUsersInFnTableLastNameTest()
+ {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ List<String> list = new ArrayList<>();
+ String str = "Test";
+ String str2 = "Test new";
+ String str1 = "Test new1";
+ list.add(str);
+ list.add(str1);
+ list.add(str2);
+ Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list);
+ List<EPUser> userList = new ArrayList();
+ EPUser user = mockUser.mockEPUser();
+ user.setLastName(null);
+ userList.add(user);
+ Mockito.when( this.userService.getUserByFirstLastName("Test","Test new")).thenReturn(userList);
+ assertEquals(searchServiceImpl.searchUsersInPhoneBook("Test"), "[]"); }
+
+
+
+ @Test
+ public void searchUserByUserIdTest()
+ {
+ List<EPUser> userList = new ArrayList();
+ EPUser user = mockUser.mockEPUser();
+ user.setLastName("Test new");
+ userList.add(user);
+ List<EPUser> foundUsers = new ArrayList<EPUser>();
+ Mockito.when(this.userService.getUserByUserId("guestT")).thenReturn(userList);
+
+ EPUser expectedUser = searchServiceImpl.searchUserByUserId("guestT");
+ assertEquals(user, expectedUser);
+ }
+
+ @Test
+ public void searchUserByUserIdExceptionTest()
+ {
+ Mockito.when(this.userService.getUserByUserId("guestT")).thenThrow(nullPointerException);
+ assertNull(searchServiceImpl.searchUserByUserId("guestT"));
+
+ }
+
+ @Test
+ public void searchUsersByUserIdTest()
+ {
+
+ List<EPUser> userList = new ArrayList();
+ EPUser user = mockUser.mockEPUser();
+ user.setLastName("Test new");
+ userList.add(user);
+ Mockito.when(this.userService.getUserByUserId("guestT")).thenReturn(userList);
+ List<UserWithNameSurnameTitle> foundUsers = searchServiceImpl.searchUsersByUserId(user);
+ assertEquals(foundUsers.size(), 1);
+
+ }
+
+ @Test
+ public void searchUsersByUserIdExceptionTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ user.setLastName("Test new");
+ Mockito.when(this.userService.getUserByUserId("guestT")).thenThrow(nullPointerException);
+ List<UserWithNameSurnameTitle> foundUsers = searchServiceImpl.searchUsersByUserId(user);
+ assertEquals(foundUsers.size(), 0);
+
+ }
+
+ @Test
+ public void searchUsersByNameExceptionTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ user.setLastName("test");
+ user.setFirstName("test");
+
+ Mockito.when(this.userService.getUserByFirstLastName("test","test")).thenThrow(nullPointerException);
+ List<UserWithNameSurnameTitle> foundUsers = searchServiceImpl.searchUsersByName(user);
+ assertEquals(foundUsers.size(), 0);
+
+ }
+}
diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/UserServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/UserServiceImplTest.java
new file mode 100644
index 00000000..63a710eb
--- /dev/null
+++ b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/UserServiceImplTest.java
@@ -0,0 +1,63 @@
+//package org.openecomp.portalapp.portal.service;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//
+//import org.junit.Before;
+//import org.junit.Test;
+//import org.junit.runner.RunWith;
+//import org.mockito.InjectMocks;
+//import org.mockito.Mock;
+//import org.mockito.Mockito;
+//import org.mockito.MockitoAnnotations;
+//import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+//import org.openecomp.portalapp.portal.utils.EPSystemProperties;
+//import org.openecomp.portalsdk.core.service.DataAccessService;
+//import org.openecomp.portalsdk.core.util.SystemProperties;
+//import org.powermock.api.mockito.PowerMockito;
+//
+//import java.io.BufferedReader;
+//import java.io.IOException;
+//import java.io.InputStreamReader;
+//import java.io.UnsupportedEncodingException;
+//import java.net.HttpURLConnection;
+//import org.powermock.core.classloader.annotations.PrepareForTest;
+//import org.powermock.modules.junit4.PowerMockRunner;
+//
+//
+//@RunWith(PowerMockRunner.class)
+//@PrepareForTest({ SystemProperties.class , EPSystemProperties.class , SystemProperties.class})
+//public class UserServiceImplTest {
+//
+//
+// @InjectMocks
+// UserServiceImpl userServiceImpl = new UserServiceImpl();
+//
+// @Mock
+// DataAccessService dataAccessService;
+//
+// @Mock
+// HttpURLConnection con;
+//
+// @Before
+// public void setup() {
+// MockitoAnnotations.initMocks(this);
+// }
+//
+// MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+//
+// HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+// HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+//
+// @Test
+// public void getUserByUserIdTest() throws UnsupportedEncodingException, IOException
+// {
+// BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
+// PowerMockito.mockStatic(SystemProperties.class);
+// PowerMockito.mockStatic(EPSystemProperties.class);
+// Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("OIDC");
+// Mockito.when(EPSystemProperties.getProperty(EPSystemProperties.AUTH_USER_SERVER)).thenReturn("http://www.google.com");
+// Mockito.when(new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"))).thenReturn(reader).thenReturn(reader);
+// userServiceImpl.getUserByUserId("guestT");
+// }
+//}