Commit fd5b24b4 authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft] Committed by Komal Makkar
Browse files

Update Storage-Notification Integration Test Flow

parent 13691756
This diff is collapsed.
......@@ -15,6 +15,7 @@
package org.opengroup.osdu.register.provider.azure.subscriber;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ISubscriptionRepository;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ITestSubscription;
import org.opengroup.osdu.register.subscriber.model.HmacSecret;
......@@ -26,26 +27,31 @@ import org.springframework.stereotype.Component;
@Component
@Primary
public class TestSubscriptionAzure implements ITestSubscription {
private final static String INTEGRATION_TEST_CORRELATION_ID = "storage-notification-it";
@Autowired
private ISubscriptionRepository subscriptionRepository;
@Autowired
private JaxRsDpsLog logger;
@Autowired
private DpsHeaders dpsHeaders;
public void performTestAcknowledgement() throws Exception {
/* Creation of Test Acknowledgement Subscription which ensures the successful delivery
of notification at the test end point */
Subscription subscription = new Subscription();
subscription.setName("AcknowledgementTestSubscription");
subscription.setDescription("Subscription for Ack of test-endpoint");
subscription.setTopic("recordstopic");
subscription.setPushEndpoint("http://TestAck/api/register/v1/test/challenge/1");
subscription.setNotificationId("testingAcknowledgement");
subscription.setId("AckSubscription");
HmacSecret secret = new HmacSecret();
secret.setValue("TestAcknowledgementSubscription");
subscription.setSecret(secret);
subscription = subscriptionRepository.create(subscription);
logger.debug("Successfully created Acknowledgement Subscription");
if (INTEGRATION_TEST_CORRELATION_ID.equalsIgnoreCase(dpsHeaders.getCorrelationId())) {
Subscription subscription = new Subscription();
subscription.setName("AcknowledgementTestSubscription");
subscription.setDescription("Subscription for Ack of test-endpoint");
subscription.setTopic("recordstopic");
subscription.setPushEndpoint("http://TestAck/api/register/v1/test/challenge/1");
subscription.setNotificationId("testingAcknowledgement");
subscription.setId("AckSubscription");
HmacSecret secret = new HmacSecret();
secret.setValue("TestAcknowledgementSubscription");
subscription.setSecret(secret);
subscription = subscriptionRepository.create(subscription);
logger.debug("Successfully created Acknowledgement Subscription");
}
}
}
......@@ -20,6 +20,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ISubscriptionRepository;
import org.opengroup.osdu.register.subscriber.model.HmacSecret;
import org.opengroup.osdu.register.subscriber.model.Subscription;
......@@ -30,15 +31,20 @@ import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
public class TestSubscriptionAzureTest {
private final static String INTEGRATION_TEST_CORRELATION_ID = "storage-notification-it";
@Mock
private ISubscriptionRepository subscriptionRepository;
@Mock
private JaxRsDpsLog logger;
@Mock
private DpsHeaders dpsHeaders;
@InjectMocks
private TestSubscriptionAzure sut;
@Test
public void createTestAcknowledgementSubscription() throws Exception {
public void shouldCreateTestAcknowledgementSubscription() throws Exception {
when(dpsHeaders.getCorrelationId()).thenReturn(INTEGRATION_TEST_CORRELATION_ID);
when(subscriptionRepository.create(getSubscription())).thenReturn(getSubscription());
sut.performTestAcknowledgement();
......@@ -49,6 +55,7 @@ public class TestSubscriptionAzureTest {
@Test
public void shouldThrowExceptionWhenSubscriptionCreationFailed() throws Exception {
when(dpsHeaders.getCorrelationId()).thenReturn(INTEGRATION_TEST_CORRELATION_ID);
when(subscriptionRepository.create(getSubscription())).thenThrow(new Exception());
Exception exception = assertThrows(Exception.class, () -> {
......@@ -60,6 +67,16 @@ public class TestSubscriptionAzureTest {
verify(subscriptionRepository, times(1)).create(getSubscription());
}
@Test
public void shouldNotCreateTestAcknowledgementSubscriptionForNonITCorrelationId() throws Exception {
when(dpsHeaders.getCorrelationId()).thenReturn("invalid correlation-id");
sut.performTestAcknowledgement();
verify(logger, times(0)).debug("Successfully created Acknowledgement Subscription");
verify(subscriptionRepository, times(0)).create(getSubscription());
}
private Subscription getSubscription() {
Subscription subscription = new Subscription();
subscription.setName("AcknowledgementTestSubscription");
......
......@@ -42,7 +42,6 @@ import org.springframework.web.context.annotation.RequestScope;
@RequestScope
@Validated
public class SubscriberListenerApi {
@Autowired
private ISignatureService signatureService;
@Autowired
......
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