Skip to content
Snippets Groups Projects
Commit fc4b7437 authored by Guillaume Caillet's avatar Guillaume Caillet
Browse files

Make integration tests more robust by deleting previous subscription

parent 1617f045
No related branches found
No related tags found
1 merge request!437merge code to gitlab
......@@ -15,6 +15,7 @@ import org.opengroup.osdu.core.common.notification.SubscriptionFactory;
import org.opengroup.osdu.notification.util.*;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
......@@ -44,8 +45,32 @@ public class TestNotificationsEndpoint extends TestBase {
}
@Before
public void setup() {
public void setup() throws Exception {
this.testUtils = new AwsTestUtils();
Map<String, String> headers = new HashMap<>();
headers.put(DpsHeaders.DATA_PARTITION_ID, TestUtils.getOsduTenant());
headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken());
//hardcoding user here for 200 response tests. This is just initializing the subscription creation
headers.put("x-user-id", AwsConfig.getAWSCognitoUser());
DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers);
awssubscriptionService = awsfactory.create(dpsHeaders);
try {
// Ensure that there is no previous subscription already registered
// Sometimes this can happen if previous tests didn't exit properly
// Sadly there is no method to delete a subscription from just name, so have
// to manually build the ID like this.
String subscriptionId = String.format("%s%s%s",
Config.Instance().Topic,
PARTITION_TEST,
Config.Instance().HMACPushUrl);
String encodedSubscriptionId = Base64.getEncoder().encodeToString(subscriptionId.getBytes());
awssubscriptionService.delete(encodedSubscriptionId);
}
catch (Exception e) {}
}
@After
......@@ -57,25 +82,11 @@ public class TestNotificationsEndpoint extends TestBase {
}
private void createResourceForTestParition() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put(DpsHeaders.DATA_PARTITION_ID, TestUtils.getOsduTenant());
headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken());
//hardcoding user here for 200 response tests. This is just initializing the subscription creation
headers.put("x-user-id", AwsConfig.getAWSCognitoUser());
DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers);
awssubscriptionService = awsfactory.create(dpsHeaders);
Map<String,String> h = dpsHeaders.getHeaders();
System.out.println(h);
//Create a new subscription to pub/sub
Subscription subscription = new Subscription();
subscription.setName("Subscription-test-for-notification");
subscription.setDescription("Subscription with test Partition for fetching notifications");
subscription.setTopic(Config.Instance().Topic);
//This seems to be a bug. Don't need to add the string
//subscription.setPushEndpoint(Config.Instance().HMACPushUrl + "hmac-integration-test");
subscription.setPushEndpoint(Config.Instance().HMACPushUrl);
HmacSecret secret = new HmacSecret();
secret.setValue(Config.Instance().hmacSecretValue);
......
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