From 30496c598f8d267245b37e254a6580b3331b6b16 Mon Sep 17 00:00:00 2001
From: "Kanstantsin Dubrouski [EPAM / GCP]" <kanstantsin_dubrouski@epam.com>
Date: Fri, 31 Mar 2023 13:15:08 +0000
Subject: [PATCH] Alternate GC int tests

---
 provider/notification-gc/docs/gc/README.md    |  25 ++-
 .../notification/api/TestPushEndpointGsa.java | 143 ++++++++++++++++++
 .../api/TestPushEndpointHMAC.java             | 133 ++++++++++++++++
 .../osdu/notification/util/FileUtils.java     |  39 +++++
 .../osdu/notification/util/GCPTestUtils.java  |   2 +-
 .../osdu/notification/util/HttpClient.java    | 137 +++++++++++++++++
 .../osdu/notification/util/ServicesUtils.java |  94 ++++++++++++
 .../src/test/resources/LegalTag.json          |  16 ++
 .../src/test/resources/StorageRecord.json     |  33 ++++
 9 files changed, 607 insertions(+), 15 deletions(-)
 create mode 100644 testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointGsa.java
 create mode 100644 testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointHMAC.java
 create mode 100644 testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/FileUtils.java
 create mode 100644 testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/HttpClient.java
 create mode 100644 testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/ServicesUtils.java
 create mode 100644 testing/notification-test-gc/src/test/resources/LegalTag.json
 create mode 100644 testing/notification-test-gc/src/test/resources/StorageRecord.json

diff --git a/provider/notification-gc/docs/gc/README.md b/provider/notification-gc/docs/gc/README.md
index 3be94ca7f..7802e9ce9 100644
--- a/provider/notification-gc/docs/gc/README.md
+++ b/provider/notification-gc/docs/gc/README.md
@@ -69,20 +69,17 @@ After the service has started it should be accessible via a web browser by visit
 * Maven
 * Values for the following environment variables in Config.java
 
-| name | value | description | sensitive? | source |
-| ---  | ---   | ---         | ---        | ---    |
-| `DE_OPS_TESTER` | `*****` | Service account base64 encoded string for API calls. Note: this user must have entitlements configured already, also **Private key id** of this account must be set in Register service variable SUBSCRIBER_PRIVATE_KEY_ID  | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> |
-| `DE_ADMIN_TESTER` | `*****` | Service account base64 encoded string for API calls. Note: this user must have entitlements configured already | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> |
-| `DE_EDITOR_TESTER` | `*****` | Service account base64 encoded string for API calls. Note: this user must have entitlements configured already  | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> |
-| `DE_NO_ACCESS_TESTER` | `*****` | Service account base64 encoded string for API calls. Note: this user must have entitlements configured already | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> |
-| `ENVIRONMENT` | `dev` OR `local` OR `dev_gke`| Local for running locally with services url's predefined as <http://localhost> , Dev & Dev_Gke is configurable environment | no | - |
-| `HMAC_SECRET` | ex`7a786376626e` | String in hex , must match pattern ^[a-zA-Z0-9]{8,30}+$ & be in register variable SUBSCRIBER_SECRET | yes | - |
-| `REGISTER_BASE_URL` | `http://localhost:8081/api/register/v1` | Register service url | no | - |
-| `NOTIFICATION_BASE_URL` | `http://localhost:8080/api/notification/v1/` | Notification service url  | no | - |
-| `CLIENT_TENANT` | ex `opendes` | Client tenant | no | - |
-| `OSDU_TENANT` | ex `osdu` | osdu tenant | no | - |
-| `TOPIC_ID` | ex `records-changed` | PubSub topic id | no | <https://console.cloud.google.com/cloudpubsub/topic> |
-| `REGISTER_CUSTOM_PUSH_URL_HMAC` | ex `http://localhost:8081/api/register/v1/test/challenge/hmac-integration-test` | Register testing push url | no | - |
+| name                   | value                                   | description                                                                                                                                                                                                                | sensitive? | source                                                       |
+|------------------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|--------------------------------------------------------------|
+| `DE_OPS_TESTER`        | `*****`                                 | Service account base64 encoded string for API calls. Note: this user must have entitlements configured already, also **Private key id** of this account must be set in Register service variable SUBSCRIBER_PRIVATE_KEY_ID | yes        | <https://console.cloud.google.com/iam-admin/serviceaccounts> |
+| `INTEGRATION_TESTER`   | `*****`                                 | Service account base64 encoded string for API calls.                                                                                                                                                                       | yes        | <https://console.cloud.google.com/iam-admin/serviceaccounts> |
+| `HMAC_SECRET`          | ex`7a786376626e`                        | String in hex , must match pattern ^[a-zA-Z0-9]{8,30}+$ & be in register variable SUBSCRIBER_SECRET                                                                                                                        | yes        | -                                                            |
+| `REGISTER_BASE_URL`    | `http://localhost:8081/api/register/v1` | Register service url                                                                                                                                                                                                       | no         | -                                                            |
+| `OSDU_TENANT`          | ex `osdu`                               | osdu tenant                                                                                                                                                                                                                | no         | -                                                            |
+| `INTEGRATION_AUDIENCE` | ex `osdu`                               | integration audience                                                                                                                                                                                                       | no         | -                                                            |
+| `TOPIC_ID`             | ex `records-changed`                    | PubSub topic id                                                                                                                                                                                                            | no         | <https://console.cloud.google.com/cloudpubsub/topic>         |
+| `STORAGE_HOST`         | `http://localhost:8081/api/storage/v1/` | Storage service url                                                                                                                                                                                                        | no         | -                                                            |
+| `LEGAL_HOST`           | `http://localhost:8081/api/legal/v1/`   | Legal service url                                                                                                                                                                                                          | no         | -                                                            |
 
 **Entitlements configuration for integration accounts**
 
