diff --git a/NOTICE b/NOTICE index 1598403a196b4a89902a440825c7af0864828f3e..9c310a82e2f40be802d33c0e4176cc8a0f7e0741 100644 --- a/NOTICE +++ b/NOTICE @@ -83,7 +83,7 @@ The following software have components provided under the terms of this license: - Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent) - ClassMate (from http://github.com/cowtowncoder/java-classmate) - Cloud Key Management Service (KMS) API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) -- Cloud Storage JSON API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) +- Cloud Storage JSON API v1-rev20230301-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) - Collections (from https://repo1.maven.org/maven2/commons-collections/commons-collections) - Commons Digester (from http://commons.apache.org/digester/) - Converter: Jackson (from https://github.com/square/retrofit, https://repo1.maven.org/maven2/com/squareup/retrofit2/converter-jackson) diff --git a/notification-core/pom.xml b/notification-core/pom.xml index 5feaa36ef1aa534759209946f7046468cbaa2d38..4ef452231e2b23784832dd13de43ff0f81bf9d2f 100644 --- a/notification-core/pom.xml +++ b/notification-core/pom.xml @@ -19,7 +19,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-core</name> <description>Core module for the notification service</description> <packaging>jar</packaging> @@ -27,7 +27,7 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> diff --git a/pom.xml b/pom.xml index 8b52ab8aba896c3a53ba73645832b76dc23b6ad3..1730558d17fc300817a1b26298c073521c4256d3 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <description>Root Notification Service project</description> <properties> diff --git a/provider/notification-aws/pom.xml b/provider/notification-aws/pom.xml index c13dcfbb2bf33f9aabda5c1c6e0f62cb93ae4106..69b74492038afd55c6c03bcba4e417e6c4b402f0 100644 --- a/provider/notification-aws/pom.xml +++ b/provider/notification-aws/pom.xml @@ -19,7 +19,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-aws</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-aws</name> <description>AWS implementation for Notification service</description> <packaging>jar</packaging> @@ -27,7 +27,7 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> @@ -89,7 +89,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> </dependency> <dependency> diff --git a/provider/notification-azure/pom.xml b/provider/notification-azure/pom.xml index 7d9130742c40c387d519669e09aaaf60d476511d..fbfdc6cd1b5ed2d40ee04d74b0744715b863cd27 100644 --- a/provider/notification-azure/pom.xml +++ b/provider/notification-azure/pom.xml @@ -18,7 +18,7 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>notification-azure</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-azure</name> <description>Azure implementation for Notification service</description> <packaging>jar</packaging> @@ -26,7 +26,7 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> @@ -35,7 +35,7 @@ <maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.source>${java.version}</maven.compiler.source> <jacoco-maven-plugin.version>0.8.2</jacoco-maven-plugin.version> - <osdu.notification-core.version>0.20.0-SNAPSHOT</osdu.notification-core.version> + <osdu.notification-core.version>0.21.0-SNAPSHOT</osdu.notification-core.version> <springframework.version>4.3.0.RELEASE</springframework.version> <reactor.netty.version>0.11.0.RELEASE</reactor.netty.version> <reactor.core.version>3.3.0.RELEASE</reactor.core.version> diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/SubscriptionManagerImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/SubscriptionManagerImpl.java index f97cc59d42f64840723c1a1a287b173ae02e7e99..343c31939c65575c5b0b224a42f79470cc59ef60 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/SubscriptionManagerImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/SubscriptionManagerImpl.java @@ -39,7 +39,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; import java.time.Duration; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; @@ -82,7 +85,11 @@ public class SubscriptionManagerImpl implements ISubscriptionManager { azureCosmosProperties.registerSubscriptionContainerName(), Subscription.class); ManagementClient managementClient = factory.getManager(partition); + Map<String, List<String>> topicSubscriptions = new HashMap<>(); for (Subscription subscription : subscriptionsList) { + topicSubscriptions.putIfAbsent(subscription.getTopic(), new ArrayList<>()); + topicSubscriptions.get(subscription.getTopic()).add(subscription.getNotificationId()); + // To check if its a not new subscription. if (!this.topicSubscriptions.checkIfNewTopicSubscription(partition, subscription.getTopic(), subscription.getNotificationId())) { // Update existing subscriptions and skip registration @@ -109,6 +116,26 @@ public class SubscriptionManagerImpl implements ISubscriptionManager { } } + for (Map.Entry<String, List<String>> entry : topicSubscriptions.entrySet()) { + List<String> deletedTopicSubscriptions = this.topicSubscriptions.getDeletedTopicSubscriptions(partition, entry.getKey(), entry.getValue()); + if (deletedTopicSubscriptions.isEmpty()) { + continue; + } + for (String deletedSubscription : deletedTopicSubscriptions) { + try { + LOGGER.info("Found deleted subscription " + deletedSubscription + " for topic " + entry.getKey()); + SubscriptionClient subscriptionClient = this.subscriptionClientFactory + .getSubscriptionClient(partition, entry.getKey(), deletedSubscription); + subscriptionClient.close(); + LOGGER.info("Closed deleted subscription " + deletedSubscription + " for topic " + entry.getKey()); + } catch (InterruptedException | ServiceBusException e) { + LOGGER.error("Error while closing subscription client {}", e.getMessage(), e); + } catch (Exception e) { + LOGGER.error("Unknown exception occurred while closing subscription client: ", e); + } + } + } + } catch (AppException e) { LOGGER.error("Error creating Cosmos Client {}", e.getMessage(), e); } catch (Exception e) { diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptions.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptions.java index 92eb9abbaf015c5605d4990eece4ab00b13070f7..3e3cabea7bedcb96eccdeefe3abf89be3a4de02f 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptions.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptions.java @@ -49,4 +49,17 @@ public class TopicSubscriptions { this.existingTopicSubscriptions.putAll(this.currentTopicSubscriptions); this.currentTopicSubscriptions.clear(); } + + public List<String> getDeletedTopicSubscriptions(String partition, String sbTopicName, List<String> subscriptions) { + if (existingTopicSubscriptions.get(partition) == null) { + return new ArrayList<>(); + } + Map<String, List<String>> existingTopics = existingTopicSubscriptions.get(partition); + if (existingTopics.get(sbTopicName) == null || existingTopics.get(sbTopicName).isEmpty()) { + return new ArrayList<>(); + } + List<String> existingSubscriptions = existingTopics.get(sbTopicName); + existingSubscriptions.removeAll(subscriptions); + return existingSubscriptions; + } } diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java index 86296de13d6710f56a214396292d64a87a9fef52..efa74f5234671095982b708ea011d2c441c02877 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java @@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit; import static java.lang.Thread.sleep; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doNothing; @@ -182,6 +183,16 @@ public class SubscriptionManagerImplTest { verify(subscriptionClient, times(1)).registerMessageHandler(any(), any(), any()); } + @Test + public void shouldCloseSubscriptionClientWhenSubscriptionIsDeleted() throws ServiceBusException, InterruptedException { + when(topicSubscriptions.checkIfNewTopicSubscription(anyString(), anyString(), anyString())).thenReturn(false); + when(subscriptionClientFactory.getSubscriptionClient(dataPartition, sbTopic, sbSubscription)).thenReturn(subscriptionClient); + doNothing().when(topicSubscriptions).updateCurrentTopicSubscriptions(anyString(), anyString(), anyString()); + when(topicSubscriptions.getDeletedTopicSubscriptions(anyString(), anyString(), anyList())).thenReturn(Collections.singletonList(getHmac_subscription().getNotificationId())); + subscriptionManager.subscribeNotificationsEvent(); + verify(subscriptionClient, times(1)).close(); + } + private static Subscription getHmac_subscription() { Subscription hmac_subscription = new Subscription(); hmac_subscription.setName("hamc_test_subscription"); diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java index 3f657ed0bda9be6028838fc8decd97ea984707f2..d80372c78bf91b3911c673575531bcf6b52406f5 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java @@ -9,6 +9,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -76,4 +77,14 @@ public class TopicSubscriptionsTest { assertEquals(existingTopicSubscriptions.size(), 1); assertEquals(currentTopicSubscriptions.size(), 0); } + + @Test + public void deletedSubscriptionFoundTest() { + final String DELETED_SUBSCRIPTION = "test678asdeleted"; + existingTopicSubscriptions.get(PARTITION).get(SBTOPICNAME).add(DELETED_SUBSCRIPTION); + + List<String> deletedSubscriptions = topicSubscriptions.getDeletedTopicSubscriptions(PARTITION, SBTOPICNAME, Arrays.asList(EXISTINGSUBSCRIPTION)); + assertEquals(1, deletedSubscriptions.size()); + assertEquals(DELETED_SUBSCRIPTION, deletedSubscriptions.get(0)); + } } diff --git a/provider/notification-gc/docs/gc/README.md b/provider/notification-gc/docs/gc/README.md index 3be94ca7f27a767c4d509114f39d599e71793531..7802e9ce9e6b64d0c956f1cc37db8d956364508f 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/provider/notification-gc/pom.xml b/provider/notification-gc/pom.xml index 803e1fe68418bdb1742508bb52f2190e29c05396..a81b7af3b7d6afedd5f3f5eeee502a3d2fb8dc8d 100644 --- a/provider/notification-gc/pom.xml +++ b/provider/notification-gc/pom.xml @@ -18,7 +18,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-gc</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-gc</name> <description>Google Cloud implementation for Notification service</description> <packaging>jar</packaging> @@ -26,7 +26,7 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> @@ -53,7 +53,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <exclusions> <exclusion> <groupId>com.google.apis</groupId> diff --git a/provider/notification-ibm/pom.xml b/provider/notification-ibm/pom.xml index 07d88887a3ef8b83a92073675d88dc3b445bcca9..8209f41d6a64d57c69f9fe407018a5527392bf9b 100644 --- a/provider/notification-ibm/pom.xml +++ b/provider/notification-ibm/pom.xml @@ -16,7 +16,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-ibm</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-ibm</name> <description>IBM implementation for Notification service</description> <packaging>jar</packaging> @@ -24,7 +24,7 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> @@ -34,7 +34,7 @@ <maven.compiler.source>${java.version}</maven.compiler.source> <undertow-websockets-jsr.version>2.2.11.Final</undertow-websockets-jsr.version> <jackson-dataformat-cbor.version>2.13.0</jackson-dataformat-cbor.version> - <jackson-databind.version>2.13.2.2</jackson-databind.version> + <jackson-databind.version>2.13.4.2</jackson-databind.version> <jackson.version>2.13.2</jackson.version> <spring-boot-maven-plugin.version>2.7.6</spring-boot-maven-plugin.version> </properties> @@ -114,7 +114,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <exclusions> <exclusion> <groupId>io.netty</groupId> diff --git a/testing/notification-test-anthos/pom.xml b/testing/notification-test-anthos/pom.xml index f3d335dbffbbe62fee7cd31c891159aef266a6ed..60be9c1649c4c2f760978b2be54a23659afff2be 100644 --- a/testing/notification-test-anthos/pom.xml +++ b/testing/notification-test-anthos/pom.xml @@ -21,12 +21,12 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification-testing</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <artifactId>notification-test-anthos</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-test-anthos</name> <description>Integration tests Anthos for notification</description> <packaging>jar</packaging> @@ -41,7 +41,7 @@ <dependency> <groupId>org.opengroup.osdu.notification</groupId> <artifactId>notification-test-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.opengroup.osdu</groupId> diff --git a/testing/notification-test-aws/pom.xml b/testing/notification-test-aws/pom.xml index 3fd61dd23245c99ec7e6f40f88517ceeb5a66590..a4fe32f8e980af2def669bcbcaba171139db437a 100644 --- a/testing/notification-test-aws/pom.xml +++ b/testing/notification-test-aws/pom.xml @@ -21,13 +21,13 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification-testing</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-test-aws</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-test-aws</name> <description>AWS Integration tests for Notification Service</description> <packaging>jar</packaging> @@ -54,7 +54,7 @@ <dependency> <groupId>org.opengroup.osdu.notification</groupId> <artifactId>notification-test-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.opengroup.osdu</groupId> diff --git a/testing/notification-test-azure/pom.xml b/testing/notification-test-azure/pom.xml index 185f8e8d9fdc205d911e748fa032b07f2634d012..48ef23cf10d2e353f1069bfda94b5972cd5317a5 100644 --- a/testing/notification-test-azure/pom.xml +++ b/testing/notification-test-azure/pom.xml @@ -21,13 +21,13 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification-testing</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-test-azure</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-test-azure</name> <description>Integration tests Azure for notification</description> <packaging>jar</packaging> @@ -42,7 +42,7 @@ <dependency> <groupId>org.opengroup.osdu.notification</groupId> <artifactId>notification-test-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> </dependency> <dependency> diff --git a/testing/notification-test-core/pom.xml b/testing/notification-test-core/pom.xml index 7c182b0f60373ef8f59d01aaefeb73c81660876b..b9cff2209c1b84c439a02d5c345e48a6fc726f44 100644 --- a/testing/notification-test-core/pom.xml +++ b/testing/notification-test-core/pom.xml @@ -21,13 +21,13 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification-testing</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.opengroup.osdu.notification</groupId> <artifactId>notification-test-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-test-core</name> <description>Integration tests core for notification</description> <packaging>jar</packaging> diff --git a/testing/notification-test-gc/pom.xml b/testing/notification-test-gc/pom.xml index 4f3d69dd94e8609aed3b45a5165f985a7fc83794..ce832bf463cb8204965278737ed3126b04a9d9f3 100644 --- a/testing/notification-test-gc/pom.xml +++ b/testing/notification-test-gc/pom.xml @@ -21,12 +21,12 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification-testing</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <artifactId>notification-test-gc</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-test-gc</name> <description>Integration tests Google Cloud for notification</description> <packaging>jar</packaging> @@ -41,7 +41,7 @@ <dependency> <groupId>org.opengroup.osdu.notification</groupId> <artifactId>notification-test-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.opengroup.osdu</groupId> 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 0000000000000000000000000000000000000000..a03e0303451b55effedd1923ee035472314a0ea8 --- /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 0000000000000000000000000000000000000000..d759d196634fd7e1d59bc1b4865c50c36c639ac6 --- /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 0000000000000000000000000000000000000000..fc0713c1665b4db5276e88a9b6c8b1c64085fa4d --- /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 dc7766bedd9bc24e24cbb1b956bbc7ec3e8ed5f9..7d569a091be07fa882a2966d96515fb634f0d898 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 0000000000000000000000000000000000000000..d32424a1eafbc604902a0b2f5cb30bc38809c776 --- /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 0000000000000000000000000000000000000000..a9a892872315c30bc247e5cec2f436c44bd267c0 --- /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 0000000000000000000000000000000000000000..e9629c72a833ef80a685f15d028679e75ac6edb6 --- /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 0000000000000000000000000000000000000000..724c4a75ef2dfb7a4124f04d2e1bc42cdc860f2e --- /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 diff --git a/testing/notification-test-ibm/pom.xml b/testing/notification-test-ibm/pom.xml index 12bf944e444e27f9fc2c8cad47dae77a1e005b6b..bae3a57c4aca21c08a184916031f2854696fdf5c 100644 --- a/testing/notification-test-ibm/pom.xml +++ b/testing/notification-test-ibm/pom.xml @@ -18,13 +18,13 @@ <parent> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification-testing</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.opengroup.osdu</groupId> <artifactId>notification-test-ibm</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <name>notification-test-ibm</name> <description>Integration tests IBM for notification</description> <packaging>jar</packaging> @@ -45,7 +45,7 @@ <dependency> <groupId>org.opengroup.osdu.notification</groupId> <artifactId>notification-test-core</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.opengroup.osdu</groupId> diff --git a/testing/pom.xml b/testing/pom.xml index 0238b45196f83d85bb5340b04f62a1acc77dc605..766204d30ae9d520b384985c86f595c29fb21629 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -18,7 +18,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.opengroup.osdu</groupId> <artifactId>os-notification-testing</artifactId> - <version>0.20.0-SNAPSHOT</version> + <version>0.21.0-SNAPSHOT</version> <description>Root Notification Service project</description> <packaging>pom</packaging>