本文整理汇总了Java中org.wso2.carbon.device.mgt.common.DeviceManagementException类的典型用法代码示例。如果您正苦于以下问题:Java DeviceManagementException类的具体用法?Java DeviceManagementException怎么用?Java DeviceManagementException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeviceManagementException类属于org.wso2.carbon.device.mgt.common包,在下文中一共展示了DeviceManagementException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEffectivePolicy
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(dependsOnMethods = ("activatePolicies"))
public void getEffectivePolicy(DeviceIdentifier identifier) throws DeviceManagementException, PolicyEvaluationException {
log.debug("Getting effective policy for device started ..........");
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
List<Device> devices = service.getAllDevices(ANDROID, false);
PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
for (Device device : devices) {
identifier.setType(device.getType());
identifier.setId(device.getDeviceIdentifier());
Policy policy = evaluationPoint.getEffectivePolicy(identifier);
if (policy != null) {
log.debug("Name of the policy applied to device is " + policy.getPolicyName());
} else {
log.debug("No policy is applied to device.");
}
}
}
示例2: testIsCompliantThrowingDeviceManagementException
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(description = "This test case tests handling DeviceManagementException when testing policy compliance",
dependsOnMethods = "testIsCompliant2")
public void testIsCompliantThrowingDeviceManagementException() throws Exception {
DeviceManagementProviderService serviceMock = mock(DeviceManagementProviderService.class);
doThrow(new DeviceManagementException()).when(serviceMock).getDevice(any(DeviceIdentifier.class), anyBoolean());
PolicyManagementDataHolder instance = PolicyManagementDataHolder.getInstance();
DeviceManagementProviderService service = instance.getDeviceManagementService();
instance.setDeviceManagementService(serviceMock);
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setType(DEVICE_TYPE_E);
deviceIdentifier.setId(String.valueOf(device5.getDeviceIdentifier()));
monitoringManager.isCompliant(deviceIdentifier);
} catch (Exception e) {
if (!(e.getCause() instanceof DeviceManagementException)) {
throw e;
}
} finally {
instance.setDeviceManagementService(service);
}
}
示例3: changeDeviceStatus
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
/**
* Change device status.
*
* @param type Device type
* @param id Device id
* @param newsStatus Device new status
* @return {@link Response} object
*/
@PUT
@Path("/{type}/{id}/changestatus")
public Response changeDeviceStatus(@PathParam("type") @Size(max = 45) String type,
@PathParam("id") @Size(max = 45) String id,
@QueryParam("newStatus") EnrolmentInfo.Status newsStatus) {
RequestValidationUtil.validateDeviceIdentifier(type, id);
DeviceManagementProviderService deviceManagementProviderService =
DeviceMgtAPIUtils.getDeviceManagementService();
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type);
Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier, false);
if (persistedDevice == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
boolean response = deviceManagementProviderService.changeDeviceStatus(deviceIdentifier, newsStatus);
return Response.status(Response.Status.OK).entity(response).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while changing device status of type : " + type + " and " +
"device id : " + id;
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
示例4: getPolicyFromWrapper
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
private Policy getPolicyFromWrapper(@Valid PolicyWrapper policyWrapper) throws DeviceManagementException {
Policy policy = new Policy();
policy.setPolicyName(policyWrapper.getPolicyName());
policy.setDescription(policyWrapper.getDescription());
policy.setProfile(DeviceMgtUtil.convertProfile(policyWrapper.getProfile()));
policy.setOwnershipType(policyWrapper.getOwnershipType());
policy.setActive(policyWrapper.isActive());
policy.setRoles(policyWrapper.getRoles());
policy.setUsers(policyWrapper.getUsers());
policy.setCompliance(policyWrapper.getCompliance());
policy.setDeviceGroups(policyWrapper.getDeviceGroups());
//TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here.
List<Device> devices = new ArrayList<Device>();
List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers();
if (deviceIdentifiers != null) {
for (DeviceIdentifier id : deviceIdentifiers) {
devices.add(DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id, false));
}
}
policy.setDevices(devices);
policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
return policy;
}
示例5: testIsEnrolled
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(description = "This test case tests IsEnrolled method of the DeviceTypeManager",
dependsOnMethods = {"testEnrollDevice"})
public void testIsEnrolled() throws DeviceManagementException {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
sampleDevice2.getType());
DeviceIdentifier nonExistingCustomDeviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
customDevice.getType());
Assert.assertFalse(androidDeviceTypeManager.isEnrolled(nonExistingDeviceIdentifier),
"Device with NON-Existing ID is not enrolled, but this shows as enrolled");
Assert.assertTrue(androidDeviceTypeManager.isEnrolled(deviceIdentifier),
"Enrolled device is shown as un-enrolled");
Assert.assertFalse(customDeviceTypeManager.isEnrolled(nonExistingCustomDeviceIdentifier),
"Custom device type manager returns an non-existing device as enrolled");
Assert.assertTrue(customDeviceTypeManager.isEnrolled(new DeviceIdentifier(customDeviceType, customDeviceType))
, "Enrolled device is shown as un-enrolled in custom device type manager");
}
示例6: testUpdateDeviceProperties
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test (description = "This test case tests the updateDeviceProperties method")
public void testUpdateDeviceProperties() throws DeviceManagementException {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(customDeviceType, customDeviceType);
Device customDevice = customDeviceTypeManager
.getDevice(deviceIdentifier);
List<Device.Property> list = customDevice.getProperties();
Assert.assertEquals(customDevice.getProperties().size(), 2,
"GetDevice call" + " failed in custom deviceTypeManager");
Device.Property property = list.get(0);
property.setValue(updatedDeviceTypePropertyValue);
customDeviceTypeManager.updateDeviceProperties(deviceIdentifier, list);
customDevice = customDeviceTypeManager
.getDevice(deviceIdentifier);
Assert.assertEquals(customDevice.getProperties().get(0).getValue(), updatedDeviceTypePropertyValue,
"GetDevice call" + " failed in custom deviceTypeManager");
}
示例7: testDeviceByDate
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testDeviceByDate() throws DeviceManagementException, TransactionManagementException,
DeviceDetailsMgtDAOException, NoSuchFieldException, IllegalAccessException {
MockDataSource dataSource = setDatasourceForGetDevice();
if (dataSource != null) {
setMockDeviceCount(dataSource.getConnection(0));
}
Device initialDevice = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
DEVICE_TYPE));
addDeviceInformation(initialDevice);
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
DEVICE_TYPE), yesterday());
cleanupMockDatasource(dataSource);
if (!isMock()) {
Assert.assertTrue(device != null);
}
}
示例8: testUpdateDeviceWithUnsuccessfulDeviceModification
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(description = "Test update device when device modification is unsuccessful.")
public void testUpdateDeviceWithUnsuccessfulDeviceModification() throws DeviceManagementException,
DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getAuthenticatedUser")).toReturn(AUTHENTICATED_USER);
Device testDevice = DeviceMgtAPITestHelper.generateDummyDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Mockito.when(this.deviceManagementProviderService.getDevice(Mockito.any())).thenReturn(testDevice);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(true);
Mockito.when(this.deviceManagementProviderService.modifyEnrollment(Mockito.any())).thenReturn(false);
Response response = deviceAgentService.updateDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER, testDevice);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode(),
"The response status should be 304");
Mockito.reset(this.deviceManagementProviderService);
Mockito.reset(this.deviceAccessAuthorizationService);
}
示例9: isEnrolled
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@GET
@Path("/{type}/{id}/status")
@Override
public Response isEnrolled(@PathParam("type") String type, @PathParam("id") String id) {
boolean result;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type);
try {
result = DeviceMgtAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier);
if (result) {
return Response.status(Response.Status.OK).build();
} else {
return Response.status(Response.Status.NO_CONTENT).build();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while checking enrollment status of the device.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
示例10: testUpdateOperationWithInvalidDeviceIdentifier
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(description = "Test update operation method with invalid device identifier.")
public void testUpdateOperationWithInvalidDeviceIdentifier() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "isValidDeviceIdentifier"))
.toReturn(false);
Operation operation = new Operation();
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceAgentService.updateOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
operation);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
Mockito.reset(this.deviceManagementProviderService);
}
示例11: updateDevice
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Path("/updateDevice")
@POST
public boolean updateDevice(@QueryParam("deviceId") String deviceId,
@QueryParam("name") String name) throws DeviceManagementException {
DeviceManagement deviceManagement = new DeviceManagement();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(FireAlarmConstants.DEVICE_TYPE);
Device device = deviceManagement.getDevice(deviceIdentifier);
device.setDeviceIdentifier(deviceId);
// device.setDeviceTypeId(deviceTypeId);
device.setDateOfLastUpdate(new Date().getTime());
device.setName(name);
device.setType(FireAlarmConstants.DEVICE_TYPE);
boolean updated = deviceManagement.update(device);
return updated;
}
示例12: unregisterDeviceType
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
/**
* Un-registers an existing device type from the device management metadata repository.
*
* @param typeName device type
* @return status of the operation
*/
public static boolean unregisterDeviceType(String typeName) throws DeviceManagementException {
try {
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
DeviceType deviceType = deviceTypeDAO.getDeviceType(typeName);
if (deviceType != null) {
DeviceType dt = new DeviceType();
dt.setName(typeName);
deviceTypeDAO.removeDeviceType(typeName);
}
return true;
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while registering the device type '" +
typeName + "'", e);
}
}
示例13: testGetConfiguration
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(description = "This test case tests the get configuration of the populated device management service though"
+ " DeviceTypeGeneratorService", dependsOnMethods = {"testPopulateDeviceManagementService"})
public void testGetConfiguration() throws DeviceManagementException, ClassNotFoundException, JAXBException {
PlatformConfiguration platformConfiguration = generatedDeviceManagementService.getDeviceManager()
.getConfiguration();
Assert.assertNotNull(platformConfiguration,
"Default platform configuration is not added to sample device " + "type from the file system");
List<ConfigurationEntry> configurationEntries = platformConfiguration.getConfiguration();
Assert.assertNotNull(configurationEntries,
"Platform Configuration entries are not parsed and saved " + "correctly for device type sample");
Assert.assertEquals(configurationEntries.size(), 1,
"Platform configuration is not saved correctly for " + "device type sample");
ConfigurationEntry configurationEntry = configurationEntries.get(0);
Assert.assertEquals(configurationEntry.getName(), Utils.TEST_STRING,
"Platform Configuration for device type " + "sample is not saved correctly");
String contentType = configurationEntry.getContentType();
Assert.assertEquals(contentType, "String",
"Content type added in default platform configuration is different from the retrieved value");
}
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:25,代码来源:HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java
示例14: addCommandOperationInvalidDeviceIds
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test
public void addCommandOperationInvalidDeviceIds() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
startTenantFlowAsNonAdmin();
try {
ArrayList<DeviceIdentifier> invalidDevices = new ArrayList<>();
for (int i = 0; i < 3; i++) {
invalidDevices.add(new DeviceIdentifier(INVALID_DEVICE + i, DEVICE_TYPE));
}
invalidDevices.addAll(this.deviceIds);
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
Operation.Type.COMMAND, COMMAND_OPERATON_CODE), invalidDevices);
Assert.assertEquals(activity.getActivityStatus().size(), invalidDevices.size(),
"The operation response for add operation only have - " + activity.getActivityStatus().size());
for (int i = 0; i < activity.getActivityStatus().size(); i++) {
ActivityStatus status = activity.getActivityStatus().get(i);
if (i < 3) {
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.INVALID);
} else {
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.UNAUTHORIZED);
}
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例15: testUpdateDeviceWithNoDeviceAccessPermission
import org.wso2.carbon.device.mgt.common.DeviceManagementException; //导入依赖的package包/类
@Test(description = "Test update device when user does not have device access permission.")
public void testUpdateDeviceWithNoDeviceAccessPermission() throws DeviceManagementException,
DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Device testDevice = DeviceMgtAPITestHelper.generateDummyDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Mockito.when(this.deviceManagementProviderService.getDevice(Mockito.any())).thenReturn(testDevice);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(false);
Response response = deviceAgentService.updateDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER, testDevice);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"The response status should be 401");
Mockito.reset(this.deviceManagementProviderService);
Mockito.reset(this.deviceAccessAuthorizationService);
}