mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fix test cases
This commit is contained in:
parent
fbaf21adc6
commit
3565e03c1b
@ -25,6 +25,7 @@ import org.wso2.carbon.context.CarbonContext;
|
|||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
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.DeviceTypeNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
@ -506,18 +507,22 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@PathParam("type") @Size(max = 45) String type,
|
@PathParam("type") @Size(max = 45) String type,
|
||||||
@PathParam("id") @Size(max = 45) String id,
|
@PathParam("id") @Size(max = 45) String id,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
List<Feature> features;
|
List<Feature> features = new ArrayList<>();
|
||||||
DeviceManagementProviderService dms;
|
DeviceManagementProviderService dms;
|
||||||
try {
|
try {
|
||||||
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
||||||
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
FeatureManager fm = dms.getFeatureManager(type);
|
FeatureManager fm;
|
||||||
if (fm == null) {
|
try {
|
||||||
|
fm = dms.getFeatureManager(type);
|
||||||
|
} catch (DeviceTypeNotFoundException e) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
new ErrorResponse.ErrorResponseBuilder()
|
||||||
"registered with the given type '" + type + "'").build()).build();
|
.setMessage("No device type found with name '" + type + "'").build()).build();
|
||||||
|
}
|
||||||
|
if (fm != null) {
|
||||||
|
features = fm.getFeatures();
|
||||||
}
|
}
|
||||||
features = fm.getFeatures();
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while retrieving the list of features of '" + type + "' device, which " +
|
String msg = "Error occurred while retrieving the list of features of '" + type + "' device, which " +
|
||||||
"carries the id '" + id + "'";
|
"carries the id '" + id + "'";
|
||||||
|
|||||||
@ -38,6 +38,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
@ -107,14 +108,19 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
|
|||||||
@Path("/{type}/features")
|
@Path("/{type}/features")
|
||||||
public Response getFeatures(@PathParam("type") @Size(max = 45) String type,
|
public Response getFeatures(@PathParam("type") @Size(max = 45) String type,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
List<Feature> features;
|
List<Feature> features = new ArrayList<>();
|
||||||
DeviceManagementProviderService dms;
|
DeviceManagementProviderService dms;
|
||||||
try {
|
try {
|
||||||
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
FeatureManager fm = dms.getFeatureManager(type);
|
FeatureManager fm;
|
||||||
if (fm == null) {
|
try {
|
||||||
features = new ArrayList<>();
|
fm = dms.getFeatureManager(type);
|
||||||
} else {
|
} catch (DeviceTypeNotFoundException e) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder()
|
||||||
|
.setMessage("No device type found with name '" + type + "'").build()).build();
|
||||||
|
}
|
||||||
|
if (fm != null) {
|
||||||
features = fm.getFeatures();
|
features = fm.getFeatures();
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import org.wso2.carbon.context.CarbonContext;
|
|||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
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.DeviceTypeNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
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.app.mgt.ApplicationManagementException;
|
||||||
@ -437,26 +438,15 @@ public class DeviceManagementServiceImplTest {
|
|||||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
|
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")
|
@Test(description = "Testing getting device features when unable to get the feature manager")
|
||||||
public void testGetFeaturesException() throws DeviceManagementException {
|
public void testGetFeaturesException() throws DeviceTypeNotFoundException {
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString()))
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString()))
|
||||||
.thenThrow(new DeviceManagementException());
|
.thenThrow(new DeviceTypeNotFoundException());
|
||||||
Response response = this.deviceManagementService
|
Response response = this.deviceManagementService
|
||||||
.getFeaturesOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
.getFeaturesOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
||||||
Mockito.reset(this.deviceManagementProviderService);
|
Mockito.reset(this.deviceManagementProviderService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -171,7 +171,7 @@ public class DeviceTypeManagementAdminServiceTest {
|
|||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
|
||||||
.toReturn(this.deviceTypeGeneratorService);
|
.toReturn(this.deviceTypeGeneratorService);
|
||||||
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(TEST_DEVICE_TYPE, deviceType);
|
||||||
Assert.assertNotNull(response, "The response should not be null");
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
"The Response Status code should be 200.");
|
"The Response Status code should be 200.");
|
||||||
@ -185,7 +185,7 @@ public class DeviceTypeManagementAdminServiceTest {
|
|||||||
.toReturn(this.deviceTypeGeneratorService);
|
.toReturn(this.deviceTypeGeneratorService);
|
||||||
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
|
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
|
||||||
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(TEST_DEVICE_TYPE, deviceType);
|
||||||
Assert.assertNotNull(response, "The response should not be null");
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
"The Response Status code should be 400.");
|
"The Response Status code should be 400.");
|
||||||
@ -196,7 +196,7 @@ public class DeviceTypeManagementAdminServiceTest {
|
|||||||
public void testUpdateDeviceTypeWithNullDeviceType() {
|
public void testUpdateDeviceTypeWithNullDeviceType() {
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Response response = this.deviceTypeManagementAdminService.updateDeviceType(null);
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(TEST_DEVICE_TYPE, null);
|
||||||
Assert.assertNotNull(response, "The response should not be null");
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
"The Response Status code should be 400.");
|
"The Response Status code should be 400.");
|
||||||
@ -210,7 +210,7 @@ public class DeviceTypeManagementAdminServiceTest {
|
|||||||
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString()))
|
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString()))
|
||||||
.thenThrow(new DeviceManagementException());
|
.thenThrow(new DeviceManagementException());
|
||||||
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
|
||||||
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
|
Response response = this.deviceTypeManagementAdminService.updateDeviceType(TEST_DEVICE_TYPE, deviceType);
|
||||||
Assert.assertNotNull(response, "The response should not be null");
|
Assert.assertNotNull(response, "The response should not be null");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
"The Response Status code should be 500.");
|
"The Response Status code should be 500.");
|
||||||
|
|||||||
@ -89,7 +89,7 @@ public class DeviceTypeManagementServiceTest {
|
|||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenThrow(new DeviceManagementException());
|
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenThrow(new DeviceManagementException());
|
||||||
Response response = this.deviceTypeManagementService.getDeviceTypes();
|
Response response = this.deviceTypeManagementService.getDeviceTypes(MODIFIED_SINCE);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
"The response status should be 500.");
|
"The response status should be 500.");
|
||||||
@ -100,7 +100,7 @@ public class DeviceTypeManagementServiceTest {
|
|||||||
public void testExistingDeviceTypesModifiedError() throws Exception {
|
public void testExistingDeviceTypesModifiedError() throws Exception {
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenThrow(new
|
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenThrow(new
|
||||||
DeviceManagementException());
|
DeviceManagementException());
|
||||||
Response response = this.deviceTypeManagementService.getDeviceTypes(MODIFIED_SINCE);
|
Response response = this.deviceTypeManagementService.getDeviceTypes(MODIFIED_SINCE);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
@ -142,8 +142,9 @@ public class DeviceTypeManagementServiceTest {
|
|||||||
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn(null);
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn(null);
|
||||||
Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE);
|
Response response = this.deviceTypeManagementService.getFeatures(TEST_DEVICE_TYPE, MODIFIED_SINCE);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
"The response status should be 404.");
|
"The response status should be 200.");
|
||||||
|
Assert.assertEquals(response.getEntity().toString(), "[]", "The response should be [].");
|
||||||
Mockito.reset(deviceManagementProviderService);
|
Mockito.reset(deviceManagementProviderService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +152,7 @@ public class DeviceTypeManagementServiceTest {
|
|||||||
public void testGetDeviceTypes() throws Exception {
|
public void testGetDeviceTypes() throws Exception {
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Response response = this.deviceTypeManagementService.getDeviceTypes();
|
Response response = this.deviceTypeManagementService.getDeviceTypes(MODIFIED_SINCE);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
"The response status should be 200.");
|
"The response status should be 200.");
|
||||||
@ -163,7 +164,7 @@ public class DeviceTypeManagementServiceTest {
|
|||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
List<DeviceType> deviceTypes = DeviceMgtAPITestHelper.getDummyDeviceTypeList(5);
|
List<DeviceType> deviceTypes = DeviceMgtAPITestHelper.getDummyDeviceTypeList(5);
|
||||||
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenReturn(deviceTypes);
|
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenReturn(deviceTypes);
|
||||||
Response response = this.deviceTypeManagementService.getDeviceTypes();
|
Response response = this.deviceTypeManagementService.getDeviceTypes(MODIFIED_SINCE);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
"The response state should be 200");
|
"The response state should be 200");
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.common;
|
||||||
|
|
||||||
|
public class DeviceTypeNotFoundException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3821589758650454161L;
|
||||||
|
|
||||||
|
public DeviceTypeNotFoundException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceTypeNotFoundException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceTypeNotFoundException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceTypeNotFoundException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceTypeNotFoundException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -486,7 +486,7 @@ public interface DeviceManagementProviderService {
|
|||||||
|
|
||||||
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException;
|
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException;
|
||||||
|
|
||||||
FeatureManager getFeatureManager(String deviceType) throws DeviceManagementException;
|
FeatureManager getFeatureManager(String deviceType) throws DeviceTypeNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy method to get the tenant configuration of a given platform.
|
* Proxy method to get the tenant configuration of a given platform.
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManager;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceNotification;
|
import org.wso2.carbon.device.mgt.common.DeviceNotification;
|
||||||
import org.wso2.carbon.device.mgt.common.DevicePropertyNotification;
|
import org.wso2.carbon.device.mgt.common.DevicePropertyNotification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
||||||
@ -171,14 +172,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FeatureManager getFeatureManager(String deviceType) throws DeviceManagementException {
|
public FeatureManager getFeatureManager(String deviceType) throws DeviceTypeNotFoundException {
|
||||||
DeviceManager deviceManager = this.getDeviceManager(deviceType);
|
DeviceManager deviceManager = this.getDeviceManager(deviceType);
|
||||||
if (deviceManager == null) {
|
if (deviceManager == null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device Manager associated with the device type '" + deviceType + "' is null. " +
|
log.debug("Device Manager associated with the device type '" + deviceType + "' is null. " +
|
||||||
"Therefore, not attempting method 'getFeatureManager'");
|
"Therefore, not attempting method 'getFeatureManager'");
|
||||||
}
|
}
|
||||||
return null;
|
throw new DeviceTypeNotFoundException("Device type '" + deviceType + "' not found.");
|
||||||
}
|
}
|
||||||
return deviceManager.getFeatureManager();
|
return deviceManager.getFeatureManager();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.context.CarbonContext;
|
|||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
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.DeviceTypeNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
@ -499,7 +500,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
try {
|
try {
|
||||||
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
||||||
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
FeatureManager fm = dms.getFeatureManager(type);
|
FeatureManager fm;
|
||||||
|
try {
|
||||||
|
fm = dms.getFeatureManager(type);
|
||||||
|
} catch (DeviceTypeNotFoundException e) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
||||||
|
"registered with the given type '" + type + "'").build()).build();
|
||||||
|
}
|
||||||
if (fm == null) {
|
if (fm == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
||||||
|
|||||||
@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceTypeNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
@ -76,11 +77,18 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
|
|||||||
DeviceManagementProviderService dms;
|
DeviceManagementProviderService dms;
|
||||||
try {
|
try {
|
||||||
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
FeatureManager fm = dms.getFeatureManager(type);
|
FeatureManager fm;
|
||||||
|
try {
|
||||||
|
fm = dms.getFeatureManager(type);
|
||||||
|
} catch (DeviceTypeNotFoundException e) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
||||||
|
"registered with the given type '" + type + "'").build()).build();
|
||||||
|
}
|
||||||
if (fm == null) {
|
if (fm == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
|
||||||
"registered with the given type '" + type + "'").build()).build();
|
"registered with the given type '" + type + "'").build()).build();
|
||||||
}
|
}
|
||||||
features = fm.getFeatures();
|
features = fm.getFeatures();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
|
|||||||
@ -31,9 +31,9 @@ import org.testng.annotations.BeforeClass;
|
|||||||
import org.testng.annotations.ObjectFactory;
|
import org.testng.annotations.ObjectFactory;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
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.DeviceTypeNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
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.app.mgt.ApplicationManagementException;
|
||||||
@ -437,7 +437,7 @@ public class DeviceManagementServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "Testing getting device features when feature manager is not registered for the device type")
|
@Test(description = "Testing getting device features when feature manager is not registered for the device type")
|
||||||
public void testGetFeaturesOfDeviceWhenFeatureManagerIsNotRegistered() throws DeviceManagementException {
|
public void testGetFeaturesOfDeviceWhenFeatureManagerIsNotRegistered() throws DeviceTypeNotFoundException {
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn(null);
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString())).thenReturn(null);
|
||||||
@ -448,14 +448,14 @@ public class DeviceManagementServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "Testing getting device features when unable to get the feature manager")
|
@Test(description = "Testing getting device features when unable to get the feature manager")
|
||||||
public void testGetFeaturesException() throws DeviceManagementException {
|
public void testGetFeaturesException() throws DeviceTypeNotFoundException {
|
||||||
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
|
||||||
.toReturn(this.deviceManagementProviderService);
|
.toReturn(this.deviceManagementProviderService);
|
||||||
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString()))
|
Mockito.when(this.deviceManagementProviderService.getFeatureManager(Mockito.anyString()))
|
||||||
.thenThrow(new DeviceManagementException());
|
.thenThrow(new DeviceTypeNotFoundException());
|
||||||
Response response = this.deviceManagementService
|
Response response = this.deviceManagementService
|
||||||
.getFeaturesOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
.getFeaturesOfDevice(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null);
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
|
||||||
Mockito.reset(this.deviceManagementProviderService);
|
Mockito.reset(this.deviceManagementProviderService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user