From 24542900e951ea4ee4b18c1d6c0aa00a975d45b0 Mon Sep 17 00:00:00 2001 From: Yash Dholakia <ysdholak@amazon.com> Date: Tue, 11 Jul 2023 19:23:33 +0000 Subject: [PATCH] Fix Integration tests --- .../subscriptions/RecordUtils.java | 3 +- .../TestNotificationsEndpoint.java | 56 ++++++++++++++++--- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/RecordUtils.java b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/RecordUtils.java index 3c14f0b4d..adef2dece 100644 --- a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/RecordUtils.java +++ b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/RecordUtils.java @@ -76,11 +76,10 @@ public class RecordUtils { return record; } - public static final String getAclSuffix(boolean isTestPartition) { + public static String getAclSuffix(boolean isTestPartition) { String environment = getEnvironment(); //build.gradle currently throws exception if a variable is set to empty or not set at all //workaround by setting it to an "empty" string to construct the url - if (environment.equalsIgnoreCase("empty")) environment = ""; if (!environment.isEmpty()) environment = "." + environment; 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 1e4f99832..377cedff0 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 @@ -23,6 +23,8 @@ import static org.junit.Assert.assertEquals; public class TestNotificationsEndpoint extends TestBase { + private String subscriptionId_TestPartition; + private String subscriptionId; private ISubscriptionService awssubscriptionService; private TestUtils testUtils; @@ -46,17 +48,55 @@ public class TestNotificationsEndpoint extends TestBase { } @Before - public void setup() throws Exception { + public void setup() { this.testUtils = new AwsTestUtils(); } @After @Override public void tearDown() throws Exception { - //LegalTagUtils.delete(LEGAL_TAG, testUtils.getOpsToken()); + LegalTagUtils.delete(LEGAL_TAG_TEST, testUtils.getOpsToken(), true); + LegalTagUtils.delete(LEGAL_TAG, testUtils.getOpsToken(), false); this.testUtils = null; } + 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); + + subscription.setSecret(secret); + try { + Subscription subscriptionCreated = awssubscriptionService.create(subscription); + System.out.println("Subscription created successfully"); + String notificationId = subscriptionCreated.getNotificationId(); + subscriptionId_TestPartition = subscriptionCreated.getId(); + Config.Instance().NotificationId = notificationId; + }catch (SubscriptionException e){ + System.out.println("Subscription exception inner response : " + e.getHttpResponse()); + throw e; + } + } + private void createResource() throws Exception { Map<String, String> headers = new HashMap<>(); headers.put(DpsHeaders.DATA_PARTITION_ID, TestUtils.getOsduTenant()); @@ -73,7 +113,7 @@ public class TestNotificationsEndpoint extends TestBase { //Create a new subscription to pub/sub Subscription subscription = new Subscription(); subscription.setName("Subscription-test-for-notification"); - subscription.setDescription("Subscription test for fetching notifications"); + subscription.setDescription("Subscription 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"); @@ -110,7 +150,7 @@ public class TestNotificationsEndpoint extends TestBase { public void testVerifyNotificationReceivedWhenDataPartitionIdIsDifferent() throws Exception { try { LegalTagUtils.create(LEGAL_TAG_TEST, testUtils.getOpsToken(), true); - createResource(); + createResourceForTestParition(); final String correlationId = UUID.randomUUID().toString(); ClientResponse response = createStorageRecordForTestPartition(correlationId); assertEquals(201, response.getStatus()); @@ -124,10 +164,9 @@ public class TestNotificationsEndpoint extends TestBase { int exitValue = process.exitValue(); assertEquals(exitValue, 1); } catch (Exception e) { - System.out.println("Error while verifying notification service" + Arrays.toString(e.getStackTrace())); + System.out.println("Error while verifying notification service. Error = " + e.getMessage() + " Stack Trace = " + Arrays.toString(e.getStackTrace())); } finally { - awssubscriptionService.delete(subscriptionId); - LegalTagUtils.delete(LEGAL_TAG_TEST, testUtils.getOpsToken(), true); + awssubscriptionService.delete(subscriptionId_TestPartition); } } @@ -149,10 +188,9 @@ public class TestNotificationsEndpoint extends TestBase { int exitValue = process.exitValue(); assertEquals(exitValue, 0); } catch (Exception e) { - System.out.println("Error while verifying notification service" + Arrays.toString(e.getStackTrace())); + System.out.println("Error while verifying notification service. Error = " + e.getMessage() + " Stack Trace = " + Arrays.toString(e.getStackTrace())); } finally { awssubscriptionService.delete(subscriptionId); - LegalTagUtils.delete(LEGAL_TAG_TEST, testUtils.getOpsToken(), false); } } } -- GitLab