From fc4b743785ea3273c2e6789fa6c42af826e7a75b Mon Sep 17 00:00:00 2001 From: Guillaume Caillet <cailletg@amazon.com> Date: Wed, 30 Aug 2023 10:59:17 -0400 Subject: [PATCH] Make integration tests more robust by deleting previous subscription --- .../TestNotificationsEndpoint.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/TestNotificationsEndpoint.java b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/TestNotificationsEndpoint.java index 1da461784..751f96afb 100644 --- a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/TestNotificationsEndpoint.java +++ b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/TestNotificationsEndpoint.java @@ -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); -- GitLab