|
|
@ -34,13 +34,25 @@ import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.impl.SearchManagerServiceImpl;
|
|
|
|
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.service.api.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@ -78,7 +90,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
@BeforeClass
|
|
|
|
public void init() throws Exception {
|
|
|
|
public void init() {
|
|
|
|
log.info("Initializing DeviceManagementServiceImpl tests");
|
|
|
|
log.info("Initializing DeviceManagementServiceImpl tests");
|
|
|
|
initMocks(this);
|
|
|
|
initMocks(this);
|
|
|
|
this.deviceManagementProviderService = Mockito
|
|
|
|
this.deviceManagementProviderService = Mockito
|
|
|
@ -88,7 +100,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing if the device is enrolled when the device is enrolled.")
|
|
|
|
@Test(description = "Testing if the device is enrolled when the device is enrolled.")
|
|
|
|
public void testIsEnrolledWhenDeviceIsEnrolled() throws Exception {
|
|
|
|
public void testIsEnrolledWhenDeviceIsEnrolled() throws DeviceManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
|
|
@ -101,7 +113,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing if the device is enrolled when the device is not enrolled.",
|
|
|
|
@Test(description = "Testing if the device is enrolled when the device is not enrolled.",
|
|
|
|
dependsOnMethods = "testIsEnrolledWhenDeviceIsEnrolled")
|
|
|
|
dependsOnMethods = "testIsEnrolledWhenDeviceIsEnrolled")
|
|
|
|
public void testIsEnrolledWhenDeviceIsNotEnrolled() throws Exception {
|
|
|
|
public void testIsEnrolledWhenDeviceIsNotEnrolled() throws DeviceManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
|
|
@ -114,7 +126,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing if the device enrolled api when exception occurred.",
|
|
|
|
@Test(description = "Testing if the device enrolled api when exception occurred.",
|
|
|
|
dependsOnMethods = "testIsEnrolledWhenDeviceIsNotEnrolled")
|
|
|
|
dependsOnMethods = "testIsEnrolledWhenDeviceIsNotEnrolled")
|
|
|
|
public void testIsEnrolledError() throws Exception {
|
|
|
|
public void testIsEnrolledError() throws DeviceManagementException {
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
Mockito.when(this.deviceManagementProviderService.isEnrolled(Mockito.any(DeviceIdentifier.class)))
|
|
|
@ -126,7 +138,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices when request exists both name and role.")
|
|
|
|
@Test(description = "Testing get devices when request exists both name and role.")
|
|
|
|
public void testGetDevicesWhenBothNameAndRoleAvailable() throws Exception {
|
|
|
|
public void testGetDevicesWhenBothNameAndRoleAvailable() {
|
|
|
|
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, "getDeviceAccessAuthorizationService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
|
|
@ -138,7 +150,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices with correct request.")
|
|
|
|
@Test(description = "Testing get devices with correct request.")
|
|
|
|
public void testGetDevices() throws Exception {
|
|
|
|
public void testGetDevices() {
|
|
|
|
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, "getDeviceAccessAuthorizationService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
|
|
@ -167,7 +179,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices when DeviceAccessAuthorizationService is not available")
|
|
|
|
@Test(description = "Testing get devices when DeviceAccessAuthorizationService is not available")
|
|
|
|
public void testGetDevicesWithErroneousDeviceAccessAuthorizationService() throws Exception {
|
|
|
|
public void testGetDevicesWithErroneousDeviceAccessAuthorizationService() {
|
|
|
|
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, "getDeviceAccessAuthorizationService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
|
|
@ -179,7 +191,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices when user is the device admin")
|
|
|
|
@Test(description = "Testing get devices when user is the device admin")
|
|
|
|
public void testGetDevicesWhenUserIsAdmin() throws Exception {
|
|
|
|
public void testGetDevicesWhenUserIsAdmin() throws DeviceAccessAuthorizationException {
|
|
|
|
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, "getDeviceAccessAuthorizationService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
|
|
@ -222,7 +234,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices with IF-Modified-Since")
|
|
|
|
@Test(description = "Testing get devices with IF-Modified-Since")
|
|
|
|
public void testGetDevicesWithModifiedSince() throws Exception {
|
|
|
|
public void testGetDevicesWithModifiedSince() {
|
|
|
|
String ifModifiedSince = new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(new Date());
|
|
|
|
String ifModifiedSince = new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(new Date());
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
@ -248,7 +260,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices with Since")
|
|
|
|
@Test(description = "Testing get devices with Since")
|
|
|
|
public void testGetDevicesWithSince() throws Exception {
|
|
|
|
public void testGetDevicesWithSince() {
|
|
|
|
String since = new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(new Date());
|
|
|
|
String since = new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(new Date());
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
@ -274,7 +286,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices when unable to retrieve devices")
|
|
|
|
@Test(description = "Testing get devices when unable to retrieve devices")
|
|
|
|
public void testGetDeviceServerErrorWhenGettingDeviceList() throws Exception {
|
|
|
|
public void testGetDeviceServerErrorWhenGettingDeviceList() throws DeviceManagementException {
|
|
|
|
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, "getDeviceAccessAuthorizationService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
|
|
@ -283,7 +295,8 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
.toReturn(TENANT_AWARE_USERNAME);
|
|
|
|
.toReturn(TENANT_AWARE_USERNAME);
|
|
|
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
|
|
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
|
|
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
|
|
|
Mockito.when(this.deviceManagementProviderService.getAllDevices(Mockito.any(PaginationRequest.class), Mockito.anyBoolean()))
|
|
|
|
Mockito.when(this.deviceManagementProviderService
|
|
|
|
|
|
|
|
.getAllDevices(Mockito.any(PaginationRequest.class), Mockito.anyBoolean()))
|
|
|
|
.thenThrow(new DeviceManagementException());
|
|
|
|
.thenThrow(new DeviceManagementException());
|
|
|
|
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
Response response = this.deviceManagementService
|
|
|
@ -294,7 +307,7 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices when unable to check if the user is the admin user")
|
|
|
|
@Test(description = "Testing get devices when unable to check if the user is the admin user")
|
|
|
|
public void testGetDevicesServerErrorWhenCheckingAdminUser() throws Exception {
|
|
|
|
public void testGetDevicesServerErrorWhenCheckingAdminUser() throws DeviceAccessAuthorizationException {
|
|
|
|
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, "getDeviceAccessAuthorizationService"))
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
|
|
|
@ -312,4 +325,232 @@ public class DeviceManagementServiceImplTest {
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
Mockito.reset(this.deviceAccessAuthorizationService);
|
|
|
|
Mockito.reset(this.deviceAccessAuthorizationService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices with correct request")
|
|
|
|
|
|
|
|
public void testGetDeviceTypesByUser() throws DeviceManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
|
|
|
|
|
|
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService.getDeviceByUser(true, 10, 5);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
|
|
|
|
|
|
|
response = this.deviceManagementService.getDeviceByUser(false, 10, 5);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing get devices with correct request when unable to get devices.")
|
|
|
|
|
|
|
|
public void testGetDeviceTypesByUserException() throws DeviceManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
|
|
|
|
|
|
|
|
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
|
|
|
|
|
|
|
|
Mockito.when(this.deviceManagementProviderService.getDevicesOfUser(Mockito.any(PaginationRequest.class)))
|
|
|
|
|
|
|
|
.thenThrow(new DeviceManagementException());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService.getDeviceByUser(true, 10, 5);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing delete device with correct request.")
|
|
|
|
|
|
|
|
public void testDeleteDevice() {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService.deleteDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString());
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing delete unavailable device.")
|
|
|
|
|
|
|
|
public void testDeleteUnavailableDevice() throws DeviceManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.deviceManagementProviderService
|
|
|
|
|
|
|
|
.getDevice(Mockito.any(DeviceIdentifier.class), Mockito.anyBoolean())).thenReturn(null);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService.deleteDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString());
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
|
|
|
|
|
|
|
Mockito.reset(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing delete device when unable to delete device.")
|
|
|
|
|
|
|
|
public void testDeleteDeviceException() throws DeviceManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.deviceManagementProviderService.disenrollDevice(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
|
|
|
|
.thenThrow(new DeviceManagementException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService.deleteDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString());
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
|
|
|
|
|
|
|
|
Mockito.reset(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting device location")
|
|
|
|
|
|
|
|
public void testGetDeviceLocation() {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceInformationManagerService")).
|
|
|
|
|
|
|
|
toReturn(Mockito.mock(DeviceInformationManagerImpl.class, Mockito.RETURNS_MOCKS));
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getDeviceLocation(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting device location when unable to retrieve location")
|
|
|
|
|
|
|
|
public void testGetDeviceLocationException() throws DeviceDetailsMgtException {
|
|
|
|
|
|
|
|
DeviceInformationManager deviceInformationManager = Mockito
|
|
|
|
|
|
|
|
.mock(DeviceInformationManagerImpl.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceInformationManagerService")).
|
|
|
|
|
|
|
|
toReturn(deviceInformationManager);
|
|
|
|
|
|
|
|
Mockito.when(deviceInformationManager.getDeviceLocation(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
|
|
|
|
.thenThrow(new DeviceDetailsMgtException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getDeviceLocation(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting device information")
|
|
|
|
|
|
|
|
public void testGetDeviceInformation() {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceInformationManagerService")).
|
|
|
|
|
|
|
|
toReturn(Mockito.mock(DeviceInformationManagerImpl.class, Mockito.RETURNS_MOCKS));
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getDeviceInformation(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting device information when unable to retrieve information")
|
|
|
|
|
|
|
|
public void testGetDeviceInformationException() throws DeviceDetailsMgtException {
|
|
|
|
|
|
|
|
DeviceInformationManager deviceInformationManager = Mockito
|
|
|
|
|
|
|
|
.mock(DeviceInformationManagerImpl.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceInformationManagerService")).
|
|
|
|
|
|
|
|
toReturn(deviceInformationManager);
|
|
|
|
|
|
|
|
Mockito.when(deviceInformationManager.getDeviceInfo(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
|
|
|
|
.thenThrow(new DeviceDetailsMgtException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getDeviceInformation(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting device features")
|
|
|
|
|
|
|
|
public void testGetFeaturesOfDevice() {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getFeaturesOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting device features when feature manager is not registered for the device type")
|
|
|
|
|
|
|
|
public void testGetFeaturesOfDeviceWhenFeatureManagerIsNotRegistered() throws DeviceManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn(null);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getFeaturesOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
|
|
|
|
|
|
|
Mockito.reset(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting device features when unable to get the feature manager")
|
|
|
|
|
|
|
|
public void testGetFeaturesException() throws DeviceManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString()))
|
|
|
|
|
|
|
|
.thenThrow(new DeviceManagementException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getFeaturesOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
|
|
|
Mockito.reset(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing search devices")
|
|
|
|
|
|
|
|
public void testSearchDevices() {
|
|
|
|
|
|
|
|
SearchManagerService searchManagerService = Mockito.mock(SearchManagerServiceImpl.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getSearchManagerService"))
|
|
|
|
|
|
|
|
.toReturn(searchManagerService);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.searchDevices(10, 5, new SearchContext());
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects to return HTTP 200 when the search is successful");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing search devices when unable to search devices")
|
|
|
|
|
|
|
|
public void testSearchDevicesException() throws SearchMgtException {
|
|
|
|
|
|
|
|
SearchManagerService searchManagerService = Mockito.mock(SearchManagerServiceImpl.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getSearchManagerService"))
|
|
|
|
|
|
|
|
.toReturn(searchManagerService);
|
|
|
|
|
|
|
|
Mockito.when(searchManagerService.search(Mockito.any(SearchContext.class))).thenThrow(new SearchMgtException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.searchDevices(10, 5, new SearchContext());
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects HTTP 500 when an exception occurred while searching the device");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting installed applications of a device")
|
|
|
|
|
|
|
|
public void testGetInstalledApplications() {
|
|
|
|
|
|
|
|
ApplicationManagementProviderService applicationManagementProviderService = Mockito
|
|
|
|
|
|
|
|
.mock(ApplicationManagementProviderService.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAppManagementService"))
|
|
|
|
|
|
|
|
.toReturn(applicationManagementProviderService);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getInstalledApplications(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), "", 10, 5);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects to return HTTP 200 when the application list is retrieved successfully.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting installed applications of a device when unable to fetch applications")
|
|
|
|
|
|
|
|
public void testGetInstalledApplicationsException() throws ApplicationManagementException {
|
|
|
|
|
|
|
|
ApplicationManagementProviderService applicationManagementProviderService = Mockito
|
|
|
|
|
|
|
|
.mock(ApplicationManagementProviderService.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAppManagementService"))
|
|
|
|
|
|
|
|
.toReturn(applicationManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(
|
|
|
|
|
|
|
|
applicationManagementProviderService.getApplicationListForDevice(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
|
|
|
|
.thenThrow(new ApplicationManagementException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getInstalledApplications(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), "", 10, 5);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects HTTP 500 when an exception occurred while retrieving application list of the device");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting operation list of a device")
|
|
|
|
|
|
|
|
public void testGetDeviceOperations() {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getDeviceOperations(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), "", 10, 5, DEFAULT_USERNAME);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects to return HTTP 200 when the operation is retrieved successfully.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting operation list of a device when unable to retrieve operations")
|
|
|
|
|
|
|
|
public void testGetDeviceOperationsException() throws OperationManagementException {
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
|
|
|
|
|
|
|
.toReturn(this.deviceManagementProviderService);
|
|
|
|
|
|
|
|
Mockito.when(this.deviceManagementProviderService.getOperations(Mockito.any(DeviceIdentifier.class),
|
|
|
|
|
|
|
|
Mockito.any(PaginationRequest.class))).thenThrow(new OperationManagementException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getDeviceOperations(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), "", 10, 5, DEFAULT_USERNAME);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects to return HTTP 500 when an exception occurred while retrieving operation list of the device");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting effective policy of a device")
|
|
|
|
|
|
|
|
public void testGetEffectivePolicyOfDevice() throws PolicyManagementException {
|
|
|
|
|
|
|
|
PolicyManagerService policyManagerService = Mockito.mock(PolicyManagerService.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getPolicyManagementService"))
|
|
|
|
|
|
|
|
.toReturn(policyManagerService);
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getEffectivePolicyOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects to return HTTP 200 when retrieving effective policy is successful");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Testing getting effective policy of a device when unable to retrieve effective policy")
|
|
|
|
|
|
|
|
public void testGetEffectivePolicyOfDeviceException() throws PolicyManagementException {
|
|
|
|
|
|
|
|
PolicyManagerService policyManagerService = Mockito.mock(PolicyManagerService.class, Mockito.RETURNS_MOCKS);
|
|
|
|
|
|
|
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getPolicyManagementService"))
|
|
|
|
|
|
|
|
.toReturn(policyManagerService);
|
|
|
|
|
|
|
|
Mockito.when(policyManagerService.getAppliedPolicyToDevice(Mockito.any(DeviceIdentifier.class)))
|
|
|
|
|
|
|
|
.thenThrow(new PolicyManagementException());
|
|
|
|
|
|
|
|
Response response = this.deviceManagementService
|
|
|
|
|
|
|
|
.getEffectivePolicyOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
|
|
|
|
|
|
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
|
|
|
|
|
|
|
"Expects to return HTTP 500 when an exception occurred while getting effective policy of the device");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|