|
|
@ -18,6 +18,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
|
|
|
|
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.*;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.UserManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.UserManagementProviderService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.UserManagementProviderService;
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
import org.mockito.invocation.InvocationOnMock;
|
|
|
|
import org.mockito.invocation.InvocationOnMock;
|
|
|
@ -40,12 +42,10 @@ import io.entgra.device.mgt.core.device.mgt.common.spi.OTPManagementService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.service.OTPManagementServiceImpl;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.service.OTPManagementServiceImpl;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.BasicUserInfo;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.EnrollmentInvitation;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.UserInfo;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.UserManagementService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.UserManagementService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.user.api.RealmConfiguration;
|
|
|
|
import org.wso2.carbon.user.api.RealmConfiguration;
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
@ -88,9 +88,10 @@ public class UserManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
@BeforeClass
|
|
|
|
public void setup() throws UserStoreException {
|
|
|
|
public void init() throws UserStoreException {
|
|
|
|
initMocks(this);
|
|
|
|
initMocks(this);
|
|
|
|
userManagementService = new UserManagementServiceImpl();
|
|
|
|
userManagementService = new UserManagementServiceImpl();
|
|
|
|
|
|
|
|
userManagementProviderService = Mockito.mock(UserManagementProviderService.class);
|
|
|
|
userStoreManager = Mockito.mock(UserStoreManager.class, Mockito.RETURNS_MOCKS);
|
|
|
|
userStoreManager = Mockito.mock(UserStoreManager.class, Mockito.RETURNS_MOCKS);
|
|
|
|
deviceManagementProviderService = Mockito
|
|
|
|
deviceManagementProviderService = Mockito
|
|
|
|
.mock(DeviceManagementProviderServiceImpl.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
.mock(DeviceManagementProviderServiceImpl.class, Mockito.CALLS_REAL_METHODS);
|
|
|
@ -114,6 +115,8 @@ public class UserManagementServiceImplTest {
|
|
|
|
public void testAddUser() throws UserStoreException, ConfigurationManagementException, DeviceManagementException {
|
|
|
|
public void testAddUser() throws UserStoreException, ConfigurationManagementException, DeviceManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
Mockito.doReturn(true).when(userStoreManager).isExistingUser("admin");
|
|
|
|
Mockito.doReturn(true).when(userStoreManager).isExistingUser("admin");
|
|
|
@ -152,11 +155,27 @@ public class UserManagementServiceImplTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This method tests the getUser method of UserManagementService", dependsOnMethods =
|
|
|
|
@Test(description = "This method tests the getUser method of UserManagementService", dependsOnMethods =
|
|
|
|
"testAddUser")
|
|
|
|
"testAddUser")
|
|
|
|
public void testGetUser() throws UserStoreException {
|
|
|
|
public void testGetUser() throws UserStoreException, UserManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
|
|
|
|
BasicUserInfo basicUserInfo = new BasicUserInfo();
|
|
|
|
|
|
|
|
Mockito.doReturn(basicUserInfo).when(userManagementProviderService)
|
|
|
|
|
|
|
|
.getUser(Mockito.anyString());
|
|
|
|
Response response = userManagementService.getUser(TEST_USERNAME, null, null);
|
|
|
|
Response response = userManagementService.getUser(TEST_USERNAME, null, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "User retrieval failed");
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "User retrieval failed");
|
|
|
|
|
|
|
|
Mockito.reset(userManagementProviderService);
|
|
|
|
|
|
|
|
basicUserInfo.setUsername(TEST_USERNAME);
|
|
|
|
|
|
|
|
basicUserInfo.setFirstname(TEST_USERNAME);
|
|
|
|
|
|
|
|
basicUserInfo.setLastname(TEST_USERNAME);
|
|
|
|
|
|
|
|
basicUserInfo.setEmailAddress("test@gmail.com");
|
|
|
|
|
|
|
|
Mockito.doReturn(basicUserInfo).when(userManagementProviderService)
|
|
|
|
|
|
|
|
.getUser(Mockito.anyString());
|
|
|
|
|
|
|
|
response = userManagementService.getUser("test", null, null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
|
|
|
|
"GetUser request failed with valid parameters");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
BasicUserInfo userInfo = (BasicUserInfo) response.getEntity();
|
|
|
|
BasicUserInfo userInfo = (BasicUserInfo) response.getEntity();
|
|
|
|
Assert.assertEquals(userInfo.getFirstname(), TEST_USERNAME,
|
|
|
|
Assert.assertEquals(userInfo.getFirstname(), TEST_USERNAME,
|
|
|
|
"Retrieved user object is different from the original one " + "saved");
|
|
|
|
"Retrieved user object is different from the original one " + "saved");
|
|
|
@ -188,15 +207,24 @@ public class UserManagementServiceImplTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This method tests the getRolesOfUser method of UserManagementService", dependsOnMethods =
|
|
|
|
@Test(description = "This method tests the getRolesOfUser method of UserManagementService", dependsOnMethods =
|
|
|
|
{"testUpdateUser"})
|
|
|
|
{"testUpdateUser"})
|
|
|
|
public void testGetRolesOfUser() {
|
|
|
|
public void testGetRolesOfUser() throws UserManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
|
|
|
|
List<String> roles= new ArrayList<>();
|
|
|
|
|
|
|
|
Mockito.doReturn(roles).when(userManagementProviderService)
|
|
|
|
|
|
|
|
.getRoles(Mockito.anyString());
|
|
|
|
Response response = userManagementService.getRolesOfUser(TEST2_USERNAME, null);
|
|
|
|
Response response = userManagementService.getRolesOfUser(TEST2_USERNAME, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
|
|
|
"Roles of a non-existing user was successfully retrieved");
|
|
|
|
"Roles of a non-existing user was successfully retrieved");
|
|
|
|
|
|
|
|
Mockito.reset(userManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.doReturn(roles).when(userManagementProviderService)
|
|
|
|
|
|
|
|
.getRoles(Mockito.anyString());
|
|
|
|
response = userManagementService.getRolesOfUser(TEST_USERNAME, null);
|
|
|
|
response = userManagementService.getRolesOfUser(TEST_USERNAME, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
"Retrieval of roles of a existing user failed.");
|
|
|
|
"Retrieval of roles of a existing user failed.");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This method tests the IsUserExists method of UserManagementService", dependsOnMethods =
|
|
|
|
@Test(description = "This method tests the IsUserExists method of UserManagementService", dependsOnMethods =
|
|
|
@ -232,12 +260,13 @@ public class UserManagementServiceImplTest {
|
|
|
|
public void testGetUserNames() throws UserStoreException {
|
|
|
|
public void testGetUserNames() throws UserStoreException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
Mockito.doReturn(new String[] { TEST_USERNAME }).when(userStoreManager)
|
|
|
|
Mockito.doReturn(new String[] { TEST_USERNAME }).when(userStoreManager)
|
|
|
|
.listUsers(Mockito.anyString(), Mockito.anyInt());
|
|
|
|
.listUsers(Mockito.anyString(), Mockito.anyInt());
|
|
|
|
Response response = userManagementService.getUserNames(TEST_USERNAME, null, "00", 0, 0);
|
|
|
|
Response response = userManagementService.getUserNames(TEST_USERNAME, null, "00", 0, 0);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
"Getting user names is failed for a valid request");
|
|
|
|
"Getting user names is failed for a valid request");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This method tests the getUsers method of UserManagementService",
|
|
|
|
@Test(description = "This method tests the getUsers method of UserManagementService",
|
|
|
@ -245,6 +274,8 @@ public class UserManagementServiceImplTest {
|
|
|
|
public void testGetUsers() {
|
|
|
|
public void testGetUsers() {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(userStoreManager);
|
|
|
|
.toReturn(userStoreManager);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
Response response = userManagementService.getUsers(null, "00", 0, 10, null);
|
|
|
|
Response response = userManagementService.getUsers(null, "00", 0, 10, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "GetUsers request failed");
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "GetUsers request failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -303,6 +334,8 @@ public class UserManagementServiceImplTest {
|
|
|
|
+ "DeviceManagementProviderService", dependsOnMethods = {"testGetUserCount"})
|
|
|
|
+ "DeviceManagementProviderService", dependsOnMethods = {"testGetUserCount"})
|
|
|
|
public void testNegativeScenarios1()
|
|
|
|
public void testNegativeScenarios1()
|
|
|
|
throws ConfigurationManagementException, DeviceManagementException, OTPManagementException {
|
|
|
|
throws ConfigurationManagementException, DeviceManagementException, OTPManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
@ -322,41 +355,61 @@ public class UserManagementServiceImplTest {
|
|
|
|
response = userManagementService.inviteToEnrollDevice(enrollmentInvitation);
|
|
|
|
response = userManagementService.inviteToEnrollDevice(enrollmentInvitation);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Invite existing users to enroll device succeeded under erroneous conditions");
|
|
|
|
"Invite existing users to enroll device succeeded under erroneous conditions");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This method tests the behaviour of the different methods when there is an issue is "
|
|
|
|
@Test(description = "This method tests the behaviour of the different methods when there is an issue is "
|
|
|
|
+ "userStoreManager", dependsOnMethods = {"testNegativeScenarios1"})
|
|
|
|
+ "userStoreManager", dependsOnMethods = {"testNegativeScenarios1"})
|
|
|
|
public void testNegativeScenarios2() throws UserStoreException {
|
|
|
|
public void testNegativeScenarios2() throws UserStoreException, UserManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
Mockito.doThrow(new UserStoreException()).when(userStoreManager).isExistingUser(TEST3_USERNAME);
|
|
|
|
Mockito.doThrow(new UserStoreException()).when(userStoreManager).isExistingUser(TEST3_USERNAME);
|
|
|
|
Response response = userManagementService.getUser(TEST3_USERNAME, null, null);
|
|
|
|
Response response = userManagementService.getUser(TEST3_USERNAME, null, null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
|
|
|
|
"Response returned successful for a user retrieval with problematic inputs");
|
|
|
|
|
|
|
|
Mockito.when(this.userManagementProviderService.getUser(Mockito.anyString()))
|
|
|
|
|
|
|
|
.thenThrow(new UserManagementException());
|
|
|
|
|
|
|
|
response = userManagementService.getUser(TEST3_USERNAME, null, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for a user retrieval with problematic inputs");
|
|
|
|
"Response returned successful for a user retrieval with problematic inputs");
|
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
|
userInfo.setUsername(TEST3_USERNAME);
|
|
|
|
userInfo.setUsername(TEST3_USERNAME);
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.userManagementProviderService.getUser(Mockito.anyString()))
|
|
|
|
|
|
|
|
.thenThrow(new UserManagementException());
|
|
|
|
response = userManagementService.addUser(userInfo);
|
|
|
|
response = userManagementService.addUser(userInfo);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for a user addition with problematic inputs");
|
|
|
|
"Response returned successful for a user addition with problematic inputs");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.userManagementProviderService.getUser(Mockito.anyString()))
|
|
|
|
|
|
|
|
.thenThrow(new UserManagementException());
|
|
|
|
response = userManagementService.updateUser(TEST3_USERNAME, null, userInfo);
|
|
|
|
response = userManagementService.updateUser(TEST3_USERNAME, null, userInfo);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for a user updating request with problematic inputs");
|
|
|
|
"Response returned successful for a user updating request with problematic inputs");
|
|
|
|
response = userManagementService.removeUser(TEST3_USERNAME, null);
|
|
|
|
response = userManagementService.removeUser(TEST3_USERNAME, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
|
|
|
"Response returned successful for a user removal request with problematic inputs");
|
|
|
|
"Response returned successful for a user removal request with problematic inputs");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.userManagementProviderService.getUser(Mockito.anyString()))
|
|
|
|
|
|
|
|
.thenThrow(new UserManagementException());
|
|
|
|
response = userManagementService.getRolesOfUser(TEST3_USERNAME, null);
|
|
|
|
response = userManagementService.getRolesOfUser(TEST3_USERNAME, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for a user role retrieval request with problematic inputs");
|
|
|
|
"Response returned successful for a user role retrieval request with problematic inputs");
|
|
|
|
response = userManagementService.isUserExists(TEST3_USERNAME);
|
|
|
|
response = userManagementService.isUserExists(TEST3_USERNAME);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for checking existence of user under problematic conditions");
|
|
|
|
"Response returned successful for checking existence of user under problematic conditions");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This method tests the behaviour of various methods when there is an issue with UserStore "
|
|
|
|
@Test(description = "This method tests the behaviour of various methods when there is an issue with UserStore "
|
|
|
|
+ "Manager", dependsOnMethods = {"testNegativeScenarios2"})
|
|
|
|
+ "Manager", dependsOnMethods = {"testNegativeScenarios2"})
|
|
|
|
public void testNegativeScenarios3() throws UserStoreException {
|
|
|
|
public void testNegativeScenarios3() throws UserStoreException, UserManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
.toReturn(this.userStoreManager);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserManagementService"))
|
|
|
|
|
|
|
|
.toReturn(userManagementProviderService);
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserRealm")).toReturn(userRealm);
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserRealm")).toReturn(userRealm);
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreCountRetrieverService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreCountRetrieverService"))
|
|
|
|
.toReturn(null);
|
|
|
|
.toReturn(null);
|
|
|
@ -370,12 +423,17 @@ public class UserManagementServiceImplTest {
|
|
|
|
.getUserClaimValue(Mockito.any(), Mockito.any(), Mockito.any());
|
|
|
|
.getUserClaimValue(Mockito.any(), Mockito.any(), Mockito.any());
|
|
|
|
Mockito.doThrow(new UserStoreException()).when(userStoreManager)
|
|
|
|
Mockito.doThrow(new UserStoreException()).when(userStoreManager)
|
|
|
|
.listUsers(Mockito.anyString(), Mockito.anyInt());
|
|
|
|
.listUsers(Mockito.anyString(), Mockito.anyInt());
|
|
|
|
|
|
|
|
Mockito.when(this.userManagementProviderService.getUsers(Mockito.anyString(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt()))
|
|
|
|
|
|
|
|
.thenThrow(new UserManagementException());
|
|
|
|
Response response = userManagementService.getUsers(TEST_USERNAME, "00", 0, 10, null);
|
|
|
|
Response response = userManagementService.getUsers(TEST_USERNAME, "00", 0, 10, null);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for a users retrieval request.");
|
|
|
|
"Response returned successful for a users retrieval request.");
|
|
|
|
response = userManagementService.getUserCount();
|
|
|
|
response = userManagementService.getUserCount();
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for a user count retrieval request.");
|
|
|
|
"Response returned successful for a user count retrieval request.");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.userManagementProviderService.getUserNames(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt()))
|
|
|
|
|
|
|
|
.thenThrow(new UserManagementException());
|
|
|
|
response = userManagementService.getUserNames(TEST_USERNAME, null, "00", 0, 10);
|
|
|
|
response = userManagementService.getUserNames(TEST_USERNAME, null, "00", 0, 10);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Response returned successful for a user count retrieval request.");
|
|
|
|
"Response returned successful for a user count retrieval request.");
|
|
|
@ -385,6 +443,7 @@ public class UserManagementServiceImplTest {
|
|
|
|
response = userManagementService.inviteExistingUsersToEnrollDevice(deviceEnrollmentInvitation);
|
|
|
|
response = userManagementService.inviteExistingUsersToEnrollDevice(deviceEnrollmentInvitation);
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
"Invite existing users to enroll device succeeded under erroneous conditions");
|
|
|
|
"Invite existing users to enroll device succeeded under erroneous conditions");
|
|
|
|
|
|
|
|
Mockito.reset(this.userManagementProviderService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|