From 1f0cee026f2398488725bb348c8169ff72238755 Mon Sep 17 00:00:00 2001
From: Guillaume Caillet <cailletg@amazon.com>
Date: Tue, 22 Aug 2023 14:20:12 -0400
Subject: [PATCH] AWS Fixing testVerifyNotificationReceived integration test

---
 .gitlab-ci.yml                                | 10 ++++------
 devops/aws/pipeline/override-stages.yml       | 20 +++++++++++++++++++
 .../subscriptions/LegalTagUtils.java          |  3 ---
 .../subscriptions/RecordUtils.java            | 11 +---------
 .../subscriptions/StorageTestUtils.java       |  3 ---
 .../TestNotificationsEndpoint.java            |  4 +++-
 .../subscriptions/verify_register-logs.sh     | 11 +++++-----
 7 files changed, 34 insertions(+), 28 deletions(-)
 create mode 100644 devops/aws/pipeline/override-stages.yml
 mode change 100644 => 100755 testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/verify_register-logs.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 342908b2a..3840a1f6b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -39,12 +39,10 @@ include:
     file: "cloud-providers/gc-global.yml"
 
   - project: "osdu/platform/ci-cd-pipelines"
-    file: "cloud-providers/aws-global.yml"
+    file: "cloud-providers/ibm.yml"
 
-  - project: "osdu/platform/ci-cd-pipelines"
-    file: "cloud-providers/aws-maven.yml"
+  # aws
+  - local: "devops/aws/pipeline/override-stages.yml"
 
-  - project: "osdu/platform/ci-cd-pipelines"
-    file: "cloud-providers/ibm.yml"
+  - local: "devops/gc/pipeline/override-stages.yml"
 
-  - local: "devops/gc/pipeline/override-stages.yml"
\ No newline at end of file
diff --git a/devops/aws/pipeline/override-stages.yml b/devops/aws/pipeline/override-stages.yml
new file mode 100644
index 000000000..16fb9baf7
--- /dev/null
+++ b/devops/aws/pipeline/override-stages.yml
@@ -0,0 +1,20 @@
+include:
+  - project: "osdu/platform/ci-cd-pipelines"
+    file: "cloud-providers/aws-global.yml"
+  - project: "osdu/platform/ci-cd-pipelines"
+    file: "cloud-providers/aws-global-variables.yml"
+  - project: "osdu/platform/ci-cd-pipelines"
+    file: "cloud-providers/aws-global.yml"
+  - project: "osdu/platform/ci-cd-pipelines"
+    file: "cloud-providers/aws-maven.yml"
+
+aws-test-java:
+  script:
+    - export KUBECONFIG=/tmp/kubeconfig-${RANDOM}.yaml
+    - echo "ROLE $EKS_CLUSTER_MGMT_ROLE"
+    - echo "CLUSTER $EKS_CLUSTER_NAME"
+    - aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME --role-arn $EKS_CLUSTER_MGMT_ROLE
+    - chmod 600 $KUBECONFIG
+
+    - $MAVEN_BUILD $INTEGRATION_TEST_DIR maven-aws-integration-test-output.log ${AWS_MAVEN_TEST_COMMAND_OVERRIDE:-test} --update-snapshots -DdisableXmlReport=true
+
diff --git a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/LegalTagUtils.java b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/LegalTagUtils.java
index 086093862..43fc4e536 100644
--- a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/LegalTagUtils.java
+++ b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/LegalTagUtils.java
@@ -34,9 +34,6 @@ public class LegalTagUtils {
 
     protected static String getLegalUrl() {
         String legalUrl = System.getProperty("LEGAL_URL", System.getenv("LEGAL_URL"));
-        if (legalUrl == null || legalUrl.contains("-null")) {
-            legalUrl = "https://os-legal-dot-opendes.appspot.com/api/legal/v1/";
-        }
         return legalUrl;
     }
 
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 adef2dece..4c7516521 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
@@ -77,16 +77,7 @@ public class RecordUtils {
     }
 
     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.isEmpty())
-            environment = "." + environment;
-
-        return String.format("%s%s.%s", TenantUtils.getTenantName(isTestPartition), environment, domain);
+        return String.format("%s.%s", TenantUtils.getTenantName(isTestPartition), domain);
     }
 
-    public static String getEnvironment() {
-        return System.getProperty("DEPLOY_ENV", System.getenv("DEPLOY_ENV"));
-    }
 }
diff --git a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/StorageTestUtils.java b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/StorageTestUtils.java
index befe02863..fd7a216d0 100644
--- a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/StorageTestUtils.java
+++ b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/StorageTestUtils.java
@@ -54,9 +54,6 @@ public class StorageTestUtils {
 
     public static String getApiPath(String api) throws Exception {
         String baseUrl = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL"));
-        if (baseUrl == null || baseUrl.contains("-null")) {
-            baseUrl = "https://localhost:8443/api/storage/v2/";
-        }
         URL mergedURL = new URL(baseUrl + api);
         System.out.println(mergedURL.toString());
         return mergedURL.toString();
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..180960463 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
@@ -112,12 +112,14 @@ public class TestNotificationsEndpoint extends TestBase {
 
             //Run Bash File to fetch logs from register endpoint and verify that notification was received
             String bashFileToExecute = "src/test/java/org/opengroup/osdu/notification/subscriptions/verify_register-logs.sh " + correlationId;
+
             Process process = Runtime.getRuntime().exec(bashFileToExecute);
             process.waitFor();
+
             int exitValue = process.exitValue();
             assertEquals(exitValue, 0);
         } catch (Exception e) {
-            System.out.println("Error while verifying notification service. Error = " + e.getMessage() + " Stack Trace = " + Arrays.toString(e.getStackTrace()));
+            throw e;
         } finally {
             awssubscriptionService.delete(subscriptionId_TestPartition);
         }
diff --git a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/verify_register-logs.sh b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/verify_register-logs.sh
old mode 100644
new mode 100755
index 6832babe4..bacda8d64
--- a/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/verify_register-logs.sh
+++ b/testing/notification-test-aws/src/test/java/org/opengroup/osdu/notification/subscriptions/verify_register-logs.sh
@@ -1,8 +1,9 @@
-register_pod=$(kubectl get pods --all-namespaces -o=jsonpath='{range .items..metadata}{.name}{"\n"}{end}' | fgrep os-register-)
-register_logs=$(kubectl logs $register_pod -n osdu-instance-$OSDU_INSTANCE_NAME-core --since=2m)
+CORE_K8S_NAMESPACE="$AWS_SERVICE_NAMESPACE-core"
+register_pod=$(kubectl get pods -n $CORE_K8S_NAMESPACE | grep "Running" | grep "os-register" | awk '{ print $1 }')
+register_logs=$(kubectl logs $register_pod -n $CORE_K8S_NAMESPACE --since=2m)
 
 if echo $register_logs | grep $1; then
-  return 0
+  exit 0
 else
-  return 1
-fi
\ No newline at end of file
+  exit 1
+fi
-- 
GitLab