Merge pull request #1082 from menakaj/master

Fixing code formatting issues in device mgt Unit Tests.
revert-70aa11f8
Ruwan 7 years ago committed by GitHub
commit 5231166083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,6 +30,7 @@ import org.testng.IObjectFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.caching.impl.CacheImpl;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -93,7 +94,6 @@ public class DeviceAgentServiceTest {
private static final String TEST_DEVICE_TYPE = "TEST-DEVICE-TYPE";
private static final String TEST_DEVICE_IDENTIFIER = "11222334455";
private static final String AUTHENTICATED_USER = "admin";
private static final String TENANT_DOMAIN = "carbon.super";
private static final String MONITOR_OPERATION = "POLICY_MONITOR";
private static Device demoDevice;
@ -119,35 +119,32 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test device Enrollment when the device is null")
public void testEnrollDeviceWithDeviceIsNULL() {
public void testEnrollDeviceWithNullDevice() {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Response response = this.deviceAgentService.enrollDevice(null);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
}
@Test(description = "Test device enrollment when device type is null.")
public void testEnrollDeviceWithDeviceTypeNull() {
public void testEnrollDeviceWithNullDeviceType() {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Device device = DeviceMgtAPITestHelper.generateDummyDevice(null, TEST_DEVICE_IDENTIFIER);
Response response = this.deviceAgentService.enrollDevice(device);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
}
@Test(description = "Test device enrollment of a device with null device identifier.")
public void testEnrollNewDeviceWithDeviceIdentifierIsNull() {
public void testEnrollNewDeviceWithNullDeviceIdentifier() {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Device device = DeviceMgtAPITestHelper.generateDummyDevice(TEST_DEVICE_TYPE, null);
Response response = this.deviceAgentService.enrollDevice(device);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
@ -173,12 +170,10 @@ public class DeviceAgentServiceTest {
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAuthenticatedUser"))
.toReturn(AUTHENTICATED_USER);
EnrolmentInfo enrolmentInfo = demoDevice.getEnrolmentInfo();
enrolmentInfo.setStatus(EnrolmentInfo.Status.INACTIVE);
demoDevice.setEnrolmentInfo(enrolmentInfo);
Mockito.when(this.deviceManagementProviderService.getDevice(Mockito.any())).thenReturn(demoDevice);
Response response = this.deviceAgentService.enrollDevice(demoDevice);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
@ -187,12 +182,11 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test the device enrollment with device management exception.")
public void testEnrollDeviceWithException() throws DeviceManagementException {
public void testEnrollDeviceWithDeviceManagementException() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAuthenticatedUser"))
.toReturn(AUTHENTICATED_USER);
Device device = DeviceMgtAPITestHelper.generateDummyDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
enrolmentInfo.setStatus(EnrolmentInfo.Status.INACTIVE);
@ -200,7 +194,6 @@ public class DeviceAgentServiceTest {
Mockito.when(this.deviceManagementProviderService.getDevice(Mockito.any())).thenReturn(device);
Mockito.when(this.deviceManagementProviderService.enrollDevice(Mockito.any()))
.thenThrow(new DeviceManagementException());
Response response = this.deviceAgentService.enrollDevice(device);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
@ -221,7 +214,7 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test dis-enrolling non existing device.")
public void testDisEnrollNonExistingDevice() throws DeviceManagementException {
public void testDisEnrollWithNonExistingDevice() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Response response = deviceAgentService.disEnrollDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
@ -230,8 +223,8 @@ public class DeviceAgentServiceTest {
"The response status should be 204");
}
@Test(description = "Test dis-enrolling device error")
public void testDisEnrollingDeviceError() throws DeviceManagementException {
@Test(description = "Test dis-enrolling device where device management exception is thrown.")
public void testDisEnrollingDeviceWithDeviceManagementException() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.disenrollDevice(Mockito.any())).thenThrow(new
@ -244,14 +237,13 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test device update scenario with device management exception.")
public void testUpdateDeviceDMException() throws DeviceManagementException {
public void testUpdateDeviceWithDeviceManagementException() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getDevice(Mockito.any())).thenThrow(new
DeviceManagementException());
Device testDevice = DeviceMgtAPITestHelper.generateDummyDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
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.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -263,20 +255,18 @@ public class DeviceAgentServiceTest {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Response response = deviceAgentService.updateDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER, null);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
}
@Test(description = "Test the update device scenario when there is no enrolled device.")
public void testUpdatingNonExistingDevice() throws DeviceManagementException {
public void testUpdateDeviceWithNonExistingDevice() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getDevice(Mockito.any())).thenReturn(null);
Device testDevice = DeviceMgtAPITestHelper.generateDummyDevice(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
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_FOUND.getStatusCode(),
"The response status should be 404");
@ -284,14 +274,13 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test update device with device access authorization exception.")
public void testEnrollDeviceWithDeviceAccessAuthException() throws DeviceManagementException,
public void testEnrollDeviceWithDeviceAccessAuthorizationException() 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)))
.thenThrow(new DeviceAccessAuthorizationException());
@ -311,7 +300,6 @@ public class DeviceAgentServiceTest {
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);
@ -324,16 +312,15 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test update device when device modification is unsuccessful.")
public void testUpdateDeviceNOTModify() throws DeviceManagementException, DeviceAccessAuthorizationException {
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);
@ -347,20 +334,20 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test updating device when modify enrollment throws exception")
public void testUpdateDeviceWithModifyEnrollmentFailure() throws DeviceManagementException, DeviceAccessAuthorizationException {
public void testUpdateDeviceWithModifyEnrollmentFailure() 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())).thenThrow(new DeviceManagementException());
Mockito.when(this.deviceManagementProviderService.modifyEnrollment(Mockito.any()))
.thenThrow(new DeviceManagementException());
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.INTERNAL_SERVER_ERROR.getStatusCode(),
@ -377,9 +364,7 @@ public class DeviceAgentServiceTest {
"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);
@ -396,14 +381,13 @@ public class DeviceAgentServiceTest {
public void testPublishEventsWithNullPayload() {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
Mockito.when(this.privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
Mockito.when(this.privilegedCarbonContext.getTenantDomain())
.thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, Object> payload = null;
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
List<Object> payloadList = null;
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
@ -413,47 +397,47 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test publish events with no device access authorization.")
public void testPublishEventsWithOutAuthorization() throws DeviceAccessAuthorizationException {
public void testPublishEventsWithoutAuthorization() throws DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(false);
Mockito.when(this.privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
Mockito.when(this.privilegedCarbonContext.getTenantDomain())
.thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, Object> payload = new HashMap<>();
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"The response status should be 401");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"The response status should be 401");
Mockito.reset(this.deviceAccessAuthorizationService);
}
@Test
public void testPublishEventsWithDeviceAccessAuthException() throws DeviceAccessAuthorizationException {
@Test(description = "Test publish events when device access authorization exception is thrown.")
public void testPublishEventsWithDeviceAccessAuthorizationException() throws DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
.toReturn(this.deviceAccessAuthorizationService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenThrow(new DeviceAccessAuthorizationException());
Mockito.when(this.privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
Mockito.when(this.privilegedCarbonContext.getTenantDomain())
.thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, Object> payload = new HashMap<>();
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -461,30 +445,28 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test event publishing when the event stream dao is null.")
public void testEventPublishWithNullEventAttributesAndNullEventStreamDefDAO() throws DeviceAccessAuthorizationException, RemoteException {
public void testEventPublishWithNullEventAttributesAndNullEventStreamDefDAO()
throws DeviceAccessAuthorizationException, RemoteException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
.toReturn(this.deviceAccessAuthorizationService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(true);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventStreamAdminServiceStub"))
.toReturn(this.eventStreamAdminServiceStub);
Mockito.when(this.eventStreamAdminServiceStub.getStreamDefinitionDto(Mockito.anyString())).thenReturn(null);
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
@ -511,22 +493,19 @@ public class DeviceAgentServiceTest {
Mockito.when(eventStreamDefinitionDto.getPayloadData()).thenReturn(new EventStreamAttributeDto[]{});
EventsPublisherService eventPublisherService = Mockito.mock(EventsPublisherServiceImpl.class,
Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventPublisherService")).toReturn
(eventPublisherService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventPublisherService"))
.toReturn(eventPublisherService);
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -552,31 +531,29 @@ public class DeviceAgentServiceTest {
Mockito.when(eventStreamDefinitionDto.getPayloadData()).thenReturn(new EventStreamAttributeDto[]{});
EventsPublisherService eventPublisherService = Mockito.mock(EventsPublisherServiceImpl.class,
Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventPublisherService")).toReturn
(eventPublisherService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventPublisherService"))
.toReturn(eventPublisherService);
Mockito.when(eventPublisherService.publishEvent(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
Mockito.any(), Mockito.any())).thenReturn(true);
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList,
TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200");
}
@Test(description = "Test event publishing when PublishEvents throws DataPublisherConfigurationException.")
public void testPublishEventsDataPublisherConfig() throws DeviceAccessAuthorizationException, RemoteException, DataPublisherConfigurationException {
public void testPublishEventsDataPublisherConfigurationException() throws DeviceAccessAuthorizationException,
RemoteException, DataPublisherConfigurationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
@ -599,24 +576,20 @@ public class DeviceAgentServiceTest {
Mockito.when(eventPublisherService.publishEvent(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
Mockito.any(), Mockito.any())).thenThrow(
new DataPublisherConfigurationException("meta data[0] should have the device Id field"));
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
}
@Test(description = "Test Publish events with Axis Fault.")
@ -631,17 +604,15 @@ public class DeviceAgentServiceTest {
.toThrow(new AxisFault(""));
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -659,7 +630,6 @@ public class DeviceAgentServiceTest {
.toThrow(new RemoteException());
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
@ -669,7 +639,8 @@ public class DeviceAgentServiceTest {
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -687,7 +658,6 @@ public class DeviceAgentServiceTest {
.toThrow(new JWTClientException());
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
@ -697,7 +667,8 @@ public class DeviceAgentServiceTest {
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -715,7 +686,6 @@ public class DeviceAgentServiceTest {
.toThrow(new UserStoreException());
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
@ -725,7 +695,8 @@ public class DeviceAgentServiceTest {
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -753,9 +724,7 @@ public class DeviceAgentServiceTest {
.toReturn(false);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceAgentService.getPendingOperations(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode(),
@ -771,9 +740,7 @@ public class DeviceAgentServiceTest {
.toReturn(true);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceAgentService.getPendingOperations(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertNotNull(response.getEntity(), "Response entity should not be null.");
@ -783,16 +750,15 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test the scenario when get pending operations throw OperationManagementException.")
public void testGetPendingOperationsWithOperationManagementException() throws DeviceManagementException, OperationManagementException {
public void testGetPendingOperationsWithOperationManagementException() throws DeviceManagementException,
OperationManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "isValidDeviceIdentifier"))
.toReturn(true);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getPendingOperations(Mockito.any())).thenThrow(new
OperationManagementException());
Response response = this.deviceAgentService.getPendingOperations(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
@ -811,7 +777,6 @@ public class DeviceAgentServiceTest {
.toReturn(true);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenThrow(new DeviceManagementException());
Response response = this.deviceAgentService.getPendingOperations(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertNotNull(response.getEntity(), "Response entity should not be null.");
@ -825,8 +790,7 @@ public class DeviceAgentServiceTest {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(new ArrayList<String>() {
});
.thenReturn(new ArrayList<String>() {});
Response response = this.deviceAgentService.getNextPendingOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
@ -842,9 +806,7 @@ public class DeviceAgentServiceTest {
.toReturn(false);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceAgentService.getNextPendingOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
@ -860,9 +822,7 @@ public class DeviceAgentServiceTest {
.toReturn(true);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceAgentService.getNextPendingOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertNotNull(response.getEntity(), "Response entity should not be null.");
@ -872,18 +832,17 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test get next pending operation with operation management exception.")
public void getNextPendingOperationWithOperationManagementException() throws DeviceManagementException, OperationManagementException {
public void getNextPendingOperationWithOperationManagementException() throws DeviceManagementException,
OperationManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "isValidDeviceIdentifier"))
.toReturn(true);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getNextPendingOperation(Mockito.any())).thenThrow(new
OperationManagementException());
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getNextPendingOperation(Mockito.any())).thenThrow(
new OperationManagementException());
Response response = this.deviceAgentService.getNextPendingOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertNotNull(response.getEntity(), "Response entity should not be null.");
@ -900,7 +859,6 @@ public class DeviceAgentServiceTest {
.toReturn(true);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenThrow(new DeviceManagementException());
Response response = this.deviceAgentService.getNextPendingOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertNotNull(response.getEntity(), "Response entity should not be null.");
@ -914,10 +872,8 @@ public class DeviceAgentServiceTest {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(new ArrayList<String>() {
});
.thenReturn(new ArrayList<String>() {});
Operation operation = new Operation();
Response response = this.deviceAgentService.updateOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
operation);
Assert.assertNotNull(response, "The response should not be null");
@ -930,11 +886,9 @@ public class DeviceAgentServiceTest {
public void testUpdateOperationWithNullOperation() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceAgentService.updateOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
null);
Assert.assertNotNull(response, "The response should not be null");
@ -949,13 +903,10 @@ public class DeviceAgentServiceTest {
.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);
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");
@ -970,13 +921,10 @@ public class DeviceAgentServiceTest {
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "isValidDeviceIdentifier"))
.toReturn(true);
Operation operation = new Operation();
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
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");
@ -986,7 +934,8 @@ public class DeviceAgentServiceTest {
}
@Test(description = "Test the update Operation method with Policy Monitoring Operation.")
public void testUpdateOperationSuccessWithPolicyMonitorOperation() throws DeviceManagementException, PolicyComplianceException {
public void testUpdateOperationSuccessWithPolicyMonitorOperation() throws DeviceManagementException,
PolicyComplianceException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "isValidDeviceIdentifier"))
@ -1003,9 +952,7 @@ public class DeviceAgentServiceTest {
operation.setPayLoad(null);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
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");
@ -1024,12 +971,9 @@ public class DeviceAgentServiceTest {
Operation operation = new Operation();
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Mockito.doThrow(new OperationManagementException()).when(this.deviceManagementProviderService)
.updateOperation(Mockito.any(), Mockito.any());
Response response = this.deviceAgentService.updateOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
operation);
Assert.assertNotNull(response, "The response should not be null");
@ -1050,7 +994,6 @@ public class DeviceAgentServiceTest {
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenThrow(new DeviceManagementException());
Response response = this.deviceAgentService.updateOperation(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
operation);
Assert.assertNotNull(response, "The response should not be null");
@ -1079,9 +1022,7 @@ public class DeviceAgentServiceTest {
operation.setPayLoad(null);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
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");
@ -1104,9 +1045,8 @@ public class DeviceAgentServiceTest {
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(new ArrayList<String>() {});
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
Operation.Status.COMPLETED);
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER, Operation.Status.COMPLETED);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
@ -1116,14 +1056,11 @@ public class DeviceAgentServiceTest {
public void testGetOperationSuccess() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
Operation.Status.COMPLETED);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER, Operation.Status.COMPLETED);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200");
@ -1134,16 +1071,13 @@ public class DeviceAgentServiceTest {
OperationManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getOperationsByDeviceAndStatus(Mockito.any(), Mockito.any()
)).thenThrow(new OperationManagementException());
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
Operation.Status.COMPLETED);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenReturn(deviceTypes);
Mockito.when(this.deviceManagementProviderService.getOperationsByDeviceAndStatus(Mockito.any(), Mockito.any()))
.thenThrow(new OperationManagementException());
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER, Operation.Status.COMPLETED);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
@ -1154,13 +1088,12 @@ public class DeviceAgentServiceTest {
public void testGetOperationsWithDeviceManagementException() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
List<String> deviceTypes = new ArrayList<>();
deviceTypes.add(TEST_DEVICE_TYPE);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
.thenThrow(new DeviceManagementException());
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER,
Operation.Status.COMPLETED);
Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER, Operation.Status.COMPLETED);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");

@ -83,24 +83,18 @@ public class DeviceTypeManagementAdminServiceTest {
public void testGetDeviceTypes() {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Response response = this.deviceTypeManagementAdminService.getDeviceTypes();
log.info(response.getEntity());
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "The Response status code " +
"should be 200.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The Response status code should be 200.");
}
@Test(description = "Test the error scenario of getting all the device types.")
public void testGetDeviceTypesError() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(deviceManagementProviderService.getDeviceTypes()).thenThrow(new DeviceManagementException());
Response response = this.deviceTypeManagementAdminService.getDeviceTypes();
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The expected status code is 500.");
@ -111,12 +105,8 @@ public class DeviceTypeManagementAdminServiceTest {
public void testAddDeviceTypeWithExistingName() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE_1, TEST_DEVICE_TYPE_ID_1);
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
log.info(response.getEntity());
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.CONFLICT.getStatusCode(),
"The Response Status code should be 409.");
@ -126,14 +116,9 @@ public class DeviceTypeManagementAdminServiceTest {
public void testAddDeviceTypeWithUnqualifiedName() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE_2, TEST_DEVICE_TYPE_ID_2);
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
log.info(response.getEntity());
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The Response Status code should be 400.");
@ -146,12 +131,9 @@ public class DeviceTypeManagementAdminServiceTest {
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
.toReturn(this.deviceTypeGeneratorService);
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The Response Status code should be 200.");
@ -162,11 +144,7 @@ public class DeviceTypeManagementAdminServiceTest {
public void testAddDeviceTypeWithNoDeviceType() {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Response response = this.deviceTypeManagementAdminService.addDeviceType(null);
log.info(response.getEntity());
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The Response Status code should be 409.");
@ -178,10 +156,8 @@ public class DeviceTypeManagementAdminServiceTest {
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenThrow(new
DeviceManagementException());
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
Response response = this.deviceTypeManagementAdminService.addDeviceType(deviceType);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The Response Status code should be 500.");
@ -194,10 +170,8 @@ public class DeviceTypeManagementAdminServiceTest {
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
.toReturn(this.deviceTypeGeneratorService);
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The Response Status code should be 200.");
@ -210,10 +184,8 @@ public class DeviceTypeManagementAdminServiceTest {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceTypeGeneratorService"))
.toReturn(this.deviceTypeGeneratorService);
Mockito.when(deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The Response Status code should be 400.");
@ -224,9 +196,7 @@ public class DeviceTypeManagementAdminServiceTest {
public void testUpdateDeviceTypeWithNullDeviceType() {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Response response = this.deviceTypeManagementAdminService.updateDeviceType(null);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The Response Status code should be 400.");
@ -237,13 +207,10 @@ public class DeviceTypeManagementAdminServiceTest {
public void testUpdateDeviceTypeWithException() throws DeviceManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString()))
.thenThrow(new DeviceManagementException());
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
Response response = this.deviceTypeManagementAdminService.updateDeviceType(deviceType);
Assert.assertNotNull(response, "The response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The Response Status code should be 500.");

@ -89,7 +89,6 @@ public class DeviceTypeManagementServiceTest {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenThrow(new DeviceManagementException());
Response response = this.deviceTypeManagementService.getDeviceTypes();
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
@ -103,7 +102,6 @@ public class DeviceTypeManagementServiceTest {
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes()).thenThrow(new
DeviceManagementException());
Response response = this.deviceTypeManagementService.getDeviceTypes(MODIFIED_SINCE);
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
@ -163,10 +161,8 @@ public class DeviceTypeManagementServiceTest {
public void testGetDeviceTypesWithDeviceTypes() throws Exception {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
List<DeviceType> deviceTypes = DeviceMgtAPITestHelper.getDummyDeviceTypeList(5);
Mockito.when(this.deviceManagementProviderService.getDeviceTypes()).thenReturn(deviceTypes);
Response response = this.deviceTypeManagementService.getDeviceTypes();
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
@ -189,7 +185,6 @@ public class DeviceTypeManagementServiceTest {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString())).thenReturn(null);
Response response = this.deviceTypeManagementService.getDeviceTypeByName(TEST_DEVICE_TYPE);
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode(),
@ -203,7 +198,6 @@ public class DeviceTypeManagementServiceTest {
.toReturn(this.deviceManagementProviderService);
Mockito.when(this.deviceManagementProviderService.getDeviceType(Mockito.anyString()))
.thenThrow(new DeviceManagementException());
Response response = this.deviceTypeManagementService.getDeviceTypeByName(TEST_DEVICE_TYPE);
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
@ -227,10 +221,8 @@ public class DeviceTypeManagementServiceTest {
Method clearMetaEntryInfo = DeviceTypeManagementServiceImpl.class.getDeclaredMethod("clearMetaEntryInfo",
DeviceType.class);
clearMetaEntryInfo.setAccessible(true);
DeviceType deviceType = DeviceMgtAPITestHelper.getDummyDeviceType(TEST_DEVICE_TYPE, TEST_DEVICE_TYPE_ID);
DeviceType returned = (DeviceType) clearMetaEntryInfo.invoke(this.deviceTypeManagementService, deviceType);
Assert.assertNotNull(returned.getDeviceTypeMetaDefinition(), "The response object is null.");
}
}

@ -35,6 +35,9 @@ import java.util.Properties;
import static org.mockito.MockitoAnnotations.initMocks;
/**
* This contains unit tests for PermissionManagerService class.
*/
@PrepareForTest(PermissionUtils.class)
public class PermissionManagerServiceTest {
@ -47,7 +50,6 @@ public class PermissionManagerServiceTest {
//For create properties to retrieve permission.
private static final String HTTP_METHOD = "HTTP_METHOD";
private static final String URL = "URL";
private Permission permission;
private PermissionManagerService permissionManagerService;
@ -72,7 +74,6 @@ public class PermissionManagerServiceTest {
try {
PowerMockito.mockStatic(PermissionUtils.class);
PowerMockito.when(PermissionUtils.putPermission(permission)).thenReturn(true);
Assert.assertTrue(permissionManagerService.addPermission(permission));
} catch (PermissionManagementException e) {
log.error("Error creating permission " + e.getErrorMessage());
@ -83,7 +84,6 @@ public class PermissionManagerServiceTest {
"from the permission tree.")
public void testGetPermission() throws PermissionManagementException {
Permission permission = permissionManagerService.getPermission(createProperties());
Assert.assertEquals(permission.getMethod(), PERMISSION_METHOD);
Assert.assertEquals(permission.getName(), PERMISSION_NAME);
Assert.assertEquals(permission.getPath(), PERMISSION_PATH);

@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.search;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.powermock.api.mockito.PowerMockito;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -31,7 +30,6 @@ import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
@ -43,19 +41,14 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.sql.DataSource;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* This class holds unit test cases for org.wso2.carbon.device.mgt.core.search.mgt.impl.ProcessorImpl
* */
public class ProcessorImplTest extends BaseDeviceManagementTest{
*/
public class ProcessorImplTest extends BaseDeviceManagementTest {
private DeviceAccessAuthorizationService deviceAccessAuthorizationService;
private static final Log log = LogFactory.getLog(SearchManagementServiceTest.class);
@ -67,7 +60,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
public void init() throws Exception {
deviceAccessAuthorizationService = DeviceManagementDataHolder.getInstance()
.getDeviceAccessAuthorizationService();
for (int i = 0; i < 5; i++) {
deviceIdentifiers.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
}
@ -76,7 +68,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
List<Device> devices = TestDataHolder.generateDummyDeviceData(deviceIdentifiers);
for (Device device : devices) {
device.setDeviceInfo(Utils.getDeviceInfo());
@ -91,27 +82,23 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
}
@Test(description = "Test the Search Processor")
public void testWithNoDeviceAccessAuthorization() throws Exception {
public void testWithNoDeviceAccessAuthorization() throws NoSuchFieldException, IllegalAccessException,
SearchMgtException {
SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>();
Condition cond = new Condition();
cond.setKey("batteryLevel");
cond.setOperator("=");
cond.setValue("40");
cond.setState(Condition.State.AND);
conditions.add(cond);
context.setConditions(conditions);
ProcessorImpl processor = new ProcessorImpl();
Field deviceAccessAuthorizationServiceField = ProcessorImpl.class.getDeclaredField
("deviceAccessAuthorizationService");
deviceAccessAuthorizationServiceField.setAccessible(true);
deviceAccessAuthorizationServiceField.set(processor, null);
List<Device> searchedDevices = processor.execute(context);
Assert.assertEquals(0, searchedDevices.size());
}
@ -120,9 +107,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
public void testInvalidState() throws SearchMgtException {
SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>();
ChangeEnumValues.addEnum(Condition.State.class, "BLA");
Condition.State state = Condition.State.valueOf("BLA");
Condition cond = new Condition();
@ -147,7 +132,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
conditions.add(cond3);
context.setConditions(conditions);
ProcessorImpl processor = new ProcessorImpl();
try {
processor.execute(context);
@ -161,13 +145,11 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
@Test(description = "Test when Device Access Authorization is null", expectedExceptions = {IllegalStateException
.class}, dependsOnMethods = {"testWithNoDeviceAccessAuthorization", "testInvalidState"})
public void testProcessorInitializationError() throws ClassNotFoundException, NoSuchMethodException,
NoSuchFieldException,
IllegalAccessException, SearchMgtException {
NoSuchFieldException, IllegalAccessException, SearchMgtException {
DeviceManagementDataHolder deviceManagementDataHolder = DeviceManagementDataHolder.getInstance();
Field field = DeviceManagementDataHolder.class.getDeclaredField("deviceAccessAuthorizationService");
field.setAccessible(true);
field.set(deviceManagementDataHolder, null);
ProcessorImpl processor = new ProcessorImpl();
processor.execute(null);
}

@ -72,8 +72,8 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl();
List<Device> devices = TestDataHolder.generateDummyDeviceData(deviceIdentifiers);
for (Device device : devices) {
deviceMgtService.enrollDevice(device);
}
@ -90,6 +90,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
}
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE, true);
for (Device device : returnedDevices) {
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
@ -108,9 +109,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
cond.setValue("40");
cond.setState(Condition.State.OR);
conditions.add(cond);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices != null);
@ -127,9 +126,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
cond.setValue("Karandeniya");
cond.setState(Condition.State.AND);
conditions.add(cond);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices != null);
@ -146,9 +143,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
cond.setValue("Colombo");
cond.setState(Condition.State.AND);
conditions.add(cond);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices.size() == 0);
@ -165,12 +160,9 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
cond.setValue("SM-T520");
cond.setState(Condition.State.AND);
conditions.add(cond);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices != null);
}
@ -185,12 +177,9 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
cond.setValue("3.56");
cond.setState(Condition.State.AND);
conditions.add(cond);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices != null);
}
@ -205,12 +194,9 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
cond.setValue("SM-T520");
cond.setState(Condition.State.OR);
conditions.add(cond);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices != null);
}
@ -232,9 +218,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
cond.setValue("bbb");
cond.setState(Condition.State.OR);
conditions.add(cond);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
try {
service.search(context);
@ -293,7 +277,6 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
conditions.add(cond6);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices != null);
@ -333,7 +316,6 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
conditions.add(condition4);
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<Device> devices = service.search(context);
Assert.assertTrue(devices != null);

@ -66,7 +66,6 @@ public class SearchMgtUtilTest {
public void testConvertStringToList() {
List<String> stringList = Utils.convertStringToList("some string");
List<String> expected = this.getStringList();
Assert.assertEquals(stringList, expected);
}

@ -41,16 +41,12 @@ public class ChangeEnumValues {
private static void setFailSafeFieldValue(Field field, Object target, Object value) throws NoSuchFieldException,
IllegalAccessException {
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
int modifiers = modifiersField.getInt(field);
modifiers &= ~Modifier.FINAL;
modifiersField.setInt(field, modifiers);
FieldAccessor fa = reflectionFactory.newFieldAccessor(field, false);
fa.set(target, value);
}
@ -115,15 +111,10 @@ public class ChangeEnumValues {
try {
T[] previousValues = (T[]) valuesField.get(enumType);
List<T> values = new ArrayList<T>(Arrays.asList(previousValues));
T newValue = (T) makeEnum(enumType, enumName, values.size(), new Class<?>[]{}, new Object[]{});
values.add(newValue);
setFailSafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0)));
cleanEnumCache(enumType);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}

@ -51,7 +51,6 @@ public class Utils {
deviceInfo.setLocation(getSampleDeviceLocation());
Map<String, String> propertyMap = new HashMap<>();
propertyMap.put("BATTERY_VOLTAGE", "40");
propertyMap.put("BATTERY_HEALTH", "Good");
propertyMap.put("BATTERY_STATUS", "SWElLED");
@ -61,14 +60,11 @@ public class Utils {
propertyMap.put("CPU_IRQ", "1");
propertyMap.put("IMEI", "e6f236ac82537a8e");
propertyMap.put("IMSI", "432659632123654845");
deviceInfo.setDeviceDetailsMap(propertyMap);
return deviceInfo;
}
private static DeviceLocation getSampleDeviceLocation(){
public static DeviceLocation getSampleDeviceLocation(){
DeviceLocation deviceLocation = new DeviceLocation();
deviceLocation.setDeviceIdentifier(Utils.getDeviceIdentifier());
deviceLocation.setLatitude(76.2422);
@ -80,7 +76,6 @@ public class Utils {
deviceLocation.setZip("80360");
deviceLocation.setCountry("Sri Lanka");
deviceLocation.setDeviceId(1);
return deviceLocation;
}
@ -88,11 +83,6 @@ public class Utils {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setType(TestDataHolder.TEST_DEVICE_TYPE);
deviceIdentifier.setId("12345");
return deviceIdentifier;
}
}

Loading…
Cancel
Save