diff --git a/NOTICE b/NOTICE index c9614b38e0275afec22cd281145553c48fc33229..9abc551c8ba291682535717edc47756f169298be 100644 --- a/NOTICE +++ b/NOTICE @@ -462,7 +462,6 @@ EPL-1.0 ======================================================================== The following software have components provided under the terms of this license: -- Angus Activation Registries (from https://repo1.maven.org/maven2/org/eclipse/angus/angus-activation) - AspectJ Weaver (from http://www.aspectj.org, https://www.eclipse.org/aspectj/) - JUnit Jupiter (Aggregator) (from https://junit.org/junit5/) - JUnit Jupiter API (from http://junit.org/junit5/, https://junit.org/junit5/) @@ -548,6 +547,7 @@ GPL-3.0-only ======================================================================== The following software have components provided under the terms of this license: +- Angus Activation Registries (from https://repo1.maven.org/maven2/org/eclipse/angus/angus-activation) - Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca) - Java Servlet 4.0 API @@ -732,5 +732,4 @@ unknown ======================================================================== The following software have components provided under the terms of this license: -- Angus Activation Registries (from https://repo1.maven.org/maven2/org/eclipse/angus/angus-activation) - JUnit Jupiter (Aggregator) (from https://junit.org/junit5/) diff --git a/provider/notification-azure/pom.xml b/provider/notification-azure/pom.xml index f6dbcdfd2f07ccbdc3b283a7edc5bd7dbbd70f0e..d79335b9792576b58b4764da4f2587fba35456d0 100644 --- a/provider/notification-azure/pom.xml +++ b/provider/notification-azure/pom.xml @@ -39,7 +39,7 @@ <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> - <osdu.corelibazure.version>0.24.0</osdu.corelibazure.version> + <osdu.corelibazure.version>0.25.0-rc1</osdu.corelibazure.version> <osdu.oscorecommon.version>0.24.0</osdu.oscorecommon.version> <junit.version>5.6.0</junit.version> <jjwt.version>3.8.1</jjwt.version> diff --git a/testing/notification-test-azure/pom.xml b/testing/notification-test-azure/pom.xml index b11cbc755fcafb3a6520b91a263c16e4211fc894..fa615a7ffe91d2ee23592af10d62f8a4d1c2fc91 100644 --- a/testing/notification-test-azure/pom.xml +++ b/testing/notification-test-azure/pom.xml @@ -48,7 +48,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>core-lib-azure</artifactId> - <version>0.24.0</version> + <version>0.25.0-rc1</version> <exclusions> <exclusion> diff --git a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java index 16fcf01733e85b8cf39b61d88f52376d5175b144..d5e43585a3945f58f033262b3ca569b4d2d80264 100644 --- a/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java +++ b/testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestStorageIntegration.java @@ -14,7 +14,11 @@ package org.opengroup.osdu.notification.api; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.sun.jersey.api.client.ClientResponse; +import lombok.extern.slf4j.Slf4j; import org.apache.catalina.connector.Response; import org.apache.commons.lang3.time.StopWatch; import org.asynchttpclient.util.Assertions; @@ -32,14 +36,13 @@ import org.opengroup.osdu.notification.util.*; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import static org.opengroup.osdu.notification.util.TestUtils.indentatedBody; +@Slf4j public class TestStorageIntegration extends BaseTestTemplate { - - Logger logger= Logger.getLogger(""); private String subscriptionId = null; private String notificationId = null; private final String ackSubscriptionId = "AckSubscription"; @@ -88,7 +91,7 @@ public class TestStorageIntegration extends BaseTestTemplate { headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken()); DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers); subscriptionService = factory.create(dpsHeaders); - logger.info("dps headers created."); + log.info("dps headers created."); // Create a new subscription Subscription subscription = new Subscription(); @@ -105,10 +108,10 @@ public class TestStorageIntegration extends BaseTestTemplate { subscriptionId = subscriptionCreated.getId(); Config.Instance().NotificationId = notificationId; } catch (SubscriptionException e) { - System.out.println("Subscription exception inner response : " + e.getHttpResponse()); + log.error("Subscription exception inner response : ", e.getHttpResponse()); throw e; } - logger.info("New subscription created"); + log.info("New subscription created"); } private void deleteAckSubscription() throws SubscriptionException { @@ -116,9 +119,10 @@ public class TestStorageIntegration extends BaseTestTemplate { subscriptionService.delete(ackSubscriptionId); } catch (SubscriptionException e) { if (e.getHttpResponse().getResponseCode() == Response.SC_NOT_FOUND) { - System.out.println("Test Ack Subscription Not Found for deletion."); + log.info("Test Ack Subscription Not Found for deletion."); return; } + log.error("Unable to delete Test Ack Subscription. Deletion Failed.", e); Assert.fail("Unable to delete Test Ack Subscription. Deletion Failed." + e); throw e; } @@ -145,23 +149,23 @@ public class TestStorageIntegration extends BaseTestTemplate { try { // Creates an actual subscription with a test endpoint i.e REGISTER_CUSTOM_PUSH_URL_HMAC this.createResource(); - logger.info("Actual subscription with a test endpoint created successfully"); + log.info("Actual subscription with a test endpoint created successfully"); // Delay to get the above subscription registered by Notification Service TimeUnit.SECONDS.sleep(600); - logger.info("Subscription registered by Notification service successfully"); + log.info("Subscription registered by Notification service successfully"); // Delete the Test Ack subscription if there exists any as a part of cleanup. // The Test Ack Subscription gets created if the the test endpoint of actual subscription // created above receives notification from Notification Service. this.deleteAckSubscription(); // Delete legal tag - logger.info("Cleaning up previous Legal Tag if any. "); + log.info("Cleaning up previous Legal Tag if any. "); LegalTagUtils.delete(LEGAL_TAG, this.testUtils.getAdminToken()); // Create legal tag used in storage record - logger.info("Creating New legal tag"); + log.info("Creating New legal tag"); LegalTagUtils.create(LEGAL_TAG, this.testUtils.getAdminToken()); @@ -170,7 +174,21 @@ public class TestStorageIntegration extends BaseTestTemplate { // test endpoint i.e REGISTER_CUSTOM_PUSH_URL_HMAC which creates the Test ack Subscription. String URL = Config.Instance().StorageServicePath; ClientResponse response = descriptor.run(URL, "", this.testUtils.getAdminToken()); - assertEquals(error(response.getEntity(String.class)), 201, response.getStatus()); + if (response != null) { + JsonNode rootNode = null; + ObjectMapper objectMapper = new ObjectMapper(); + try { + String responseBody = response.getEntity(String.class); + rootNode = objectMapper.readTree(responseBody); + // Remove the "secret" field + if (((ObjectNode) rootNode).has("secret")) + ((ObjectNode) rootNode).remove("secret"); + log.info(String.format("\nThis is the response received : %s\nResponse Body:%s\nResponse Headers: %s\nResponse Status code: %s", response, indentatedBody(objectMapper.writeValueAsString(rootNode)), response.getHeaders(), response.getStatus())); + } catch (Exception ex) { + log.error("Exception in response in test case: ", ex); + } + } + assertEquals(error("error while adding storage record"), 201, response.getStatus()); TimeUnit.SECONDS.sleep(120); // Verification of Test Ack Subscription creation from the above process. @@ -183,25 +201,25 @@ public class TestStorageIntegration extends BaseTestTemplate { while (ackSubscription == null && retryCount > 0) { TimeUnit.SECONDS.sleep(timeOut); ackSubscription = subscriptionService.get(ackSubscriptionId); - logger.info("Retry time: "+retryCount+" to get Test Ack subscription."); + log.info(String.format("Retry time: %s to get Test Ack subscription.", retryCount)); retryCount--; } Assertions.assertNotNull(ackSubscription, "Unable to retrieve test ack subscription. Elapsed time in minutes : " + (stopWatch.getTime(TimeUnit.MINUTES))); if (ackSubscription != null) { assertEquals("Unexpected Test Ack Subscription.", ackNotificationId, ackSubscription.getNotificationId()); } - logger.info("IT run successful"); + log.info("IT run successful"); stopWatch.stop(); } catch (Exception e) { fail("An exception occurred :" + e); } finally { - logger.info("Executing finally block"); + log.info("Executing finally block"); // Delete Actual Subscription - this.deleteResource(); + this.deleteResource(); // Deletion of Test Ack Subscription this.deleteAckSubscription(); // Delete legal tag - logger.info("Deleting legal tag"); + log.info("Deleting legal tag"); LegalTagUtils.delete(LEGAL_TAG, this.testUtils.getAdminToken()); } diff --git a/testing/notification-test-core/pom.xml b/testing/notification-test-core/pom.xml index 33cac08f225e2b127cd6b8cff98fc986707bfb9d..f25c1f9d9bc4b2275041b4d09b4c63c7cc30e2da 100644 --- a/testing/notification-test-core/pom.xml +++ b/testing/notification-test-core/pom.xml @@ -144,6 +144,12 @@ <artifactId>commons-lang3</artifactId> <version>3.13.0</version> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.22</version> + <scope>compile</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java b/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java index ac3e3f8a705b4bc2687926f718ab567fcf31edcb..0e8ae7f04ad3a300b6baa23f0642969a3e51a263 100644 --- a/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java +++ b/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java @@ -23,7 +23,6 @@ import java.net.URL; import java.security.SecureRandom; import java.security.cert.X509Certificate; import java.util.*; -import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; @@ -32,13 +31,21 @@ import javax.net.ssl.X509TrustManager; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; +import lombok.extern.slf4j.Slf4j; +@Slf4j public abstract class TestUtils { - static Logger logger = Logger.getLogger(""); + protected String serviceAccountFile; protected static String opsToken = null; protected static String adminToken = null; @@ -79,90 +86,105 @@ public abstract class TestUtils { public static ClientResponse send(String path, String httpMethod, String token, String requestBody, String query, Map<String, String> headers, boolean enforceHttp) throws Exception { - ClientResponse response; + ClientResponse response = null; Client client = getClient(); client.setConnectTimeout(300000); client.setReadTimeout(300000); client.setFollowRedirects(false); String url = getApiPath(path + query, enforceHttp); - System.out.println(url); - System.out.println(httpMethod); - System.out.println(requestBody); - System.out.println(headers); - WebResource webResource = client.resource(url); - final WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON) - .header("Authorization", token); - int retryCount = 2; - headers.forEach((k, v) -> builder.header(k, v)); - try{ - response = builder.method(httpMethod, ClientResponse.class, requestBody); - while (retryCount > 0) { + int count = 1; + int MaxRetry = 3; + while (count < MaxRetry) { + try { + headers.put("correlation-id", headers.getOrDefault("correlation-id", UUID.randomUUID().toString())); + WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON) + .header("Authorization", token); + headers.forEach((k, v) -> builder.header(k, v)); + //removing Auth header before logging + headers.remove("Authorization"); + log.info(String.format("\nRequest URL: %s %s\nRequest Headers: %s\nRequest Body: %s", httpMethod, url, headers, requestBody)); + log.info(String.format("Attempt: #%s/%s, CorrelationId: %s", count, MaxRetry, headers.get("correlation-id"))); + response = builder.method(httpMethod, ClientResponse.class, requestBody); if (response.getStatusInfo().getFamily().equals(Response.Status.Family.valueOf("SERVER_ERROR"))) { - System.out.println("got resoponse : " + response.getStatusInfo()); + count++; Thread.sleep(5000); - System.out.println("Retrying.. "); - response = builder.method(httpMethod, ClientResponse.class, requestBody); - } else + continue; + } else { break; - retryCount--; - } - System.out.println("sending response from TestUtils send method"); - return response; - } catch (Exception e) { - if (e.getCause() instanceof SocketTimeoutException) { - System.out.println("Retrying in case of socket timeout exception"); - return builder.method(httpMethod, ClientResponse.class, requestBody); + } + } catch (Exception ex) { + log.error("Exception While Making Request: ", ex); + count++; + if (count == MaxRetry) { + throw new AssertionError("Error: Send request error", ex); + } + } finally { + //log response body + log.info("sending response from TestUtils send method"); + if(response!=null) + log.info(String.format("\nThis is the response received : %s\nResponse Headers: %s\nResponse Status code: %s", response, response.getHeaders(), response.getStatus())); } - e.printStackTrace(); - throw new AssertionError("Error: Send request error", e); } + return response; } public static ClientResponse send(String url, String path, String httpMethod, String token, String requestBody, String query, Map<String, String> headers, boolean enforceHttp) throws Exception { - ClientResponse response; + ClientResponse response = null; Client client = getClient(); client.setConnectTimeout(300000); client.setReadTimeout(300000); client.setFollowRedirects(false); String URL = getApiPath(url, path + query, enforceHttp); - System.out.println(url + path); - System.out.println(httpMethod); - System.out.println(requestBody); - System.out.println(headers); WebResource webResource = client.resource(URL); - final WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON); - if (!token.isEmpty()) { - logger.info("Token is not empty so adding to request header"); - builder.header("Authorization", token); - } - int retryCount = 2; - headers.forEach((k, v) -> builder.header(k, v)); - try{ - response = builder.method(httpMethod, ClientResponse.class, requestBody); - while (retryCount > 0) { + int count = 1; + int MaxRetry = 3; + while (count < MaxRetry) { + try { + headers.put("correlation-id", headers.getOrDefault("correlation-id", UUID.randomUUID().toString())); + WebResource.Builder builder = webResource.type(MediaType.APPLICATION_JSON); + if (!token.isEmpty()) { + log.info("Token is not empty so adding to request header"); + builder.header("Authorization", token); + } + headers.forEach((k, v) -> builder.header(k, v)); + //removing Auth header before logging + headers.remove("Authorization"); + log.info(String.format("\nRequest URL: %s %s\nRequest Headers: %s\nRequest Body: %s", httpMethod, URL, headers, indentatedBody(requestBody))); + log.info(String.format("Attempt: #%s/%s, CorrelationId: %s", count, MaxRetry, headers.get("correlation-id"))); + response = builder.method(httpMethod, ClientResponse.class, requestBody); if (response.getStatusInfo().getFamily().equals(Response.Status.Family.valueOf("SERVER_ERROR"))) { - System.out.println("got resoponse : " + response.getStatusInfo()); + count++; Thread.sleep(5000); - System.out.println("Retrying.. "); - response = builder.method(httpMethod, ClientResponse.class, requestBody); - } else + continue; + } else { break; - retryCount--; - } - System.out.println("sending response from TestUtils send method"); - return response; - } catch (Exception e) { - if (e.getCause() instanceof SocketTimeoutException) { - System.out.println("Retrying in case of socket timeout exception"); - return builder.method(httpMethod, ClientResponse.class, requestBody); + } + } catch (Exception ex) { + log.error("Exception While Making Request: ", ex); + count++; + if (count == MaxRetry) { + throw new AssertionError("Error: Send request error", ex); + } + } finally { + //log response body + log.info("sending response from TestUtils send method"); + if(response!=null) + log.info(String.format("\nThis is the response received : %s\nResponse Headers: %s\nResponse Status code: %s", response, response.getHeaders(), response.getStatus())); } - e.printStackTrace(); - throw new AssertionError("Error: Send request error", e); } + return response; + } + public static String indentatedBody(String responseBody) { + JsonParser jsonParser = new JsonParser(); + if( responseBody== null) + return responseBody; + JsonElement jsonElement = jsonParser.parse(responseBody); + String indentedResponseEntity =new GsonBuilder().setPrettyPrinting().create().toJson(jsonElement); + return indentedResponseEntity; } @SuppressWarnings("unchecked") @@ -204,9 +226,9 @@ public abstract class TestUtils { sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { - logger.info("Exception occurred"); + log.info("Exception occurred"); } - logger.info("Creating client"); + log.info("Creating client"); return Client.create(); } } \ No newline at end of file