diff --git a/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointGsa.java b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointGsa.java
new file mode 100644
index 000000000..a03e03034
--- /dev/null
+++ b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointGsa.java
@@ -0,0 +1,143 @@
+/*
+ *  Copyright 2020-2023 Google LLC
+ *  Copyright 2020-2023 EPAM Systems, Inc
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.opengroup.osdu.notification.api;
+
+import com.google.common.base.Strings;
+import com.sun.jersey.api.client.ClientResponse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.opengroup.osdu.core.common.model.http.DpsHeaders;
+import org.opengroup.osdu.core.common.model.notification.*;
+import org.opengroup.osdu.core.common.notification.ISubscriptionService;
+import org.opengroup.osdu.core.common.notification.SubscriptionAPIConfig;
+import org.opengroup.osdu.core.common.notification.SubscriptionException;
+import org.opengroup.osdu.core.common.notification.SubscriptionFactory;
+import org.opengroup.osdu.notification.util.GCPTestUtils;
+import org.opengroup.osdu.notification.util.ServicesUtils;
+import org.opengroup.osdu.notification.util.TestUtils;
+
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+public class TestPushEndpointGsa {
+  public static final String REGISTER_BASE_URL = "REGISTER_BASE_URL";
+  public static final String TOPIC_ID = "TOPIC_ID";
+  public static final String INTEGRATION_AUDIENCE = "INTEGRATION_AUDIENCE";
+  public static final String OSDU_TENANT = "OSDU_TENANT";
+  public static final String STORAGE_HOST = "STORAGE_HOST";
+  public static final String LEGAL_HOST = "LEGAL_HOST";
+  public static final String DE_OPS_TESTER = "DE_OPS_TESTER";
+  private String subscriptionId = null;
+  private String notificationId = null;
+  private ISubscriptionService subscriptionService;
+  private static SubscriptionFactory factory;
+  private TestUtils testUtils = new GCPTestUtils();
+  private final String suffix = String.valueOf(System.currentTimeMillis());
+  private String baseRegisterUrl;
+  private String topic;
+  private String tenant;
+  private String integrationAudience;
+  private String storageHost;
+  private String legalHost;
+  private static final String LEGAL_TAG_NAME = "notification-test-gsa";
+  private ServicesUtils servicesUtils;
+
+  @After
+  public void deleteResource() throws Exception {
+    subscriptionService.delete(subscriptionId);
+    servicesUtils.deleteStorageRecords(3, suffix);
+    servicesUtils.deleteLegalTag(LEGAL_TAG_NAME);
+  }
+
+  @Before
+  public void createResource() throws Exception {
+    baseRegisterUrl = System.getProperty(REGISTER_BASE_URL, System.getenv(REGISTER_BASE_URL));
+    topic = System.getProperty(TOPIC_ID, System.getenv(TOPIC_ID));
+    integrationAudience = System.getProperty(INTEGRATION_AUDIENCE, System.getenv(INTEGRATION_AUDIENCE));
+    tenant = System.getProperty(OSDU_TENANT, System.getenv(OSDU_TENANT));
+    if (Strings.isNullOrEmpty(integrationAudience)) {
+      integrationAudience = tenant;
+    }
+    storageHost = System.getProperty(STORAGE_HOST, System.getenv(STORAGE_HOST));
+    legalHost = System.getProperty(LEGAL_HOST, System.getenv(LEGAL_HOST));
+    servicesUtils = new ServicesUtils(storageHost, legalHost, testUtils, tenant);
+    servicesUtils.createLegalTag(LEGAL_TAG_NAME);
+    createResourceInPartition(tenant);
+  }
+
+  @Test
+  public void testPushEndpoint() throws Exception {
+    servicesUtils.createStorageRecords(suffix, 3, LEGAL_TAG_NAME);
+    Thread.sleep(10000);
+    assertNotNull(subscriptionId);
+    assertNotNull(notificationId);
+    Map<String, String> headers = new HashMap<>();
+    headers.put(DpsHeaders.DATA_PARTITION_ID, tenant);
+    ClientResponse clientResponse = testUtils.send(baseRegisterUrl, "/test-gc/state", "GET", testUtils.getOpsToken(), null, "",
+        headers, false);
+    Map<String, Number> response = new HashMap<>();
+    response = testUtils.getResult(clientResponse, 200, response.getClass());
+    assertNotNull(response);
+    assertTrue(response.containsKey(suffix));
+    assertTrue(response.get(suffix).longValue() >= 3);
+  }
+
+  private void createResourceInPartition(String partitionId) throws Exception {
+
+    SubscriptionAPIConfig config = SubscriptionAPIConfig.builder().rootUrl(baseRegisterUrl).build();
+    factory = new SubscriptionFactory(config);
+
+    Map<String, String> headers = new HashMap<>();
+    headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
+    headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken());
+    DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers);
+    subscriptionService = factory.create(dpsHeaders);
+
+    Subscription subscription = new Subscription();
+    subscription.setName("subscription-integration-test-gsa-" + suffix);
+    subscription.setDescription("subscription created for gsa integration test " + suffix);
+    subscription.setTopic(topic);
+    subscription.setPushEndpoint(getPushUrl());
+
+    Secret gsaSecret = new GsaSecret();
+    GsaSecretValue gsaSecretValue = new GsaSecretValue();
+    gsaSecretValue.setAudience(integrationAudience);
+    String opsTester = System.getProperty(DE_OPS_TESTER, System.getenv(DE_OPS_TESTER));
+    gsaSecretValue.setKey(new String(Base64.getDecoder().decode(opsTester)));
+    gsaSecret.setSecretType("GSA");
+    ((GsaSecret) gsaSecret).setValue(gsaSecretValue);
+    subscription.setSecret(gsaSecret);
+    try {
+      Subscription subscriptionCreated = subscriptionService.create(subscription);
+      notificationId = subscriptionCreated.getNotificationId();
+      subscriptionId = subscriptionCreated.getId();
+    } catch (SubscriptionException e) {
+      System.out.println("Subscription exception inner response : " + e.getHttpResponse());
+      throw e;
+    }
+  }
+
+  private String getPushUrl() {
+    return baseRegisterUrl + "/test-gc/gsa-challenge/" + suffix;
+  }
+
+}
diff --git a/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointHMAC.java b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointHMAC.java
new file mode 100644
index 000000000..d759d1966
--- /dev/null
+++ b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/api/TestPushEndpointHMAC.java
@@ -0,0 +1,133 @@
+/*
+ *  Copyright 2020-2023 Google LLC
+ *  Copyright 2020-2023 EPAM Systems, Inc
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.opengroup.osdu.notification.api;
+
+import com.sun.jersey.api.client.ClientResponse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.opengroup.osdu.core.common.model.http.DpsHeaders;
+import org.opengroup.osdu.core.common.model.notification.HmacSecret;
+import org.opengroup.osdu.core.common.model.notification.Subscription;
+import org.opengroup.osdu.core.common.notification.ISubscriptionService;
+import org.opengroup.osdu.core.common.notification.SubscriptionAPIConfig;
+import org.opengroup.osdu.core.common.notification.SubscriptionException;
+import org.opengroup.osdu.core.common.notification.SubscriptionFactory;
+import org.opengroup.osdu.notification.util.GCPTestUtils;
+import org.opengroup.osdu.notification.util.ServicesUtils;
+import org.opengroup.osdu.notification.util.TestUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class TestPushEndpointHMAC {
+  public static final String REGISTER_BASE_URL = "REGISTER_BASE_URL";
+  public static final String TOPIC_ID = "TOPIC_ID";
+  public static final String HMAC_SECRET = "HMAC_SECRET";
+  public static final String OSDU_TENANT = "OSDU_TENANT";
+  public static final String STORAGE_HOST = "STORAGE_HOST";
+  public static final String LEGAL_HOST = "LEGAL_HOST";
+  private String subscriptionId = null;
+  private String notificationId = null;
+  private ISubscriptionService subscriptionService;
+  private static SubscriptionFactory factory;
+  private TestUtils testUtils = new GCPTestUtils();
+  private final String suffix = String.valueOf(System.currentTimeMillis());
+  private String baseRegisterUrl;
+  private String topic;
+  private String hmacSecretValue;
+  private String tenant;
+  private String storageHost;
+  private String legalHost;
+  private static final String LEGAL_TAG_NAME = "notification-test-hmac";
+  private ServicesUtils servicesUtils;
+
+  @After
+  public void deleteResource() throws Exception {
+    subscriptionService.delete(subscriptionId);
+    servicesUtils.deleteStorageRecords(3, suffix);
+    servicesUtils.deleteLegalTag(LEGAL_TAG_NAME);
+  }
+
+  @Before
+  public void createResource() throws Exception {
+    baseRegisterUrl = System.getProperty(REGISTER_BASE_URL, System.getenv(REGISTER_BASE_URL));
+    topic = System.getProperty(TOPIC_ID, System.getenv(TOPIC_ID));
+    hmacSecretValue = System.getProperty(HMAC_SECRET, System.getenv(HMAC_SECRET));
+    tenant = System.getProperty(OSDU_TENANT, System.getenv(OSDU_TENANT));
+    storageHost = System.getProperty(STORAGE_HOST, System.getenv(STORAGE_HOST));
+    legalHost = System.getProperty(LEGAL_HOST, System.getenv(LEGAL_HOST));
+    servicesUtils = new ServicesUtils(storageHost, legalHost, testUtils, tenant);
+    servicesUtils.createLegalTag(LEGAL_TAG_NAME);
+    createResourceInPartition(tenant);
+  }
+
+  @Test
+  public void testPushEndpoint() throws Exception {
+    servicesUtils.createStorageRecords(suffix, 3, LEGAL_TAG_NAME);
+    Thread.sleep(10000);
+    assertNotNull(subscriptionId);
+    assertNotNull(notificationId);
+    Map<String, String> headers = new HashMap<>();
+    headers.put(DpsHeaders.DATA_PARTITION_ID, tenant);
+    ClientResponse clientResponse = testUtils.send(baseRegisterUrl, "/test-gc/state", "GET", testUtils.getOpsToken(), null, "",
+        headers, false);
+    Map<String, Number> response = new HashMap<>();
+    response = testUtils.getResult(clientResponse, 200, response.getClass());
+    assertNotNull(response);
+    assertTrue(response.containsKey(suffix));
+    assertTrue(response.get(suffix).longValue() >= 3);
+  }
+
+  private void createResourceInPartition(String partitionId) throws Exception {
+
+    SubscriptionAPIConfig config = SubscriptionAPIConfig.builder().rootUrl(baseRegisterUrl).build();
+    factory = new SubscriptionFactory(config);
+
+    Map<String, String> headers = new HashMap<>();
+    headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
+    headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken());
+    DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers);
+    subscriptionService = factory.create(dpsHeaders);
+
+    Subscription subscription = new Subscription();
+    subscription.setName("subscription-integration-test-hmac-" + suffix);
+    subscription.setDescription("subscription created for hmac integration test " + suffix);
+    subscription.setTopic(topic);
+    subscription.setPushEndpoint(getPushUrl());
+    HmacSecret secret = new HmacSecret();
+    secret.setValue(hmacSecretValue);
+
+    subscription.setSecret(secret);
+    try {
+      Subscription subscriptionCreated = subscriptionService.create(subscription);
+      notificationId = subscriptionCreated.getNotificationId();
+      subscriptionId = subscriptionCreated.getId();
+    } catch (SubscriptionException e) {
+      System.out.println("Subscription exception inner response : " + e.getHttpResponse());
+      throw e;
+    }
+  }
+
+  private String getPushUrl() {
+    return baseRegisterUrl + "/test-gc/challenge/" + suffix;
+  }
+}
diff --git a/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/FileUtils.java b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/FileUtils.java
new file mode 100644
index 000000000..fc0713c16
--- /dev/null
+++ b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/FileUtils.java
@@ -0,0 +1,39 @@
+/*
+ *  Copyright 2020-2023 Google LLC
+ *  Copyright 2020-2023 EPAM Systems, Inc
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.opengroup.osdu.notification.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+public class FileUtils {
+  public String readFromLocalFilePath(String filePath) throws IOException {
+
+    InputStream inStream = this.getClass().getResourceAsStream(filePath);
+    BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
+    StringBuilder stringBuilder = new StringBuilder();
+
+    String eachLine = "";
+    while ((eachLine = br.readLine()) != null) {
+      stringBuilder.append(eachLine);
+    }
+
+    return stringBuilder.toString();
+  }
+}
diff --git a/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java
index dc7766bed..7d569a091 100644
--- a/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java
+++ b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java
@@ -36,7 +36,7 @@ public class GCPTestUtils extends TestUtils {
   @Override
   public synchronized String getAdminToken() throws Exception {
     if (Strings.isNullOrEmpty(adminToken)) {
-      adminToken = getToken("DE_ADMIN_TESTER");
+      adminToken = getToken("INTEGRATION_TESTER");
     }
     return adminToken;
   }
diff --git a/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/HttpClient.java b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/HttpClient.java
new file mode 100644
index 000000000..d32424a1e
--- /dev/null
+++ b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/HttpClient.java
@@ -0,0 +1,137 @@
+/*
+ *  Copyright 2020-2023 Google LLC
+ *  Copyright 2020-2023 EPAM Systems, Inc
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.opengroup.osdu.notification.util;
+
+import com.google.gson.Gson;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import javax.ws.rs.core.MediaType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.security.SecureRandom;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+
+public class HttpClient {
+  private HttpClient(){
+  }
+
+  public static ClientResponse send(String url, String path, String httpMethod,
+                                    Map<String, String> headers,
+                                    String requestBody, String query) throws Exception {
+
+    String normalizedUrl = new URI(String.format("%s/%s", url, path)).normalize().toString();
+    normalizedUrl = StringUtils.removeEnd(normalizedUrl, "/");
+    log(httpMethod, normalizedUrl + query, headers, requestBody);
+    Client client = getClient();
+
+    WebResource webResource = client.resource(normalizedUrl + query);
+    WebResource.Builder builder = webResource.accept(MediaType.APPLICATION_JSON)
+        .type(MediaType.APPLICATION_JSON);
+    headers.forEach(builder::header);
+
+    if ("POST".equals(httpMethod) && StringUtils.isEmpty(requestBody)) {
+      requestBody = "{}"; //solves 411 error when sending empty-body POST request
+    }
+
+    return builder.method(httpMethod, ClientResponse.class, requestBody);
+  }
+
+  private static void log(String method, String url, Map<String, String> headers, String body) {
+    System.out.println(String.format("%s: %s", method, url));
+    System.out.println(body);
+  }
+
+  @SuppressWarnings("unchecked")
+  public static <T> T getResult(ClientResponse response, int exepectedStatus, Class<T> classOfT) {
+    assertEquals(exepectedStatus, response.getStatus());
+    if (exepectedStatus == 204) {
+      return null;
+    }
+
+    assertEquals("application/json; charset=UTF-8", response.getType().toString());
+    String json = response.getEntity(String.class);
+    if (classOfT == String.class) {
+      return (T) json;
+    }
+
+    Gson gson = new Gson();
+    return gson.fromJson(json, classOfT);
+  }
+
+  protected static Client getClient() {
+    TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
+      @Override
+      public X509Certificate[] getAcceptedIssuers() {
+        return null;
+      }
+
+      @Override
+      public void checkClientTrusted(X509Certificate[] certs, String authType) {
+      }
+
+      @Override
+      public void checkServerTrusted(X509Certificate[] certs, String authType) {
+      }
+    }};
+
+    try {
+      SSLContext sc = SSLContext.getInstance("TLS");
+      sc.init(null, trustAllCerts, new SecureRandom());
+      HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
+    } catch (Exception e) {
+    }
+    allowMethods("PATCH");
+    return Client.create();
+  }
+
+  private static void allowMethods(String... methods) {
+    try {
+      Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
+
+      Field modifiersField = Field.class.getDeclaredField("modifiers");
+      modifiersField.setAccessible(true);
+      modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);
+
+      methodsField.setAccessible(true);
+
+      String[] oldMethods = (String[]) methodsField.get(null);
+      Set<String> methodsSet = new LinkedHashSet<>(Arrays.asList(oldMethods));
+      methodsSet.addAll(Arrays.asList(methods));
+      String[] newMethods = methodsSet.toArray(new String[0]);
+
+      methodsField.set(null/*static field*/, newMethods);
+    } catch (NoSuchFieldException | IllegalAccessException e) {
+      throw new IllegalStateException(e);
+    }
+  }
+}
diff --git a/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/ServicesUtils.java b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/ServicesUtils.java
new file mode 100644
index 000000000..a9a892872
--- /dev/null
+++ b/testing/notification-test-gc/src/test/java/org/opengroup/osdu/notification/util/ServicesUtils.java
@@ -0,0 +1,94 @@
+/*
+ *  Copyright 2020-2023 Google LLC
+ *  Copyright 2020-2023 EPAM Systems, Inc
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.opengroup.osdu.notification.util;
+
+import com.sun.jersey.api.client.ClientResponse;
+import org.opengroup.osdu.core.common.model.http.DpsHeaders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ServicesUtils {
+  private String storageHost;
+  private String legalHost;
+  private TestUtils testUtils;
+  private String partitionId;
+  private FileUtils fileUtils;
+
+  public ServicesUtils(String storageHost, String legalHost, TestUtils testUtils, String partitionId) {
+    this.storageHost = storageHost;
+    this.legalHost = legalHost;
+    this.testUtils = testUtils;
+    this.partitionId = partitionId;
+    this.fileUtils = new FileUtils();
+  }
+
+  public ClientResponse createLegalTag(String tagName) throws Exception {
+    String legalBody = fileUtils.readFromLocalFilePath("/LegalTag.json");
+    legalBody = legalBody.replace("{{tagName}}", tagName);
+    Map<String, String> headers = new HashMap<>();
+    headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
+    headers.put(DpsHeaders.AUTHORIZATION, testUtils.getAdminToken());
+
+    ClientResponse legalResponse = HttpClient.send(legalHost, "legaltags", "POST", headers, legalBody, "");
+
+    boolean createdOrAlreadyExists = legalResponse.getStatus() == 201 || legalResponse.getStatus() == 409;
+    assertTrue(createdOrAlreadyExists);
+    return legalResponse;
+  }
+
+  public void deleteLegalTag(String tagName) throws Exception{
+    Map<String, String> headers = new HashMap<>();
+    headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
+    headers.put(DpsHeaders.AUTHORIZATION, testUtils.getAdminToken());
+    ClientResponse legalResponse = HttpClient.send(legalHost, String.format("legaltags/%s", tagName), "DELETE",
+        headers, "", "");
+    assertEquals(204, legalResponse.getStatus());
+  }
+
+  public void createStorageRecords(String suffix, int count, String legalTag) throws Exception{
+    String body = fileUtils.readFromLocalFilePath("/StorageRecord.json");
+    body = body.replace("{{data-partition-id}}", partitionId);
+    body = body.replace("{{legal-tag}}", partitionId + "-" + legalTag);
+    for (int i = 0; i < count; i++) {
+      String actualBody = body.replace("{{ids-suffix}}", suffix + String.valueOf(i));
+      Map<String, String> headers = new HashMap<>();
+      headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
+      headers.put(DpsHeaders.AUTHORIZATION, testUtils.getAdminToken());
+      ClientResponse storageResponse = HttpClient.send(storageHost, "records", "PUT",
+          headers, actualBody, "");
+      assertEquals(201, storageResponse.getStatus());
+    }
+  }
+
+  public void deleteStorageRecords(int count, String suffix) throws Exception{
+    for (int i = 0; i < count; i++) {
+      Map<String, String> headers = new HashMap<>();
+      headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
+      headers.put(DpsHeaders.AUTHORIZATION, testUtils.getAdminToken());
+      String recordId = partitionId + ":dataset--ConnectedSource.Generic:notification-test-" + suffix + i;
+      ClientResponse storageResponse = HttpClient.send(storageHost, "records/" + recordId, "DELETE",
+          headers, "", "");
+      assertEquals(204, storageResponse.getStatus());
+    }
+  }
+
+}
diff --git a/testing/notification-test-gc/src/test/resources/LegalTag.json b/testing/notification-test-gc/src/test/resources/LegalTag.json
new file mode 100644
index 000000000..e9629c72a
--- /dev/null
+++ b/testing/notification-test-gc/src/test/resources/LegalTag.json
@@ -0,0 +1,16 @@
+{
+  "name": "{{tagName}}",
+  "properties": {
+    "countryOfOrigin": [
+      "US"
+    ],
+    "contractId": "A1234",
+    "expirationDate": 2222222222222,
+    "originator": "Default",
+    "dataType": "Public Domain Data",
+    "securityClassification": "Public",
+    "personalData": "No Personal Data",
+    "exportClassification": "EAR99"
+  },
+  "description": "Test legal tag for notification"
+}
\ No newline at end of file
diff --git a/testing/notification-test-gc/src/test/resources/StorageRecord.json b/testing/notification-test-gc/src/test/resources/StorageRecord.json
new file mode 100644
index 000000000..724c4a75e
--- /dev/null
+++ b/testing/notification-test-gc/src/test/resources/StorageRecord.json
@@ -0,0 +1,33 @@
+[
+  {
+    "id": "{{data-partition-id}}:dataset--ConnectedSource.Generic:notification-test-{{ids-suffix}}",
+    "kind": "{{data-partition-id}}:wks:dataset--ConnectedSource.Generic:1.0.0",
+    "data": {
+      "Name": "name",
+      "DatasetProperties": {
+        "ConnectedSourceDataJobId": "no-data",
+        "ConnectedSourceRegistryEntryId": "no-data",
+        "SourceDataPartitionId": "no-data",
+        "SourceRecordId": "no-data"
+      }
+    },
+    "namespace": "{{data-partition-id}}:osdu",
+    "legal": {
+      "legaltags": [
+        "{{legal-tag}}"
+      ],
+      "otherRelevantDataCountries": [
+        "US"
+      ],
+      "status": "compliant"
+    },
+    "acl": {
+      "viewers": [
+        "data.default.viewers@{{data-partition-id}}.osdu-gcp.go3-nrg.projects.epam.com"
+      ],
+      "owners": [
+        "data.default.owners@{{data-partition-id}}.osdu-gcp.go3-nrg.projects.epam.com"
+      ]
+    }
+  }
+]
\ No newline at end of file
-- 
GitLab