diff --git a/provider/notification-azure/lombok.config b/provider/notification-azure/lombok.config index a23edb413fc5d2e329b180ce25ef307f0c408874..830508fe89ceb1ad0507662c9891484eb99f3988 100644 --- a/provider/notification-azure/lombok.config +++ b/provider/notification-azure/lombok.config @@ -1,2 +1,3 @@ +# The file makes Jacoco understand that the Lambok's @Data's creation, should not be accounted for Jacoco's analysis. config.stopBubbling = true lombok.addLombokGeneratedAnnotation = true \ No newline at end of file diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java index 259f0174107b3175aae2fba51414a95e62eded4b..6af2a92f784cc9e24bd95d0fc5e075e47612abf5 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java @@ -17,6 +17,7 @@ package org.opengroup.osdu.notification.provider.azure; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; @@ -31,6 +32,7 @@ import java.io.StringReader; import java.util.Map; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -337,7 +339,7 @@ public class EventGridRequestBodyExtractorTest { @Test public void should_throwWhenHandshakeRequest_extractDataFromRequestBody() throws IOException { - String vaidRequestRoot = " [{\n" + + String inVaidRequestRoot = " [{\n" + " \"id\": \"testId\",\n" + " \"topic\": \"testTopic\",\n" + " \"subject\": \"\",\n" + @@ -350,7 +352,7 @@ public class EventGridRequestBodyExtractorTest { " \"metadataVersion\": \"1\",\n" + " \"dataVersion\": \"2\"\n" + " }]"; - BufferedReader reader = new BufferedReader(new StringReader(vaidRequestRoot)); + BufferedReader reader = new BufferedReader(new StringReader(inVaidRequestRoot)); when(this.httpServletRequest.getReader()).thenReturn(reader); sut = new EventGridRequestBodyExtractor(httpServletRequest, log); @@ -360,4 +362,51 @@ public class EventGridRequestBodyExtractorTest { Assert.assertNull(observedAttributes); } + @Test + public void should_returnNotificationId_extractNotificationIdFromRequestBody() throws IOException { + // Set Up + String vaidRequestRoot = "[{\n" + + " \"id\": \"2425\",\n" + + " \"eventType\": \"recordInserted\",\n" + + " \"subject\": \"myapp/vehicles/motorcycles\",\n" + + " \"data\": {\n" + + " \"attributes\": {\n" + + " \"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" + + " \"data-partition-id\": \"opendes\"\n" + + " },\n" + + " \"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n" + + " \"messageId\": \"136969346945\"\n" + + " },\n" + + " \"dataVersion\": \"1.0\",\n" + + " \"metadataVersion\": \"1\",\n" + + " \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" + + " \"topic\": \"/subscriptions/asdf/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" + + " }]"; + BufferedReader reader = new BufferedReader(new StringReader(vaidRequestRoot)); + when(this.httpServletRequest.getReader()).thenReturn(reader); + when(this.httpServletRequest.getHeader("Aeg-Subscription-Name")).thenReturn("NotificationId"); + sut = new EventGridRequestBodyExtractor(httpServletRequest, log); + + // Act + String observed = sut.extractNotificationIdFromRequestBody(); + + // Assert + Assert.assertEquals("NotificationId", observed); + + // Set Up + when(this.httpServletRequest.getHeader("Aeg-Subscription-Name")).thenReturn(null); + + try { + // Act + this.sut.extractNotificationIdFromRequestBody(); + + // Asset + fail("Should Throw Exception"); + } catch (AppException appException){ + Assert.assertEquals(HttpStatus.BAD_REQUEST.value(), appException.getError().getCode()); + Assert.assertEquals("Subscription ID not found", appException.getError().getMessage()); + } catch (Exception exception) { + fail("Should Throw AppException"); + } + } }