mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Modify test cases related to device enrollment invitation
This commit is contained in:
parent
1b0c19cb02
commit
0e018679b8
@ -15,6 +15,23 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you 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.wso2.carbon.device.mgt.jaxrs.service.impl;
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
||||||
@ -34,6 +51,10 @@ import org.testng.annotations.Test;
|
|||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.OTPManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.otp.mgt.service.OTPManagementServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfo;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfo;
|
||||||
@ -66,9 +87,11 @@ public class UserManagementServiceImplTest {
|
|||||||
private UserStoreManager userStoreManager;
|
private UserStoreManager userStoreManager;
|
||||||
private UserManagementService userManagementService;
|
private UserManagementService userManagementService;
|
||||||
private DeviceManagementProviderService deviceManagementProviderService;
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
private OTPManagementService otpManagementService;
|
||||||
private static final String DEFAULT_DEVICE_USER = "Internal/devicemgt-user";
|
private static final String DEFAULT_DEVICE_USER = "Internal/devicemgt-user";
|
||||||
private UserRealm userRealm;
|
private UserRealm userRealm;
|
||||||
private EnrollmentInvitation enrollmentInvitation;
|
private EnrollmentInvitation enrollmentInvitation;
|
||||||
|
private DeviceEnrollmentInvitation deviceEnrollmentInvitation;
|
||||||
private List<String> userList;
|
private List<String> userList;
|
||||||
private static final String TEST_USERNAME = "test";
|
private static final String TEST_USERNAME = "test";
|
||||||
private static final String TEST2_USERNAME = "test2";
|
private static final String TEST2_USERNAME = "test2";
|
||||||
@ -86,6 +109,7 @@ public class UserManagementServiceImplTest {
|
|||||||
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);
|
||||||
|
otpManagementService = Mockito.mock(OTPManagementServiceImpl.class, Mockito.CALLS_REAL_METHODS);
|
||||||
userRealm = Mockito.mock(UserRealm.class);
|
userRealm = Mockito.mock(UserRealm.class);
|
||||||
RealmConfiguration realmConfiguration = Mockito.mock(RealmConfiguration.class);
|
RealmConfiguration realmConfiguration = Mockito.mock(RealmConfiguration.class);
|
||||||
Mockito.doReturn(null).when(realmConfiguration).getSecondaryRealmConfig();
|
Mockito.doReturn(null).when(realmConfiguration).getSecondaryRealmConfig();
|
||||||
@ -97,6 +121,8 @@ public class UserManagementServiceImplTest {
|
|||||||
enrollmentInvitation.setRecipients(recipients);
|
enrollmentInvitation.setRecipients(recipients);
|
||||||
userList = new ArrayList<>();
|
userList = new ArrayList<>();
|
||||||
userList.add(TEST_USERNAME);
|
userList.add(TEST_USERNAME);
|
||||||
|
deviceEnrollmentInvitation = new DeviceEnrollmentInvitation();
|
||||||
|
deviceEnrollmentInvitation.setUsernames(userList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "This method tests the addUser method of UserManagementService")
|
@Test(description = "This method tests the addUser method of UserManagementService")
|
||||||
@ -205,13 +231,11 @@ public class UserManagementServiceImplTest {
|
|||||||
|
|
||||||
@Test(description = "This method tests the send invitation method of UserManagementService", dependsOnMethods =
|
@Test(description = "This method tests the send invitation method of UserManagementService", dependsOnMethods =
|
||||||
{"testIsUserExists"})
|
{"testIsUserExists"})
|
||||||
public void testSendInvitation() throws ConfigurationManagementException, DeviceManagementException {
|
public void testSendInvitation() throws OTPManagementException {
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getOTPManagementService"))
|
||||||
.toReturn(this.userStoreManager);
|
.toReturn(this.otpManagementService);
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
Mockito.doNothing().when(otpManagementService).sendDeviceEnrollmentInvitationMail(Mockito.any());
|
||||||
.toReturn(this.deviceManagementProviderService);
|
Response response = userManagementService.inviteExistingUsersToEnrollDevice(deviceEnrollmentInvitation);
|
||||||
Mockito.doNothing().when(deviceManagementProviderService).sendEnrolmentInvitation(Mockito.any(), Mockito.any());
|
|
||||||
Response response = userManagementService.inviteExistingUsersToEnrollDevice(userList);
|
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
"Inviting existing users to enroll device failed");
|
"Inviting existing users to enroll device failed");
|
||||||
}
|
}
|
||||||
@ -240,7 +264,7 @@ public class UserManagementServiceImplTest {
|
|||||||
|
|
||||||
@Test(description = "This method tests the inviteToEnrollDevice method of UserManagementService",
|
@Test(description = "This method tests the inviteToEnrollDevice method of UserManagementService",
|
||||||
dependsOnMethods = "testGetUsers")
|
dependsOnMethods = "testGetUsers")
|
||||||
public void testInviteToEnrollDevice() {
|
public void testInviteToEnrollDevice() throws ConfigurationManagementException, DeviceManagementException {
|
||||||
URL resourceUrl = ClassLoader.getSystemResource("testng.xml");
|
URL resourceUrl = ClassLoader.getSystemResource("testng.xml");
|
||||||
System.setProperty("carbon.home", resourceUrl.getPath());
|
System.setProperty("carbon.home", resourceUrl.getPath());
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
|
||||||
@ -248,6 +272,7 @@ public class UserManagementServiceImplTest {
|
|||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAuthenticatedUser")).toReturn(TEST_USERNAME);
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAuthenticatedUser")).toReturn(TEST_USERNAME);
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
|
Mockito.doNothing().when(deviceManagementProviderService).sendEnrolmentInvitation(Mockito.any(), Mockito.any());
|
||||||
EnrollmentInvitation enrollmentInvitation = new EnrollmentInvitation();
|
EnrollmentInvitation enrollmentInvitation = new EnrollmentInvitation();
|
||||||
List<String> recipients = new ArrayList<>();
|
List<String> recipients = new ArrayList<>();
|
||||||
recipients.add(TEST_USERNAME);
|
recipients.add(TEST_USERNAME);
|
||||||
@ -289,16 +314,22 @@ public class UserManagementServiceImplTest {
|
|||||||
|
|
||||||
@Test(description = "This method tests the behaviour of methods when there is an issue with "
|
@Test(description = "This method tests the behaviour of methods when there is an issue with "
|
||||||
+ "DeviceManagementProviderService", dependsOnMethods = {"testGetUserCount"})
|
+ "DeviceManagementProviderService", dependsOnMethods = {"testGetUserCount"})
|
||||||
public void testNegativeScenarios1() throws ConfigurationManagementException, DeviceManagementException {
|
public void testNegativeScenarios1()
|
||||||
|
throws ConfigurationManagementException, DeviceManagementException, OTPManagementException {
|
||||||
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"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAuthenticatedUser")).toReturn(TEST_USERNAME);
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAuthenticatedUser")).toReturn(TEST_USERNAME);
|
||||||
Mockito.reset(deviceManagementProviderService);
|
Mockito.reset(deviceManagementProviderService);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getOTPManagementService"))
|
||||||
|
.toReturn(this.otpManagementService);
|
||||||
|
Mockito.reset(otpManagementService);
|
||||||
Mockito.doThrow(new DeviceManagementException()).when(deviceManagementProviderService)
|
Mockito.doThrow(new DeviceManagementException()).when(deviceManagementProviderService)
|
||||||
.sendEnrolmentInvitation(Mockito.any(), Mockito.any());
|
.sendEnrolmentInvitation(Mockito.any(), Mockito.any());
|
||||||
Response response = userManagementService.inviteExistingUsersToEnrollDevice(userList);
|
Mockito.doThrow(new OTPManagementException()).when(otpManagementService)
|
||||||
|
.sendDeviceEnrollmentInvitationMail(Mockito.any());
|
||||||
|
Response 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");
|
||||||
response = userManagementService.inviteToEnrollDevice(enrollmentInvitation);
|
response = userManagementService.inviteToEnrollDevice(enrollmentInvitation);
|
||||||
@ -346,6 +377,8 @@ public class UserManagementServiceImplTest {
|
|||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Mockito.reset(this.userStoreManager);
|
Mockito.reset(this.userStoreManager);
|
||||||
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getOTPManagementService"))
|
||||||
|
.toReturn(this.otpManagementService);
|
||||||
Mockito.doThrow(new UserStoreException()).when(userStoreManager)
|
Mockito.doThrow(new UserStoreException()).when(userStoreManager)
|
||||||
.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)
|
||||||
@ -362,7 +395,7 @@ 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");
|
||||||
response = userManagementService.inviteExistingUsersToEnrollDevice(userList);
|
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");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import org.wso2.carbon.device.mgt.common.*;
|
|||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
|
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
||||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
@ -142,4 +143,9 @@ public class TestDeviceManagementService implements DeviceManagementService {
|
|||||||
public DeviceTypePlatformDetails getDeviceTypePlatformDetails() {
|
public DeviceTypePlatformDetails getDeviceTypePlatformDetails() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceEnrollmentInvitationDetails getDeviceEnrollmentInvitationDetails() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,6 +44,7 @@ import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
|||||||
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||||
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
|
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
||||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
@ -131,4 +132,9 @@ public class TypeXDeviceManagementService implements DeviceManagementService {
|
|||||||
public DeviceTypePlatformDetails getDeviceTypePlatformDetails() {
|
public DeviceTypePlatformDetails getDeviceTypePlatformDetails() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceEnrollmentInvitationDetails getDeviceEnrollmentInvitationDetails() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user