Skip to content
Snippets Groups Projects
Commit 614cdbb1 authored by Smitha Manjunath's avatar Smitha Manjunath
Browse files

increase code coverage to 80%

parent 9d9a37aa
No related branches found
No related tags found
3 merge requests!232Update os-core-lib-azure,!231initial commit,!196Azure | Increasing Code coverage
......@@ -86,6 +86,7 @@ public class ProcessNotification {
LOGGER.info("Message delivery status is 'Abandon' with notificationId: {}, Count: {}", notificationContent.getNotificationId(), message.getDeliveryCount());
} else {
LOGGER.error(NOT_ACKNOWLEDGE);
throw new Exception(NOT_ACKNOWLEDGE);
}
}else{
requestTelemetry.setResponseCode("200");
......
......@@ -13,6 +13,9 @@ import org.opengroup.osdu.notification.provider.azure.messageBus.interfaces.IPul
import org.opengroup.osdu.notification.provider.azure.messageBus.models.TopicSubscriptionsTest;
import org.opengroup.osdu.notification.provider.azure.models.NotificationContent;
import java.util.HashMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@RunWith(MockitoJUnitRunner.class)
......@@ -34,8 +37,10 @@ public class RequestBodyAdapterTest {
@Test
public void extractNotificationContentTest() {
NotificationContent expected = new NotificationContent("recordsTopic",null,new HashMap<String,String>(),false);
NotificationContent actual = requestBodyAdapter.extractNotificationContent(message,"recordsTopic");
assertNotNull(actual);
assertEquals(expected,actual);
assertEquals(actual.getNotificationId(),"recordsTopic");
}
}
......@@ -6,49 +6,74 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.notification.provider.azure.messageBus.thread.ThreadScope;
import org.opengroup.osdu.notification.provider.azure.messageBus.thread.ThreadScopeTest;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doNothing;
@RunWith(MockitoJUnitRunner.class)
public class TopicSubscriptionsTest {
private static String PARTITION = "opendes";
private static String SBTOPICNAME = "recordsTopic";
private static String SUBSCRIPTION = "test123asjdk";
private Map<String, Map<String, List<String>>> existingTopicSubscriptions = new HashMap<>();
private Map<String, Map<String, List<String>>> currentTopicSubscriptions = new HashMap<>();
private static final String PARTITION = "opendes";
private static final String SBTOPICNAME = "recordsTopic";
private static final String CURRENTSUBSCRIPTION = "test123asjdk";
private static final String EXISTINGSUBSCRIPTION = "test345asjdk";
@InjectMocks
TopicSubscriptions topicSubscriptions;
private final Map<String, Map<String, List<String>>> existingTopicSubscriptions = new HashMap<>();
private final Map<String, Map<String, List<String>>> currentTopicSubscriptions = new HashMap<>();
@Before
public void setup() {
Map<String, List<String>> existingSubscriptionMap = new HashMap<>();
List<String> existingSubscriptionList = new ArrayList<>();
existingSubscriptionList.add(EXISTINGSUBSCRIPTION);
existingSubscriptionMap.put(SBTOPICNAME, existingSubscriptionList);
existingTopicSubscriptions.put(PARTITION, existingSubscriptionMap);
Map<String, List<String>> currentSubscriptionMap = new HashMap<>();
List<String> currentSubscriptionList = new ArrayList<>();
currentSubscriptionList.add(CURRENTSUBSCRIPTION);
currentSubscriptionMap.put(SBTOPICNAME, currentSubscriptionList);
currentTopicSubscriptions.put(PARTITION, currentSubscriptionMap);
MockitoAnnotations.openMocks(TopicSubscriptionsTest.this);
ReflectionTestUtils.setField(topicSubscriptions, "existingTopicSubscriptions", existingTopicSubscriptions);
ReflectionTestUtils.setField(topicSubscriptions, "currentTopicSubscriptions", currentTopicSubscriptions);
}
@Test
public void checkIfNewTopicSubscriptionTest(){
boolean actual = topicSubscriptions.checkIfNewTopicSubscription(PARTITION,SBTOPICNAME,SUBSCRIPTION);
assertEquals(actual,true);
public void checkIfNewTopicSubscriptionTest_true() {
boolean actual = topicSubscriptions.checkIfNewTopicSubscription("closedes", SBTOPICNAME, EXISTINGSUBSCRIPTION);
assertEquals(actual, true);
}
@Test
public void updateCurrentTopicSubscriptionsTest(){
topicSubscriptions.updateCurrentTopicSubscriptions(PARTITION,SBTOPICNAME,SUBSCRIPTION);
public void checkIfNewTopicSubscriptionTest_false() {
boolean actual = topicSubscriptions.checkIfNewTopicSubscription(PARTITION, SBTOPICNAME, EXISTINGSUBSCRIPTION);
assertEquals(actual, false);
}
@Test
public void clearTopicSubscriptionsTest(){
public void updateCurrentTopicSubscriptionsTest() {
topicSubscriptions.updateCurrentTopicSubscriptions(PARTITION, SBTOPICNAME, "test678");
List<String> subscriptions = currentTopicSubscriptions.get(PARTITION).get(SBTOPICNAME);
assertEquals(subscriptions.size(), 2);
assertEquals(subscriptions.get(1), "test678");
}
@Test
public void clearTopicSubscriptionsTest() {
topicSubscriptions.clearTopicSubscriptions();
assertEquals(existingTopicSubscriptions.size(), 1);
assertEquals(currentTopicSubscriptions.size(), 0);
}
}
......@@ -9,6 +9,8 @@ import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
import static org.junit.Assert.fail;
@RunWith(MockitoJUnitRunner.class)
public class ThreadDpsHeadersTest {
@InjectMocks
......@@ -23,8 +25,12 @@ public class ThreadDpsHeadersTest {
}
@Test
public void setThreadContextTest(){
threadDpsHeaders.setThreadContext("opendes","ut");
public void setThreadContextTest() {
try {
threadDpsHeaders.setThreadContext("opendes", "ut");
} catch (Exception e) {
fail("didn't expect any exceptions here");
}
}
}
......@@ -30,20 +30,24 @@ public class ThreadSignatureServiceTest {
}
@Test
public void getSignedSignatureTest() throws SignatureServiceException {
String actual = threadSignatureService.getSignedSignature(URL, SECRET);
assertNotNull(actual);
public void getSignedSignatureTest() {
assertDoesNotThrow(() -> {
String actual = threadSignatureService.getSignedSignature(URL, SECRET);
assertNotNull(actual);
});
}
@Test
public void getSignedSignatureTest_withExpiryTimeAndNonce() throws SignatureServiceException {
String actual = threadSignatureService.getSignedSignature(URL,SECRET,String.valueOf(System.currentTimeMillis()+120000),SECRET);
assertNotNull(actual);
public void getSignedSignatureTest_withExpiryTimeAndNonce() {
assertDoesNotThrow(() -> {
String actual = threadSignatureService.getSignedSignature(URL, SECRET, String.valueOf(System.currentTimeMillis() + 120000), SECRET);
assertNotNull(actual);
});
}
@Test(expected = SignatureServiceException.class)
public void getSignedSignatureTest_withExpiryTimeAndNonce_signatureServiceException() throws SignatureServiceException {
threadSignatureService.getSignedSignature(URL,"",String.valueOf(System.currentTimeMillis()+120000),SECRET);
threadSignatureService.getSignedSignature(URL, "", String.valueOf(System.currentTimeMillis() + 120000), SECRET);
}
@Test
......
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