Commit b9262bc8 authored by Komal Makkar's avatar Komal Makkar
Browse files

adding UTs

parent 766db006
Pipeline #9372 passed with stages
in 17 minutes and 31 seconds
# 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
......@@ -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");
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment