Skip to content
Snippets Groups Projects
Commit bee69b7c authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft] Committed by Komal Makkar
Browse files

Update Test Ack Flow

parent 0d94ff18
No related branches found
No related tags found
1 merge request!114Update Test Ack Flow
...@@ -16,7 +16,6 @@ package org.opengroup.osdu.register.provider.azure.subscriber; ...@@ -16,7 +16,6 @@ package org.opengroup.osdu.register.provider.azure.subscriber;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; 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.provider.interfaces.subscriber.ITestSubscription;
import org.opengroup.osdu.register.subscriber.model.HmacSecret; import org.opengroup.osdu.register.subscriber.model.HmacSecret;
import org.opengroup.osdu.register.subscriber.model.Subscription; import org.opengroup.osdu.register.subscriber.model.Subscription;
...@@ -29,7 +28,7 @@ import org.springframework.stereotype.Component; ...@@ -29,7 +28,7 @@ import org.springframework.stereotype.Component;
public class TestSubscriptionAzure implements ITestSubscription { public class TestSubscriptionAzure implements ITestSubscription {
private final static String INTEGRATION_TEST_CORRELATION_ID = "storage-notification-it"; private final static String INTEGRATION_TEST_CORRELATION_ID = "storage-notification-it";
@Autowired @Autowired
private ISubscriptionRepository subscriptionRepository; private CosmosSubscription cosmosSubscription;
@Autowired @Autowired
private JaxRsDpsLog logger; private JaxRsDpsLog logger;
@Autowired @Autowired
...@@ -50,7 +49,7 @@ public class TestSubscriptionAzure implements ITestSubscription { ...@@ -50,7 +49,7 @@ public class TestSubscriptionAzure implements ITestSubscription {
HmacSecret secret = new HmacSecret(); HmacSecret secret = new HmacSecret();
secret.setValue("TestAcknowledgementSubscription"); secret.setValue("TestAcknowledgementSubscription");
subscription.setSecret(secret); subscription.setSecret(secret);
subscription = subscriptionRepository.create(subscription); subscription = cosmosSubscription.createSubscription(subscription);
logger.debug("Successfully created Acknowledgement Subscription"); logger.debug("Successfully created Acknowledgement Subscription");
} }
} }
......
...@@ -21,12 +21,9 @@ import org.mockito.Mock; ...@@ -21,12 +21,9 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; 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.HmacSecret;
import org.opengroup.osdu.register.subscriber.model.Subscription; import org.opengroup.osdu.register.subscriber.model.Subscription;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
...@@ -34,7 +31,7 @@ public class TestSubscriptionAzureTest { ...@@ -34,7 +31,7 @@ public class TestSubscriptionAzureTest {
private final static String INTEGRATION_TEST_CORRELATION_ID = "storage-notification-it"; private final static String INTEGRATION_TEST_CORRELATION_ID = "storage-notification-it";
@Mock @Mock
private ISubscriptionRepository subscriptionRepository; private CosmosSubscription cosmosSubscription;
@Mock @Mock
private JaxRsDpsLog logger; private JaxRsDpsLog logger;
@Mock @Mock
...@@ -45,26 +42,12 @@ public class TestSubscriptionAzureTest { ...@@ -45,26 +42,12 @@ public class TestSubscriptionAzureTest {
@Test @Test
public void shouldCreateTestAcknowledgementSubscription() throws Exception { public void shouldCreateTestAcknowledgementSubscription() throws Exception {
when(dpsHeaders.getCorrelationId()).thenReturn(INTEGRATION_TEST_CORRELATION_ID); when(dpsHeaders.getCorrelationId()).thenReturn(INTEGRATION_TEST_CORRELATION_ID);
when(subscriptionRepository.create(getSubscription())).thenReturn(getSubscription()); when(cosmosSubscription.createSubscription(getSubscription())).thenReturn(getSubscription());
sut.performTestAcknowledgement(); sut.performTestAcknowledgement();
verify(logger, times(1)).debug("Successfully created Acknowledgement Subscription"); verify(logger, times(1)).debug("Successfully created Acknowledgement Subscription");
verify(subscriptionRepository, times(1)).create(getSubscription()); verify(cosmosSubscription, times(1)).createSubscription(getSubscription());
}
@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, () -> {
sut.performTestAcknowledgement();
});
assertNotNull(exception);
verify(logger, times(0)).debug("Successfully created Acknowledgement Subscription");
verify(subscriptionRepository, times(1)).create(getSubscription());
} }
@Test @Test
...@@ -74,7 +57,7 @@ public class TestSubscriptionAzureTest { ...@@ -74,7 +57,7 @@ public class TestSubscriptionAzureTest {
sut.performTestAcknowledgement(); sut.performTestAcknowledgement();
verify(logger, times(0)).debug("Successfully created Acknowledgement Subscription"); verify(logger, times(0)).debug("Successfully created Acknowledgement Subscription");
verify(subscriptionRepository, times(0)).create(getSubscription()); verify(cosmosSubscription, times(0)).createSubscription(getSubscription());
} }
private Subscription getSubscription() { private Subscription getSubscription() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment