From 7dcd2be02e96f6a201e3d08a93821a93889c520f Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Thu, 19 Dec 2019 11:40:20 +0530 Subject: [PATCH] Complete tests to remove devices --- .../DeviceTypeManagementAdminServiceTest.java | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java index c26c0463ee..3ee922c1f4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementAdminServiceTest.java @@ -15,6 +15,23 @@ * specific language governing permissions and limitations * under the License. */ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://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; @@ -218,31 +235,35 @@ public class DeviceTypeManagementAdminServiceTest { } @Test(description = "Test delete device type with correct request.") - public void testDeleteDeviceType() { + public void testDeleteDeviceType() throws DeviceManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) - .toReturn(this.deviceManagementProviderService); - Response response = this.deviceTypeManagementAdminService.deleteDeviceType(TEST_DEVICE_TYPE); - Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + .toReturn(deviceManagementProviderService); + Mockito.when(deviceManagementProviderService. + deleteDeviceType(Mockito.anyString(), Mockito.any(DeviceType.class))). + thenReturn(true); + Response response = deviceTypeManagementAdminService.deleteDeviceType(TEST_DEVICE_TYPE); + Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); } @Test(description = "Test delete device type when unavailable.") public void testDeleteNonExistingDeviceType() throws DeviceManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) - .toReturn(this.deviceManagementProviderService); + .toReturn(deviceManagementProviderService); Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null); - Response response = this.deviceTypeManagementAdminService.deleteDeviceType(TEST_DEVICE_TYPE); + Response response = deviceTypeManagementAdminService.deleteDeviceType(TEST_DEVICE_TYPE); Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); - Mockito.reset(this.deviceManagementProviderService); + Mockito.reset(deviceManagementProviderService); } @Test(description = "Test delete device type when DeviceManagementException is thrown.") public void testDeleteDeviceTypeWithException() throws DeviceManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) - .toReturn(this.deviceManagementProviderService); - Mockito.when(this.deviceManagementProviderService.deleteDeviceType(TEST_DEVICE_TYPE)) - .thenThrow(new DeviceManagementException()); - Response response = this.deviceTypeManagementAdminService.deleteDeviceType(TEST_DEVICE_TYPE); + .toReturn(deviceManagementProviderService); + Mockito.when(deviceManagementProviderService. + deleteDeviceType(Mockito.anyString(), Mockito.any(DeviceType.class))). + thenThrow(new DeviceManagementException()); + Response response = deviceTypeManagementAdminService.deleteDeviceType(TEST_DEVICE_TYPE); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); - Mockito.reset(this.deviceManagementProviderService); + Mockito.reset(deviceManagementProviderService); } }