From a80f0246adc5119636e123f0046fcf34b25f71d8 Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Fri, 20 Oct 2017 11:24:53 +0530 Subject: [PATCH] Extended the test cases for the Publish event method. --- .../service/impl/DeviceAgentServiceTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java index 6c222e8311..108d294ea1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceAgentServiceTest.java @@ -59,7 +59,9 @@ import org.wso2.carbon.utils.CarbonUtils; import javax.cache.CacheManager; import javax.ws.rs.core.Response; import java.rmi.RemoteException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.mockito.MockitoAnnotations.initMocks; @@ -394,6 +396,14 @@ public class DeviceAgentServiceTest { Assert.assertNotNull(response, "Response should not be null"); Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), "The response status should be 400"); + + + List payloadList = null; + 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"); } @Test(description = "Test publish events with no device access authorization.") @@ -411,6 +421,13 @@ public class DeviceAgentServiceTest { Assert.assertNotNull(response, "Response should not be null"); Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "The response status should be 401"); + + List payloadList = new ArrayList<>(); + 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); } @@ -428,6 +445,12 @@ public class DeviceAgentServiceTest { 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 payloadList = new ArrayList<>(); + 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"); Mockito.reset(this.deviceAccessAuthorizationService); } @@ -453,6 +476,12 @@ public class DeviceAgentServiceTest { Assert.assertNotNull(response, "Response should not be null"); Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), "The response status should be 400"); + + List payloadList = new ArrayList<>(); + 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"); Mockito.reset(eventStreamAdminServiceStub); } @@ -489,6 +518,12 @@ public class DeviceAgentServiceTest { 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 payloadList = new ArrayList<>(); + 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 Event publishing success scenario.") @@ -526,6 +561,12 @@ public class DeviceAgentServiceTest { Assert.assertNotNull(response, "Response should not be null"); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "The response status should be 200"); + + List payloadList = new ArrayList<>(); + 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.") @@ -563,6 +604,13 @@ public class DeviceAgentServiceTest { 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 payloadList = new ArrayList<>(); + 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.") @@ -585,6 +633,12 @@ public class DeviceAgentServiceTest { 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 payloadList = new ArrayList<>(); + 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 Publishing events when EventStreamAdminService throws Remote exception.") @@ -607,6 +661,12 @@ public class DeviceAgentServiceTest { 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 payloadList = new ArrayList<>(); + 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 Publishing events when EventStreamAdminService throws JWT exception.") @@ -629,6 +689,12 @@ public class DeviceAgentServiceTest { 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 payloadList = new ArrayList<>(); + 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 Publishing events when EventStreamAdminService throws User Store exception.") @@ -651,5 +717,11 @@ public class DeviceAgentServiceTest { 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 payloadList = new ArrayList<>(); + 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"); } }