diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee2aee09d7d5e2094a8981724cdced105a177640..d899fa0f76f65338e2be5afa02795ca48f0189cd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -80,3 +80,124 @@ include: eslint-sast: rules: - when: never + +.maven: + image: maven:3.9.3-eclipse-temurin-17 + tags: ['osdu-medium'] + variables: + MAVEN_REPO_PATH: "$CI_PROJECT_DIR/.m2/repository" + MAVEN_CLI_OPTS: "--batch-mode --settings=$CI_PROJECT_DIR/.mvn/community-maven.settings.xml" + + cache: + paths: + - $MAVEN_REPO_PATH + + artifacts: + paths: + - ./**/target/*.jar + - ./**/maven-*-output.txt + when: always + expire_in: 2 days + + before_script: + - | # Check for the presence of a maven wrapper script + apt-get update && apt-get install -y python3 + if [ -e "$CI_PROJECT_DIR/mvnw" ]; then + export MAVEN_BINARY="$CI_PROJECT_DIR/mvnw" + unset MAVEN_CONFIG + mkdir -pv .mvn/wrapper + else + export MAVEN_BINARY="mvn" + fi + - export MAVEN="$MAVEN_BINARY $MAVEN_CLI_OPTS -Dmaven.repo.local=$MAVEN_REPO_PATH" + - echo $MAVEN_BINARY + - echo $MAVEN_CLI_OPTS + - echo $MAVEN_REPO_PATH + - echo $MAVEN + - mkdir -pv $MAVEN_REPO_PATH + - export ALL_MAVEN_BUILD_DIRS_Z=$(mktemp) + - python3 --version + + # This scans for all pom.xml files that aren't listed as a child pom (as + # determine by the presence of a <parent> tag). + - | + (python3 | sort -z > $ALL_MAVEN_BUILD_DIRS_Z) <<EOF + from xml.dom.minidom import parse + import os + import sys + + allPomFiles = set() + submoduleFiles = set() + + for root, dirnames, filenames in os.walk(os.environ['CI_PROJECT_DIR']): + if 'pom.xml' in filenames: + pomFile = os.path.join(root, 'pom.xml') + allPomFiles.add(pomFile) + + dom = parse(pomFile) + for modules in dom.getElementsByTagName('modules'): + for module in modules.getElementsByTagName('module'): + submoduleFiles.add(os.path.join(root, module.firstChild.nodeValue, "pom.xml")) + + for pomFile in allPomFiles: + if pomFile not in submoduleFiles: + dir = os.path.dirname(pomFile) + sys.stdout.write(dir + '\0') + EOF + - xargs -0rn 1 echo < $ALL_MAVEN_BUILD_DIRS_Z + + # This creates a script for running maven, capturing output to a file. + # - First argument is the directory to build from + # - Second argument is the name to use for the logfile + # - The remaining arguments are the maven command to run + - export MAVEN_BUILD=$(tempfile -m 755 -p build -s .sh) + - echo "#!/bin/bash" > $MAVEN_BUILD + - | + cat >> $MAVEN_BUILD <<EOF + id=maven_build_\$(echo "\$@" | sha1sum | head -c 7) + cd "\$1"; shift + outputFile="\$1"; shift + + echo "********************************************************************************" + echo -e "\e[0Ksection_start:\$(date +%s):\${id}\r\e[0K\e[1m\$(pwd)\e[0m" + echo -e "\e[32;1m\$MAVEN" "\$@" "\e[0m" + + if \$MAVEN "\$@" > "\$outputFile" 2>&1; then + tail -n 25 "\$outputFile"; + echo -e "\e[36m**** Showing the last 25 lines of the passed build (above). See Job artifacts for full log details *****\e[0m"; + echo -e "\e[0Ksection_end:\$(date +%s):\${id}\r\e[0K" + else + tail -n 200 "\$outputFile"; + echo -e "\e[31m**** Showing the last 200 lines of the failed build (above). See Job artifacts for full log details *****\e[0m"; + echo -e "\e[0Ksection_end:\$(date +%s):\${id}\r\e[0K" + exit 255; + fi + EOF + + # This creates a script for applying the $MAVEN_BUILD script to all build directories + - export MAVEN_FOREACH=$(tempfile -m 755 -p fr-ec -s .sh) + - echo "#!/bin/sh" > $MAVEN_FOREACH + - echo 'xargs -0rI {} $MAVEN_BUILD {} "$@" < $ALL_MAVEN_BUILD_DIRS_Z' >> $MAVEN_FOREACH + +gemnasium-maven-dependency_scanning: + variables: + DS_JAVA_VERSION: 17 + +azure_containerize: + variables: + AZURE_CONTAINERIZE_REPOSITORY: "-b jdk-17 https://gitlab-ci-token:${CI_JOB_TOKEN}@community.opengroup.org/osdu/platform/deployment-and-operations/base-containers-azure/service-base-image" + +azure_test: + image: community.opengroup.org:5555/osdu/platform/deployment-and-operations/base-containers-azure/azure-maven17:v0.0.1 + +aws-test-java: + image: $CI_REGISTRY/osdu/platform/deployment-and-operations/base-containers-aws/aws-maven/aws-maven:v2.0 + +aws-mongodb-test-java: + image: $CI_REGISTRY/osdu/platform/deployment-and-operations/base-containers-aws/aws-maven/aws-maven:v2.0 + +fossa-analyze: + image: $CI_REGISTRY/divido/fossa-with-cache:v0.9-jdk17 +fossa-check-notice: + image: $CI_REGISTRY/divido/fossa-with-cache:v0.9-jdk17 + diff --git a/NOTICE b/NOTICE index 76698d733a74168a0d2a66a1d4ceb85b1df1a4f1..bce291a089946832c028cb272fbde56e1ad4c4a8 100644 --- a/NOTICE +++ b/NOTICE @@ -460,7 +460,6 @@ The following software have components provided under the terms of this license: - OpenCensus (from https://github.com/census-instrumentation/opencensus-java, https://github.com/census-instrumentation/opencensus-proto) - PWDB :: Database (from https://repo1.maven.org/maven2/org/linguafranca/pwdb/database) - PostgreSQL JDBC Driver -- PowerMock (from http://www.powermock.org, https://repo1.maven.org/maven2/org/powermock/powermock-api-mockito) - Protocol Buffer extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-protobuf) - Proton-J (from https://repo1.maven.org/maven2/org/apache/qpid/proton-j) - QUIC functionality for the Reactor Netty library (from https://github.com/reactor/reactor-netty) diff --git a/pom.xml b/pom.xml index bb633af94f00d481be7c8791dc483bb57fb1a879..010a7e9a9389e8e23fe3a5853f61bff306d96a7d 100644 --- a/pom.xml +++ b/pom.xml @@ -22,9 +22,9 @@ <description>Root Storage Service project</description> <properties> - <java.version>1.8</java.version> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> <docker.image.prefix>opendes</docker.image.prefix> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <os-core-common.version>0.23.0-rc1</os-core-common.version> @@ -133,8 +133,7 @@ <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> - <version>1.18.8</version> - <scope>provided</scope> + <version>1.18.28</version> </dependency> @@ -219,7 +218,7 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.7.4</version> + <version>3.0.0</version> <executions> <execution> diff --git a/provider/storage-aws/README.md b/provider/storage-aws/README.md index 4fbb82debd21c9e3ad48247edd4cad5f9665c34b..2f51fa240cba681b72d6b4c6d44dd544c52b5869 100644 --- a/provider/storage-aws/README.md +++ b/provider/storage-aws/README.md @@ -9,9 +9,9 @@ These instructions will get you a copy of the project up and running on your loc ### Prerequisites Pre-requisites -* JDK 8 (https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html) +* JDK 17 (https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html) * Maven 3.8.3 or later -* Lombok 1.16 or later +* Lombok 1.28 or later * OSDU Instance deployed on AWS ### Service Configuration @@ -49,7 +49,7 @@ example: $ mvn --version Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739) Maven home: /usr/local/Cellar/maven/3.8.3/libexec -Java version: 1.8.0_312, vendor: Amazon.com Inc., runtime: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre +Java version: 17.0.7 ... ``` diff --git a/provider/storage-aws/build-aws/Dockerfile b/provider/storage-aws/build-aws/Dockerfile index df97310e977e0267095ad1b9fc39b09fa979cdc5..753434acd8d98546807b66dda8226f45ae30b194 100644 --- a/provider/storage-aws/build-aws/Dockerfile +++ b/provider/storage-aws/build-aws/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. # https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html -FROM amazoncorretto:8 +FROM amazoncorretto:17 ARG JAR_FILE=provider/storage-aws/target/*spring-boot.jar diff --git a/provider/storage-aws/build-aws/buildspec.yaml b/provider/storage-aws/build-aws/buildspec.yaml index de3c3b4760b73781b8afaeb080b2d954b0e09aee..50f747611855b1a91066e6e648d8c3df1a2ab503 100644 --- a/provider/storage-aws/build-aws/buildspec.yaml +++ b/provider/storage-aws/build-aws/buildspec.yaml @@ -30,7 +30,7 @@ env: phases: install: runtime-versions: - java: corretto8 + java: corretto17 commands: # fix error noted here: https://github.com/yarnpkg/yarn/issues/7866 - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - diff --git a/provider/storage-aws/build-aws/entrypoint.sh b/provider/storage-aws/build-aws/entrypoint.sh index 412f71afd92e9c2ed3e50a2863cb5675c8a69b43..6b4b3b53fb4aef0c5cccc4d6994788af69506e50 100755 --- a/provider/storage-aws/build-aws/entrypoint.sh +++ b/provider/storage-aws/build-aws/entrypoint.sh @@ -1,4 +1 @@ - - - java $JAVA_OPTS -jar /app.jar \ No newline at end of file diff --git a/provider/storage-aws/pom.xml b/provider/storage-aws/pom.xml index 34073426746cdaca1b54db5a9a710f649f2a8a59..0ce9e670adbf311e7100c9667cd2c0e397e71c70 100644 --- a/provider/storage-aws/pom.xml +++ b/provider/storage-aws/pom.xml @@ -32,6 +32,9 @@ <packaging>jar</packaging> <properties> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> <aws.version>1.11.1018</aws.version> <deployment.environment>dev</deployment.environment> <version.number>0.23.0-SNAPSHOT</version.number> @@ -152,11 +155,6 @@ <version>3.9.0</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <version>2.0.2</version> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> @@ -179,7 +177,7 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.7.4</version> + <version>3.0.0</version> <executions> <execution> <goals> diff --git a/provider/storage-aws/src/test/java/org/opengroup/osdu/storage/provider/aws/api/UserAccessServiceTest.java b/provider/storage-aws/src/test/java/org/opengroup/osdu/storage/provider/aws/api/UserAccessServiceTest.java index 3fcd003146ee72a39390c795fc7b2a7f6139a4e0..2fd1d21fac23ec1ba52c45818ed7b4280c898e52 100644 --- a/provider/storage-aws/src/test/java/org/opengroup/osdu/storage/provider/aws/api/UserAccessServiceTest.java +++ b/provider/storage-aws/src/test/java/org/opengroup/osdu/storage/provider/aws/api/UserAccessServiceTest.java @@ -21,25 +21,21 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.powermock.reflect.Whitebox; import org.mockito.junit.MockitoJUnitRunner; -import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; import org.opengroup.osdu.core.common.model.entitlements.Acl; -import org.opengroup.osdu.core.common.model.entitlements.EntitlementsException; import org.opengroup.osdu.core.common.model.entitlements.GroupInfo; import org.opengroup.osdu.core.common.model.entitlements.Groups; -import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.storage.RecordMetadata; import org.opengroup.osdu.storage.StorageApplication; import org.opengroup.osdu.storage.provider.aws.cache.GroupCache; import org.opengroup.osdu.storage.provider.aws.security.UserAccessService; - import org.opengroup.osdu.storage.provider.aws.util.CacheHelper; import org.opengroup.osdu.storage.service.EntitlementsAndCacheServiceImpl; - import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; import java.util.List; @@ -68,10 +64,10 @@ public class UserAccessServiceTest { record.setUser("not a user"); CacheHelper cacheHelper = Mockito.mock(CacheHelper.class); - Whitebox.setInternalState(CUT, "cacheHelper", cacheHelper); + ReflectionTestUtils.setField(CUT, "cacheHelper", cacheHelper); GroupCache cache = Mockito.mock(GroupCache.class); - Whitebox.setInternalState(CUT, "cache", cache); + ReflectionTestUtils.setField(CUT, "cache", cache); IEntitlementsService entitlementsService = Mockito.mock(IEntitlementsService.class); Groups groups = new Groups(); @@ -85,12 +81,12 @@ public class UserAccessServiceTest { Mockito.when(entitlementsExtension.getGroups(Mockito.any())).thenReturn(groups); IEntitlementsFactory factory = Mockito.mock(IEntitlementsFactory.class); - Whitebox.setInternalState(CUT, "entitlementsFactory", factory); + ReflectionTestUtils.setField(CUT, "entitlementsFactory", factory); Mockito.when(entitlementsExtension.getGroups(Mockito.any())).thenReturn(groups); DpsHeaders dpsHeaders = Mockito.mock(DpsHeaders.class); - Whitebox.setInternalState(CUT, "dpsHeaders", dpsHeaders); + ReflectionTestUtils.setField(CUT, "dpsHeaders", dpsHeaders); } @Test diff --git a/provider/storage-azure/README.md b/provider/storage-azure/README.md index b5c779798d9838d5db24b8778d117c257e201c1b..912549e10c23540eabaada2efb5ca4dc29588739 100644 --- a/provider/storage-azure/README.md +++ b/provider/storage-azure/README.md @@ -9,7 +9,7 @@ os-storage-azure is a [Spring Boot](https://spring.io/projects/spring-boot) serv In order to run this service locally, you will need the following: - [Maven 3.6.0+](https://maven.apache.org/download.cgi) -- [AdoptOpenJDK8](https://adoptopenjdk.net/) +- [AdoptOpenJDK17](https://adoptopenjdk.net/) - Infrastructure dependencies, deployable through the relevant [infrastructure template](https://dev.azure.com/slb-des-ext-collaboration/open-data-ecosystem/_git/infrastructure-templates?path=%2Finfra&version=GBmaster&_a=contents) - While not a strict dependency, example commands in this document use [bash](https://www.gnu.org/software/bash/) @@ -94,7 +94,7 @@ Check that maven is installed: $ mvn --version Apache Maven 3.6.0 Maven home: /usr/share/maven -Java version: 1.8.0_212, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk8u212-b04/jre +Java version: 17.0.7 ... ``` diff --git a/provider/storage-azure/pom.xml b/provider/storage-azure/pom.xml index 8482822f4b9bee4519134b1297044edb87aced99..8fe47e278ecfc41d5edcd53186c12fc2cb446c05 100644 --- a/provider/storage-azure/pom.xml +++ b/provider/storage-azure/pom.xml @@ -29,6 +29,9 @@ <packaging>jar</packaging> <version>0.23.0-SNAPSHOT</version> <properties> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> <azure.appservice.resourcegroup /> <azure.appservice.plan /> <azure.appservice.appname /> @@ -37,11 +40,17 @@ <osdu.storage-core.version>0.23.0-SNAPSHOT</osdu.storage-core.version> <junit.version>4.12</junit.version> <mockito.version>1.10.19</mockito.version> - <powermock.version>2.0.2</powermock.version> <nimbus-jose-jwt-azure.version>8.20.1</nimbus-jose-jwt-azure.version> <azure-storage-blob.version>12.10.2</azure-storage-blob.version> <azure-spring-data-cosmos.version>3.21.0</azure-spring-data-cosmos.version> <spring-webmvc.version>5.3.22</spring-webmvc.version> + <argLine> + --add-opens=java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED + </argLine> </properties> <dependencyManagement> @@ -199,6 +208,7 @@ <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> + <version>1.18.22</version> </dependency> <dependency> <groupId>junit</groupId> @@ -240,7 +250,7 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.7.4</version> + <version>3.0.0</version> <executions> <execution> <goals> @@ -287,7 +297,7 @@ <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <version>0.8.3</version> + <version>0.8.10</version> <executions> <execution> <goals> diff --git a/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/config/ThreadScopeTest.java b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/config/ThreadScopeTest.java index 82a21f44455397e74f3222fdb444164012df321b..9267eba49635b230e4819c1e0c9684298a6e18e5 100644 --- a/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/config/ThreadScopeTest.java +++ b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/config/ThreadScopeTest.java @@ -7,22 +7,18 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.slf4j.MDC; import org.springframework.beans.factory.ObjectFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import javax.servlet.http.HttpServletRequest; - import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; - -import static org.junit.jupiter.api.Assertions.*; @ExtendWith(MockitoExtension.class) class ThreadScopeTest { private String name = "name"; @@ -46,7 +42,7 @@ class ThreadScopeTest { @Test void shouldGetObject() { - when(scope.get(name,null)).thenReturn(obj); + when(scope.get(name,factory)).thenReturn(obj); obj = scope.get(name,factory); assertNotNull(obj); } @@ -64,7 +60,7 @@ class ThreadScopeTest { Enumeration<String> headerNames = Collections.enumeration(headers.keySet()); when(request.getHeaderNames()).thenReturn(headerNames); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); - when(request.getHeader(any())).thenReturn(any()); + when(request.getHeader(any())).thenReturn("header"); assertEquals(threadScope.get(name,factory).getClass(),dpsHeaders.getClass()); } } diff --git a/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/repository/RecordMetadataRepositoryTest.java b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/repository/RecordMetadataRepositoryTest.java index 9af2035a03058f01378219af065d4bfbf9b4634e..a292f3beff6e59feaacff440854274c7b4dc4e9a 100644 --- a/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/repository/RecordMetadataRepositoryTest.java +++ b/provider/storage-azure/src/test/java/org/opengroup/osdu/storage/provider/azure/repository/RecordMetadataRepositoryTest.java @@ -1,5 +1,6 @@ package org.opengroup.osdu.storage.provider.azure.repository; +import com.azure.cosmos.models.CosmosQueryRequestOptions; import com.azure.cosmos.models.SqlQuerySpec; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonpatch.JsonPatch; @@ -30,27 +31,12 @@ import org.springframework.test.util.ReflectionTestUtils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.only; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) public class RecordMetadataRepositoryTest { @@ -84,7 +70,7 @@ public class RecordMetadataRepositoryTest { @BeforeEach public void setup() { - when(headers.getPartitionId()).thenReturn("opendes"); + lenient().when(headers.getPartitionId()).thenReturn("opendes"); ReflectionTestUtils.setField(recordMetadataRepository, "cosmosDBName", "osdu-db"); ReflectionTestUtils.setField(recordMetadataRepository, "recordMetadataCollection", "collection"); ReflectionTestUtils.setField(recordMetadataRepository, "minBatchSizeToUseBulkUpload", 2); @@ -93,12 +79,10 @@ public class RecordMetadataRepositoryTest { @Test public void shouldFailOnCreateOrUpdate_IfAclIsNull() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("Acl of the record must not be null"); try { recordMetadataRepository.createOrUpdate(singletonList(new RecordMetadata()), Optional.empty()); } catch (IllegalArgumentException e) { - verify(logger, only()).error("Acl of the record RecordMetadata(id=null, kind=null, previousVersionKind=null, acl=null, legal=null, ancestry=null, tags={}, gcsVersionPaths=[], status=null, user=null, createTime=0, modifyUser=null, modifyTime=0, hash=null) must not be null"); + assertEquals("Acl of the record must not be null", e.getMessage()); } } @@ -263,24 +247,19 @@ public class RecordMetadataRepositoryTest { Pageable pageable = PageRequest.of(0, 8); - doReturn(page).when(operation).queryItemsPage(any(), - any(), - eq("opendes"), - any(SqlQuerySpec.class), - any(Class.class), - eq(8), - any()); + doReturn(page).when(operation).queryItemsPage(eq("opendes"), eq("osdu-db"), eq("collection"), any(SqlQuerySpec.class), any(Class.class), eq(8), any(), any(CosmosQueryRequestOptions.class)); this.recordMetadataRepository.findIdsByMetadata_kindAndMetadata_status(KIND, STATUS, pageable, Optional.of(collaborationContext)); ArgumentCaptor<SqlQuerySpec> queryCaptor = ArgumentCaptor.forClass(SqlQuerySpec.class); - verify(operation).queryItemsPage(any(), - any(), - eq("opendes"), + verify(operation).queryItemsPage(eq("opendes"), + eq("osdu-db"), + eq("collection"), queryCaptor.capture(), any(Class.class), eq(8), - any()); + any(), + any(CosmosQueryRequestOptions.class)); SqlQuerySpec capturedQuery = queryCaptor.getValue(); assertEquals(expectedQuery, capturedQuery.getQueryText()); } diff --git a/provider/storage-byoc/pom.xml b/provider/storage-byoc/pom.xml index 7f985ae7af84f8e57d44a56698f0610783af909b..1eee1589aabafe69b25f7f832021a0ff37428e8b 100644 --- a/provider/storage-byoc/pom.xml +++ b/provider/storage-byoc/pom.xml @@ -28,6 +28,12 @@ <description>Bring-Your-Own-Cloud backed up by in-memory data structures</description> <packaging>jar</packaging> + <properties> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + </properties> + <dependencies> <dependency> <groupId>org.opengroup.osdu</groupId> @@ -56,14 +62,28 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <version>2.0.2</version> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>3.11.2</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </exclusion> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework.security</groupId> @@ -77,7 +97,7 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.7.4</version> + <version>3.0.0</version> <executions> <execution> <goals> diff --git a/provider/storage-byoc/src/test/java/org/opengroup/osdu/storage/provider/byoc/api/SchemaApiTest.java b/provider/storage-byoc/src/test/java/org/opengroup/osdu/storage/provider/byoc/api/SchemaApiTest.java index 7d08e1a49b66ef8d0d6c4a4373ab8c3d4afb18db..0a2c76990c549c877ecab35afda5db7a6c296d24 100644 --- a/provider/storage-byoc/src/test/java/org/opengroup/osdu/storage/provider/byoc/api/SchemaApiTest.java +++ b/provider/storage-byoc/src/test/java/org/opengroup/osdu/storage/provider/byoc/api/SchemaApiTest.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.junit4.SpringRunner; + import static org.mockito.MockitoAnnotations.initMocks; @RunWith(SpringRunner.class) diff --git a/provider/storage-gc/README.md b/provider/storage-gc/README.md index 5b58ee1b9d6fef2b541143c67442524192c363e4..d4e2f89514f3c767b996033c7445d9245728d2b6 100644 --- a/provider/storage-gc/README.md +++ b/provider/storage-gc/README.md @@ -42,8 +42,8 @@ In the current version, the mappers are equipped with several drivers to the sto ### Requirements: 1. Mandatory - - JDK 8 - - Lombok 1.16 or later + - JDK 17 + - Lombok 1.28 or later - Maven 2. For Google Cloud only - GCloud SDK with java (latest version) @@ -63,7 +63,7 @@ Check that maven is installed: $ mvn --version Apache Maven 3.6.0 Maven home: /usr/share/maven -Java version: 1.8.0_212, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk8u212-b04/jre +Java version: 17.0.7 ... ``` diff --git a/provider/storage-gc/cloudbuild/Dockerfile.cloudbuild b/provider/storage-gc/cloudbuild/Dockerfile.cloudbuild index b00b361bf60ef217f0c0f74a01ad04e0d3715180..a10c353c80730eb96038ddb31b39b34dc3ac082d 100644 --- a/provider/storage-gc/cloudbuild/Dockerfile.cloudbuild +++ b/provider/storage-gc/cloudbuild/Dockerfile.cloudbuild @@ -1,4 +1,4 @@ -FROM azul/zulu-openjdk:8-latest +FROM azul/zulu-openjdk:17-latest WORKDIR /app diff --git a/provider/storage-gc/pom.xml b/provider/storage-gc/pom.xml index 0d2273114ab9ef29bd9d6d8c1f9132081a1e12b7..d1c65e90cd2729a69c22f96054323daaabcc25bb 100644 --- a/provider/storage-gc/pom.xml +++ b/provider/storage-gc/pom.xml @@ -33,9 +33,9 @@ <packaging>jar</packaging> <properties> - <java.version>1.8</java.version> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> <log4j.version>2.17.1</log4j.version> <spring-webmvc.version>5.3.22</spring-webmvc.version> </properties> @@ -137,12 +137,6 @@ <version>4.12</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-mockito2</artifactId> - <version>2.0.9</version> - <scope>test</scope> - </dependency> </dependencies> <build> @@ -151,7 +145,7 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.7.4</version> + <version>3.0.0</version> <configuration> <profiles> <profile> @@ -196,7 +190,7 @@ <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <version>0.7.7.201606060606</version> + <version>0.8.10</version> <executions> <execution> <goals> diff --git a/provider/storage-ibm/pom.xml b/provider/storage-ibm/pom.xml index ceeef6161ae97b7a9d8214a2e0ad4057f98b85cf..26ac1b1efe146afd8e1f9893409e82edcfa54975 100644 --- a/provider/storage-ibm/pom.xml +++ b/provider/storage-ibm/pom.xml @@ -26,6 +26,9 @@ <packaging>jar</packaging> <properties> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> <os-core-lib-ibm.version>0.17.0-rc4</os-core-lib-ibm.version> <start-class>org.opengroup.osdu.storage.provider.ibm.app.StorageIBMApplication</start-class> <jackson-dataformat-cbor.version>2.11.4</jackson-dataformat-cbor.version> @@ -76,11 +79,6 @@ <version>1.10.19</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <version>2.0.2</version> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> @@ -114,7 +112,7 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.1.9.RELEASE</version> + <version>3.0.0</version> <configuration> <mainClass>${start-class}</mainClass> </configuration> diff --git a/storage-core/pom.xml b/storage-core/pom.xml index 1a17e558a4c72c889d1f3073c817124c0bdaa9c5..d38fddf1e7684ca2c62ddcbc47808a992fb7627d 100644 --- a/storage-core/pom.xml +++ b/storage-core/pom.xml @@ -30,11 +30,17 @@ </parent> <properties> - <java.version>1.8</java.version> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> <os-core-common.version>0.23.0-rc1</os-core-common.version> <spring-webmvc.version>5.3.22</spring-webmvc.version> + <argLine> + --add-opens=java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + </argLine> </properties> <dependencyManagement> @@ -88,6 +94,7 @@ <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> + <version>2.10.1</version> </dependency> <dependency> @@ -122,21 +129,27 @@ <version>4.12</version> <scope>test</scope> </dependency> - <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 --> + <!--<!– https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 –> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito2</artifactId> <version>2.0.2</version> <scope>test</scope> - </dependency> + </dependency>--> <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 --> <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>2.0.2-beta</version> + </dependency> + + <!--<dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> - <version>3.0.0</version> + <version>4.11.0</version> <scope>test</scope> - </dependency> + </dependency>--> </dependencies> @@ -145,7 +158,7 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.7.4</version> + <version>3.0.0</version> <executions> <execution> <goals> diff --git a/storage-core/src/main/java/org/opengroup/osdu/storage/service/BatchServiceImpl.java b/storage-core/src/main/java/org/opengroup/osdu/storage/service/BatchServiceImpl.java index adff7b7055333b1a0934a7def66f83d2bdc1dc2a..1ea3c3ae7318feb99c4839a3c3140f698be9f22f 100644 --- a/storage-core/src/main/java/org/opengroup/osdu/storage/service/BatchServiceImpl.java +++ b/storage-core/src/main/java/org/opengroup/osdu/storage/service/BatchServiceImpl.java @@ -14,33 +14,21 @@ package org.opengroup.osdu.storage.service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.function.Consumer; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import com.google.common.base.Strings; +import com.google.gson.*; import org.apache.http.HttpStatus; +import org.opengroup.osdu.core.common.crs.CrsConverterClientFactory; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.crs.RecordsAndStatuses; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.CollaborationContext; import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.model.crs.RecordsAndStatuses; -import org.opengroup.osdu.core.common.crs.CrsConverterClientFactory; import org.opengroup.osdu.core.common.model.indexer.OperationType; +import org.opengroup.osdu.core.common.model.storage.Record; import org.opengroup.osdu.core.common.model.storage.*; -import org.opengroup.osdu.storage.logging.StorageAuditLogger; import org.opengroup.osdu.core.common.storage.PersistenceHelper; - -import com.google.common.base.Strings; import org.opengroup.osdu.storage.conversion.DpsConversionService; +import org.opengroup.osdu.storage.logging.StorageAuditLogger; import org.opengroup.osdu.storage.opa.model.ValidationOutputRecord; import org.opengroup.osdu.storage.opa.service.IOPAService; import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage; @@ -49,6 +37,10 @@ import org.opengroup.osdu.storage.util.CollaborationUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import java.util.*; +import java.util.function.Consumer; +import java.util.stream.Collectors; + public abstract class BatchServiceImpl implements BatchService { diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java index 9dc0e19733373159bae51f2cc76880f0350caf0a..579499071f930d98647eda236ffe97e494ea5816 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java @@ -29,16 +29,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.storage.conversion.CrsConversionService; import org.opengroup.osdu.storage.logging.ReadAuditLogsConsumer; import org.opengroup.osdu.storage.policy.service.PartitionPolicyStatusService; -import org.opengroup.osdu.storage.service.BulkUpdateRecordServiceImpl; -import org.opengroup.osdu.storage.service.DataAuthorizationService; -import org.opengroup.osdu.storage.service.IngestionServiceImpl; -import org.opengroup.osdu.storage.service.LegalServiceImpl; -import org.opengroup.osdu.storage.service.PartitionServiceImpl; -import org.opengroup.osdu.storage.service.PatchRecordsServiceImpl; -import org.opengroup.osdu.storage.service.PersistenceServiceImpl; -import org.opengroup.osdu.storage.service.QueryServiceImpl; -import org.opengroup.osdu.storage.service.RecordServiceImpl; -import org.opengroup.osdu.storage.service.SchemaServiceImpl; +import org.opengroup.osdu.storage.service.*; import org.opengroup.osdu.storage.util.RecordBlocks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiTest.java index 811da1025d4f16acbdb0d698e20a32cf5f8fb15c..49cb60b7a6e9fdb1232d0d4c8dcb9eed82409fc4 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; - import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.http.CollaborationContextFactory; import org.opengroup.osdu.core.common.model.http.CollaborationContext; @@ -20,14 +19,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import javax.inject.Provider; - import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/api/QueryApiTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/api/QueryApiTest.java index 8f6934cc61d76a72d96cb837fa7e208aecec68b9..14773da9b2b9bf80ca7e034e728dab1ea9613c6f 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/api/QueryApiTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/api/QueryApiTest.java @@ -14,33 +14,17 @@ package org.opengroup.osdu.storage.api; -import static org.junit.Assert.*; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.when; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - +import com.google.common.collect.Lists; import org.apache.http.HttpStatus; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; - -import com.google.common.collect.Lists; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.http.CollaborationContextFactory; import org.opengroup.osdu.core.common.model.http.CollaborationContext; -import org.opengroup.osdu.core.common.model.storage.MultiRecordIds; -import org.opengroup.osdu.core.common.model.storage.MultiRecordInfo; -import org.opengroup.osdu.core.common.model.storage.StorageRole; -import org.opengroup.osdu.core.common.model.storage.DatastoreQueryResult; +import org.opengroup.osdu.core.common.model.storage.Record; import org.opengroup.osdu.core.common.model.storage.*; import org.opengroup.osdu.storage.di.SchemaEndpointsConfig; import org.opengroup.osdu.storage.service.BatchService; @@ -48,6 +32,13 @@ import org.opengroup.osdu.storage.util.EncodeDecode; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; +import java.lang.reflect.Method; +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + @RunWith(MockitoJUnitRunner.Silent.class) public class QueryApiTest { private final Optional<CollaborationContext> COLLABORATION_CONTEXT = Optional.ofNullable(CollaborationContext.builder().id(UUID.fromString("9e1c4e74-3b9b-4b17-a0d5-67766558ec65")).application("TestApp").build()); diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/api/RecordApiTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/api/RecordApiTest.java index dbfa7f2fde573ebce7d274e4242117b5f8350560..36be46abb31bcbbed00c83cad5b5628dcfa3778e 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/api/RecordApiTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/api/RecordApiTest.java @@ -14,23 +14,6 @@ package org.opengroup.osdu.storage.api; -import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Random; -import java.util.UUID; - import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Test; @@ -54,6 +37,16 @@ import org.opengroup.osdu.storage.service.RecordService; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; +import java.lang.reflect.Method; +import java.util.*; + +import static java.util.Collections.singletonList; +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + @RunWith(MockitoJUnitRunner.Silent.class) public class RecordApiTest { diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/ConversionServiceTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/ConversionServiceTest.java index 77ea520d36420ba731166e634f3d65f296858732..1ed341726ed5248a0d0e20e9c38d4ddf4c165e06 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/ConversionServiceTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/ConversionServiceTest.java @@ -35,7 +35,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.opengroup.osdu.storage.conversion.CrsConversionServiceErrorMessages.UNEXPECTED_DATA_FORMAT_JSON_OBJECT; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/CrsConversionServiceTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/CrsConversionServiceTest.java index 80ed659f3a44ad98e37654b1834a173aab4962b9..3517c07b9c237279a9e6be0b7ceff3a873ac640d 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/CrsConversionServiceTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/conversion/CrsConversionServiceTest.java @@ -16,32 +16,30 @@ package org.opengroup.osdu.storage.conversion; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.apache.http.client.config.RequestConfig; -import org.opengroup.osdu.core.common.crs.CrsConversionServiceErrorMessages; -import org.opengroup.osdu.core.common.model.crs.*; -import org.opengroup.osdu.core.common.model.storage.ConversionStatus; -import org.opengroup.osdu.core.common.model.crs.CrsPropertySet; -import org.opengroup.osdu.core.common.model.crs.RecordsAndStatuses; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; -import org.opengroup.osdu.storage.di.CrsConversionConfig; -import org.opengroup.osdu.storage.di.SpringConfig; import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.crs.CrsConversionServiceErrorMessages; import org.opengroup.osdu.core.common.crs.CrsConverterFactory; import org.opengroup.osdu.core.common.crs.CrsConverterService; import org.opengroup.osdu.core.common.http.HttpResponse; -import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.crs.*; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.storage.ConversionStatus; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.storage.di.CrsConversionConfig; +import org.opengroup.osdu.storage.di.SpringConfig; import java.util.*; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/logging/AuditLoggerTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/logging/AuditLoggerTest.java index d906e8958171351d4690af5e440aad89457cc318..0bc1e8fe5066050270e345e5ea7cd797ee4c6b3c 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/logging/AuditLoggerTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/logging/AuditLoggerTest.java @@ -14,7 +14,7 @@ package org.opengroup.osdu.storage.logging; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/logging/JaxRsDpsLogTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/logging/JaxRsDpsLogTest.java index aa130c3d97ead50c30145c65c700c774932d3fa3..11e1f5d0a97305a9051547e61c645a5737e7c5f3 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/logging/JaxRsDpsLogTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/logging/JaxRsDpsLogTest.java @@ -14,23 +14,23 @@ package org.opengroup.osdu.storage.logging; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.verify; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.model.http.Request; import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.logging.ILogger; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.audit.AuditPayload; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.Request; import org.springframework.test.util.ReflectionTestUtils; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; + @RunWith(MockitoJUnitRunner.class) public class JaxRsDpsLogTest { diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/logging/ReadAuditLogsConsumerTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/logging/ReadAuditLogsConsumerTest.java index 0e108086a7f0d31ea4a2c10afb31650d32a88f14..f483997ce7b4d9d72049c63e620dce150aa8d0bd 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/logging/ReadAuditLogsConsumerTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/logging/ReadAuditLogsConsumerTest.java @@ -29,11 +29,14 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.partition.PartitionInfo; import org.opengroup.osdu.core.common.partition.Property; import org.opengroup.osdu.storage.service.IPartitionService; -import org.powermock.reflect.Whitebox; +import org.springframework.test.util.ReflectionTestUtils; import java.util.HashMap; import java.util.Map; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + @RunWith(MockitoJUnitRunner.Silent.class) public class ReadAuditLogsConsumerTest { @@ -47,10 +50,11 @@ public class ReadAuditLogsConsumerTest { @InjectMocks private ReadAuditLogsConsumer readAuditLogsConsumer; + private ICache<String, Boolean> readAuditLogSwitchCache; + @Before public void setup() { - ICache<String, Boolean> readAuditLogSwitchCache = new VmCache<>(60, 2); - Whitebox.setInternalState(readAuditLogsConsumer, "readAuditLogSwitchCache", readAuditLogSwitchCache); + readAuditLogSwitchCache = new VmCache<>(60, 2); } @Test @@ -58,12 +62,12 @@ public class ReadAuditLogsConsumerTest { Mockito.when(dpsHeaders.getPartitionId()).thenReturn("dp"); ICache<String, Boolean> readAuditLogSwitchCache = new VmCache<>(100, 1); readAuditLogSwitchCache.put("is-read-audit-logs-enabled-dp", true); - Whitebox.setInternalState(readAuditLogsConsumer, "readAuditLogSwitchCache", readAuditLogSwitchCache); + ReflectionTestUtils.setField(readAuditLogsConsumer,"readAuditLogSwitchCache", readAuditLogSwitchCache); AuditPayload auditPayload = Mockito.mock(AuditPayload.class); readAuditLogsConsumer.accept(auditPayload); - Mockito.verify(logger).audit(auditPayload); - Mockito.verifyZeroInteractions(partitionService); + verify(logger).audit(auditPayload); + verifyNoMoreInteractions(partitionService); } @Test @@ -71,11 +75,12 @@ public class ReadAuditLogsConsumerTest { Mockito.when(dpsHeaders.getPartitionId()).thenReturn("dp"); ICache<String, Boolean> readAuditLogSwitchCache = new VmCache<>(100, 1); readAuditLogSwitchCache.put("is-read-audit-logs-enabled-dp", false); - Whitebox.setInternalState(readAuditLogsConsumer, "readAuditLogSwitchCache", readAuditLogSwitchCache); AuditPayload auditPayload = Mockito.mock(AuditPayload.class); + ReflectionTestUtils.setField(readAuditLogsConsumer,"readAuditLogSwitchCache", readAuditLogSwitchCache); + readAuditLogsConsumer.accept(auditPayload); - Mockito.verifyZeroInteractions(logger, partitionService); + verifyNoMoreInteractions(logger, partitionService); } @Test @@ -90,12 +95,14 @@ public class ReadAuditLogsConsumerTest { Mockito.when(partitionService.getPartition("dp")).thenReturn(partitionInfo); Mockito.when(dpsHeaders.getPartitionId()).thenReturn("dp"); AuditPayload auditPayload = Mockito.mock(AuditPayload.class); + ReflectionTestUtils.setField(readAuditLogsConsumer,"readAuditLogSwitchCache", readAuditLogSwitchCache); + readAuditLogsConsumer.accept(auditPayload); - Mockito.verify(partitionService).getPartition("dp"); - Mockito.verify(dpsHeaders, Mockito.times(3)).getPartitionId(); - Mockito.verify(logger).info("PartitionInfo of dp has is-read-audit-logs-enabled flag as false"); - Mockito.verifyNoMoreInteractions(logger); + verify(partitionService).getPartition("dp"); + verify(dpsHeaders, Mockito.times(3)).getPartitionId(); + verify(logger).info("PartitionInfo of dp has is-read-audit-logs-enabled flag as false"); + verifyNoMoreInteractions(logger); } @Test @@ -110,12 +117,14 @@ public class ReadAuditLogsConsumerTest { Mockito.when(partitionService.getPartition("dp")).thenReturn(partitionInfo); Mockito.when(dpsHeaders.getPartitionId()).thenReturn("dp"); AuditPayload auditPayload = Mockito.mock(AuditPayload.class); + ReflectionTestUtils.setField(readAuditLogsConsumer,"readAuditLogSwitchCache", readAuditLogSwitchCache); + readAuditLogsConsumer.accept(auditPayload); - Mockito.verify(partitionService).getPartition("dp"); - Mockito.verify(dpsHeaders, Mockito.times(2)).getPartitionId(); - Mockito.verify(logger).audit(auditPayload); - Mockito.verifyNoMoreInteractions(logger); + verify(partitionService).getPartition("dp"); + verify(dpsHeaders, Mockito.times(2)).getPartitionId(); + verify(logger).audit(auditPayload); + verifyNoMoreInteractions(logger); } @Test @@ -130,15 +139,16 @@ public class ReadAuditLogsConsumerTest { Mockito.when(partitionService.getPartition("dp")).thenReturn(partitionInfo); Mockito.when(dpsHeaders.getPartitionId()).thenReturn("dp"); AuditPayload auditPayload = Mockito.mock(AuditPayload.class); + ReflectionTestUtils.setField(readAuditLogsConsumer,"readAuditLogSwitchCache", readAuditLogSwitchCache); readAuditLogsConsumer.accept(auditPayload); // on second time should use cached value readAuditLogsConsumer.accept(auditPayload); - Mockito.verify(partitionService).getPartition("dp"); - Mockito.verify(dpsHeaders, Mockito.times(4)).getPartitionId(); - Mockito.verify(logger).info("PartitionInfo of dp has is-read-audit-logs-enabled flag as false"); - Mockito.verifyNoMoreInteractions(logger); + verify(partitionService).getPartition("dp"); + verify(dpsHeaders, Mockito.times(4)).getPartitionId(); + verify(logger).info("PartitionInfo of dp has is-read-audit-logs-enabled flag as false"); + verifyNoMoreInteractions(logger); } @Test @@ -153,15 +163,16 @@ public class ReadAuditLogsConsumerTest { Mockito.when(partitionService.getPartition("dp")).thenReturn(partitionInfo); Mockito.when(dpsHeaders.getPartitionId()).thenReturn("dp"); AuditPayload auditPayload = Mockito.mock(AuditPayload.class); + ReflectionTestUtils.setField(readAuditLogsConsumer,"readAuditLogSwitchCache", readAuditLogSwitchCache); readAuditLogsConsumer.accept(auditPayload); // on second time should use cached value readAuditLogsConsumer.accept(auditPayload); - Mockito.verify(partitionService).getPartition("dp"); - Mockito.verify(dpsHeaders, Mockito.times(4)).getPartitionId(); - Mockito.verify(logger).info("PartitionInfo of dp has is-read-audit-logs-enabled flag as true"); - Mockito.verify(logger, Mockito.times(2)).audit(auditPayload); - Mockito.verifyNoMoreInteractions(logger); + verify(partitionService).getPartition("dp"); + verify(dpsHeaders, Mockito.times(4)).getPartitionId(); + verify(logger).info("PartitionInfo of dp has is-read-audit-logs-enabled flag as true"); + verify(logger, Mockito.times(2)).audit(auditPayload); + verifyNoMoreInteractions(logger); } } diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java index 30461acffca2e2798d7d2c26cfdc17d375772f20..e97a05f34ead72b3057bf0b0126f881ffa5a1e91 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/opa/OPAServiceImplTest.java @@ -30,7 +30,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java index 8648d1bdc7fe343b294832faaa95b6a73b579ff1..61cc2abf0768f7b1abb8f4570e171c1fbfebc5ea 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java @@ -38,12 +38,7 @@ import org.opengroup.osdu.storage.validation.api.PatchOperationValidator; import org.springframework.test.util.ReflectionTestUtils; import java.time.Clock; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -254,7 +249,7 @@ public class BulkUpdateRecordServiceImplTest { BulkUpdateRecordsResponse actualResponse = service.bulkUpdateRecords(param, TEST_USER, COLLABORATION_CONTEXT); - verifyZeroInteractions(entitlementsAndCacheService, headers, persistenceService); + verifyNoMoreInteractions(entitlementsAndCacheService, headers, persistenceService); verify(auditLogger, only()).createOrUpdateRecordsFail(TEST_IDS); assertTrue(actualResponse.getRecordIds().isEmpty()); diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/DataAuthorizationServiceTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/DataAuthorizationServiceTest.java index 463dd2022d2f5c84d431f318228e43db8adc84fb..6554ce64257da3496210bdf7a4b99f29086aa197 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/DataAuthorizationServiceTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/DataAuthorizationServiceTest.java @@ -18,10 +18,12 @@ import org.opengroup.osdu.storage.policy.service.PartitionPolicyStatusService; import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage; import org.springframework.test.util.ReflectionTestUtils; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java index 0cc894ab07fcaf1e8d90f99ad9f468a1f20c2129..7cf2f4156477bb7b4dbba8a9e85de8918c934a37 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java @@ -21,17 +21,17 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.opengroup.osdu.core.common.model.entitlements.Acl; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; +import org.opengroup.osdu.core.common.http.HttpResponse; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.entitlements.Acl; import org.opengroup.osdu.core.common.model.entitlements.EntitlementsException; import org.opengroup.osdu.core.common.model.entitlements.GroupInfo; import org.opengroup.osdu.core.common.model.entitlements.Groups; import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.common.http.HttpResponse; -import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; -import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.storage.RecordMetadata; import java.util.*; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java index 9a17f7cd65a642993618331fadc545c5879700e6..effd8a74388329f6c4f7c38c44f09acf0f1bc931 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java @@ -28,26 +28,27 @@ import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; +import org.opengroup.osdu.core.common.legal.ILegalService; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.entitlements.Acl; import org.opengroup.osdu.core.common.model.entitlements.EntitlementsException; import org.opengroup.osdu.core.common.model.entitlements.GroupInfo; import org.opengroup.osdu.core.common.model.entitlements.Groups; import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.common.model.entitlements.Acl; import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.legal.Legal; +import org.opengroup.osdu.core.common.model.storage.Record; +import org.opengroup.osdu.core.common.model.storage.*; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.core.common.partition.PartitionException; import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; -import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.model.storage.*; import org.opengroup.osdu.storage.logging.StorageAuditLogger; import org.opengroup.osdu.storage.opa.model.OpaError; import org.opengroup.osdu.storage.opa.model.ValidationOutputRecord; import org.opengroup.osdu.storage.opa.service.IOPAService; import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage; import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository; -import org.opengroup.osdu.core.common.legal.ILegalService; import org.opengroup.osdu.storage.util.CrcHashGenerator; import org.opengroup.osdu.storage.util.RecordBlocks; import org.opengroup.osdu.storage.util.api.RecordUtil; @@ -56,7 +57,7 @@ import org.springframework.test.util.ReflectionTestUtils; import java.util.*; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.Silent.class) diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java index 3022d73a2487efe361cc0cb386907b8d32e74f5f..db71d22ef6793f64fed9b32ec3110df1707c0fd8 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java @@ -16,8 +16,6 @@ package org.opengroup.osdu.storage.service; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Test; @@ -25,15 +23,18 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.cache.ICache; -import org.opengroup.osdu.core.common.model.legal.*; -import org.opengroup.osdu.core.common.model.storage.*; -import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.http.HttpResponse; import org.opengroup.osdu.core.common.legal.ILegalFactory; import org.opengroup.osdu.core.common.legal.ILegalProvider; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.legal.*; +import org.opengroup.osdu.core.common.model.storage.Record; +import org.opengroup.osdu.core.common.model.storage.RecordAncestry; +import org.opengroup.osdu.core.common.model.storage.RecordIdWithVersion; +import org.opengroup.osdu.core.common.model.storage.RecordMetadata; import java.util.HashMap; import java.util.List; @@ -41,7 +42,7 @@ import java.util.Map; import java.util.Set; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.Silent.class) diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/PatchRecordsServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/PatchRecordsServiceImplTest.java index 5242b48be75eb710d0e8c39c6c3f8cc665d3b4c0..71f7a3de08dfda30a7fd2c56069cc2f31289f669 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/PatchRecordsServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/PatchRecordsServiceImplTest.java @@ -13,11 +13,8 @@ import org.opengroup.osdu.core.common.model.http.CollaborationContext; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.legal.Legal; -import org.opengroup.osdu.core.common.model.storage.MultiRecordIds; -import org.opengroup.osdu.core.common.model.storage.MultiRecordInfo; import org.opengroup.osdu.core.common.model.storage.Record; -import org.opengroup.osdu.core.common.model.storage.RecordMetadata; -import org.opengroup.osdu.core.common.model.storage.TransferInfo; +import org.opengroup.osdu.core.common.model.storage.*; import org.opengroup.osdu.storage.logging.StorageAuditLogger; import org.opengroup.osdu.storage.opa.service.IOPAService; import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository; @@ -27,30 +24,16 @@ import org.opengroup.osdu.storage.validation.api.PatchInputValidator; import org.springframework.test.util.ReflectionTestUtils; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.Silent.class) public class PatchRecordsServiceImplTest { diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/PersistenceServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/PersistenceServiceImplTest.java index 444514c1adffc349b922446ca4d5b2afc9cfb7c0..eb2122875fbf458a1cd046ee0bdd23afde6b1b61 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/PersistenceServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/PersistenceServiceImplTest.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.storage.service; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonpatch.JsonPatch; +import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -27,17 +28,17 @@ import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.feature.IFeatureFlag; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.entitlements.Acl; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.CollaborationContext; import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.core.common.model.indexer.OperationType; +import org.opengroup.osdu.core.common.model.storage.Record; import org.opengroup.osdu.core.common.model.storage.*; -import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.storage.model.RecordChangedV2; import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage; import org.opengroup.osdu.storage.provider.interfaces.IMessageBus; import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository; -import org.apache.http.HttpStatus; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -45,8 +46,8 @@ import java.io.InputStream; import java.util.*; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; import static org.opengroup.osdu.storage.util.RecordConstants.COLLABORATIONS_FEATURE_NAME; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java index ecb0c750c695ca9d4ffc646f7d9baa1b836e61d8..1326092d9a8f552e9efea18f6a38e512ae30f532 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java @@ -14,13 +14,6 @@ package org.opengroup.osdu.storage.service; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; - import com.google.common.collect.Lists; import org.apache.http.HttpStatus; import org.junit.Before; @@ -52,12 +45,14 @@ import org.opengroup.osdu.storage.provider.interfaces.IRecordsMetadataRepository import org.opengroup.osdu.storage.util.RecordConstants; import org.opengroup.osdu.storage.util.api.RecordUtil; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; + +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.Silent.class) public class RecordServiceImplTest { @@ -468,7 +463,7 @@ public class RecordServiceImplTest { verify(dataAuthorizationService, only()).validateOwnerAccess(record, OperationType.delete); verify(recordRepository, never()).createOrUpdate(any(), any()); verify(auditLogger, only()).deleteRecordFail(singletonList(errorMsg)); - verifyZeroInteractions(pubSubClient); + verifyNoMoreInteractions(pubSubClient); assertEquals(1, e.getNotDeletedRecords().size()); @@ -532,7 +527,7 @@ public class RecordServiceImplTest { assertEquals("Invalid record id", e.getError().getReason()); assertEquals(errorMsg, e.getError().getMessage()); - verifyZeroInteractions(recordRepository, entitlementsAndCacheService, auditLogger, pubSubClient); + verifyNoMoreInteractions(recordRepository, entitlementsAndCacheService, auditLogger, pubSubClient); } catch (Exception e) { fail("Should not get different exception"); } diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/SchemaServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/SchemaServiceImplTest.java index e609bd52ce1f5c5d1f82d30ba7bc4ad5332d1de9..9271f10f5f89e523db9580995a6524fe20a3b7e8 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/SchemaServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/SchemaServiceImplTest.java @@ -14,35 +14,32 @@ package org.opengroup.osdu.storage.service; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ConcurrentModificationException; -import java.util.HashMap; - -import org.mockito.junit.MockitoJUnitRunner; -import org.opengroup.osdu.core.common.feature.IFeatureFlag; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.storage.provider.interfaces.IMessageBus; -import org.opengroup.osdu.storage.provider.interfaces.ISchemaRepository; import org.apache.http.HttpStatus; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; - -import org.opengroup.osdu.storage.logging.StorageAuditLogger; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.core.common.feature.IFeatureFlag; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.storage.PubSubInfo; import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.storage.SchemaItem; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.storage.logging.StorageAuditLogger; +import org.opengroup.osdu.storage.provider.interfaces.IMessageBus; +import org.opengroup.osdu.storage.provider.interfaces.ISchemaRepository; + +import java.util.ConcurrentModificationException; +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.Silent.class) public class SchemaServiceImplTest { diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/util/GlobalOtherExceptionMapperTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/util/GlobalOtherExceptionMapperTest.java index 33e7b23d232682ac4337946913b4a9db9f645217..6e540972e0c72ec9659cfe61c1c4b8c781b40e48 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/util/GlobalOtherExceptionMapperTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/util/GlobalOtherExceptionMapperTest.java @@ -4,14 +4,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; - import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.model.http.AppError; import org.opengroup.osdu.core.common.model.http.AppException; import org.springframework.http.ResponseEntity; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/util/RecordBlocksTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/util/RecordBlocksTest.java index a700a31cb01008ee0d295a34fd62518c9b2e3eda..d53987d79ba20f71c6b4a35901bf0361e4f5636b 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/util/RecordBlocksTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/util/RecordBlocksTest.java @@ -17,23 +17,13 @@ import org.opengroup.osdu.core.common.model.entitlements.Groups; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.legal.Legal; import org.opengroup.osdu.core.common.model.storage.Record; -import org.opengroup.osdu.core.common.model.storage.RecordAncestry; -import org.opengroup.osdu.core.common.model.storage.RecordData; -import org.opengroup.osdu.core.common.model.storage.RecordMetadata; -import org.opengroup.osdu.core.common.model.storage.RecordProcessing; -import org.opengroup.osdu.core.common.model.storage.RecordState; +import org.opengroup.osdu.core.common.model.storage.*; import org.opengroup.osdu.storage.provider.interfaces.ICloudStorage; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.*; @RunWith(MockitoJUnitRunner.Silent.class) public class RecordBlocksTest { diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java index bbfe5543ddfd7289f3125a190399f8c9e1a00408..b5383fd659dd8c08d6d3e4f8476cd25e90eb9430 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java @@ -14,16 +14,6 @@ package org.opengroup.osdu.storage.validation; -import static java.util.Collections.singletonList; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; -import static org.opengroup.osdu.storage.util.TestUtils.buildAppExceptionMatcher; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; - import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -38,6 +28,14 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.storage.PatchOperation; import org.opengroup.osdu.storage.validation.impl.MetadataPatchValidator; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.mockito.Mockito.*; +import static org.opengroup.osdu.storage.util.TestUtils.buildAppExceptionMatcher; + @RunWith(MockitoJUnitRunner.class) public class MetadataPatchValidatorTest { @@ -114,7 +112,7 @@ public class MetadataPatchValidatorTest { validator.validateTags(singletonList(patchOperation)); - verifyZeroInteractions(legalService, entitlementsAndCacheService, headers); + verifyNoMoreInteractions(legalService, entitlementsAndCacheService, headers); } @Test @@ -124,7 +122,7 @@ public class MetadataPatchValidatorTest { validator.validateTags(singletonList(patchOperation)); - verifyZeroInteractions(legalService, entitlementsAndCacheService, headers); + verifyNoMoreInteractions(legalService, entitlementsAndCacheService, headers); } private PatchOperation buildPatchOperation(String path, String[] value) { diff --git a/testing/pom.xml b/testing/pom.xml index f8af0515d605cc05d5b8a77dca298756e657ac2c..3fab6dce589a150e48cd28d66f1e3f4bcffef7f8 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -39,6 +39,9 @@ </modules> <properties> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <java.version>17</java.version> <log4j.version>2.17.1</log4j.version> <jackson.version>2.13.2</jackson.version> <jackson-databind.version>2.13.2.2</jackson-databind.version> diff --git a/testing/storage-test-aws/pom.xml b/testing/storage-test-aws/pom.xml index e77678b2edf7d336e6924ff5b5b4de65a853e4ab..461ded37a7b6bda41f3b80f8faeb01b9ea32c6a2 100644 --- a/testing/storage-test-aws/pom.xml +++ b/testing/storage-test-aws/pom.xml @@ -30,8 +30,9 @@ <packaging>jar</packaging> <properties> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <java.version>17</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.main.basedir>${project.basedir}</project.main.basedir> </properties> @@ -80,7 +81,7 @@ <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> - <version>2.9.1</version> + <version>2.10.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> diff --git a/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java b/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java index 7a20b9f38c96b53501e3d6a41051b5cf7d34247e..e5a1fb4503253c4f55a9d8969425a53ff94b157c 100644 --- a/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java +++ b/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java @@ -15,19 +15,10 @@ package org.opengroup.osdu.storage.records; -import com.sun.jersey.api.client.ClientResponse; - +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opengroup.osdu.storage.util.AWSTestUtils; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; +import org.junit.*; +import org.opengroup.osdu.storage.util.*; public class TestIngestRecordNotFound extends IngestRecordNotFoundTest { @@ -62,7 +53,7 @@ public class TestIngestRecordNotFound extends IngestRecordNotFoundTest { String group = String.format("data.thisDataGrpDoesNotExsist@%s", TestUtils.getAclSuffix()); String record = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG).replace(TestUtils.getAcl(), group); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); // it's a much simpler implementation to just check if the user is in the group that is being saved and if not to skip // per previous integration test requirements TestUtils.getResult(response, HttpStatus.SC_FORBIDDEN, String.class); diff --git a/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java b/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java index 04b3e1abea3da0415f9a3fdbe1c027e521269326..0b9f7e3322b1a61303e516b0f3cb01fa397415bf 100644 --- a/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java +++ b/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java @@ -15,14 +15,14 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - +import com.google.gson.Gson; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.junit.*; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; -import com.google.gson.Gson; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; @@ -61,10 +61,10 @@ public class TestRecordsApiAcceptance extends RecordsApiAcceptanceTests { String jsonInput = createJsonBody(RECORD_ID, "TestSpecialCharacters"); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - String json = response.getEntity(String.class); - assertEquals(201, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + String json = EntityUtils.toString(response.getEntity()); + assertEquals(201, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); Gson gson = new Gson(); DummyRecordsHelper.CreateRecordResponse result = gson.fromJson(json, diff --git a/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/util/SchemaUtil.java b/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/util/SchemaUtil.java index c0038e14e9a8df00e8779c0658ad6d26ebd20207..ae7bd9fe18284cb80c050cb377e63a67f89bb911 100644 --- a/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/util/SchemaUtil.java +++ b/testing/storage-test-aws/src/test/java/org/opengroup/osdu/storage/util/SchemaUtil.java @@ -15,18 +15,18 @@ package org.opengroup.osdu.storage.util; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; public class SchemaUtil { protected final String schema = TenantUtils.getTenantName() + ":storage:inttest:1.0.0" + System.currentTimeMillis(); - public static ClientResponse create(String kind, String token) throws Exception { + public static CloseableHttpResponse create(String kind, String token) throws Exception { return TestUtils.send("schemas", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), SchemaUtil.validSchemaPostBody(kind), ""); } - public static ClientResponse delete(String kind, String token) throws Exception { + public static CloseableHttpResponse delete(String kind, String token) throws Exception { return TestUtils.send("schemas/" + kind, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), "", ""); } diff --git a/testing/storage-test-azure/pom.xml b/testing/storage-test-azure/pom.xml index 2658e3b92d2c9fe2f9b8907fe9389c62f8aee3a3..1600a37a5cffa89e7eb9ebbab00a78ad31a70736 100644 --- a/testing/storage-test-azure/pom.xml +++ b/testing/storage-test-azure/pom.xml @@ -31,8 +31,9 @@ <packaging>jar</packaging> <properties> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <java.version>17</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.main.basedir>${project.basedir}</project.main.basedir> <jackson.version>2.10.1</jackson.version> @@ -121,7 +122,14 @@ </includes> </configuration> </execution> - </executions> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-junit47</artifactId> + <version>${maven-surefire-plugin.version}</version> + </dependency> + </dependencies> <configuration> <trimStackTrace>false</trimStackTrace> </configuration> diff --git a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java index f324623364765aafb14a1c2f3736154577ab5667..440b59fae4436acb5719894893d39f7252ec8d60 100644 --- a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java +++ b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java @@ -14,29 +14,19 @@ package org.opengroup.osdu.storage.query; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; +import org.junit.*; +import org.opengroup.osdu.storage.util.*; import java.util.List; import java.util.Map; import java.util.UUID; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.sun.jersey.api.client.ClientResponse; - -import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opengroup.osdu.storage.util.AzureTestUtils; -import org.opengroup.osdu.storage.util.DummyRecordsHelper; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegrationTests { @@ -70,8 +60,8 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration public void should_returnConvertedRecords_whenConversionRequiredAndNoError() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithReference(2, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -82,9 +72,9 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -94,10 +84,10 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(3, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); - ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse2.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); + CloseableHttpResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse2.getCode()); } @Override @@ -105,8 +95,8 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration public void should_returnOriginalRecordsAndConversionStatusAsNoMeta_whenConversionRequiredAndNoMetaBlockInRecord() throws Exception{ String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordNoMetaBlock(2, recordId, KIND, LEGAL_TAG); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -118,9 +108,9 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -130,10 +120,10 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(3, responseObject.records[0].data.size()); List<DummyRecordsHelper.RecordStatusMock> conversionStatuses = responseObject.conversionStatuses; - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); - ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse2.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); + CloseableHttpResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse2.getCode()); } @Override @@ -141,8 +131,8 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration public void should_returnRecordsAndConversionStatus_whenConversionRequiredAndConversionErrorExists() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordMissingValue(2, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -153,9 +143,9 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -164,10 +154,10 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration assertEquals(KIND, responseObject.records[0].kind); assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(2, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); - ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse2.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); + CloseableHttpResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse2.getCode()); } @Override @@ -175,8 +165,8 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration public void should_returnRecordsAndConversionStatus_whenConversionRequiredAndNestedPropertyProvidedInMetaBlock() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithNestedProperty(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -186,9 +176,9 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); diff --git a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java index ff9d682976da273f29acf3fc5c83637145e08f59..901f06cb9b685efa46345110a1c37e77499f3470 100644 --- a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java +++ b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java @@ -14,19 +14,10 @@ package org.opengroup.osdu.storage.records; -import com.sun.jersey.api.client.ClientResponse; - +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opengroup.osdu.storage.util.AzureTestUtils; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; +import org.junit.*; +import org.opengroup.osdu.storage.util.*; public class TestIngestRecordNotFound extends IngestRecordNotFoundTest { @@ -62,7 +53,7 @@ public class TestIngestRecordNotFound extends IngestRecordNotFoundTest { String record = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG).replace(TestUtils.getAcl(), group); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); // blob storage doesn't have blob level access per user. User has to have at least viewer access // TestUtils.getResult(response, HttpStatus.SC_FORBIDDEN, String.class); diff --git a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java index 1cf5c2514fb3cdd67553699f496c5362db21a034..cc677b6036c12ece10e20a2c12430d105646d4ec 100644 --- a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java +++ b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java @@ -16,7 +16,8 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.*; import org.opengroup.osdu.storage.util.AzureTestUtils; @@ -60,10 +61,10 @@ public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTest Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", headers, "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", headers, "", ""); - assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + assertEquals(HttpStatus.SC_FORBIDDEN, response.getCode()); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); assertEquals(403, json.get("code").getAsInt()); assertEquals("Access denied", json.get("reason").getAsString()); assertEquals("The user is not authorized to perform this action", json.get("message").getAsString()); diff --git a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java index 3557f61b87618a1af34275a6f5f868e2e5f05a18..1905acd11af4d0a48fb5d097c40943495ffe6574 100644 --- a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java +++ b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java @@ -16,7 +16,7 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.junit.*; import org.opengroup.osdu.storage.util.*; @@ -55,21 +55,21 @@ public class TestRecordsApiAcceptance extends RecordsApiAcceptanceTests { final String RECORDID_2 = TenantUtils.getTenantName() + ":marker:hij-osdu-dev-sis-internal-hq-techlog--A52C-4031-99D1---124CBB92-8C80-4668-BB48-1329C5FE241C--9"; String jsonInput = "[" + singleEntityBody(RECORDID_1, "TestCreation", KIND, LEGAL_TAG) + "," + singleEntityBody(RECORDID_2, "TestCreation", KIND, LEGAL_TAG) + "]"; - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, response.getStatus()); + assertEquals(201, response.getCode()); response = TestUtils.send("records/" + RECORDID_1, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); String responseString = TestUtils.getResult(response, 200, String.class); - JsonObject responseJson = new JsonParser().parse(responseString).getAsJsonObject(); + JsonObject responseJson = JsonParser.parseString(responseString).getAsJsonObject(); - assertEquals(200, response.getStatus()); + assertEquals(200, response.getCode()); assertEquals(RECORDID_1, responseJson.get("id").getAsString()); response = TestUtils.send("records/" + RECORDID_2, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); responseString = TestUtils.getResult(response, 200, String.class); - responseJson = new JsonParser().parse(responseString).getAsJsonObject(); - assertEquals(200, response.getStatus()); + responseJson = JsonParser.parseString(responseString).getAsJsonObject(); + assertEquals(200, response.getCode()); assertEquals(RECORDID_2, responseJson.get("id").getAsString()); } } \ No newline at end of file diff --git a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/util/DeliveryTestUtils.java b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/util/DeliveryTestUtils.java index d34dffd3e34da8de931644404a5dda10c3efae38..1950923e4e0500160991c1b1dfe097171d90de6b 100644 --- a/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/util/DeliveryTestUtils.java +++ b/testing/storage-test-azure/src/test/java/org/opengroup/osdu/storage/util/DeliveryTestUtils.java @@ -16,22 +16,16 @@ package org.opengroup.osdu.storage.util; import com.azure.identity.ClientSecretCredential; import com.azure.identity.ClientSecretCredentialBuilder; -import com.azure.storage.blob.*; - -import com.azure.storage.blob.specialized.BlockBlobClient; import com.azure.storage.blob.BlobContainerClient; +import com.azure.storage.blob.BlobContainerClientBuilder; +import com.azure.storage.blob.BlobUrlParts; +import com.azure.storage.blob.specialized.BlockBlobClient; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; -import org.apache.http.HttpStatus; import java.io.ByteArrayInputStream; import java.util.HashMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class DeliveryTestUtils { @@ -133,35 +127,6 @@ public class DeliveryTestUtils { return schema.toString(); } - public static void assertEqualsResponse(ClientResponse response, int expectedProcessed, int expectedUnprocessed) { - assertEquals(200, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); - - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); - JsonObject processedJson = json.get("processed").getAsJsonObject(); - JsonArray unprocessedJson = json.get("unprocessed").getAsJsonArray(); - - assertEquals(expectedProcessed, processedJson.size()); - assertEquals(expectedUnprocessed, unprocessedJson.size()); - } - - public static boolean IndexedDocumentsExist(ClientResponse response, Integer expectedProcessed) { - assertEquals(200, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); - - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); - JsonObject processedJson = json.get("processed").getAsJsonObject(); - return processedJson.size() == expectedProcessed; - } - - public static void assertNotAuthorized(ClientResponse response) { - assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); - assertEquals(403, json.get("code").getAsInt()); - assertEquals("Access denied", json.get("reason").getAsString()); - assertEquals("The user is not authorized to perform this action", json.get("message").getAsString()); - } - public static void deleteTestBlobs() { DeliveryTestUtils.deleteContainer(generateContainerPath(storageAccount, containerName)); for (String otherContainerName : CONTAINER_NAMES) { diff --git a/testing/storage-test-azure/src/test/resources/logback-test.xml b/testing/storage-test-azure/src/test/resources/logback-test.xml new file mode 100644 index 0000000000000000000000000000000000000000..22c6175d45f368b69c4006deb9ebf3ff5084579a --- /dev/null +++ b/testing/storage-test-azure/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/defaults.xml"/> + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) %n</pattern> + <charset>utf8</charset> + </encoder> + </appender> + <root level="INFO"> + <appender-ref ref="CONSOLE" /> + </root> +</configuration> diff --git a/testing/storage-test-baremetal/pom.xml b/testing/storage-test-baremetal/pom.xml index ea50b5d330b3d85a711e0a5f1dbcffc20b90393c..68b13c39e65a0aa45b35655d917395d2e0cf8a01 100644 --- a/testing/storage-test-baremetal/pom.xml +++ b/testing/storage-test-baremetal/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - ~ Copyright 2020-2022 Google LLC - ~ Copyright 2020-2022 EPAM Systems, Inc + ~ 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. @@ -31,8 +31,9 @@ <packaging>jar</packaging> <properties> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <java.version>17</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.main.basedir>${project.basedir}</project.main.basedir> </properties> diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java index ec3e3ff71ea70cd5d1581b1a67bff9be35383fd6..157bdfca36b15d0cd192c595528f4127718da4e2 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java @@ -1,92 +1,109 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.PubsubEndpoint; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; +import org.junit.*; +import org.opengroup.osdu.storage.util.*; + import java.util.ArrayList; import java.util.List; -import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.opengroup.osdu.storage.util.AnthosTestUtils; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; public class TestPubsubEndpoint extends PubsubEndpointTest { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - @BeforeClass - public static void classSetup() throws Exception { - PubsubEndpointTest.classSetup(ANTHOS_TEST_UTILS.getToken()); - } + @BeforeClass + public static void classSetup() throws Exception { + PubsubEndpointTest.classSetup(ANTHOS_TEST_UTILS.getToken()); + } - @AfterClass - public static void classTearDown() throws Exception { - PubsubEndpointTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } + @AfterClass + public static void classTearDown() throws Exception { + PubsubEndpointTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } - @Override - public void should_deleteIncompliantLegaltagAndInvalidateRecordsAndNotIngestAgain_whenIncompliantMessageSentToEndpoint() throws Exception { - LegalTagUtils.delete(LEGAL_TAG_1, testUtils.getToken()); - // wait until cache of opa will be rebuild - Thread.sleep(100000); + @Override + public void + should_deleteIncompliantLegaltagAndInvalidateRecordsAndNotIngestAgain_whenIncompliantMessageSentToEndpoint() + throws Exception { + LegalTagUtils.delete(LEGAL_TAG_1, testUtils.getToken()); + // wait until cache of opa will be rebuild + Thread.sleep(100000); - List<String> legalTagNames = new ArrayList<>(); - legalTagNames.add(LEGAL_TAG_1); - legalTagNames.add(LEGAL_TAG_2); - //Wait while the Storage service processes the legal tag deleted event - Thread.sleep(1000); - ClientResponse responseRecordQuery = - TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", - ""); - Assert.assertEquals(HttpStatus.SC_NOT_FOUND, responseRecordQuery.getStatus()); + List<String> legalTagNames = new ArrayList<>(); + legalTagNames.add(LEGAL_TAG_1); + legalTagNames.add(LEGAL_TAG_2); + // Wait while the Storage service processes the legal tag deleted event + Thread.sleep(1000); + CloseableHttpResponse responseRecordQuery = + TestUtils.send( + "records/" + RECORD_ID, + "GET", + HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + "", + ""); + Assert.assertEquals(HttpStatus.SC_NOT_FOUND, responseRecordQuery.getCode()); - long now = System.currentTimeMillis(); - long later = now + 2000L; - String recordIdTemp1 = TenantUtils.getTenantName() + ":endtoend:1.1." + now; - String kindTemp = TenantUtils.getTenantName() + ":test:endtoend:1.1." + now; - String recordTemp1 = RecordUtil.createDefaultJsonRecord(recordIdTemp1, kindTemp, LEGAL_TAG_1); - String recordIdTemp2 = TenantUtils.getTenantName() + ":endtoend:1.1." + later; - String recordTemp2 = RecordUtil.createDefaultJsonRecord(recordIdTemp2, kindTemp, LEGAL_TAG_2); + long now = System.currentTimeMillis(); + long later = now + 2000L; + String recordIdTemp1 = TenantUtils.getTenantName() + ":endtoend:1.1." + now; + String kindTemp = TenantUtils.getTenantName() + ":test:endtoend:1.1." + now; + String recordTemp1 = RecordUtil.createDefaultJsonRecord(recordIdTemp1, kindTemp, LEGAL_TAG_1); + String recordIdTemp2 = TenantUtils.getTenantName() + ":endtoend:1.1." + later; + String recordTemp2 = RecordUtil.createDefaultJsonRecord(recordIdTemp2, kindTemp, LEGAL_TAG_2); - ClientResponse responseInvalid = - TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp1, ""); - Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, responseInvalid.getStatus()); - Assert.assertEquals("Invalid legal tags", this.getResponseReasonFromRecordIngestResponse(responseInvalid)); - ClientResponse responseValid3 = - TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp2, ""); - Assert.assertEquals(HttpStatus.SC_CREATED, responseValid3.getStatus()); - TestUtils.send("records/" + recordIdTemp2, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - } + CloseableHttpResponse responseInvalid = + TestUtils.send( + "records", + "PUT", + HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + recordTemp1, + ""); + Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, responseInvalid.getCode()); + Assert.assertEquals( + "Invalid legal tags", this.getResponseReasonFromRecordIngestResponse(responseInvalid)); + CloseableHttpResponse responseValid3 = + TestUtils.send( + "records", + "PUT", + HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + recordTemp2, + ""); + Assert.assertEquals(HttpStatus.SC_CREATED, responseValid3.getCode()); + TestUtils.send( + "records/" + recordIdTemp2, + "DELETE", + HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + "", + ""); + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/legal/TestPopulateLegalInfoFromParentRecords.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/legal/TestPopulateLegalInfoFromParentRecords.java index 32731109dd771281818056c656d1cb43a3d8feae..116ca713b7269e5e3bd7f44b707e8ec11bb7b686 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/legal/TestPopulateLegalInfoFromParentRecords.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/legal/TestPopulateLegalInfoFromParentRecords.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.legal; @@ -20,30 +23,30 @@ import org.junit.Before; import org.junit.BeforeClass; import org.opengroup.osdu.storage.util.AnthosTestUtils; -public class TestPopulateLegalInfoFromParentRecords extends PopulateLegalInfoFromParentRecordsTests { - - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - PopulateLegalInfoFromParentRecordsTests.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - PopulateLegalInfoFromParentRecordsTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } - -} \ No newline at end of file +public class TestPopulateLegalInfoFromParentRecords + extends PopulateLegalInfoFromParentRecordsTests { + + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + PopulateLegalInfoFromParentRecordsTests.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + PopulateLegalInfoFromParentRecordsTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStorageCors.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStorageCors.java index 503c22c3999a5dedfa40e2cc8631346d9a514c63..08962abb6c629d61911532b4a113df7a6a1e0551 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStorageCors.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStorageCors.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.misc; @@ -20,15 +23,15 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestStorageCors extends StorageCorsTests { - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStress.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStress.java index 7201bb3a7631b407a123598d00bb589e17f41d3a..8e4b366825593741e3b33da78d5de70fc3cec4d4 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStress.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/misc/TestStress.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.misc; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestStress extends StressTests { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - StressTests.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - StressTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + StressTests.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + StressTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryInfoIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryInfoIntegration.java index e5d0f65f450e738f46647d66069193d0cf4661ca..1a7b2babfedac1d00e2350327017c65c5e3e3515 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryInfoIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryInfoIntegration.java @@ -1,3 +1,20 @@ +/* + * 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 + * + * https://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.storage.query; import org.junit.After; @@ -8,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestGetQueryInfoIntegration extends GetQueryInfoIntegrationTest { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - GetQueryRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - GetQueryRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + GetQueryRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + GetQueryRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryKindsIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryKindsIntegration.java index 7fcae00912c61c3a4a95d375f5d44cf948eb8bfe..9811666be172137cca691357b855bfe3fe62044a 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryKindsIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryKindsIntegration.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.query; @@ -20,15 +23,15 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestGetQueryKindsIntegration extends GetQueryKindsIntegrationTests { - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryRecordsIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryRecordsIntegration.java index 415fd0fc638f6e6ca3047c80199c8a0cf04ea0df..9d13c5e5b38ff0e879825048b96c7a44ad5f2cb6 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryRecordsIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestGetQueryRecordsIntegration.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.query; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestGetQueryRecordsIntegration extends GetQueryRecordsIntegrationTest { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - GetQueryRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - GetQueryRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + GetQueryRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + GetQueryRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java index 6d0337110719738f171860025aafdf706eb77be3..e9b656b4e1064ec382532ce200ac7f071e0a6443 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostFetchRecordsIntegration.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.query; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegrationTests { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - PostFetchRecordsIntegrationTests.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - PostFetchRecordsIntegrationTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + PostFetchRecordsIntegrationTests.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + PostFetchRecordsIntegrationTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostQueryRecordsIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostQueryRecordsIntegration.java index 032e23910614b881080e08581dcc6cf298b6d073..fe0cb7606f582ec59ed31b991c58d793dbb9f297 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostQueryRecordsIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestPostQueryRecordsIntegration.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.query; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestPostQueryRecordsIntegration extends PostQueryRecordsIntegrationTests { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - PostQueryRecordsIntegrationTests.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - PostQueryRecordsIntegrationTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + PostQueryRecordsIntegrationTests.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + PostQueryRecordsIntegrationTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestStorageQuerySuccessful.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestStorageQuerySuccessful.java index e0851bf88e057a26c816b4b9954ca4703951840e..b2c9e918fd76f1f4695682906c986f90ce356c19 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestStorageQuerySuccessful.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/query/TestStorageQuerySuccessful.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.query; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestStorageQuerySuccessful extends StorageQuerySuccessfulTest { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - StorageQuerySuccessfulTest.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - StorageQuerySuccessfulTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + StorageQuerySuccessfulTest.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + StorageQuerySuccessfulTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestDeleteRecordLogicallyAndItsVersions.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestDeleteRecordLogicallyAndItsVersions.java index 842df6301f8690847d5c11102ae5b8a59a3f6fcf..b7bcb561006fada12769d56a502692fe506719a4 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestDeleteRecordLogicallyAndItsVersions.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestDeleteRecordLogicallyAndItsVersions.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -18,19 +21,20 @@ import org.junit.After; import org.junit.Before; import org.opengroup.osdu.storage.util.AnthosTestUtils; -public class TestDeleteRecordLogicallyAndItsVersions extends DeleteRecordLogicallyAndItsVersionsTest { +public class TestDeleteRecordLogicallyAndItsVersions + extends DeleteRecordLogicallyAndItsVersionsTest { - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - super.setup(); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + super.setup(); + } - @After - @Override - public void tearDown() throws Exception { - super.tearDown(); - this.testUtils = null; - } -} \ No newline at end of file + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestGetRecordsIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestGetRecordsIntegration.java index 12166ae0bfe0228151092aed8bd2961658a80889..b7dfcaf327bebc5f769a970bbd70f321c77ed38f 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestGetRecordsIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestGetRecordsIntegration.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -22,28 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestGetRecordsIntegration extends GetRecordsIntegrationTest { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - GetRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - GetRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } - -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + GetRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + GetRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java index c537a60701ea8c69d7a32e85b62715c34228ede7..251bb2db23843e7aac95f98c4e575cc9b915c9f3 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestIngestRecordNotFound extends IngestRecordNotFoundTest { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - IngestRecordNotFoundTest.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - IngestRecordNotFoundTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + IngestRecordNotFoundTest.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + IngestRecordNotFoundTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestLogicalRecordDelete.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestLogicalRecordDelete.java index 34e2fd4867a92688e389546b756f7db007f0eb25..de869ff070573f79e08066b5f448510b4bcd558c 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestLogicalRecordDelete.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestLogicalRecordDelete.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestLogicalRecordDelete extends LogicalRecordDeleteTests { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - LogicalRecordDeleteTests.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - LogicalRecordDeleteTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + LogicalRecordDeleteTests.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + LogicalRecordDeleteTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestPurgeRecordsIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestPurgeRecordsIntegration.java index c1b8338c7b543806d74efe710bc7a79ce24b01c6..a307b852840ebcf2d563060f075d9c7d76211b76 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestPurgeRecordsIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestPurgeRecordsIntegration.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -22,27 +25,27 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestPurgeRecordsIntegration extends PurgeRecordsIntegrationTest { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - PurgeRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - PurgeRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + PurgeRecordsIntegrationTest.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + PurgeRecordsIntegrationTest.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java index 2efcfec92cf2ddbbad27fb26d19850fd241729b9..d08bc81893bc1d53d50a633d4035b05b87610f4f 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java @@ -1,86 +1,92 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; -import static org.junit.Assert.assertEquals; - import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; -import java.util.Map; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import org.opengroup.osdu.storage.util.AnthosTestUtils; -import org.opengroup.osdu.storage.util.ConfigUtils; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; + +import java.util.Map; + +import static org.junit.Assert.assertEquals; public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTests { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - @BeforeClass - public static void classSetup() throws Exception { - RecordAccessAuthorizationTests.classSetup(ANTHOS_TEST_UTILS.getToken()); - } + @BeforeClass + public static void classSetup() throws Exception { + RecordAccessAuthorizationTests.classSetup(ANTHOS_TEST_UTILS.getToken()); + } - @AfterClass - public static void classTearDown() throws Exception { - RecordAccessAuthorizationTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } + @AfterClass + public static void classTearDown() throws Exception { + RecordAccessAuthorizationTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - this.configUtils = new ConfigUtils("test.properties"); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + this.configUtils = new ConfigUtils("test.properties"); + } - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } - @Override - public void should_receiveHttp403_when_userIsNotAuthorizedToUpdateARecord() throws Exception { - boolean opaIntegrationEnabled = Boolean.parseBoolean( - System.getProperty("opa.integration.enabled", - System.getenv("OPA_INTEGRATION_ENABLED"))); - if(!opaIntegrationEnabled){ - super.should_receiveHttp403_when_userIsNotAuthorizedToUpdateARecord(); - }else { - Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), - testUtils.getNoDataAccessToken()); + @Override + public void should_receiveHttp403_when_userIsNotAuthorizedToUpdateARecord() throws Exception { + boolean opaIntegrationEnabled = + Boolean.parseBoolean( + System.getProperty( + "opa.integration.enabled", System.getenv("OPA_INTEGRATION_ENABLED"))); + if (!opaIntegrationEnabled) { + super.should_receiveHttp403_when_userIsNotAuthorizedToUpdateARecord(); + } else { + Map<String, String> headers = + HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records", "PUT", headers, - RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), ""); + CloseableHttpResponse response = + TestUtils.send( + "records", + "PUT", + headers, + RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), + ""); - assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatus()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)) - .getAsJsonObject(); - assertEquals(401, json.get("code").getAsInt()); - assertEquals("Error from compliance service", json.get("reason").getAsString()); - assertEquals( - "Legal response 401 {\"code\":401,\"reason\":\"Unauthorized\",\"message\":\"The user is not authorized to perform this action\"}", - json.get("message").getAsString()); - } + assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode()); + JsonObject json = + JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); + assertEquals(401, json.get("code").getAsInt()); + assertEquals("Error from compliance service", json.get("reason").getAsString()); + assertEquals( + "Legal response 401 {\"code\":401,\"reason\":\"Unauthorized\",\"message\":\"The user is not authorized to perform this action\"}", + json.get("message").getAsString()); } + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordWithNullField.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordWithNullField.java index a8fa3c2aaeac6a39c8b7b911bdeba5b339c68585..f516ce543aeaa2e432d78099bbfe86690c8db13b 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordWithNullField.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordWithNullField.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -20,18 +23,17 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestRecordWithNullField extends RecordWithNullFieldTest { - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - super.setup(); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + super.setup(); + } - @After - @Override - public void tearDown() throws Exception { - super.tearDown(); - this.testUtils = null; - } - -} \ No newline at end of file + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java index 292e7945527c0e55a12af2a39f40bbe2d2023bbd..6ccc37cb63c41d66973317c9c16a0c343995b1f7 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestRecordsApiAcceptance.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -23,29 +26,28 @@ import org.opengroup.osdu.storage.util.ConfigUtils; public class TestRecordsApiAcceptance extends RecordsApiAcceptanceTests { - private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); - - @BeforeClass - public static void classSetup() throws Exception { - RecordsApiAcceptanceTests.classSetup(ANTHOS_TEST_UTILS.getToken()); - } - - @AfterClass - public static void classTearDown() throws Exception { - RecordsApiAcceptanceTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); - } - - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - this.configUtils = new ConfigUtils("test.properties"); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } - -} \ No newline at end of file + private static final AnthosTestUtils ANTHOS_TEST_UTILS = new AnthosTestUtils(); + + @BeforeClass + public static void classSetup() throws Exception { + RecordsApiAcceptanceTests.classSetup(ANTHOS_TEST_UTILS.getToken()); + } + + @AfterClass + public static void classTearDown() throws Exception { + RecordsApiAcceptanceTests.classTearDown(ANTHOS_TEST_UTILS.getToken()); + } + + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + this.configUtils = new ConfigUtils("test.properties"); + } + + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestUpdateRecordsMetadata.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestUpdateRecordsMetadata.java index 4e38d3b1f9ece1d00ba2ec895aaa9d5e38e8211f..37a685f4564af62ef570b029f2a876f70a37c2e7 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestUpdateRecordsMetadata.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/records/TestUpdateRecordsMetadata.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.records; @@ -20,17 +23,17 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestUpdateRecordsMetadata extends UpdateRecordsMetadataTest { - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - super.setup(); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + super.setup(); + } - @After - @Override - public void tearDown() throws Exception { - super.tearDown(); - this.testUtils = null; - } + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + this.testUtils = null; + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestCreateSchemaIntegration.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestCreateSchemaIntegration.java index 2d8fcb1ebb235fae4edabbf27ab41b2d00d43671..6c4f34dcaf8b0a88ecae74f239c89fb8b3d260d0 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestCreateSchemaIntegration.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestCreateSchemaIntegration.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.schema; @@ -20,16 +23,15 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestCreateSchemaIntegration extends CreateSchemaIntegrationTests { - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } - -} \ No newline at end of file + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } +} diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestStorageSchemaNegative.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestStorageSchemaNegative.java index fbeafb122d780caf321064e5d781711bdb95586b..00bbc604a644009ffe8201b81ee6ec843a46a4b2 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestStorageSchemaNegative.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/schema/TestStorageSchemaNegative.java @@ -1,16 +1,19 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.schema; @@ -20,16 +23,15 @@ import org.opengroup.osdu.storage.util.AnthosTestUtils; public class TestStorageSchemaNegative extends StorageSchemaNegativeTest { - @Before - @Override - public void setup() throws Exception { - this.testUtils = new AnthosTestUtils(); - } - - @After - @Override - public void tearDown() throws Exception { - this.testUtils = null; - } + @Before + @Override + public void setup() throws Exception { + this.testUtils = new AnthosTestUtils(); + } + @After + @Override + public void tearDown() throws Exception { + this.testUtils = null; + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/AnthosTestUtils.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/AnthosTestUtils.java index f16c076f9e6b5a6bcd02269c67d81a1256b9ca72..2e75ee3cbeaeef803bd6ca8bc1d05af8cbc49dbd 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/AnthosTestUtils.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/AnthosTestUtils.java @@ -1,52 +1,57 @@ -// Copyright 2017-2019, Schlumberger -// -// 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. +/* + * 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 + * + * https://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.storage.util; import com.google.common.base.Strings; + import java.util.Optional; public class AnthosTestUtils extends TestUtils { - private static final OpenIDTokenProvider openIDTokenProvider = new OpenIDTokenProvider(); + private static final OpenIDTokenProvider openIDTokenProvider = new OpenIDTokenProvider(); - public AnthosTestUtils() { - domain = Optional.ofNullable(System.getProperty("GROUP_ID", System.getenv("GROUP_ID"))) - .orElse("group"); - } + public AnthosTestUtils() { + domain = + Optional.ofNullable(System.getProperty("GROUP_ID", System.getenv("GROUP_ID"))) + .orElse("group"); + } - @Override - public synchronized String getToken() throws Exception { - if (Strings.isNullOrEmpty(token)) { - token = openIDTokenProvider.getToken(); - } - return "Bearer " + token; + @Override + public synchronized String getToken() throws Exception { + if (Strings.isNullOrEmpty(token)) { + token = openIDTokenProvider.getToken(); } + return "Bearer " + token; + } - @Override - public synchronized String getNoDataAccessToken() throws Exception { - if (Strings.isNullOrEmpty(noDataAccesstoken)) { - noDataAccesstoken = openIDTokenProvider.getNoAccessToken(); - } - return "Bearer " + noDataAccesstoken; + @Override + public synchronized String getNoDataAccessToken() throws Exception { + if (Strings.isNullOrEmpty(noDataAccesstoken)) { + noDataAccesstoken = openIDTokenProvider.getNoAccessToken(); } + return "Bearer " + noDataAccesstoken; + } - @Override - public String getDataRootUserToken() throws Exception { - if (Strings.isNullOrEmpty(dataRootToken)) { - dataRootToken = openIDTokenProvider.getDataRootToken(); - } - return "Bearer " + dataRootToken; + @Override + public String getDataRootUserToken() throws Exception { + if (Strings.isNullOrEmpty(dataRootToken)) { + dataRootToken = openIDTokenProvider.getDataRootToken(); } + return "Bearer " + dataRootToken; + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/OpenIDTokenProvider.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/OpenIDTokenProvider.java index 20af37c742ce455c7790a90010da6c03a35898e1..6d6ecd7680bde75da0eddfdda1ac1b18ec7944f0 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/OpenIDTokenProvider.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/OpenIDTokenProvider.java @@ -1,6 +1,6 @@ /* - * Copyright 2020-2022 Google LLC - * Copyright 2020-2022 EPAM Systems, Inc + * 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. @@ -17,95 +17,96 @@ package org.opengroup.osdu.storage.util; -import com.nimbusds.oauth2.sdk.AuthorizationGrant; -import com.nimbusds.oauth2.sdk.ClientCredentialsGrant; -import com.nimbusds.oauth2.sdk.ParseException; -import com.nimbusds.oauth2.sdk.Scope; -import com.nimbusds.oauth2.sdk.TokenRequest; -import com.nimbusds.oauth2.sdk.TokenResponse; +import com.nimbusds.oauth2.sdk.*; import com.nimbusds.oauth2.sdk.auth.ClientAuthentication; import com.nimbusds.oauth2.sdk.auth.ClientSecretBasic; import com.nimbusds.oauth2.sdk.auth.Secret; import com.nimbusds.oauth2.sdk.id.ClientID; import com.nimbusds.openid.connect.sdk.OIDCTokenResponseParser; -import java.io.IOException; -import java.net.URI; -import java.util.Objects; import net.minidev.json.JSONObject; import org.opengroup.osdu.storage.util.conf.OpenIDProviderConfig; +import java.io.IOException; +import java.net.URI; +import java.util.Objects; public class OpenIDTokenProvider { - private static final OpenIDProviderConfig openIDProviderConfig = OpenIDProviderConfig.Instance(); - private static final String ID_TOKEN = "id_token"; - private final AuthorizationGrant clientGrant = new ClientCredentialsGrant(); - private final URI tokenEndpointURI; - private final Scope scope; - private final ClientAuthentication clientAuthentication; - private final ClientAuthentication noAccessClientAuthentication; - private final ClientAuthentication dataRootAuthentication; + private static final OpenIDProviderConfig openIDProviderConfig = OpenIDProviderConfig.Instance(); + private static final String ID_TOKEN = "id_token"; + private final AuthorizationGrant clientGrant = new ClientCredentialsGrant(); + private final URI tokenEndpointURI; + private final Scope scope; + private final ClientAuthentication clientAuthentication; + private final ClientAuthentication noAccessClientAuthentication; + private final ClientAuthentication dataRootAuthentication; - public OpenIDTokenProvider() { - this.tokenEndpointURI = openIDProviderConfig.getProviderMetadata().getTokenEndpointURI(); - this.scope = new Scope(openIDProviderConfig.getScopes()); - this.clientAuthentication = - new ClientSecretBasic( - new ClientID(openIDProviderConfig.getClientId()), - new Secret(openIDProviderConfig.getClientSecret()) - ); - this.noAccessClientAuthentication = - new ClientSecretBasic( - new ClientID(openIDProviderConfig.getNoAccessClientId()), - new Secret(openIDProviderConfig.getNoAccessClientSecret()) - ); - this.dataRootAuthentication = - new ClientSecretBasic( - new ClientID(openIDProviderConfig.getDataRootClientId()), - new Secret(openIDProviderConfig.getDataRootClientSecret()) - ); - } + public OpenIDTokenProvider() { + this.tokenEndpointURI = openIDProviderConfig.getProviderMetadata().getTokenEndpointURI(); + this.scope = new Scope(openIDProviderConfig.getScopes()); + this.clientAuthentication = + new ClientSecretBasic( + new ClientID(openIDProviderConfig.getClientId()), + new Secret(openIDProviderConfig.getClientSecret())); + this.noAccessClientAuthentication = + new ClientSecretBasic( + new ClientID(openIDProviderConfig.getNoAccessClientId()), + new Secret(openIDProviderConfig.getNoAccessClientSecret())); + this.dataRootAuthentication = + new ClientSecretBasic( + new ClientID(openIDProviderConfig.getDataRootClientId()), + new Secret(openIDProviderConfig.getDataRootClientSecret())); + } - public String getToken() { - try { - TokenRequest request = new TokenRequest(this.tokenEndpointURI, this.clientAuthentication, this.clientGrant, this.scope); - return requestToken(request); - } catch (ParseException | IOException e) { - throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e); - } + public String getToken() { + try { + TokenRequest request = + new TokenRequest( + this.tokenEndpointURI, this.clientAuthentication, this.clientGrant, this.scope); + return requestToken(request); + } catch (ParseException | IOException e) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e); } + } - public String getNoAccessToken() { - try { - TokenRequest request = new TokenRequest(this.tokenEndpointURI, this.noAccessClientAuthentication, this.clientGrant, this.scope); - return requestToken(request); - } catch (ParseException | IOException e) { - throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e); - } + public String getNoAccessToken() { + try { + TokenRequest request = + new TokenRequest( + this.tokenEndpointURI, + this.noAccessClientAuthentication, + this.clientGrant, + this.scope); + return requestToken(request); + } catch (ParseException | IOException e) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e); } + } - public String getDataRootToken(){ - try { - TokenRequest request = new TokenRequest(this.tokenEndpointURI, this.dataRootAuthentication, this.clientGrant, this.scope); - return requestToken(request); - } catch (ParseException | IOException e) { - throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e); - } + public String getDataRootToken() { + try { + TokenRequest request = + new TokenRequest( + this.tokenEndpointURI, this.dataRootAuthentication, this.clientGrant, this.scope); + return requestToken(request); + } catch (ParseException | IOException e) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables", e); } + } - private String requestToken(TokenRequest tokenRequest) throws ParseException, IOException { + private String requestToken(TokenRequest tokenRequest) throws ParseException, IOException { - TokenResponse parse = OIDCTokenResponseParser.parse(tokenRequest.toHTTPRequest().send()); + TokenResponse parse = OIDCTokenResponseParser.parse(tokenRequest.toHTTPRequest().send()); - if (!parse.indicatesSuccess()) { - throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables"); - } + if (!parse.indicatesSuccess()) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables"); + } - JSONObject jsonObject = parse.toSuccessResponse().toJSONObject(); - String idTokenValue = jsonObject.getAsString(ID_TOKEN); - if (Objects.isNull(idTokenValue) || idTokenValue.isEmpty()) { - throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables"); - } - return idTokenValue; + JSONObject jsonObject = parse.toSuccessResponse().toJSONObject(); + String idTokenValue = jsonObject.getAsString(ID_TOKEN); + if (Objects.isNull(idTokenValue) || idTokenValue.isEmpty()) { + throw new RuntimeException("Unable get credentials from INTEGRATION_TESTER variables"); } + return idTokenValue; + } } diff --git a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/conf/OpenIDProviderConfig.java b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/conf/OpenIDProviderConfig.java index 9aea19e97b9f8ff2dd1bfb16c0ceaf18580f0e81..fe348c8cc666bf5ca1b6fa7ae3c009a7448a5b81 100644 --- a/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/conf/OpenIDProviderConfig.java +++ b/testing/storage-test-baremetal/src/test/java/org/opengroup/osdu/storage/util/conf/OpenIDProviderConfig.java @@ -1,6 +1,6 @@ /* - * Copyright 2020-2022 Google LLC - * Copyright 2020-2022 EPAM Systems, Inc + * 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. @@ -25,95 +25,104 @@ import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata; public class OpenIDProviderConfig { - public static final String TEST_OPENID_PROVIDER_CLIENT_ID = "TEST_OPENID_PROVIDER_CLIENT_ID"; - public static final String TEST_OPENID_PROVIDER_CLIENT_SECRET = "TEST_OPENID_PROVIDER_CLIENT_SECRET"; - public static final String TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID = "TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID"; - public static final String TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET = "TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET"; - public static final String DATA_ROOT_OPENID_PROVIDER_CLIENT_ID = "DATA_ROOT_OPENID_PROVIDER_CLIENT_ID"; - public static final String DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET = "DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET"; - public static final String TEST_OPENID_PROVIDER_URL = "TEST_OPENID_PROVIDER_URL"; - - private String clientId; - private String clientSecret; - private String noAccessClientId; - private String noAccessClientSecret; - private String dataRootClientId; - private String dataRootClientSecret; - private String url; - private final String[] scopes = {"openid"}; - private static final OpenIDProviderConfig openIDProviderConfig = new OpenIDProviderConfig(); - private static OIDCProviderMetadata providerMetadata; - - public static OpenIDProviderConfig Instance() { - try { - openIDProviderConfig.clientId = - System.getProperty(TEST_OPENID_PROVIDER_CLIENT_ID, - System.getenv(TEST_OPENID_PROVIDER_CLIENT_ID)); - - openIDProviderConfig.clientSecret = - System.getProperty(TEST_OPENID_PROVIDER_CLIENT_SECRET, - System.getenv(TEST_OPENID_PROVIDER_CLIENT_SECRET)); - - openIDProviderConfig.noAccessClientId = - System.getProperty(TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID, - System.getenv(TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID)); - - openIDProviderConfig.noAccessClientSecret = - System.getProperty(TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET, - System.getenv(TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET)); - - openIDProviderConfig.url = - System.getProperty(TEST_OPENID_PROVIDER_URL, - System.getenv(TEST_OPENID_PROVIDER_URL)); - - openIDProviderConfig.dataRootClientId = - System.getProperty(DATA_ROOT_OPENID_PROVIDER_CLIENT_ID, - System.getenv(DATA_ROOT_OPENID_PROVIDER_CLIENT_ID)); - - openIDProviderConfig.dataRootClientSecret = - System.getProperty(DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET, - System.getenv(DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET)); - - Issuer issuer = new Issuer(openIDProviderConfig.url); - OIDCProviderConfigurationRequest request = new OIDCProviderConfigurationRequest(issuer); - HTTPRequest httpRequest = request.toHTTPRequest(); - HTTPResponse httpResponse = httpRequest.send(); - providerMetadata = OIDCProviderMetadata.parse(httpResponse.getContentAsJSONObject()); - } catch (Exception e) { - throw new RuntimeException("Malformed token provider configuration", e); - } - return openIDProviderConfig; + public static final String TEST_OPENID_PROVIDER_CLIENT_ID = "TEST_OPENID_PROVIDER_CLIENT_ID"; + public static final String TEST_OPENID_PROVIDER_CLIENT_SECRET = + "TEST_OPENID_PROVIDER_CLIENT_SECRET"; + public static final String TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID = + "TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID"; + public static final String TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET = + "TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET"; + public static final String DATA_ROOT_OPENID_PROVIDER_CLIENT_ID = + "DATA_ROOT_OPENID_PROVIDER_CLIENT_ID"; + public static final String DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET = + "DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET"; + public static final String TEST_OPENID_PROVIDER_URL = "TEST_OPENID_PROVIDER_URL"; + + private String clientId; + private String clientSecret; + private String noAccessClientId; + private String noAccessClientSecret; + private String dataRootClientId; + private String dataRootClientSecret; + private String url; + private final String[] scopes = {"openid"}; + private static final OpenIDProviderConfig openIDProviderConfig = new OpenIDProviderConfig(); + private static OIDCProviderMetadata providerMetadata; + + public static OpenIDProviderConfig Instance() { + try { + openIDProviderConfig.clientId = + System.getProperty( + TEST_OPENID_PROVIDER_CLIENT_ID, System.getenv(TEST_OPENID_PROVIDER_CLIENT_ID)); + + openIDProviderConfig.clientSecret = + System.getProperty( + TEST_OPENID_PROVIDER_CLIENT_SECRET, + System.getenv(TEST_OPENID_PROVIDER_CLIENT_SECRET)); + + openIDProviderConfig.noAccessClientId = + System.getProperty( + TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID, + System.getenv(TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID)); + + openIDProviderConfig.noAccessClientSecret = + System.getProperty( + TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET, + System.getenv(TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET)); + + openIDProviderConfig.url = + System.getProperty(TEST_OPENID_PROVIDER_URL, System.getenv(TEST_OPENID_PROVIDER_URL)); + + openIDProviderConfig.dataRootClientId = + System.getProperty( + DATA_ROOT_OPENID_PROVIDER_CLIENT_ID, + System.getenv(DATA_ROOT_OPENID_PROVIDER_CLIENT_ID)); + + openIDProviderConfig.dataRootClientSecret = + System.getProperty( + DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET, + System.getenv(DATA_ROOT_OPENID_PROVIDER_CLIENT_SECRET)); + + Issuer issuer = new Issuer(openIDProviderConfig.url); + OIDCProviderConfigurationRequest request = new OIDCProviderConfigurationRequest(issuer); + HTTPRequest httpRequest = request.toHTTPRequest(); + HTTPResponse httpResponse = httpRequest.send(); + providerMetadata = OIDCProviderMetadata.parse(httpResponse.getContentAsJSONObject()); + } catch (Exception e) { + throw new RuntimeException("Malformed token provider configuration", e); } + return openIDProviderConfig; + } - public String getClientId() { - return clientId; - } + public String getClientId() { + return clientId; + } - public String getClientSecret() { - return clientSecret; - } + public String getClientSecret() { + return clientSecret; + } - public String getNoAccessClientId() { - return noAccessClientId; - } + public String getNoAccessClientId() { + return noAccessClientId; + } - public String getNoAccessClientSecret() { - return noAccessClientSecret; - } + public String getNoAccessClientSecret() { + return noAccessClientSecret; + } - public String[] getScopes() { - return scopes; - } + public String[] getScopes() { + return scopes; + } - public OIDCProviderMetadata getProviderMetadata() { - return providerMetadata; - } + public OIDCProviderMetadata getProviderMetadata() { + return providerMetadata; + } - public String getDataRootClientId() { - return dataRootClientId; - } + public String getDataRootClientId() { + return dataRootClientId; + } - public String getDataRootClientSecret() { - return dataRootClientSecret; - } + public String getDataRootClientSecret() { + return dataRootClientSecret; + } } diff --git a/testing/storage-test-core/pom.xml b/testing/storage-test-core/pom.xml index 5c0b638f50831e8a22907ab1058c4ee24f63f80f..7a60ad17bbc0acc3d841f8b62f31274beb256dde 100644 --- a/testing/storage-test-core/pom.xml +++ b/testing/storage-test-core/pom.xml @@ -22,17 +22,20 @@ <relativePath>../pom.xml</relativePath> </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>org.opengroup.osdu.storage</groupId> - <artifactId>storage-test-core</artifactId> - <version>0.23.0-SNAPSHOT</version> - <packaging>jar</packaging> - <properties> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.main.basedir>${project.basedir}</project.main.basedir> - </properties> + <modelVersion>4.0.0</modelVersion> + <groupId>org.opengroup.osdu.storage</groupId> + <artifactId>storage-test-core</artifactId> + <version>0.23.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <java.version>17</java.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.main.basedir>${project.basedir}</project.main.basedir> + </properties> + <dependencies> <dependency> <groupId>com.sun.jersey</groupId> @@ -53,8 +56,7 @@ <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> - <version>1.18.10</version> - <scope>provided</scope> + <version>1.18.26</version> </dependency> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> @@ -73,6 +75,11 @@ <version>0.22.0</version> <scope>compile</scope> </dependency> + <dependency> + <groupId>org.apache.httpcomponents.client5</groupId> + <artifactId>httpclient5</artifactId> + <version>5.2.1</version> + </dependency> </dependencies> diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/PubsubEndpoint/PubsubEndpointTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/PubsubEndpoint/PubsubEndpointTest.java index 25f91171b1ff5e9917055162bd76423bcb89867e..12db425def5b375e40d22de80a20d1659ee97c89 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/PubsubEndpoint/PubsubEndpointTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/PubsubEndpoint/PubsubEndpointTest.java @@ -14,18 +14,21 @@ package org.opengroup.osdu.storage.PubsubEndpoint; -import java.util.ArrayList; -import java.util.Base64; -import java.util.List; - -import org.apache.http.HttpStatus; -import org.junit.*; - import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.http.HttpStatus; +import org.junit.Assert; +import org.junit.Test; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Base64; +import java.util.List; public abstract class PubsubEndpointTest extends TestBase { protected static final long NOW = System.currentTimeMillis(); @@ -42,13 +45,13 @@ public abstract class PubsubEndpointTest extends TestBase { public static void classSetup(String token) throws Exception { LegalTagUtils.create(LEGAL_TAG_1, token); String record1 = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG_1); - ClientResponse responseValid = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), record1, ""); - Assert.assertEquals(HttpStatus.SC_CREATED, responseValid.getStatus()); + CloseableHttpResponse responseValid = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), record1, ""); + Assert.assertEquals(HttpStatus.SC_CREATED, responseValid.getCode()); LegalTagUtils.create(LEGAL_TAG_2, token); String record2 = RecordUtil.createDefaultJsonRecord(RECORD_ID_2, KIND, LEGAL_TAG_2); - ClientResponse responseValid2 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), record2, ""); - Assert.assertEquals(HttpStatus.SC_CREATED, responseValid2.getStatus()); + CloseableHttpResponse responseValid2 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), record2, ""); + Assert.assertEquals(HttpStatus.SC_CREATED, responseValid2.getCode()); } public static void classTearDown(String token) throws Exception { @@ -71,14 +74,14 @@ public abstract class PubsubEndpointTest extends TestBase { legalTagNames.add(LEGAL_TAG_2); String requestBody = this.requestBodyToEndpoint(legalTagNames); - ClientResponse responseEndpoint = TestUtils.send("push-handlers/legaltag-changed?token=" + PUBSUB_TOKEN, "POST", + CloseableHttpResponse responseEndpoint = TestUtils.send("push-handlers/legaltag-changed?token=" + PUBSUB_TOKEN, "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), requestBody, ""); - System.out.println(" getEntity" + responseEndpoint.getEntity(String.class)); - Assert.assertEquals(HttpStatus.SC_OK, responseEndpoint.getStatus()); + System.out.println(" getEntity" + EntityUtils.toString(responseEndpoint.getEntity())); + Assert.assertEquals(HttpStatus.SC_OK, responseEndpoint.getCode()); System.out.println("ok"); - ClientResponse responseRecordQuery = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", + CloseableHttpResponse responseRecordQuery = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - Assert.assertEquals(HttpStatus.SC_NOT_FOUND, responseRecordQuery.getStatus()); + Assert.assertEquals(HttpStatus.SC_NOT_FOUND, responseRecordQuery.getCode()); long now = System.currentTimeMillis(); long later = now + 2000L; @@ -88,11 +91,11 @@ public abstract class PubsubEndpointTest extends TestBase { String recordIdTemp2 = TenantUtils.getTenantName() + ":endtoend:1.1." + later; String recordTemp2 = RecordUtil.createDefaultJsonRecord(recordIdTemp2, kindTemp, LEGAL_TAG_2); - ClientResponse responseInvalid = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp1, ""); - Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, responseInvalid.getStatus()); + CloseableHttpResponse responseInvalid = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp1, ""); + Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, responseInvalid.getCode()); Assert.assertEquals("Invalid legal tags", this.getResponseReasonFromRecordIngestResponse(responseInvalid)); - ClientResponse responseValid3 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp2, ""); - Assert.assertEquals(HttpStatus.SC_CREATED, responseValid3.getStatus()); + CloseableHttpResponse responseValid3 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp2, ""); + Assert.assertEquals(HttpStatus.SC_CREATED, responseValid3.getCode()); TestUtils.send("records/" + recordIdTemp2, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); } @@ -126,8 +129,15 @@ public abstract class PubsubEndpointTest extends TestBase { return output.toString(); } - protected String getResponseReasonFromRecordIngestResponse(ClientResponse response) { - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + protected String getResponseReasonFromRecordIngestResponse(CloseableHttpResponse response) { + JsonObject json = null; + try { + json = new JsonParser().parse(EntityUtils.toString(response.getEntity())).getAsJsonObject(); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } return json.get("reason").getAsString(); } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/legal/PopulateLegalInfoFromParentRecordsTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/legal/PopulateLegalInfoFromParentRecordsTests.java index 9a3086a6653d8632f38933fafcda015996ec2d3f..c847f4cb996a41218ab113c6df09808f0a69a38e 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/legal/PopulateLegalInfoFromParentRecordsTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/legal/PopulateLegalInfoFromParentRecordsTests.java @@ -14,30 +14,24 @@ package org.opengroup.osdu.storage.legal; -import static org.opengroup.osdu.storage.util.LegalTagUtils.createRandomName; -import static org.apache.http.HttpStatus.SC_BAD_REQUEST; -import static org.apache.http.HttpStatus.SC_CREATED; -import static org.apache.http.HttpStatus.SC_OK; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; -import org.junit.*; - import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import org.opengroup.osdu.storage.util.*; +import io.jsonwebtoken.lang.Collections; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.junit.Test; import org.opengroup.osdu.storage.util.DummyRecordsHelper.CreateRecordResponse; import org.opengroup.osdu.storage.util.DummyRecordsHelper.RecordResultMock; -import com.sun.jersey.api.client.ClientResponse; +import org.opengroup.osdu.storage.util.*; -import io.jsonwebtoken.lang.Collections; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.http.HttpStatus.*; +import static org.junit.Assert.*; +import static org.opengroup.osdu.storage.util.LegalTagUtils.createRandomName; public abstract class PopulateLegalInfoFromParentRecordsTests extends TestBase { @@ -122,35 +116,35 @@ public abstract class PopulateLegalInfoFromParentRecordsTests extends TestBase { Lists.newArrayList(LEGAL_TAG_CHILD_THAT_WILL_NOT_BE_CREATED), Lists.newArrayList("FR", "US", "CA"), null); - ClientResponse response = TestUtils.send("records", "PUT", + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), childBody, ""); - assertEquals(SC_BAD_REQUEST, response.getStatus()); + assertEquals(SC_BAD_REQUEST, response.getCode()); } @Test public void should_return400_when_noParentRecordAndNoChildLegalTagsProvided() throws Exception { String body = createBody(CHILD_ID_THAT_IS_NOT_CREATED, "childname", null, Lists.newArrayList("FR", "US"), null); - ClientResponse response = TestUtils.send("records", "PUT", + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); - assertEquals(SC_BAD_REQUEST, response.getStatus()); + assertEquals(SC_BAD_REQUEST, response.getCode()); } @Test public void should_returnErrorCode400_when_noParentRecordAndNoORDCValuesProvided() throws Exception { String body = createBody(CHILD_ID_THAT_IS_NOT_CREATED, "childname", Lists.newArrayList(LEGAL_TAG_PARENT_ONE), null, null); - ClientResponse response = TestUtils.send("records", "PUT", + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); - assertEquals(SC_BAD_REQUEST, response.getStatus()); + assertEquals(SC_BAD_REQUEST, response.getCode()); } protected RecordResultMock retrieveRecord(String recordId) throws Exception { System.out.println("Retrieving record=" + recordId); - ClientResponse response = TestUtils.send("records/" + recordId, "GET", + CloseableHttpResponse response = TestUtils.send("records/" + recordId, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - String responseBody = response.getEntity(String.class); + String responseBody = EntityUtils.toString(response.getEntity()); System.out.println(" responseBody=" + responseBody); - assertEquals(SC_OK, response.getStatus()); + assertEquals(SC_OK, response.getCode()); return GSON.fromJson(responseBody, RecordResultMock.class); } @@ -210,13 +204,13 @@ public abstract class PopulateLegalInfoFromParentRecordsTests extends TestBase { String parentBody = createBody(parentId, dataValue, Lists.newArrayList(legalTagForParent), ordc, parents); System.out.println("createAndAssertRecord"); System.out.println("parentBody=" + parentId + " " + parentBody); - ClientResponse response = TestUtils.send("records", "PUT", + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), parentBody, ""); - String responseBody = response.getEntity(String.class); + String responseBody = EntityUtils.toString(response.getEntity()); System.out.println("responseBody=" + parentId + " " + responseBody); - assertEquals(SC_CREATED, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + assertEquals(SC_CREATED, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); CreateRecordResponse result = GSON.fromJson(responseBody, CreateRecordResponse.class); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StorageCorsTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StorageCorsTests.java index 49da117d1ba599cce1094e728316386686b82c39..d95ca50a862fee67dd19038c71ce0d3425f2e343 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StorageCorsTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StorageCorsTests.java @@ -14,19 +14,14 @@ package org.opengroup.osdu.storage.misc; -import javax.ws.rs.core.MultivaluedMap; - +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; -import org.junit.Test; import org.junit.Ignore; - +import org.junit.Test; import org.opengroup.osdu.storage.util.HeaderUtils; import org.opengroup.osdu.storage.util.TenantUtils; import org.opengroup.osdu.storage.util.TestBase; import org.opengroup.osdu.storage.util.TestUtils; -import com.sun.jersey.api.client.ClientResponse; - -import java.util.Map; import static org.junit.Assert.*; @@ -35,26 +30,24 @@ public abstract class StorageCorsTests extends TestBase { @Test @Ignore public void should_returnProperStatusCodeAndResponseHeaders_when_sendingPreflightOptionsRequest() throws Exception { - ClientResponse response = TestUtils.send("query/kinds", "OPTIONS", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1"); - assertEquals(HttpStatus.SC_OK, response.getStatus()); - - MultivaluedMap<String, String> headers = response.getHeaders(); + CloseableHttpResponse response = TestUtils.send("query/kinds", "OPTIONS", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1"); + assertEquals(HttpStatus.SC_OK, response.getCode()); - assertEquals("*", headers.get("Access-Control-Allow-Origin").get(0)); + assertEquals("*", response.getHeaders("Access-Control-Allow-Origin")[0]); assertEquals( "origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey", - headers.get("Access-Control-Allow-Headers").get(0)); + response.getHeaders("Access-Control-Allow-Headers")[0]); assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", - headers.get("Access-Control-Allow-Methods").get(0)); - assertEquals("true", headers.get("Access-Control-Allow-Credentials").get(0)); - assertEquals("DENY", headers.get("X-Frame-Options").get(0)); - assertEquals("1; mode=block", headers.get("X-XSS-Protection").get(0)); - assertEquals("nosniff", headers.get("X-Content-Type-Options").get(0)); - assertEquals("no-cache, no-store, must-revalidate", headers.get("Cache-Control").get(0)); - assertEquals("default-src 'self'", headers.get("Content-Security-Policy").get(0)); - assertTrue(headers.get("Strict-Transport-Security").get(0).contains("max-age=31536000")); - assertTrue(headers.get("Strict-Transport-Security").get(0).contains("includeSubDomains")); - assertEquals("0", headers.get("Expires").get(0)); - assertNotNull(headers.get("correlation-id").get(0)); + response.getHeaders("Access-Control-Allow-Methods")[0]); + assertEquals("true", response.getHeaders("Access-Control-Allow-Credentials")[0]); + assertEquals("DENY", response.getHeaders("X-Frame-Options")[0]); + assertEquals("1; mode=block", response.getHeaders("X-XSS-Protection")[0]); + assertEquals("nosniff", response.getHeaders("X-Content-Type-Options")[0]); + assertEquals("no-cache, no-store, must-revalidate", response.getHeaders("Cache-Control")[0]); + assertEquals("default-src 'self'", response.getHeaders("Content-Security-Policy")[0]); + assertTrue(response.getHeaders("Strict-Transport-Security")[0].getValue().contains("max-age=31536000")); + assertTrue(response.getHeaders("Strict-Transport-Security")[0].getValue().contains("includeSubDomains")); + assertEquals("0", response.getHeaders("Expires")[0]); + assertNotNull(response.getHeaders("correlation-id")[0]); } } \ No newline at end of file diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StressTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StressTests.java index b6e008d36a8d0fce32da031ddd59b167c2f8722a..6a0ab68ce8479c9acc059523e3794ba949bcd00b 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StressTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/StressTests.java @@ -14,18 +14,18 @@ package org.opengroup.osdu.storage.misc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import com.google.gson.Gson; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.junit.Test; +import org.opengroup.osdu.storage.records.RecordsApiAcceptanceTests; +import org.opengroup.osdu.storage.util.*; import java.util.ArrayList; import java.util.List; -import org.junit.*; - -import com.google.gson.Gson; -import org.opengroup.osdu.storage.records.RecordsApiAcceptanceTests; -import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public abstract class StressTests extends TestBase { @@ -76,14 +76,14 @@ public abstract class StressTests extends TestBase { json = "[" + json + "]"; long startMillis = System.currentTimeMillis(); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), json, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), json, ""); long totalMillis = System.currentTimeMillis() - startMillis; System.out.println(String.format("Took %s milliseconds to Create %s 1KB records", totalMillis, ids.size())); - String responseJson = response.getEntity(String.class); + String responseJson = EntityUtils.toString(response.getEntity()); System.out.println(responseJson); - assertEquals(201, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + assertEquals(201, response.getCode()); + assertTrue(response.getEntity().getContentType().toString().contains("application/json")); Gson gson = new Gson(); DummyRecordsHelper.CreateRecordResponse result = gson.fromJson(responseJson, DummyRecordsHelper.CreateRecordResponse.class); @@ -94,20 +94,20 @@ public abstract class StressTests extends TestBase { startMillis = System.currentTimeMillis(); response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), json, "?skipdupes=false"); totalMillis = System.currentTimeMillis() - startMillis; - assertEquals(201, response.getStatus()); + assertEquals(201, response.getCode()); System.out.println(String.format("Took %s milliseconds to Update %s 1KB records", totalMillis, ids.size())); startMillis = System.currentTimeMillis(); response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), json, "?skipdupes=false"); totalMillis = System.currentTimeMillis() - startMillis; - assertEquals(201, response.getStatus()); + assertEquals(201, response.getCode()); System.out.println(String.format("Took %s milliseconds to Update %s 1KB records when when skipdupes is true", totalMillis, ids.size())); startMillis = System.currentTimeMillis(); response = TestUtils.send("records/" + ids.get(0), "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); totalMillis = System.currentTimeMillis() - startMillis; - assertEquals(200, response.getStatus()); + assertEquals(200, response.getCode()); System.out.println(String.format("Took %s milliseconds to GET 1 1KB record", totalMillis)); ids.parallelStream().forEach((id) -> { diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/SwaggerIntegrationTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/SwaggerIntegrationTests.java index 113e7176b61d3257db30021e6513f398d2999e21..22a65e9737474073e4cc055b7f5e42c96cf9b9d6 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/SwaggerIntegrationTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/misc/SwaggerIntegrationTests.java @@ -1,31 +1,32 @@ package org.opengroup.osdu.storage.misc; -import static org.junit.Assert.assertEquals; - -import com.sun.jersey.api.client.ClientResponse; -import java.util.Collections; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; import org.junit.Test; import org.opengroup.osdu.storage.util.TestBase; import org.opengroup.osdu.storage.util.TestUtils; +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + public abstract class SwaggerIntegrationTests extends TestBase { - public static final String SWAGGER_API_PATH = "swagger"; + public static final String SWAGGER_API_PATH = "swagger-ui/index.html"; public static final String SWAGGER_API_DOCS_PATH = "api-docs"; @Test public void shouldReturn200_whenSwaggerApiIsCalled() throws Exception { - ClientResponse response = TestUtils - .send(SWAGGER_API_PATH, "GET", Collections.emptyMap(), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils + .send(SWAGGER_API_PATH, "GET", new HashMap<>(), "", ""); + assertEquals(HttpStatus.SC_OK, response.getCode()); } @Test public void shouldReturn200_whenSwaggerApiDocsIsCalled() throws Exception { - ClientResponse response = TestUtils - .send(SWAGGER_API_DOCS_PATH, "GET", Collections.emptyMap(), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils + .send(SWAGGER_API_DOCS_PATH, "GET", new HashMap<>(), "", ""); + assertEquals(HttpStatus.SC_OK, response.getCode()); } } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryInfoIntegrationTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryInfoIntegrationTest.java index 360a2c0dafb0f2d08aedaad541ec8b2722ebceb1..5ccf73a860af3d57ac0a6997476ebde5f9467207 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryInfoIntegrationTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryInfoIntegrationTest.java @@ -1,17 +1,12 @@ package org.opengroup.osdu.storage.query; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; import org.junit.Test; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestBase; -import org.opengroup.osdu.storage.util.TestUtils; -import org.opengroup.osdu.storage.util.VersionInfoUtils; +import org.opengroup.osdu.storage.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; public abstract class GetQueryInfoIntegrationTest extends TestBase { @@ -19,10 +14,10 @@ public abstract class GetQueryInfoIntegrationTest extends TestBase { @Test public void should_returnInfo() throws Exception { - ClientResponse response = TestUtils + CloseableHttpResponse response = TestUtils .send("info", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); VersionInfoUtils.VersionInfo responseObject = VERSION_INFO_UTILS.getVersionInfoFromResponse(response); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryKindsIntegrationTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryKindsIntegrationTests.java index 6ca3b1058b056815d3bad53450812b7204d70d57..2cbcd891b074c52a36db7b53ef6710a630e6768b 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryKindsIntegrationTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryKindsIntegrationTests.java @@ -14,14 +14,14 @@ package org.opengroup.osdu.storage.query; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.Test; - import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public abstract class GetQueryKindsIntegrationTests extends TestBase { @@ -30,8 +30,8 @@ public abstract class GetQueryKindsIntegrationTests extends TestBase { @Test public void should_returnMax1000Results_when_settingLimitToAValueLessThan1() throws Exception { if (configUtils != null && configUtils.getIsSchemaEndpointsEnabled()) { - ClientResponse response = TestUtils.send("query/kinds", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=0"); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/kinds", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=0"); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.QueryResultMock responseObject = RECORD_HELPER.getQueryResultMockFromResponse(response); @@ -42,21 +42,21 @@ public abstract class GetQueryKindsIntegrationTests extends TestBase { @Test public void should_return400ErrorResult_when_givingAnInvalidCursorParameter() throws Exception { if (configUtils != null && configUtils.getIsSchemaEndpointsEnabled()) { - ClientResponse response = TestUtils.send("query/kinds", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", + CloseableHttpResponse response = TestUtils.send("query/kinds", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?cursor=badCursorString"); - assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getCode()); - assertEquals( - "{\"code\":400,\"reason\":\"Cursor invalid\",\"message\":\"The requested cursor does not exist or is invalid\"}", - response.getEntity(String.class)); + assertEquals( + "{\"code\":400,\"reason\":\"Cursor invalid\",\"message\":\"The requested cursor does not exist or is invalid\"}", + EntityUtils.toString(response.getEntity())); } } @Test public void should_return2Results_when_requesting2Items() throws Exception { if (configUtils != null && configUtils.getIsSchemaEndpointsEnabled()) { - ClientResponse response = TestUtils.send("query/kinds", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=2"); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/kinds", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=2"); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.QueryResultMock responseObject = RECORD_HELPER.getQueryResultMockFromResponse(response); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryRecordsIntegrationTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryRecordsIntegrationTest.java index f2726c65923eb65ab560da9a0cc0ae6456c51a0c..db44fa7ac454a79ee38213d0a6854f34b5ae0151 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryRecordsIntegrationTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/GetQueryRecordsIntegrationTest.java @@ -16,24 +16,19 @@ package org.opengroup.osdu.storage.query; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; import org.apache.commons.lang3.StringUtils; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.Test; -import org.opengroup.osdu.storage.util.DummyRecordsHelper; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestBase; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; +import java.io.IOException; import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; public abstract class GetQueryRecordsIntegrationTest extends TestBase { @@ -48,8 +43,8 @@ public abstract class GetQueryRecordsIntegrationTest extends TestBase { LegalTagUtils.create(LEGAL_TAG, token); String jsonInput = RecordUtil.createDefaultJsonRecords(5, RECORD_ID, KIND, LEGAL_TAG); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); - assertEquals(201, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); + assertEquals(201, response.getCode()); } public static void classTearDown(String token) throws Exception { @@ -64,8 +59,8 @@ public abstract class GetQueryRecordsIntegrationTest extends TestBase { @Test public void should_return5Ids_when_requestingKindThatHas5Entries() throws Exception { - ClientResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?kind=" + KIND); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?kind=" + KIND); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.QueryResultMock responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); assertEquals(5, responseObject.results.length); @@ -78,8 +73,8 @@ public abstract class GetQueryRecordsIntegrationTest extends TestBase { Set<String> result = new HashSet<>(); // first call - ClientResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=2&kind=" + KIND); - if (response.getStatus() != 200) { + CloseableHttpResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=2&kind=" + KIND); + if (response.getCode() != 200) { fail(formResponseCheckingMessage(response)); } DummyRecordsHelper.QueryResultMock responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); @@ -94,7 +89,7 @@ public abstract class GetQueryRecordsIntegrationTest extends TestBase { // second call response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=2&cursor=" + cursor + "&kind=" + KIND); - if (response.getStatus() != 200) { + if (response.getCode() != 200) { fail(formResponseCheckingMessage(response)); } responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); @@ -109,7 +104,7 @@ public abstract class GetQueryRecordsIntegrationTest extends TestBase { // third call response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=2&cursor=" + cursor + "&kind=" + KIND); - if (response.getStatus() != 200) { + if (response.getCode() != 200) { fail(formResponseCheckingMessage(response)); } responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); @@ -122,15 +117,15 @@ public abstract class GetQueryRecordsIntegrationTest extends TestBase { @Test public void should_returnError400_when_usingKindThatHasBadFormat() throws Exception { - ClientResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1&kind=bad:kind"); - assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1&kind=bad:kind"); + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getCode()); } @Test public void should_returnNoResults_when_usingKindThatDoesNotExist() throws Exception { - ClientResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", + CloseableHttpResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1&kind=nonexisting:kind:formatted:1.0.0"); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.QueryResultMock responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); assertEquals(0, responseObject.results.length); @@ -138,28 +133,35 @@ public abstract class GetQueryRecordsIntegrationTest extends TestBase { @Test public void should_returnError400_when_usingInvalidCursorParameter() throws Exception { - ClientResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", + CloseableHttpResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1&cursor=MY_BAD_CURSOR&kind=" + RECORDS_HELPER.KIND); - assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getCode()); } @Test public void should_returnError400_when_notProvidingKindParameter() throws Exception { - ClientResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1&kind="); - assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1&kind="); + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getCode()); response = TestUtils.send("query/records", "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?limit=1"); - assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getCode()); } - protected String formResponseCheckingMessage(ClientResponse response) { - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + protected String formResponseCheckingMessage(CloseableHttpResponse response) { + JsonObject json; + try { + json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } StringBuilder output = new StringBuilder(); output.append("API is not acting properly, responde code is: ") - .append(String.valueOf(response.getStatus())) + .append(String.valueOf(response.getCode())) .append(". And the reason is: ") .append(json.get("reason").getAsString()) - .append(response.getHeaders().get("correlation-id")); + .append(response.getHeaders("correlation-id")[0]); return output.toString(); } } \ No newline at end of file diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostFetchRecordsIntegrationTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostFetchRecordsIntegrationTests.java index d664466b108b16e39bf829474bc4a12a93f1b4d0..74e875a87f8d15afda092fb69d6a1c1685269d28 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostFetchRecordsIntegrationTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostFetchRecordsIntegrationTests.java @@ -16,20 +16,17 @@ package org.opengroup.osdu.storage.query; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; -import org.junit.Ignore; +import org.opengroup.osdu.storage.util.*; import java.util.List; import java.util.Map; import java.util.UUID; -import static org.junit.Assert.*; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public abstract class PostFetchRecordsIntegrationTests extends TestBase { protected static final long NOW = System.currentTimeMillis(); @@ -57,8 +54,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnSingleRecordMatching_when_noConversionRequired() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithReference(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -68,9 +65,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "none"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); @@ -84,16 +81,16 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals(KIND, responseObject.records[0].kind); assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } @Test public void should_returnRecordMatchingAndRecordNotFound_when_noConversionRequired() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithReference(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -104,9 +101,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "none"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); @@ -121,8 +118,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals(KIND, responseObject.records[0].kind); assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } @Test @@ -139,9 +136,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "none"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getCode()); } @Test @@ -149,8 +146,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnConvertedRecords_whenConversionRequiredAndNoError() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithReference(2, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -161,9 +158,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -174,10 +171,10 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(3, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); - ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse2.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); + CloseableHttpResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse2.getCode()); } @@ -186,8 +183,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnConvertedRecords_whenConversionRequiredAndNoErrorWithMultiplePairOfCoordinates() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithMultiplePairOfCoordinates(2, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -198,9 +195,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -210,10 +207,10 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(5, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); - ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse2.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); + CloseableHttpResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse2.getCode()); } @@ -222,8 +219,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnOriginalRecordsAndConversionStatusAsNoMeta_whenConversionRequiredAndNoMetaBlockInRecord() throws Exception{ String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordNoMetaBlock(2, recordId, KIND, LEGAL_TAG); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -235,9 +232,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -249,18 +246,18 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals(3, responseObject.records[0].data.size()); List<DummyRecordsHelper.RecordStatusMock> conversionStatuses = responseObject.conversionStatuses; assertEquals("CRS Conversion: Meta Block is missing or empty in this record, no conversion applied.", conversionStatuses.get(0).errors.get(0)); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); - ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse2.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); + CloseableHttpResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse2.getCode()); } @Test public void should_returnRecordsAndConversionStatus_whenConversionRequiredAndConversionErrorExists() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordMissingValue(2, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -271,9 +268,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -286,10 +283,10 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { List<DummyRecordsHelper.RecordStatusMock> conversionStatuses = responseObject.conversionStatuses; assertEquals("CRS conversion: Unknown coordinate pair 'z'.", conversionStatuses.get(0).errors.get(1)); assertEquals("CRS conversion: property 'Y' is missing in datablock, no conversion applied to this property and its corresponding pairing property.", conversionStatuses.get(0).errors.get(0)); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); - ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse2.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); + CloseableHttpResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse2.getCode()); } @Test @@ -297,8 +294,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAndConversionStatus_whenConversionRequiredAndNestedPropertyProvidedInMetaBlock() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithNestedProperty(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -308,9 +305,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -320,16 +317,16 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals(KIND, responseObject.records[0].kind); assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } //@Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @Test public void should_returnRecordsAndConversionStatus_whenConversionRequiredAndNestedPropertyProvidedInMetaBlock1() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithNestedProperty(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE, "CRS"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -339,9 +336,9 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -350,16 +347,16 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals(KIND, responseObject.records[0].kind); assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } @Test public void should_returnRecordsAndConversionStatus_whenDateAndFormatProvidedInMetaBlock() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordsWithDateFormat(1, recordId, KIND, LEGAL_TAG, "yyyy-MM-dd", "creationDate", "2019-08-03", DATETIME_PERSISTABLE_REFERENCE); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -369,8 +366,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -380,8 +377,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals(KIND, responseObject.records[0].kind); assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -389,8 +386,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAndConversionStatus_whenNestedArrayOfPropertiesProvidedWithoutError() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithNestedArrayOfProperties(1, recordId, KIND, LEGAL_TAG, UNIT_PERSISTABLE_REFERENCE, "Unit"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 12); @@ -400,8 +397,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -414,8 +411,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { List<DummyRecordsHelper.RecordStatusMock> conversionStatuses = responseObject.conversionStatuses; assertEquals("SUCCESS", conversionStatuses.get(0).status); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 12, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 12, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -423,8 +420,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAndConversionStatus_whenNestedArrayOfPropertiesProvidedWithInvalidValues() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithNestedArrayOfPropertiesAndInvalidValues(1, recordId, KIND, LEGAL_TAG, UNIT_PERSISTABLE_REFERENCE, "Unit"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 12); @@ -434,8 +431,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -449,8 +446,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals("ERROR", conversionStatuses.get(0).status); assertEquals("Unit conversion: illegal value for property markers[1].measuredDepth", conversionStatuses.get(0).errors.get(0)); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 12, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 12, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -458,8 +455,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAndConversionStatus_whenInhomogeneousNestedArrayOfPropertiesProvidedWithoutError() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithInhomogeneousNestedArrayOfProperties(1, recordId, KIND, LEGAL_TAG, UNIT_PERSISTABLE_REFERENCE, "Unit"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 13); @@ -469,8 +466,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -483,8 +480,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { List<DummyRecordsHelper.RecordStatusMock> conversionStatuses = responseObject.conversionStatuses; assertEquals("SUCCESS", conversionStatuses.get(0).status); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 13, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 13, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -492,8 +489,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAndConversionStatus_whenInhomogeneousNestedArrayOfPropertiesProvidedWithInvalidValues() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithInhomogeneousNestedArrayOfPropertiesAndInvalidValues(1, recordId, KIND, LEGAL_TAG, UNIT_PERSISTABLE_REFERENCE, "Unit"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 13); @@ -503,8 +500,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -518,8 +515,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals("ERROR", conversionStatuses.get(0).status); assertEquals("Unit conversion: illegal value for property markers[1].measuredDepth", conversionStatuses.get(0).errors.get(0)); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 13, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 13, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -527,8 +524,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAndConversionStatus_whenInhomogeneousNestedArrayOfPropertiesProvidedWithIndexOutOfBoundary() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithInhomogeneousNestedArrayOfPropertiesAndIndexOutOfBoundary(1, recordId, KIND, LEGAL_TAG, UNIT_PERSISTABLE_REFERENCE, "Unit"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 13); @@ -538,8 +535,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -553,8 +550,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertEquals("SUCCESS", conversionStatuses.get(0).status); assertEquals("Unit conversion: property markers[2].measuredDepth missing", conversionStatuses.get(0).errors.get(0)); - ClientResponse deleteResponse = TestUtils.send("records/" + recordId + 13, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse.getStatus()); + CloseableHttpResponse deleteResponse = TestUtils.send("records/" + recordId + 13, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -562,8 +559,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAfterCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockTypePoint() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsPoint", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -573,8 +570,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -586,8 +583,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -595,8 +592,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAfterCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockTypeMultiPoint() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsMultiPoint", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -606,8 +603,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -619,8 +616,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -628,8 +625,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAfterCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockTypePolygon() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsPolygon", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -639,8 +636,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -652,8 +649,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -661,8 +658,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAfterCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockTypeMultiPolygon() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsMultiPolygon", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -672,8 +669,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -685,8 +682,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -694,8 +691,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAfterCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockTypeLineString() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsLineString", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -705,8 +702,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -718,8 +715,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -727,8 +724,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAfterCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockTypeMultiLineString() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsMultiLineString", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -738,8 +735,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -751,8 +748,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -760,8 +757,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnRecordsAfterCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockTypeGeometryCollection() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsGeometryCollection", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -771,8 +768,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -784,8 +781,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -793,8 +790,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnConvertedRecords_whenConversionRequiredWithAsIngestedCoordinatesBlockWithError() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithInvalidAsIngestedCoordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsPoint", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -804,8 +801,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -817,8 +814,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } // @Ignore // Ignoring the test for now, once we have CRS converter we should enable this test @@ -826,8 +823,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { public void should_returnConvertedRecords_whenConversionNotRequiredWithAsIngestedCoordinatesAndWgs84CoordinatesBlocks() throws Exception { String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString(); String jsonInput = RecordUtil.createJsonRecordWithWGS84Coordinates(1, recordId, KIND, LEGAL_TAG, PERSISTABLE_REFERENCE_CRS, PERSISTABLE_REFERENCE_UNIT_Z, "AnyCrsPoint", "SpatialLocation"); - ClientResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - assertEquals(201, createResponse.getStatus()); + CloseableHttpResponse createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + assertEquals(201, createResponse.getCode()); JsonArray records = new JsonArray(); records.add(recordId + 0); @@ -837,8 +834,8 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;"); - ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -850,7 +847,7 @@ public abstract class PostFetchRecordsIntegrationTests extends TestBase { assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty()); assertEquals(1, responseObject.records[0].data.size()); - ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(204, deleteResponse1.getStatus()); + CloseableHttpResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(204, deleteResponse1.getCode()); } } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostQueryRecordsIntegrationTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostQueryRecordsIntegrationTests.java index 976a684d01678a8ce82f70a359b4ce61893d51ea..788a15e1315244be166edd3924bd476fedfa8429 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostQueryRecordsIntegrationTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/PostQueryRecordsIntegrationTests.java @@ -14,19 +14,18 @@ package org.opengroup.osdu.storage.query; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.http.HttpStatus; -import org.junit.*; - import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public abstract class PostQueryRecordsIntegrationTests extends TestBase { @@ -41,8 +40,8 @@ public abstract class PostQueryRecordsIntegrationTests extends TestBase { LegalTagUtils.create(LEGAL_TAG, token); String jsonInput = RecordUtil.createDefaultJsonRecords(3, RECORD_ID, KIND, LEGAL_TAG); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); - assertEquals(201, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); + assertEquals(201, response.getCode()); } public static void classTearDown(String token) throws Exception { @@ -63,9 +62,9 @@ public abstract class PostQueryRecordsIntegrationTests extends TestBase { body.add("records", records); body.add("attributes", attributes); - ClientResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.RecordsMock responseObject = RECORDS_HELPER.getRecordsMockFromResponse(response); @@ -91,9 +90,9 @@ public abstract class PostQueryRecordsIntegrationTests extends TestBase { body.add("records", records); body.add("attributes", attributes); - ClientResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.RecordsMock responseObject = RECORDS_HELPER.getRecordsMockFromResponse(response); @@ -113,9 +112,9 @@ public abstract class PostQueryRecordsIntegrationTests extends TestBase { body.add("records", records); body.add("attributes", attributes); - ClientResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.RecordsMock responseObject = RECORDS_HELPER.getRecordsMockFromResponse(response); @@ -140,9 +139,9 @@ public abstract class PostQueryRecordsIntegrationTests extends TestBase { body.add("records", records); body.add("attributes", attributes); - ClientResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), + CloseableHttpResponse response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.RecordsMock responseObject = RECORDS_HELPER.getRecordsMockFromResponse(response); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/StorageQuerySuccessfulTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/StorageQuerySuccessfulTest.java index d22d6f00fce8021ae3f0ff8d775d66a894b09cea..31bf7c1a5235d6f09d0e9d00b5cb6b7cc3622e74 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/StorageQuerySuccessfulTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/query/StorageQuerySuccessfulTest.java @@ -14,19 +14,18 @@ package org.opengroup.osdu.storage.query; -import static org.junit.Assert.assertEquals; - -import javax.ws.rs.HttpMethod; - -import org.apache.http.HttpStatus; -import org.junit.*; - import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.model.CreatedRecordInStorage; import org.opengroup.osdu.storage.model.GetCursorValue; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import javax.ws.rs.HttpMethod; + +import static org.junit.Assert.assertEquals; public abstract class StorageQuerySuccessfulTest extends TestBase { @@ -54,30 +53,30 @@ public abstract class StorageQuerySuccessfulTest extends TestBase { @Test public void should_retrieveAllKinds_when_toCursorIdIsGiven() throws Exception { if (configUtils != null && configUtils.getIsSchemaEndpointsEnabled()) { - ClientResponse recordResponse = TestUtils.send("query/kinds?limit=10", HttpMethod.GET, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse recordResponse = TestUtils.send("query/kinds?limit=10", HttpMethod.GET, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); GetCursorValue getCursorValue = TestUtils.getResult(recordResponse, HttpStatus.SC_OK, GetCursorValue.class); String cursorValue = getCursorValue.getCursor(); - assertEquals(HttpStatus.SC_OK, recordResponse.getStatus()); + assertEquals(HttpStatus.SC_OK, recordResponse.getCode()); assertEquals(cursorValue, getCursorValue.getCursor()); - ClientResponse recordResponseWithCursorValue = TestUtils.send("query/kinds?cursor=" + cursorValue + "&limit=10", + CloseableHttpResponse recordResponseWithCursorValue = TestUtils.send("query/kinds?cursor=" + cursorValue + "&limit=10", HttpMethod.GET, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, recordResponseWithCursorValue.getStatus()); + assertEquals(HttpStatus.SC_OK, recordResponseWithCursorValue.getCode()); } } @Test public void should_retrieveAllRecords_when_kindIsGiven() throws Exception { - ClientResponse recordResponse = createTestRecord(KIND_ONE, KIND_ID_ONE, LEGAL_TAG_NAME); - assertEquals(HttpStatus.SC_CREATED, recordResponse.getStatus()); - ClientResponse recordResponseGet = TestUtils.send("query/records?kind=" + KIND_ONE, HttpMethod.GET, + CloseableHttpResponse recordResponse = createTestRecord(KIND_ONE, KIND_ID_ONE, LEGAL_TAG_NAME); + assertEquals(HttpStatus.SC_CREATED, recordResponse.getCode()); + CloseableHttpResponse recordResponseGet = TestUtils.send("query/records?kind=" + KIND_ONE, HttpMethod.GET, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, recordResponseGet.getStatus()); + assertEquals(HttpStatus.SC_OK, recordResponseGet.getCode()); } @Test public void should_queryToFetchMultipleRecords_when_recordIsGiven() throws Exception { - ClientResponse recordResponse = createTestRecord(KIND_ONE, KIND_ID_ONE, LEGAL_TAG_NAME); + CloseableHttpResponse recordResponse = createTestRecord(KIND_ONE, KIND_ID_ONE, LEGAL_TAG_NAME); CreatedRecordInStorage recordResult = TestUtils.getResult(recordResponse, HttpStatus.SC_CREATED, CreatedRecordInStorage.class); JsonArray recordIDS = new JsonArray(); @@ -88,12 +87,12 @@ public abstract class StorageQuerySuccessfulTest extends TestBase { createSearchRecordPayload.add("records", recordIDS); createSearchRecordPayload.add("attributes", attribute); String path = "query/records"; - ClientResponse recordResponsePost = TestUtils.send(path, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse recordResponsePost = TestUtils.send(path, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), createSearchRecordPayload.toString(), ""); - assertEquals(HttpStatus.SC_OK, recordResponsePost.getStatus()); + assertEquals(HttpStatus.SC_OK, recordResponsePost.getCode()); } - protected ClientResponse createTestRecord(String kind, String id, String legalName) throws Exception { + protected CloseableHttpResponse createTestRecord(String kind, String id, String legalName) throws Exception { String jsonInputRecord = RecordUtil.createDefaultJsonRecord(id, kind, legalName); return TestUtils.send(RECORD, HttpMethod.PUT, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputRecord, ""); } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsPurgeTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsPurgeTest.java index ca29b17f494b5765b073fcf414dc6fe1ae3421df..7128bb3b8d504d96e26a96fe4c4fb04b5819b3d0 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsPurgeTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsPurgeTest.java @@ -1,24 +1,19 @@ package org.opengroup.osdu.storage.records; import com.google.api.client.util.Strings; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.Test; -import org.opengroup.osdu.storage.util.DummyRecordsHelper; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestBase; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; +import java.io.IOException; import java.util.Map; import java.util.UUID; -import static org.apache.http.HttpStatus.SC_CREATED; -import static org.apache.http.HttpStatus.SC_NOT_FOUND; -import static org.apache.http.HttpStatus.SC_NO_CONTENT; +import static org.apache.http.HttpStatus.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -62,10 +57,10 @@ public abstract class CollaborationRecordsPurgeTest extends TestBase { @Test public void should_purgeAllRecordVersionsOnlyInCollaborationContext() throws Exception { if (!isCollaborationEnabled) return; - ClientResponse response = TestUtils.send("records/" + RECORD_PURGE_ID, "DELETE", getHeadersWithxCollaboration(COLLABORATION1_ID, testUtils.getToken()), "", ""); - assertEquals(SC_NO_CONTENT, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_PURGE_ID, "DELETE", getHeadersWithxCollaboration(COLLABORATION1_ID, testUtils.getToken()), "", ""); + assertEquals(SC_NO_CONTENT, response.getCode()); response = TestUtils.send("records/" + RECORD_PURGE_ID, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, testUtils.getToken()), "", ""); - assertEquals(SC_NOT_FOUND, response.getStatus()); + assertEquals(SC_NOT_FOUND, response.getCode()); response = TestUtils.send("records/" + RECORD_PURGE_ID, "GET", getHeadersWithxCollaboration(COLLABORATION2_ID, testUtils.getToken()), "", ""); assertRecordVersion(response, RECORD_PURGE_V3); } @@ -73,11 +68,11 @@ public abstract class CollaborationRecordsPurgeTest extends TestBase { private static Long createRecord(String recordId, String collaborationId, String kind, String token) throws Exception { String jsonInput = RecordUtil.createDefaultJsonRecord(recordId, kind, LEGAL_TAG_NAME_A); - ClientResponse response = TestUtils.send("records", "PUT", getHeadersWithxCollaboration(collaborationId, token), jsonInput, ""); - assertEquals(SC_CREATED, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + CloseableHttpResponse response = TestUtils.send("records", "PUT", getHeadersWithxCollaboration(collaborationId, token), jsonInput, ""); + assertEquals(SC_CREATED, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); - String responseBody = response.getEntity(String.class); + String responseBody = EntityUtils.toString(response.getEntity()); DummyRecordsHelper.CreateRecordResponse result = GSON.fromJson(responseBody, DummyRecordsHelper.CreateRecordResponse.class); return Long.parseLong(result.recordIdVersions[0].split(":")[3]); @@ -91,10 +86,17 @@ public abstract class CollaborationRecordsPurgeTest extends TestBase { return headers; } - private static void assertRecordVersion(ClientResponse response, Long expectedVersion) { - assertEquals(HttpStatus.SC_OK, response.getStatus()); + private static void assertRecordVersion(CloseableHttpResponse response, Long expectedVersion) { + assertEquals(HttpStatus.SC_OK, response.getCode()); - String responseBody = response.getEntity(String.class); + String responseBody = null; + try { + responseBody = EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } DummyRecordsHelper.RecordResultMock result = GSON.fromJson(responseBody, DummyRecordsHelper.RecordResultMock.class); assertEquals(expectedVersion.longValue(), Long.parseLong(result.version)); } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsRetrieveTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsRetrieveTest.java index aba47e6a8325bfbef742919ddea9383de22c9df8..2a1813e5aa1635402b17394ba3a4e77fb0709a73 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsRetrieveTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsRetrieveTest.java @@ -16,24 +16,18 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.Test; -import org.opengroup.osdu.storage.util.DummyRecordsHelper; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestBase; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; import java.util.Arrays; import java.util.List; import java.util.UUID; import static org.apache.http.HttpStatus.SC_OK; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import static org.opengroup.osdu.storage.util.HeaderUtils.getHeadersWithxCollaboration; import static org.opengroup.osdu.storage.util.TestUtils.assertRecordVersion; import static org.opengroup.osdu.storage.util.TestUtils.createRecordInCollaborationContext_AndReturnVersion; @@ -100,7 +94,7 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { public void should_getLatestVersion_when_validRecordIdAndCollaborationIdAreProvided() throws Exception { if (!isCollaborationEnabled) return; //get record1 --> v1 - ClientResponse response = TestUtils.send("records/" + RECORD_ID_1, "GET", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID_1, "GET", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); assertRecordVersion(response, RECORD1_V1); //get record1 with guid1 --> v3 response = TestUtils.send("records/" + RECORD_ID_1, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); @@ -110,25 +104,25 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { assertRecordVersion(response, RECORD1_V4); //get record2 with guid1 --> 404 response = TestUtils.send("records/" + RECORD_ID_2, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); } @Test public void should_getCorrectRecordVersion_when_validRecordIdAndCollaborationIdAndRecordVersionAreProvided() throws Exception { if (!isCollaborationEnabled) return; //get record1 with v2 with context guid1 - ClientResponse response = TestUtils.send("records/" + RECORD_ID_1 + "/" + RECORD1_V2, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID_1 + "/" + RECORD1_V2, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); assertRecordVersion(response, RECORD1_V2); //get 404 for record1 with v2 with context guid2 response = TestUtils.send("records/" + RECORD_ID_1 + "/" + RECORD1_V2, "GET", getHeadersWithxCollaboration(COLLABORATION2_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); } @Test public void should_getAllRecordVersions_when_validRecordIdAndCollaborationIdAreProvided() throws Exception { if (!isCollaborationEnabled) return; //I will get only v1 for record1 with no context - ClientResponse response = TestUtils.send("records/versions/" + RECORD_ID_1, "GET", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); + CloseableHttpResponse response = TestUtils.send("records/versions/" + RECORD_ID_1, "GET", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); RecordsApiAcceptanceTests.GetVersionsResponse versionsResponse = TestUtils.getResult(response, 200, RecordsApiAcceptanceTests.GetVersionsResponse.class); assertEquals(1, versionsResponse.versions.length); assertEquals(RECORD1_V1, versionsResponse.versions[0]); @@ -145,21 +139,21 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { @Test public void should_getRecordsOnlyInCollaborationContext_whenQueryByKind() throws Exception { if (!isCollaborationEnabled) return; - ClientResponse response = TestUtils.send("query/records", "GET", getHeadersWithxCollaboration(COLLABORATION2_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", "?kind=" + KIND1); - assertEquals(SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records", "GET", getHeadersWithxCollaboration(COLLABORATION2_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", "?kind=" + KIND1); + assertEquals(SC_OK, response.getCode()); DummyRecordsHelper.QueryResultMock responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); assertEquals(2, responseObject.results.length); assertTrue(Arrays.stream(responseObject.results).anyMatch(RECORD_ID_1::equals)); assertTrue(Arrays.stream(responseObject.results).anyMatch(RECORD_ID_2::equals)); response = TestUtils.send("query/records", "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", "?kind=" + KIND1); - assertEquals(SC_OK, response.getStatus()); + assertEquals(SC_OK, response.getCode()); responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); assertEquals(1, responseObject.results.length); assertTrue(Arrays.stream(responseObject.results).anyMatch(RECORD_ID_1::equals)); response = TestUtils.send("query/records", "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", "?kind=" + KIND3); - assertEquals(SC_OK, response.getStatus()); + assertEquals(SC_OK, response.getCode()); responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); assertEquals(0, responseObject.results.length); } @@ -167,8 +161,8 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { @Test public void should_getEmptyRecordsInNoCollaborationContext_whenQueryByKind() throws Exception { if (!isCollaborationEnabled) return; - ClientResponse response = TestUtils.send("query/records", "GET", getHeadersWithxCollaboration(null, null, TENANT_NAME, testUtils.getToken()), "", "?kind=" + KIND2); - assertEquals(SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records", "GET", getHeadersWithxCollaboration(null, null, TENANT_NAME, testUtils.getToken()), "", "?kind=" + KIND2); + assertEquals(SC_OK, response.getCode()); DummyRecordsHelper.QueryResultMock responseObject = RECORDS_HELPER.getQueryResultMockFromResponse(response); assertEquals(0, responseObject.results.length); } @@ -183,8 +177,8 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { records.add(RECORD_ID_3); JsonObject body = new JsonObject(); body.add("records", records); - ClientResponse response = TestUtils.send("query/records:batch", "POST", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records:batch", "POST", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -199,7 +193,7 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { // If I fetch records 1, 2, and 3 in no context, I should get a 200 with records 1 and 2 response = TestUtils.send("query/records:batch", "POST", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); @@ -223,8 +217,8 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { records.add(RECORD_ID_3); JsonObject body = new JsonObject(); body.add("records", records); - ClientResponse response = TestUtils.send("query/records", "POST", getHeadersWithxCollaboration(COLLABORATION2_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("query/records", "POST", getHeadersWithxCollaboration(COLLABORATION2_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.RecordsMock responseObject = RECORDS_HELPER.getRecordsMockFromResponse(response); assertEquals(3, responseObject.records.length); @@ -239,7 +233,7 @@ public abstract class CollaborationRecordsRetrieveTest extends TestBase { // If I query records 1, 2 and 3 in context guid1, I should get 2xx with records 1 and 3 response = TestUtils.send("query/records", "POST", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); responseObject = RECORDS_HELPER.getRecordsMockFromResponse(response); assertEquals(2, responseObject.records.length); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsSoftDeleteTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsSoftDeleteTest.java index ef3b9e27b86dbd96410bd29493ac5a5203daffe7..8389a431948b62937a74f3ddeafa4c7b000498a8 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsSoftDeleteTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationRecordsSoftDeleteTest.java @@ -1,7 +1,7 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonArray; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.Test; @@ -75,11 +75,11 @@ public abstract class CollaborationRecordsSoftDeleteTest extends TestBase { @Test public void should_softDeleteSingleRecordWithinCollaborationContext_when_validRecordIdsAndCollaborationIdAreProvided() throws Exception { if (!isCollaborationEnabled) return; - ClientResponse response = TestUtils.send("records/" + RECORD_ID_1 + ":delete", "POST", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID_1 + ":delete", "POST", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_1, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_1, "GET", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); assertRecordVersion(response, RECORD1_V3); @@ -94,14 +94,14 @@ public abstract class CollaborationRecordsSoftDeleteTest extends TestBase { JsonArray body = new JsonArray(); body.add(RECORD_ID_2); body.add(RECORD_ID_3); - ClientResponse response = TestUtils.send("records/delete", "POST", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/delete", "POST", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), body.toString(), ""); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_2, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_3, "GET", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_2, "GET", getHeadersWithxCollaboration(COLLABORATION2_ID, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); assertRecordVersion(response, RECORD2_V2); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationUpdateRecordsMetadataTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationUpdateRecordsMetadataTest.java index 5e0453da02612dd9f305439504ca73345b36768a..166ed9d793c1515015f46f734322bd51e3fab04c 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationUpdateRecordsMetadataTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/CollaborationUpdateRecordsMetadataTest.java @@ -2,19 +2,13 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.junit.After; import org.junit.Test; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestBase; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; import static org.apache.http.HttpStatus.SC_OK; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.opengroup.osdu.storage.records.CollaborationRecordsPurgeTest.COLLABORATION1_ID; import static org.opengroup.osdu.storage.records.UpdateRecordsMetadataTest.TAG_KEY; import static org.opengroup.osdu.storage.records.UpdateRecordsMetadataTest.TAG_VALUE1; @@ -48,15 +42,15 @@ public abstract class CollaborationUpdateRecordsMetadataTest extends TestBase { //update record with tags in one collaboration context JsonObject updateBody = RecordUtil.buildUpdateTagBody(RECORD_PATCH_ID, "add", TAG_KEY + ":" + TAG_VALUE1); - ClientResponse patchResponse = TestUtils.send("records", "PATCH", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TenantUtils.getTenantName(), testUtils.getToken()), updateBody.toString(), ""); - assertEquals(SC_OK, patchResponse.getStatus()); + CloseableHttpResponse patchResponse = TestUtils.send("records", "PATCH", getHeadersWithxCollaboration(COLLABORATION1_ID, APPLICATION_NAME, TenantUtils.getTenantName(), testUtils.getToken()), updateBody.toString(), ""); + assertEquals(SC_OK, patchResponse.getCode()); } @Test public void shouldMaintainAndUpdateRecordInRespctiveCollaborationContext() throws Exception { if (!isCollaborationEnabled) return; //assert record with no collaboration context - ClientResponse getResponse = TestUtils.send("records/" + RECORD_PATCH_ID, "GET", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); + CloseableHttpResponse getResponse = TestUtils.send("records/" + RECORD_PATCH_ID, "GET", getHeadersWithxCollaboration(null, APPLICATION_NAME, TENANT_NAME, testUtils.getToken()), "", ""); String responseBody = assertRecordVersionAndReturnResponseBody(getResponse, RECORD_PATCH_V1); JsonObject resultObject = bodyToJsonObject(responseBody); assertNull(resultObject.get("tags")); @@ -77,6 +71,6 @@ public abstract class CollaborationUpdateRecordsMetadataTest extends TestBase { } private static JsonObject bodyToJsonObject(String json) { - return new JsonParser().parse(json).getAsJsonObject(); + return JsonParser.parseString(json).getAsJsonObject(); } } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DataRootAccessTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DataRootAccessTest.java index 3c918ed7638660093223cb2aadcf637c81590958..7accc9b71d2f9cafc39fab409a352412e6a30d9e 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DataRootAccessTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DataRootAccessTest.java @@ -17,25 +17,20 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.jersey.api.client.ClientResponse; -import java.util.Map; -import java.util.stream.Stream; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.Test; -import org.opengroup.osdu.storage.util.DummyRecordsHelper; -import org.opengroup.osdu.storage.util.EntitlementsUtil; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestBase; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; + +import java.util.Map; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public abstract class DataRootAccessTest extends TestBase { @@ -53,14 +48,14 @@ public abstract class DataRootAccessTest extends TestBase { GROUP_EMAIL = createDataGroup(headers); String createRecordBody = RecordUtil.createJsonRecordWithCustomAcl(RECORD_ID, KIND, LEGAL_TAG, GROUP_EMAIL); - ClientResponse response = TestUtils.send( + CloseableHttpResponse response = TestUtils.send( "records", "PUT", headers, createRecordBody, "" ); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); } public static void classTearDown(String token) throws Exception { @@ -87,7 +82,7 @@ public abstract class DataRootAccessTest extends TestBase { TenantUtils.getTenantName(), testUtils.getDataRootUserToken()); - ClientResponse queryResponse = TestUtils.send( + CloseableHttpResponse queryResponse = TestUtils.send( "query/records", "POST", headersWithUsersDataRootAccess, @@ -98,20 +93,20 @@ public abstract class DataRootAccessTest extends TestBase { DummyRecordsHelper.RecordsMock responseObject = new DummyRecordsHelper().getRecordsMockFromResponse( queryResponse); - assertEquals(HttpStatus.SC_OK, queryResponse.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse.getCode()); assertEquals(1, responseObject.records.length); assertEquals(RECORD_ID, Stream.of(responseObject.records).findFirst().get().id); } protected static String createDataGroup(Map<String, String> headersWithValidAccessToken) throws Exception { - ClientResponse entitlementsGroup = EntitlementsUtil.createEntitlementsGroup( + CloseableHttpResponse entitlementsGroup = EntitlementsUtil.createEntitlementsGroup( headersWithValidAccessToken, DATA_GROUP_ID, GROUP_DESCRIPTION ); - assertTrue(entitlementsGroup.getType().toString().contains("application/json")); - String json = entitlementsGroup.getEntity(String.class); + assertTrue(entitlementsGroup.getEntity().getContentType().contains("application/json")); + String json = EntityUtils.toString(entitlementsGroup.getEntity()); Gson gson = new Gson(); JsonObject groupEntity = gson.fromJson(json, JsonObject.class); return groupEntity.get("email").getAsString(); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DeleteRecordLogicallyAndItsVersionsTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DeleteRecordLogicallyAndItsVersionsTest.java index f8140636f65bf14c7b112b70ec536f7c6073d4bd..4a9523caaae2a9a317bc8a16d67a4db1dbf997dd 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DeleteRecordLogicallyAndItsVersionsTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/DeleteRecordLogicallyAndItsVersionsTest.java @@ -14,18 +14,17 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; - +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.Before; import org.junit.Test; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import static org.junit.Assert.assertEquals; public abstract class DeleteRecordLogicallyAndItsVersionsTest extends TestBase { @@ -42,9 +41,9 @@ public abstract class DeleteRecordLogicallyAndItsVersionsTest extends TestBase { LegalTagUtils.create(LEGAL_TAG, testUtils.getToken()); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createJsonRecordWithData(RECORD_ID, KIND, LEGAL_TAG, "v1"), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); } @After @@ -57,13 +56,13 @@ public abstract class DeleteRecordLogicallyAndItsVersionsTest extends TestBase { @Test public void should_deleteRecordAndAllVersionsLogically_when_userIsAuthorized() throws Exception { - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createJsonRecordWithData(RECORD_ID, KIND, LEGAL_TAG, "v2"), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); - ClientResponse versionResponse = TestUtils.send("records/versions/" + RECORD_ID, "GET", + CloseableHttpResponse versionResponse = TestUtils.send("records/versions/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, versionResponse.getStatus()); + assertEquals(HttpStatus.SC_OK, versionResponse.getCode()); String versions = TestUtils.getResult(versionResponse, HttpStatus.SC_OK, String.class); JsonObject content = new JsonParser().parse(versions).getAsJsonObject(); @@ -72,15 +71,15 @@ public abstract class DeleteRecordLogicallyAndItsVersionsTest extends TestBase { String versionOne = versionArray.get(0).toString(); String versionTwo = versionArray.get(1).toString(); - ClientResponse deleteResponse = TestUtils.send("records/", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse deleteResponse = TestUtils.send("records/", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "{'anything':'anything'}", RECORD_ID + ":delete"); - assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getStatus()); + assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getCode()); response = TestUtils.send("records/" + RECORD_ID + "/" + versionOne, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); response = TestUtils.send("records/" + RECORD_ID + "/" + versionTwo, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); } } \ No newline at end of file diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/GetRecordsIntegrationTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/GetRecordsIntegrationTest.java index c46795bedfc9fb93ae5d0b0faf9ad97e7c11c9bb..1de8d269478244505c8dce7982e010a14f560354 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/GetRecordsIntegrationTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/GetRecordsIntegrationTest.java @@ -15,13 +15,13 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonArray; -import org.apache.http.HttpStatus; -import org.junit.Test; - import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; import static org.junit.Assert.*; @@ -45,9 +45,9 @@ public abstract class GetRecordsIntegrationTest extends TestBase { String jsonInput = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG_NAME_A); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); - assertEquals(201, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); + assertEquals(201, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); } public static void classTearDown(String token) throws Exception { @@ -59,10 +59,10 @@ public abstract class GetRecordsIntegrationTest extends TestBase { @Test public void should_getRecord_when_validRecordIdIsProvided() throws Exception { - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_OK, response.getCode()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); JsonObject dataJson = json.get("data").getAsJsonObject(); JsonObject acl = json.get("acl").getAsJsonObject(); @@ -80,14 +80,14 @@ public abstract class GetRecordsIntegrationTest extends TestBase { @Test public void should_getRecord_withoutDuplicates_when_duplicateAclAndLegaltagsAreProvided() throws Exception { String jsonInputWithDuplicates = RecordUtil.createRecordWithDuplicateAclAndLegaltags(ANOTHER_RECORD_ID, KIND, LEGAL_TAG_NAME_A); - ClientResponse putResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputWithDuplicates, ""); - assertEquals(201, putResponse.getStatus()); - assertTrue(putResponse.getType().toString().contains("application/json")); + CloseableHttpResponse putResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputWithDuplicates, ""); + assertEquals(201, putResponse.getCode()); + assertTrue(putResponse.getEntity().getContentType().contains("application/json")); - ClientResponse response = TestUtils.send("records/" + ANOTHER_RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/" + ANOTHER_RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_OK, response.getCode()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); JsonObject acl = json.get("acl").getAsJsonObject(); JsonObject legal = json.get("legal").getAsJsonObject(); @@ -100,11 +100,11 @@ public abstract class GetRecordsIntegrationTest extends TestBase { @Test public void should_getOnlyTheCertainDataFields_when_attributesAreProvided() throws Exception { - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "?attribute=data.count&attribute=data.int-tag.score-int"); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); JsonObject dataJson = json.get("data").getAsJsonObject(); JsonObject acl = json.get("acl").getAsJsonObject(); @@ -120,10 +120,10 @@ public abstract class GetRecordsIntegrationTest extends TestBase { @Test public void should_notReturnFieldsAlreadyInDatastore_when_returningRecord() throws Exception { - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_OK, response.getCode()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); assertNotNull(json.get("id")); assertNotNull(json.get("kind")); @@ -141,13 +141,13 @@ public abstract class GetRecordsIntegrationTest extends TestBase { @Test public void should_legaltagChange_when_updateRecordWithLegaltag() throws Exception { String newJsonInput = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG_NAME_B); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), newJsonInput, "?skipdupes=false"); - assertEquals(201, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), newJsonInput, "?skipdupes=false"); + assertEquals(201, response.getCode()); response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); assertEquals(RECORD_ID, json.get("id").getAsString()); assertEquals(KIND, json.get("kind").getAsString()); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/IngestRecordNotFoundTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/IngestRecordNotFoundTest.java index 9453c6ff7c120984fb77b74e68deda9d43f672ff..18850cdcec12c23c353b41750929ea47f1ec36ee 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/IngestRecordNotFoundTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/IngestRecordNotFoundTest.java @@ -14,15 +14,14 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; - -import org.apache.http.HttpStatus; -import org.junit.*; - import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import static org.junit.Assert.assertEquals; public abstract class IngestRecordNotFoundTest extends TestBase { @@ -47,10 +46,10 @@ public abstract class IngestRecordNotFoundTest extends TestBase { String record = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG).replace(TestUtils.getAcl(), group); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); String result = TestUtils.getResult(response, HttpStatus.SC_BAD_REQUEST, String.class); - JsonObject jsonResponse = new JsonParser().parse(result).getAsJsonObject(); + JsonObject jsonResponse = JsonParser.parseString(result).getAsJsonObject(); assertEquals("Error on writing record", jsonResponse.get("reason").getAsString()); assertEquals("Could not find group \"" + group + "\".", jsonResponse.get("message").getAsString()); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalBatchRecordsDeleteTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalBatchRecordsDeleteTests.java index ab20e58af6b9ce6f047676a73fec05438b221fc6..fda71289cdaf251788f5973f0d83f445f6e9eaff 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalBatchRecordsDeleteTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalBatchRecordsDeleteTests.java @@ -18,7 +18,8 @@ import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.Test; import org.opengroup.osdu.storage.util.*; @@ -43,39 +44,39 @@ public abstract class LogicalBatchRecordsDeleteTests extends TestBase { public void should_deleteRecordsLogically_successfully() throws Exception { String requestBody = String.format("[\"%s\",\"%s\"]", RECORD_ID_1, RECORD_ID_2); - ClientResponse response = TestUtils.send("records/delete", "POST", + CloseableHttpResponse response = TestUtils.send("records/delete", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), requestBody, EMPTY); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_1, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_2, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); } @Test public void should_deleteRecordsLogically_withPartialSuccess_whenOneRecordNotFound() throws Exception { String requestBody = String.format("[\"%s\",\"%s\",\"%s\"]", RECORD_ID_1, RECORD_ID_2, NOT_EXISTED_RECORD_ID); - ClientResponse deleteResponse = TestUtils.send("records/delete", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse deleteResponse = TestUtils.send("records/delete", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), requestBody, EMPTY); - assertEquals(SC_MULTI_STATUS, deleteResponse.getStatus()); + assertEquals(SC_MULTI_STATUS, deleteResponse.getCode()); - JsonArray jsonBody = new JsonParser().parse(deleteResponse.getEntity(String.class)).getAsJsonArray(); + JsonArray jsonBody = JsonParser.parseString(EntityUtils.toString(deleteResponse.getEntity())).getAsJsonArray(); assertEquals(1, jsonBody.size()); assertEquals(getValueFromDeleteResponseJsonArray(jsonBody, "notDeletedRecordId"), NOT_EXISTED_RECORD_ID); assertEquals(getValueFromDeleteResponseJsonArray(jsonBody, "message"), "Record with id '" + NOT_EXISTED_RECORD_ID + "' not found"); - ClientResponse response = TestUtils.send("records/" + RECORD_ID_1, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(SC_NOT_FOUND, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID_1, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(SC_NOT_FOUND, response.getCode()); response = TestUtils.send("records/" + RECORD_ID_2, "GET",HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(SC_NOT_FOUND, response.getStatus()); + assertEquals(SC_NOT_FOUND, response.getCode()); } public void setup(String token) throws Exception { @@ -84,13 +85,13 @@ public abstract class LogicalBatchRecordsDeleteTests extends TestBase { String firstBody = createBody(RECORD_ID_1, "anything", Lists.newArrayList(LEGAL_TAG), Lists.newArrayList("BR", "IT")); String secondBody = createBody(RECORD_ID_2, "anything", Lists.newArrayList(LEGAL_TAG), Lists.newArrayList("BR", "IT")); - ClientResponse firstResponse = TestUtils.send("records", "PUT", + CloseableHttpResponse firstResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), firstBody, ""); - ClientResponse secondResponse = TestUtils.send("records", "PUT", + CloseableHttpResponse secondResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), secondBody, ""); - assertEquals(HttpStatus.SC_CREATED, firstResponse.getStatus()); - assertEquals(HttpStatus.SC_CREATED, secondResponse.getStatus()); + assertEquals(HttpStatus.SC_CREATED, firstResponse.getCode()); + assertEquals(HttpStatus.SC_CREATED, secondResponse.getCode()); } public void tearDown(String token) throws Exception { diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalRecordDeleteTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalRecordDeleteTests.java index e2e98977854ddcfee27e4229e069a7c346bd36e8..85244338feab946f57563787c3bbcdf6403f0383 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalRecordDeleteTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/LogicalRecordDeleteTests.java @@ -14,23 +14,21 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.apache.http.HttpStatus; - import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import org.junit.After; -import org.junit.Before; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.http.HttpStatus; import org.junit.Test; -import org.opengroup.osdu.storage.util.*; import org.opengroup.osdu.storage.util.DummyRecordsHelper.CreateRecordResponse; -import com.sun.jersey.api.client.ClientResponse; +import org.opengroup.osdu.storage.util.*; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public abstract class LogicalRecordDeleteTests extends TestBase { @@ -44,12 +42,12 @@ public abstract class LogicalRecordDeleteTests extends TestBase { String body = createBody(RECORD_ID, "anything", Lists.newArrayList(LEGAL_TAG), Lists.newArrayList("BR", "IT")); - ClientResponse response = TestUtils.send("records", "PUT", + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), body, ""); - String responseBody = response.getEntity(String.class); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + String responseBody = EntityUtils.toString(response.getEntity()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); Gson gson = new Gson(); CreateRecordResponse result = gson.fromJson(responseBody, CreateRecordResponse.class); @@ -71,19 +69,19 @@ public abstract class LogicalRecordDeleteTests extends TestBase { String queryParam = String.format("records/%s:delete", RECORD_ID); // deleting - ClientResponse response = TestUtils.send(queryParam, "POST", + CloseableHttpResponse response = TestUtils.send(queryParam, "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "{'anything':'teste'}", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); // trying to get response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); // trying to delete again response = TestUtils.send(queryParam, "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "{'anything':'teste'}", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); } protected static String createBody(String id, String dataValue, List<String> legalTags, List<String> ordc) { diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/ParentRecordValidationTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/ParentRecordValidationTest.java index 205f4a18e87c0e4d3be0bd3d67608184ce2b2c5e..f2e38871242cc95d5c22fb0dd76176c48c7ba637 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/ParentRecordValidationTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/ParentRecordValidationTest.java @@ -15,7 +15,8 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.Before; @@ -52,40 +53,40 @@ public abstract class ParentRecordValidationTest extends TestBase { @Test public void shouldReturn200_whenRecordContainsValidAncestry() throws Exception { - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), ""); - String responseString = response.getEntity(String.class); - String parentIdWithVersion = new JsonParser() - .parse(responseString) + String responseString = EntityUtils.toString(response.getEntity()); + String parentIdWithVersion = JsonParser + .parseString(responseString) .getAsJsonObject() .get("recordIdVersions") .getAsJsonArray() .get(0).getAsString(); - ClientResponse response2 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response2 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecordWithParentId(RECORD_ID_2, KIND, LEGAL_TAG, parentIdWithVersion), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); - assertEquals(HttpStatus.SC_CREATED, response2.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); + assertEquals(HttpStatus.SC_CREATED, response2.getCode()); } @Test public void shouldReturn404_whenRecordAncestryNotExisted() throws Exception { String parentIdWithVersion = "opendes:test:1.1.1000000000000:1000000000000000"; - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecordWithParentId(RECORD_ID_3, KIND, LEGAL_TAG, parentIdWithVersion), ""); String expectedErrorMessage = "The record 'RecordIdWithVersion(recordId=opendes:test:1.1.1000000000000, recordVersion=1000000000000000)' was not found"; - String actualErrorMessage = new JsonParser() - .parse(response.getEntity(String.class)) - .getAsJsonObject() - .get("message") - .getAsString(); + String actualErrorMessage = JsonParser + .parseString(EntityUtils.toString(response.getEntity())) + .getAsJsonObject() + .get("message") + .getAsString(); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); assertEquals(expectedErrorMessage, actualErrorMessage); } } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PatchRecordsTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PatchRecordsTest.java index 9b84e3c0c4fd4e14131609d23ecf9bafeb2e66ea..ee0cc9a0f1a5424edb20450650ea8edb4cf072f7 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PatchRecordsTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PatchRecordsTest.java @@ -16,29 +16,19 @@ package org.opengroup.osdu.storage.records; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.opengroup.osdu.storage.util.DummyRecordsHelper; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestBase; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; public abstract class PatchRecordsTest extends TestBase { @@ -57,13 +47,13 @@ public abstract class PatchRecordsTest extends TestBase { LegalTagUtils.create(LEGAL_TAG, testUtils.getToken()); LegalTagUtils.create(LEGAL_TAG_TO_BE_PATCHED, testUtils.getToken()); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecord(RECORD_ID1, KIND, LEGAL_TAG), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecord(RECORD_ID2, KIND, LEGAL_TAG), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); } @After @@ -79,8 +69,8 @@ public abstract class PatchRecordsTest extends TestBase { List<String> records = new ArrayList<>(); records.add(RECORD_ID1); records.add(RECORD_ID2); - ClientResponse queryResponse = queryRecordsResponse(records); - assertEquals(HttpStatus.SC_OK, queryResponse.getStatus()); + CloseableHttpResponse queryResponse = queryRecordsResponse(records); + assertEquals(HttpStatus.SC_OK, queryResponse.getCode()); DummyRecordsHelper.ConvertedRecordsMock queryResponseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse); assertQueryResponse(queryResponseObject, 2); @@ -89,11 +79,11 @@ public abstract class PatchRecordsTest extends TestBase { assertEquals(null, queryResponseObject.records[0].modifyTime); assertEquals(null, queryResponseObject.records[0].modifyUser); - ClientResponse patchResponse = TestUtils.sendWithCustomMediaType("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "application/json-patch+json", getPatchPayload(records, true, false), ""); - assertEquals(HttpStatus.SC_OK, patchResponse.getStatus()); + CloseableHttpResponse patchResponse = TestUtils.sendWithCustomMediaType("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "application/json-patch+json", getPatchPayload(records, true, false), ""); + assertEquals(HttpStatus.SC_OK, patchResponse.getCode()); queryResponse = queryRecordsResponse(records); - assertEquals(HttpStatus.SC_OK, queryResponse.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse.getCode()); queryResponseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse); //modifyUser and modifyTime are not reflected appropriately, please refer to this issue https://community.opengroup.org/osdu/platform/system/storage/-/issues/171 @@ -126,18 +116,18 @@ public abstract class PatchRecordsTest extends TestBase { public void should_updateDataAndMetadataVersion_whenOnlyDataIsPatched() throws Exception { List<String> records = new ArrayList<>(); records.add(RECORD_ID1); - ClientResponse queryResponse = queryRecordsResponse(records); - assertEquals(HttpStatus.SC_OK, queryResponse.getStatus()); + CloseableHttpResponse queryResponse = queryRecordsResponse(records); + assertEquals(HttpStatus.SC_OK, queryResponse.getCode()); DummyRecordsHelper.ConvertedRecordsMock queryResponseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse); assertQueryResponse(queryResponseObject, 1); String currentVersionRecord1 = queryResponseObject.records[0].version; - ClientResponse patchResponse = TestUtils.sendWithCustomMediaType("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "application/json-patch+json", getPatchPayload(records, false, true), ""); - assertEquals(HttpStatus.SC_OK, patchResponse.getStatus()); + CloseableHttpResponse patchResponse = TestUtils.sendWithCustomMediaType("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "application/json-patch+json", getPatchPayload(records, false, true), ""); + assertEquals(HttpStatus.SC_OK, patchResponse.getCode()); queryResponse = queryRecordsResponse(records); - assertEquals(HttpStatus.SC_OK, queryResponse.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse.getCode()); queryResponseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse); assertNotEquals(currentVersionRecord1, queryResponseObject.records[0].version); @@ -151,18 +141,18 @@ public abstract class PatchRecordsTest extends TestBase { public void should_updateBothMetadataAndData_whenDataAndMetadataArePatched() throws Exception { List<String> records = new ArrayList<>(); records.add(RECORD_ID1); - ClientResponse queryResponse = queryRecordsResponse(records); - assertEquals(HttpStatus.SC_OK, queryResponse.getStatus()); + CloseableHttpResponse queryResponse = queryRecordsResponse(records); + assertEquals(HttpStatus.SC_OK, queryResponse.getCode()); DummyRecordsHelper.ConvertedRecordsMock queryResponseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse); assertQueryResponse(queryResponseObject, 1); String currentVersionRecord = queryResponseObject.records[0].version; - ClientResponse patchResponse = TestUtils.sendWithCustomMediaType("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "application/json-patch+json", getPatchPayload(records, true, true), ""); - assertEquals(HttpStatus.SC_OK, patchResponse.getStatus()); + CloseableHttpResponse patchResponse = TestUtils.sendWithCustomMediaType("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "application/json-patch+json", getPatchPayload(records, true, true), ""); + assertEquals(HttpStatus.SC_OK, patchResponse.getCode()); queryResponse = queryRecordsResponse(records); - assertEquals(HttpStatus.SC_OK, queryResponse.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse.getCode()); queryResponseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse); assertEquals(1, queryResponseObject.records.length); @@ -184,7 +174,7 @@ public abstract class PatchRecordsTest extends TestBase { //TODO: add a test to validate same 'op' and 'path' and assert expected behavior - private ClientResponse queryRecordsResponse(List<String> recordIds) throws Exception { + private CloseableHttpResponse queryRecordsResponse(List<String> recordIds) throws Exception { JsonArray records = new JsonArray(); for (String recordId : recordIds) { records.add(recordId); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PurgeRecordsIntegrationTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PurgeRecordsIntegrationTest.java index 25e47dcb7efd3ea0699119461e346fe5d0483489..fb1ed85e96d25efe76c6de134dc8616c0959bbc0 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PurgeRecordsIntegrationTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/PurgeRecordsIntegrationTest.java @@ -14,14 +14,13 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; -import org.junit.*; - +import org.junit.Test; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public abstract class PurgeRecordsIntegrationTest extends TestBase { @@ -35,9 +34,9 @@ public abstract class PurgeRecordsIntegrationTest extends TestBase { LegalTagUtils.create(LEGAL_TAG, token); String jsonInput = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); - assertEquals(201, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), jsonInput, ""); + assertEquals(201, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); } public static void classTearDown(String token) throws Exception { @@ -46,10 +45,10 @@ public abstract class PurgeRecordsIntegrationTest extends TestBase { @Test public void should_ReturnHttp204_when_purgingRecordSuccessfully() throws Exception { - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); } } \ No newline at end of file diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordAccessAuthorizationTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordAccessAuthorizationTests.java index 4dfd70e1696f8cfcb24d5b77cdc1f7abf238abd0..2376e47ae044019982a927ca937c819a6555c80c 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordAccessAuthorizationTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordAccessAuthorizationTests.java @@ -14,18 +14,20 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; - -import java.util.Map; - -import org.apache.http.HttpStatus; -import org.junit.*; - import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import java.io.IOException; +import java.util.Map; + +import static org.junit.Assert.assertEquals; public abstract class RecordAccessAuthorizationTests extends TestBase { @@ -37,10 +39,10 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { public static void classSetup(String token) throws Exception { LegalTagUtils.create(LEGAL_TAG, token); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); } public static void classTearDown(String token) throws Exception { @@ -54,7 +56,7 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "GET", headers, "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "GET", headers, "", ""); this.assertNotAuthorized(response); } @@ -64,7 +66,7 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records/versions/" + RECORD_ID, "GET", headers, "", ""); + CloseableHttpResponse response = TestUtils.send("records/versions/" + RECORD_ID, "GET", headers, "", ""); this.assertNotAuthorized(response); } @@ -74,8 +76,8 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { Map<String, String> withDataAccessHeader = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); - ClientResponse response = TestUtils.send("records/versions/" + RECORD_ID, "GET", withDataAccessHeader, "", ""); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + CloseableHttpResponse response = TestUtils.send("records/versions/" + RECORD_ID, "GET", withDataAccessHeader, "", ""); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); String version = json.get("versions").getAsJsonArray().get(0).toString(); Map<String, String> withoutDataAccessHeader = HeaderUtils.getHeaders(TenantUtils.getTenantName(), @@ -91,7 +93,7 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records/", "POST", headers, "{'anything':'anything'}", + CloseableHttpResponse response = TestUtils.send("records/", "POST", headers, "{'anything':'anything'}", RECORD_ID + ":delete"); this.assertNotAuthorized(response); @@ -102,10 +104,10 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", headers, "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", headers, "", ""); - assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + assertEquals(HttpStatus.SC_FORBIDDEN, response.getCode()); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); assertEquals(403, json.get("code").getAsInt()); assertEquals("Access denied", json.get("reason").getAsString()); } @@ -115,7 +117,7 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records", "PUT", headers, + CloseableHttpResponse response = TestUtils.send("records", "PUT", headers, RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), ""); this.assertNotAuthorized(response); @@ -131,10 +133,10 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { Map<String, String> headersWithValidAccessToken = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); - ClientResponse response = TestUtils.send("records", "PUT", headersWithValidAccessToken, + CloseableHttpResponse response = TestUtils.send("records", "PUT", headersWithValidAccessToken, RecordUtil.createDefaultJsonRecord(newRecordId, KIND, LEGAL_TAG), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); // Query for original record (no access) and recently created record (with // access) @@ -149,7 +151,7 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { body.add("records", records); response = TestUtils.send("query/records", "POST", headersWithNoDataAccessToken, body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.RecordsMock responseObject = new DummyRecordsHelper().getRecordsMockFromResponse(response); @@ -160,9 +162,16 @@ public abstract class RecordAccessAuthorizationTests extends TestBase { TestUtils.send("records/" + newRecordId, "DELETE", headersWithNoDataAccessToken, "", ""); } - protected void assertNotAuthorized(ClientResponse response) { - assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatus()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + protected void assertNotAuthorized(CloseableHttpResponse response) { + assertEquals(HttpStatus.SC_FORBIDDEN, response.getCode()); + JsonObject json = null; + try { + json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } assertEquals(403, json.get("code").getAsInt()); assertEquals("Access denied", json.get("reason").getAsString()); assertEquals("The user is not authorized to perform this action", json.get("message").getAsString()); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithEntV2OnlyAclTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithEntV2OnlyAclTest.java index ad0e38e52aaccc6097fb7b687abe45f0aab0b279..4d66f93a68e13a4398e7f7a49ef15107df29418d 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithEntV2OnlyAclTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithEntV2OnlyAclTest.java @@ -1,6 +1,6 @@ package org.opengroup.osdu.storage.records; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.Before; @@ -31,9 +31,9 @@ public abstract class RecordWithEntV2OnlyAclTest extends TestBase { @Test public void should_allow_recordWithAclThatExistsIOnlyInEntV2() throws Exception{ //create record - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createJsonRecordWithEntV2OnlyAcl(RECORD_ID, KIND, LEGAL_TAG, RECORD_ID), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); } } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithNullFieldTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithNullFieldTest.java index ac51e6597d43edb13b4031b3385c82afdeec3d65..576f18efd6767902bd19863c0b264940cd4a1ec9 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithNullFieldTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordWithNullFieldTest.java @@ -14,22 +14,20 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import com.google.gson.JsonArray; import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.http.HttpStatus; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.opengroup.osdu.storage.util.*; import org.opengroup.osdu.storage.util.DummyRecordsHelper.RecordResultMock; -import com.sun.jersey.api.client.ClientResponse; + +import static org.junit.Assert.*; public abstract class RecordWithNullFieldTest extends TestBase { @@ -57,15 +55,15 @@ public abstract class RecordWithNullFieldTest extends TestBase { public void should_returnRecordWithoutNullFields_when_recordIsIngestedWithNullFields() throws Exception { // create record with null field - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createJsonRecordWithData(RECORD_ID, KIND, LEGAL_TAG, null), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); // get record response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); JsonObject dataJson = json.get("data").getAsJsonObject(); assertEquals("58377304471659395", dataJson.get("score-int").toString()); @@ -82,7 +80,7 @@ public abstract class RecordWithNullFieldTest extends TestBase { body.add("attributes", attributes); response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); DummyRecordsHelper.RecordsMock responseObject = new DummyRecordsHelper().getRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); @@ -100,7 +98,7 @@ public abstract class RecordWithNullFieldTest extends TestBase { attributes.add("data.custom"); response = TestUtils.send("query/records", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body.toString(), ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); responseObject = new DummyRecordsHelper().getRecordsMockFromResponse(response); assertEquals(1, responseObject.records.length); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordsApiAcceptanceTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordsApiAcceptanceTests.java index 1bf1867509dce12d036ce2a1573537ecad0797cf..637b7e82f665fc262efe473dea1fef1a8b1f7017 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordsApiAcceptanceTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/RecordsApiAcceptanceTests.java @@ -14,27 +14,23 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - import com.google.common.base.Strings; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.HttpStatus; -import org.junit.*; - import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.commons.lang3.StringUtils; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.util.*; -import com.sun.jersey.api.client.ClientResponse; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.*; public abstract class RecordsApiAcceptanceTests extends TestBase { @@ -71,10 +67,10 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { public void should_createNewRecord_when_givenValidRecord_and_verifyNoAncestry() throws Exception { String jsonInput = createJsonBody(RECORD_NEW_ID, "Flor�"); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - String json = response.getEntity(String.class); - assertEquals(201, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + String json = EntityUtils.toString(response.getEntity()); + assertEquals(201, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); Gson gson = new Gson(); DummyRecordsHelper.CreateRecordResponse result = gson.fromJson(json, @@ -87,14 +83,14 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { response = TestUtils.send("records/" + RECORD_NEW_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); GetRecordResponse recordResult = TestUtils.getResult(response, 200, GetRecordResponse.class); - assertEquals("Flor�", recordResult.data.get("name")); + assertEquals("Flor?", recordResult.data.get("name")); assertEquals(null, recordResult.data.get("ancestry")); } @Test public void should_updateRecordsWithSameData_when_skipDupesIsFalse() throws Exception { - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); GetRecordResponse recordResult = TestUtils.getResult(response, 200, GetRecordResponse.class); String jsonInput = createJsonBody(RECORD_ID, "tianNew"); @@ -152,7 +148,7 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { public void should_getAnOlderVersion_and_theMostRecentVersion_and_retrieveAllVersions() throws Exception { - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); GetRecordResponse originalRecordResult = TestUtils.getResult(response, 200, GetRecordResponse.class); String jsonInput = createJsonBody(RECORD_ID, "tianNew2"); @@ -192,11 +188,11 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { String jsonInput = createJsonBody(idToDelete, "tianNew2"); // add an extra version - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); TestUtils.getResult(response, 201, DummyRecordsHelper.CreateRecordResponse.class); response = TestUtils.send("records/" + idToDelete, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); response = TestUtils.send("records/" + idToDelete, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); String notFoundResponse = TestUtils.getResult(response, 404, String.class); @@ -208,7 +204,7 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { public void should_ingestRecord_when_noRecordIdIsProvided() throws Exception { String body = createJsonBody(null, "Foo"); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); String responseString = TestUtils.getResult(response, 201, String.class); JsonObject responseJson = new JsonParser().parse(responseString).getAsJsonObject(); @@ -225,14 +221,14 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { String body = createJsonBody(RECORD_ID, "Foo"); // injesting record - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); TestUtils.getResult(response, 201, String.class); // getting record response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); String responseString = TestUtils.getResult(response, 200, String.class); - JsonObject responseJson = new JsonParser().parse(responseString).getAsJsonObject(); + JsonObject responseJson = JsonParser.parseString(responseString).getAsJsonObject(); assertEquals(RECORD_ID, responseJson.get("id").getAsString()); @@ -249,11 +245,11 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { public void should_returnWholeRecord_when_recordIsIngestedWithOtherTenantInKind() throws Exception { final String RECORD_ID = TenantUtils.getTenantName() + ":inttest:wholerecord-" + System.currentTimeMillis(); String body = createJsonBody(RECORD_ID, "Foo", KIND_WITH_OTHER_TENANT); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); TestUtils.getResult(response, 201, String.class); response = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); String responseString = TestUtils.getResult(response, 200, String.class); - JsonObject responseJson = new JsonParser().parse(responseString).getAsJsonObject(); + JsonObject responseJson = JsonParser.parseString(responseString).getAsJsonObject(); assertEquals(RECORD_ID, responseJson.get("id").getAsString()); assertEquals(KIND_WITH_OTHER_TENANT, responseJson.get("kind").getAsString()); JsonObject acl = responseJson.get("acl").getAsJsonObject(); @@ -266,7 +262,7 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { public void should_insertNewRecord_when_skipDupesIsTrue() throws Exception { final String RECORD_ID = TenantUtils.getTenantName() + ":inttest:wholerecord-" + System.currentTimeMillis(); String body = createJsonBody(RECORD_ID, "Foo"); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, "?skipdupes=true"); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, "?skipdupes=true"); DummyRecordsHelper.CreateRecordResponse result = TestUtils.getResult(response, 201, DummyRecordsHelper.CreateRecordResponse.class); assertNotNull(result); assertEquals(1, result.recordCount); @@ -274,7 +270,7 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { assertEquals(1, result.recordIdVersions.length); assertEquals(RECORD_ID, result.recordIds[0]); response = TestUtils.send("records/" + RECORD_ID, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); } @Test @@ -285,10 +281,10 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { String jsonInput = createJsonBody(RECORD_ID, "TestSpecialCharacters"); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); - String json = response.getEntity(String.class); - assertEquals(201, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, ""); + String json = EntityUtils.toString(response.getEntity()); + assertEquals(201, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); Gson gson = new Gson(); DummyRecordsHelper.CreateRecordResponse result = gson.fromJson(json, @@ -310,7 +306,7 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { // Different CSPs are responding with different status code for this error when a special character like %25 is present in the URL. // Hence the Assert Statement is marked not to be 200. // More details - https://community.opengroup.org/osdu/platform/system/storage/-/issues/61 - assertNotEquals(200, response.getStatus()); + assertNotEquals(200, response.getCode()); } } @@ -320,7 +316,7 @@ public abstract class RecordsApiAcceptanceTests extends TestBase { String jsonInput = createJsonBody(RECORD_ID_3, "tianNew"); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, "?skipdupes=false"); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, "?skipdupes=false"); DummyRecordsHelper.CreateRecordResponse result = TestUtils.getResult(response, 201, DummyRecordsHelper.CreateRecordResponse.class); assertNotNull(result); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/UpdateRecordsMetadataTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/UpdateRecordsMetadataTest.java index cc4f58e9216e60da824bec618e74af189bbdf964..3cf4bdc01fcd7c527b4480c17cd30d2c07c3d19a 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/UpdateRecordsMetadataTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/records/UpdateRecordsMetadataTest.java @@ -17,18 +17,21 @@ package org.opengroup.osdu.storage.records; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import org.junit.*; -import org.opengroup.osdu.storage.util.*; - import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.opengroup.osdu.storage.util.*; import java.util.Map; import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.apache.http.HttpStatus.*; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public abstract class UpdateRecordsMetadataTest extends TestBase { protected static final String TAG_KEY = "tagkey1"; @@ -68,18 +71,18 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { LegalTagUtils.create(LEGAL_TAG_2, testUtils.getToken()); LegalTagUtils.create(LEGAL_TAG_3, testUtils.getToken()); LegalTagUtils.create(LEGAL_TAG_4, testUtils.getToken()); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), ""); - ClientResponse response2 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response2 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecord(RECORD_ID_2, KIND, LEGAL_TAG_2), ""); - ClientResponse response3 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response3 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecord(RECORD_ID_3, KIND, LEGAL_TAG_3), ""); - ClientResponse response4 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse response4 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), RecordUtil.createDefaultJsonRecord(RECORD_ID_4, KIND, LEGAL_TAG_4), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); - assertEquals(HttpStatus.SC_CREATED, response2.getStatus()); - assertEquals(HttpStatus.SC_CREATED, response3.getStatus()); - assertEquals(HttpStatus.SC_CREATED, response4.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); + assertEquals(HttpStatus.SC_CREATED, response2.getCode()); + assertEquals(HttpStatus.SC_CREATED, response3.getCode()); + assertEquals(HttpStatus.SC_CREATED, response4.getCode()); } @@ -107,9 +110,9 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { Map<String, String> queryHeader = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); queryHeader.put("frame-of-reference", "none"); - ClientResponse queryResponse1 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), + CloseableHttpResponse queryResponse1 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), ""); - assertEquals(HttpStatus.SC_OK, queryResponse1.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse1.getCode()); DummyRecordsHelper.ConvertedRecordsMock queryResponseObject1 = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse1); assertEquals(2, queryResponseObject1.records.length); @@ -138,14 +141,14 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { updateBody.add("query", query); updateBody.add("ops", ops); - ClientResponse bulkUpdateResponse = TestUtils.send("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), updateBody.toString(), + CloseableHttpResponse bulkUpdateResponse = TestUtils.send("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), updateBody.toString(), ""); - assertEquals(HttpStatus.SC_OK, bulkUpdateResponse.getStatus()); + assertEquals(HttpStatus.SC_OK, bulkUpdateResponse.getCode()); //3. query 2 records again, check acls - ClientResponse queryResponse2 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), + CloseableHttpResponse queryResponse2 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), ""); - assertEquals(HttpStatus.SC_OK, queryResponse2.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse2.getCode()); DummyRecordsHelper.ConvertedRecordsMock queryResponseObject2 = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse2); assertEquals(2, queryResponseObject2.records.length); @@ -165,9 +168,9 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { Map<String, String> queryHeader = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); queryHeader.put("slb-frame-of-reference", "none"); - ClientResponse queryResponse1 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), + CloseableHttpResponse queryResponse1 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), ""); - assertEquals(HttpStatus.SC_OK, queryResponse1.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse1.getCode()); DummyRecordsHelper.ConvertedRecordsMock queryResponseObject1 = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse1); assertEquals(2, queryResponseObject1.records.length); @@ -200,14 +203,14 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { updateBody.add("query", query); updateBody.add("ops", ops); - ClientResponse bulkUpdateResponse = TestUtils.send("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), updateBody.toString(), + CloseableHttpResponse bulkUpdateResponse = TestUtils.send("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), updateBody.toString(), ""); - assertEquals(HttpStatus.SC_PARTIAL_CONTENT, bulkUpdateResponse.getStatus()); + assertEquals(HttpStatus.SC_PARTIAL_CONTENT, bulkUpdateResponse.getCode()); //3. query 2 records again, check acls - ClientResponse queryResponse2 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), + CloseableHttpResponse queryResponse2 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(), ""); - assertEquals(HttpStatus.SC_OK, queryResponse2.getStatus()); + assertEquals(HttpStatus.SC_OK, queryResponse2.getCode()); DummyRecordsHelper.ConvertedRecordsMock queryResponseObject2 = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse2); assertEquals(2, queryResponseObject2.records.length); @@ -220,16 +223,16 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { //add operation JsonObject updateBody = RecordUtil.buildUpdateTagBody(RECORD_ID, "add", TAG_KEY + ":" + TAG_VALUE1); - ClientResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - ClientResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); + CloseableHttpResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); + CloseableHttpResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - assertEquals(SC_OK, updateResponse.getStatus()); - assertEquals(SC_OK, recordResponse.getStatus()); + assertEquals(SC_OK, updateResponse.getCode()); + assertEquals(SC_OK, recordResponse.getCode()); - JsonObject resultObject = bodyToJsonObject(updateResponse.getEntity(String.class)); + JsonObject resultObject = bodyToJsonObject(EntityUtils.toString(updateResponse.getEntity())); assertEquals(RECORD_ID, resultObject.get("recordIds").getAsJsonArray().get(0).getAsString()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(TAG_VALUE1, resultObject.get("tags").getAsJsonObject().get(TAG_KEY).getAsString()); //replace operation @@ -237,7 +240,7 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(TAG_VALUE2, resultObject.get("tags").getAsJsonObject().get(TAG_KEY).getAsString()); //remove operation @@ -245,7 +248,7 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - resultObject = new JsonParser().parse(recordResponse.getEntity(String.class)).getAsJsonObject(); + resultObject = JsonParser.parseString(EntityUtils.toString(recordResponse.getEntity())).getAsJsonObject(); assertNull(resultObject.get("tags")); } @@ -253,16 +256,16 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { public void should_return206andUpdateTagsMetadata_whenNotExistedRecordProvided() throws Exception { JsonObject updateBody = RecordUtil.buildUpdateTagBody(NOT_EXISTED_RECORD_ID, "replace", TAG_KEY + ":" + TAG_VALUE1); - ClientResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); + CloseableHttpResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - assertEquals(SC_PARTIAL_CONTENT, updateResponse.getStatus()); - JsonObject resultObject = bodyToJsonObject(updateResponse.getEntity(String.class)); + assertEquals(SC_PARTIAL_CONTENT, updateResponse.getCode()); + JsonObject resultObject = bodyToJsonObject(EntityUtils.toString(updateResponse.getEntity())); System.out.println(resultObject.toString()); assertEquals(NOT_EXISTED_RECORD_ID, resultObject.get("notFoundRecordIds").getAsJsonArray().getAsString()); } - private static ClientResponse sendRequest(String method, String path, String body, String token) throws Exception { + private static CloseableHttpResponse sendRequest(String method, String path, String body, String token) throws Exception { return TestUtils .send(path, method, HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), body, ""); } @@ -272,7 +275,7 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { } private JsonObject bodyToJsonObject(String json) { - return new JsonParser().parse(json).getAsJsonObject(); + return JsonParser.parseString(json).getAsJsonObject(); } @Test @@ -280,16 +283,16 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { //add operation JsonObject updateBody = buildUpdateLegalBody(RECORD_ID, "add", LEGAL_TAG); - ClientResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - ClientResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); + CloseableHttpResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); + CloseableHttpResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - assertEquals(SC_OK, updateResponse.getStatus()); - assertEquals(SC_OK, recordResponse.getStatus()); + assertEquals(SC_OK, updateResponse.getCode()); + assertEquals(SC_OK, recordResponse.getCode()); - JsonObject resultObject = bodyToJsonObject(updateResponse.getEntity(String.class)); + JsonObject resultObject = bodyToJsonObject(EntityUtils.toString(updateResponse.getEntity())); assertEquals(RECORD_ID, resultObject.get("recordIds").getAsJsonArray().get(0).getAsString()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(LEGAL_TAG, resultObject.get("legal").getAsJsonObject().get("legaltags").getAsString()); //replace operation @@ -297,14 +300,14 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(LEGAL_TAG_2, resultObject.get("legal").getAsJsonObject().get("legaltags").getAsString()); //remove operation updateBody = buildUpdateLegalBody(RECORD_ID,"remove", LEGAL_TAG_2); updateResponse= sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - assertEquals(SC_BAD_REQUEST,updateResponse.getStatus()); + assertEquals(SC_BAD_REQUEST,updateResponse.getCode()); } @Test @@ -312,16 +315,16 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { //add operation JsonObject updateBody = buildUpdateAclBody(RECORD_ID, "add","/acl/viewers", ACL); - ClientResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - ClientResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); + CloseableHttpResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); + CloseableHttpResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - assertEquals(SC_OK, updateResponse.getStatus()); - assertEquals(SC_OK, recordResponse.getStatus()); + assertEquals(SC_OK, updateResponse.getCode()); + assertEquals(SC_OK, recordResponse.getCode()); - JsonObject resultObject = bodyToJsonObject(updateResponse.getEntity(String.class)); + JsonObject resultObject = bodyToJsonObject(EntityUtils.toString(updateResponse.getEntity())); assertEquals(RECORD_ID, resultObject.get("recordIds").getAsJsonArray().get(0).getAsString()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(ACL, resultObject.get("acl").getAsJsonObject().get("viewers").getAsJsonArray().get(0).getAsString()); //replace operation @@ -329,14 +332,14 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(ACL_2, resultObject.get("acl").getAsJsonObject().get("viewers").getAsJsonArray().get(0).getAsString()); //remove operation updateBody = buildUpdateAclBody(RECORD_ID,"remove","/acl/viewers", ACL_2); updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - assertEquals(SC_BAD_REQUEST,updateResponse.getStatus()); + assertEquals(SC_BAD_REQUEST,updateResponse.getCode()); } @Test @@ -344,16 +347,16 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { //add operation JsonObject updateBody = buildUpdateAclBody(RECORD_ID, "add","/acl/owners", ACL); - ClientResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - ClientResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); + CloseableHttpResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); + CloseableHttpResponse recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - assertEquals(SC_OK, updateResponse.getStatus()); - assertEquals(SC_OK, recordResponse.getStatus()); + assertEquals(SC_OK, updateResponse.getCode()); + assertEquals(SC_OK, recordResponse.getCode()); - JsonObject resultObject = bodyToJsonObject(updateResponse.getEntity(String.class)); + JsonObject resultObject = bodyToJsonObject(EntityUtils.toString(updateResponse.getEntity())); assertEquals(RECORD_ID, resultObject.get("recordIds").getAsJsonArray().get(0).getAsString()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(ACL, resultObject.get("acl").getAsJsonObject().get("owners").getAsJsonArray().get(0).getAsString()); //remove operation @@ -361,7 +364,7 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - resultObject = new JsonParser().parse(recordResponse.getEntity(String.class)).getAsJsonObject(); + resultObject = JsonParser.parseString(EntityUtils.toString(recordResponse.getEntity())).getAsJsonObject(); assertEquals(ACL, resultObject.get("acl").getAsJsonObject().get("owners").getAsJsonArray().get(0).getAsString()); @@ -370,7 +373,7 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); recordResponse = sendRequest("GET", "records/" + RECORD_ID, EMPTY, testUtils.getToken()); - resultObject = bodyToJsonObject(recordResponse.getEntity(String.class)); + resultObject = bodyToJsonObject(EntityUtils.toString(recordResponse.getEntity())); assertEquals(ACL, resultObject.get("acl").getAsJsonObject().get("owners").getAsJsonArray().get(0).getAsString()); } @@ -378,10 +381,10 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { public void should_return206andUpdateLegalMetadata_whenNotExistedRecordProvided() throws Exception { JsonObject updateBody = buildUpdateLegalBody(NOT_EXISTED_RECORD_ID, "replace", LEGAL_TAG); - ClientResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); + CloseableHttpResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - assertEquals(SC_PARTIAL_CONTENT, updateResponse.getStatus()); - JsonObject resultObject = bodyToJsonObject(updateResponse.getEntity(String.class)); + assertEquals(SC_PARTIAL_CONTENT, updateResponse.getCode()); + JsonObject resultObject = bodyToJsonObject(EntityUtils.toString(updateResponse.getEntity())); System.out.println(resultObject.toString()); assertEquals(NOT_EXISTED_RECORD_ID, resultObject.get("notFoundRecordIds").getAsJsonArray().getAsString()); @@ -391,10 +394,10 @@ public abstract class UpdateRecordsMetadataTest extends TestBase { public void should_return206andUpdateAclMetadata_whenNotExistedRecordProvided() throws Exception { JsonObject updateBody = buildUpdateAclBody(NOT_EXISTED_RECORD_ID, "replace","/acl/viewers", ACL); - ClientResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); + CloseableHttpResponse updateResponse = sendRequest("PATCH", "records", toJson(updateBody), testUtils.getToken()); - assertEquals(SC_PARTIAL_CONTENT, updateResponse.getStatus()); - JsonObject resultObject = bodyToJsonObject(updateResponse.getEntity(String.class)); + assertEquals(SC_PARTIAL_CONTENT, updateResponse.getCode()); + JsonObject resultObject = bodyToJsonObject(EntityUtils.toString(updateResponse.getEntity())); System.out.println(resultObject.toString()); assertEquals(NOT_EXISTED_RECORD_ID, resultObject.get("notFoundRecordIds").getAsJsonArray().getAsString()); diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/CreateSchemaIntegrationTests.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/CreateSchemaIntegrationTests.java index 45efbcff148e472a438cc43192e0d56e90f880a4..c98d51167a14ba2950e0394cd8028bfeb84b3bbc 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/CreateSchemaIntegrationTests.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/CreateSchemaIntegrationTests.java @@ -14,21 +14,21 @@ package org.opengroup.osdu.storage.schema; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.apache.http.HttpStatus; -import org.junit.Test; - import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.util.HeaderUtils; import org.opengroup.osdu.storage.util.TenantUtils; -import com.sun.jersey.api.client.ClientResponse; import org.opengroup.osdu.storage.util.TestBase; import org.opengroup.osdu.storage.util.TestUtils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public abstract class CreateSchemaIntegrationTests extends TestBase { protected final String schema = TenantUtils.getTenantName() + ":storage:inttest:1.0.0" @@ -41,23 +41,22 @@ public abstract class CreateSchemaIntegrationTests extends TestBase { String body = this.validPostBody(this.schema); // Create schema - ClientResponse response = TestUtils.send("schemas", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); - assertEquals("", response.getEntity(String.class)); + CloseableHttpResponse response = TestUtils.send("schemas", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); + assertEquals("", EntityUtils.toString(response.getEntity())); // Try to create again response = TestUtils.send("schemas", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), body, ""); - assertEquals(HttpStatus.SC_CONFLICT, response.getStatus()); + assertEquals(HttpStatus.SC_CONFLICT, response.getCode()); assertEquals( "{\"code\":409,\"reason\":\"Schema already registered\",\"message\":\"The schema information for the given kind already exists.\"}", - response.getEntity(String.class)); + EntityUtils.toString(response.getEntity())); // Get the schema response = TestUtils.send("schemas/" + this.schema, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(HttpStatus.SC_OK, response.getCode()); - JsonParser parser = new JsonParser(); - JsonObject json = parser.parse(response.getEntity(String.class)).getAsJsonObject(); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); assertEquals(this.schema, json.get("kind").getAsString()); assertEquals(2, json.get("schema").getAsJsonArray().size()); @@ -76,14 +75,14 @@ public abstract class CreateSchemaIntegrationTests extends TestBase { // get schema by a user belonging to another tenant, make sure DpsHeader/Tenant is per request rather than singleton response = TestUtils.send("schemas/" + this.schema, "GET", HeaderUtils.getHeaders("common", testUtils.getToken()), "", ""); - assertTrue(HttpStatus.SC_FORBIDDEN == response.getStatus() || HttpStatus.SC_UNAUTHORIZED == response.getStatus()); + assertTrue(HttpStatus.SC_FORBIDDEN == response.getCode() || HttpStatus.SC_UNAUTHORIZED == response.getCode()); // Delete schema response = TestUtils.send("schemas/" + this.schema, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus()); + assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode()); response = TestUtils.send("schemas/" + this.schema, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, response.getCode()); } } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/StorageSchemaNegativeTest.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/StorageSchemaNegativeTest.java index 5e7337391c3220e2b83acbc5e29e7092c98fdc1f..91979b3fa56ad554be4a902e3dcc78d254de279f 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/StorageSchemaNegativeTest.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/schema/StorageSchemaNegativeTest.java @@ -14,21 +14,20 @@ package org.opengroup.osdu.storage.schema; -import static org.junit.Assert.assertEquals; - -import javax.ws.rs.HttpMethod; - -import org.apache.http.HttpStatus; -import org.junit.Test; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; +import org.junit.Test; import org.opengroup.osdu.storage.util.HeaderUtils; import org.opengroup.osdu.storage.util.TenantUtils; import org.opengroup.osdu.storage.util.TestBase; import org.opengroup.osdu.storage.util.TestUtils; -import com.sun.jersey.api.client.ClientResponse; + +import javax.ws.rs.HttpMethod; + +import static org.junit.Assert.assertEquals; public abstract class StorageSchemaNegativeTest extends TestBase { @@ -41,70 +40,70 @@ public abstract class StorageSchemaNegativeTest extends TestBase { public void should_notCreateSchema_when_userDoesWrongKindFormat() throws Exception { String kind = "abc"; JsonElement jsonInputRecord = createSchemaPayload(kind); - ClientResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputRecord.toString(), ""); - assertEquals(HttpStatus.SC_BAD_REQUEST, recordResponse.getStatus()); + assertEquals(HttpStatus.SC_BAD_REQUEST, recordResponse.getCode()); } @Test public void should_notCreateSchema_when_schemaAlreadyExists() throws Exception { if (configUtils != null && configUtils.getIsSchemaEndpointsEnabled()) { JsonElement jsonInputRecord = createSchemaPayload(this.kind); - ClientResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputRecord.toString(), ""); - assertEquals(HttpStatus.SC_CREATED, recordResponse.getStatus()); - ClientResponse recordResponseCreateAgain = TestUtils.send(this.SCHEMAS, HttpMethod.POST, + assertEquals(HttpStatus.SC_CREATED, recordResponse.getCode()); + CloseableHttpResponse recordResponseCreateAgain = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputRecord.toString(), ""); - assertEquals(HttpStatus.SC_CONFLICT, recordResponseCreateAgain.getStatus()); - ClientResponse deleteResponse = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getStatus()); + assertEquals(HttpStatus.SC_CONFLICT, recordResponseCreateAgain.getCode()); + CloseableHttpResponse deleteResponse = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getCode()); } } @Test public void should_notGetKindDetails_when_userDoesSpecifyNonExistingKind() throws Exception { String kind = "abc"; - ClientResponse recordResponse = TestUtils.send(this.SCHEMAS + "/" + kind, HttpMethod.GET, + CloseableHttpResponse recordResponse = TestUtils.send(this.SCHEMAS + "/" + kind, HttpMethod.GET, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_BAD_REQUEST, recordResponse.getStatus()); + assertEquals(HttpStatus.SC_BAD_REQUEST, recordResponse.getCode()); } @Test public void should_notGetSchemaDetails_when_thereIsNoSchemaExist() throws Exception { if (configUtils != null && configUtils.getIsSchemaEndpointsEnabled()) { JsonElement jsonInputRecord = createSchemaPayload(this.kind); - ClientResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputRecord.toString(), ""); - assertEquals(HttpStatus.SC_CREATED, recordResponse.getStatus()); - ClientResponse deleteResponse = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getStatus()); - ClientResponse recordResponseNotFound = TestUtils.send(this.path, HttpMethod.GET, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", + assertEquals(HttpStatus.SC_CREATED, recordResponse.getCode()); + CloseableHttpResponse deleteResponse = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getCode()); + CloseableHttpResponse recordResponseNotFound = TestUtils.send(this.path, HttpMethod.GET, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, recordResponseNotFound.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, recordResponseNotFound.getCode()); } } @Test public void should_notDeleteSchemaByUsingKind_when_userDoesNotSpecifyWrongKind() throws Exception { - ClientResponse deleteResponseWithNoKind = TestUtils.send(this.SCHEMAS + "/" + "abc", HttpMethod.DELETE, + CloseableHttpResponse deleteResponseWithNoKind = TestUtils.send(this.SCHEMAS + "/" + "abc", HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_BAD_REQUEST, deleteResponseWithNoKind.getStatus()); + assertEquals(HttpStatus.SC_BAD_REQUEST, deleteResponseWithNoKind.getCode()); } @Test public void should_notDeleteSchemaByUsingKind_when_no_schemaExist() throws Exception { if (configUtils != null && configUtils.getIsSchemaEndpointsEnabled()) { JsonElement jsonInputRecord = createSchemaPayload(this.kind); - ClientResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), + CloseableHttpResponse recordResponse = TestUtils.send(this.SCHEMAS, HttpMethod.POST, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInputRecord.toString(), ""); - assertEquals(HttpStatus.SC_CREATED, recordResponse.getStatus()); - ClientResponse deleteResponse = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); + assertEquals(HttpStatus.SC_CREATED, recordResponse.getCode()); + CloseableHttpResponse deleteResponse = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getStatus()); - ClientResponse deleteResponseAgain = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", + assertEquals(HttpStatus.SC_NO_CONTENT, deleteResponse.getCode()); + CloseableHttpResponse deleteResponseAgain = TestUtils.send(this.path, HttpMethod.DELETE, HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - assertEquals(HttpStatus.SC_NOT_FOUND, deleteResponseAgain.getStatus()); + assertEquals(HttpStatus.SC_NOT_FOUND, deleteResponseAgain.getCode()); } } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/CustomHttpClientResponseHandler.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/CustomHttpClientResponseHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..3158130bc2be844bf4a22a09c304a97b214e4bd3 --- /dev/null +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/CustomHttpClientResponseHandler.java @@ -0,0 +1,30 @@ +package org.opengroup.osdu.storage.util; + +import lombok.extern.slf4j.Slf4j; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.*; +import org.apache.hc.core5.http.io.HttpClientResponseHandler; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.entity.StringEntity; + +import java.io.IOException; + +@Slf4j +public class CustomHttpClientResponseHandler implements HttpClientResponseHandler<CloseableHttpResponse> { + + @Override + public CloseableHttpResponse handleResponse(ClassicHttpResponse classicHttpResponse) { + HttpEntity entity = classicHttpResponse.getEntity(); + if(classicHttpResponse.getCode() != HttpStatus.SC_NO_CONTENT) { + String body = ""; + try { + body = EntityUtils.toString(entity); + } catch (IOException | ParseException e) { + log.error("unable to parse response"); + } + HttpEntity newEntity = new StringEntity(body, ContentType.parse(entity.getContentType())); + classicHttpResponse.setEntity(newEntity); + } + return (CloseableHttpResponse) classicHttpResponse; + } +} diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/DummyRecordsHelper.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/DummyRecordsHelper.java index 24e03362b11925a129222b71dec44cb9f6cfe265..09aab8af7bf86ff30979fe3cc06035bff1ced758 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/DummyRecordsHelper.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/DummyRecordsHelper.java @@ -14,14 +14,17 @@ package org.opengroup.osdu.storage.util; -import static org.junit.Assert.assertTrue; +import com.google.gson.Gson; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import java.io.IOException; import java.sql.Timestamp; import java.util.List; import java.util.Map; -import com.google.gson.Gson; -import com.sun.jersey.api.client.ClientResponse; +import static org.junit.Assert.assertTrue; public class DummyRecordsHelper { @@ -29,23 +32,44 @@ public class DummyRecordsHelper { public final String KIND = TenantUtils.getTenantName() + ":storage:inttest:1.0.0" + NOW; - public QueryResultMock getQueryResultMockFromResponse(ClientResponse response) { - assertTrue(response.getType().toString().contains("application/json")); - String json = response.getEntity(String.class); + public QueryResultMock getQueryResultMockFromResponse(CloseableHttpResponse response) { + assertTrue(response.getEntity().getContentType().contains("application/json")); + String json; + try { + json = EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } Gson gson = new Gson(); return gson.fromJson(json, QueryResultMock.class); } - public RecordsMock getRecordsMockFromResponse(ClientResponse response) { - assertTrue(response.getType().toString().contains("application/json")); - String json = response.getEntity(String.class); + public RecordsMock getRecordsMockFromResponse(CloseableHttpResponse response) { + assertTrue(response.getEntity().getContentType().contains("application/json")); + String json = null; + try { + json = EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } Gson gson = new Gson(); return gson.fromJson(json, RecordsMock.class); } - public ConvertedRecordsMock getConvertedRecordsMockFromResponse(ClientResponse response) { - assertTrue(response.getType().toString().contains("application/json")); - String json = response.getEntity(String.class); + public ConvertedRecordsMock getConvertedRecordsMockFromResponse(CloseableHttpResponse response) { + assertTrue(response.getEntity().getContentType().contains("application/json")); + String json = null; + try { + json = EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } Gson gson = new Gson(); return gson.fromJson(json, ConvertedRecordsMock.class); } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/EntitlementsUtil.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/EntitlementsUtil.java index 4562f673d26e08d9cec70bc86a2090ea1223f5ba..e7de29a952bc9b6056fdafaa32ee538e2f32a163 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/EntitlementsUtil.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/EntitlementsUtil.java @@ -18,19 +18,21 @@ package org.opengroup.osdu.storage.util; import com.google.gson.JsonObject; -import com.sun.jersey.api.client.ClientResponse; + import java.util.Map; + +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.springframework.http.HttpMethod; public class EntitlementsUtil { public static final String GROUPS_ENDPOINT = "groups"; - public static ClientResponse createEntitlementsGroup(Map<String, String> headers, - String groupName, - String groupDescription) throws Exception { + public static CloseableHttpResponse createEntitlementsGroup(Map<String, String> headers, + String groupName, + String groupDescription) throws Exception { String body = getCreateGroupBody(groupName, groupDescription); - ClientResponse response = TestUtils.send( + CloseableHttpResponse response = TestUtils.send( getEntitlementsUrl(), GROUPS_ENDPOINT, HttpMethod.POST.name(), @@ -41,10 +43,10 @@ public class EntitlementsUtil { return response; } - public static ClientResponse deleteEntitlementsGroup(Map<String, String> headers, - String groupEmail) + public static CloseableHttpResponse deleteEntitlementsGroup(Map<String, String> headers, + String groupEmail) throws Exception { - ClientResponse response = TestUtils.send( + CloseableHttpResponse response = TestUtils.send( getEntitlementsUrl(), GROUPS_ENDPOINT, HttpMethod.DELETE.name(), diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/LegalTagUtils.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/LegalTagUtils.java index 1767957e60a468d28180b1c1ab7fff3f91d7e0aa..c1fd1fcdbca39c85ecb7dc9be12ee2c55c7f07c8 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/LegalTagUtils.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/LegalTagUtils.java @@ -14,35 +14,34 @@ package org.opengroup.osdu.storage.util; -import static org.junit.Assert.assertEquals; - -import org.apache.http.HttpStatus; - import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; + +import static org.junit.Assert.assertEquals; public class LegalTagUtils { public static String createRandomName() { return TenantUtils.getTenantName() + "-storage-" + System.currentTimeMillis(); } - public static ClientResponse create(String legalTagName, String token) throws Exception { + public static CloseableHttpResponse create(String legalTagName, String token) throws Exception { return create("US", legalTagName, "2099-01-25", "Public Domain Data", token); } - protected static ClientResponse create(String countryOfOrigin, String name, String expDate, String dataType, String token) + protected static CloseableHttpResponse create(String countryOfOrigin, String name, String expDate, String dataType, String token) throws Exception { String body = getBody(countryOfOrigin, name, expDate, dataType); - ClientResponse response = TestUtils.send(getLegalUrl(), "legaltags", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), body, + CloseableHttpResponse response = TestUtils.send(getLegalUrl(), "legaltags", "POST", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), body, ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); Thread.sleep(100); return response; } - public static ClientResponse delete(String legalTagName, String token) throws Exception { + public static CloseableHttpResponse delete(String legalTagName, String token) throws Exception { return TestUtils.send(getLegalUrl(), "legaltags/" + legalTagName, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), token), "", ""); } diff --git a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/TestUtils.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/TestUtils.java index 4895dbb18193f5710c2bc6ec0753c563763f24a2..a1d2b4dd405d60e3d561122369308e33fb3b1c3c 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/TestUtils.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/TestUtils.java @@ -14,36 +14,34 @@ package org.opengroup.osdu.storage.util; +import com.google.gson.Gson; +import org.apache.commons.lang.NotImplementedException; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager; +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpStatus; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.concurrent.TimeUnit; + import static org.apache.http.HttpStatus.SC_CREATED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.opengroup.osdu.storage.util.HeaderUtils.getHeadersWithxCollaboration; import static org.opengroup.osdu.storage.util.TestBase.GSON; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.net.HttpURLConnection; -import java.net.URL; -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 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 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.lang.NotImplementedException; -import org.apache.http.HttpStatus; - public abstract class TestUtils { protected static String token = null; protected static String noDataAccesstoken = null; @@ -87,7 +85,7 @@ public abstract class TestUtils { return System.getProperty("DEPLOY_ENV", System.getenv("DEPLOY_ENV")); } - public static String getApiPath(String api) throws Exception { + public static String getApiPath(String api) throws MalformedURLException { String baseUrl = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL")); if (baseUrl == null || baseUrl.contains("-null")) { baseUrl = "https://localhost:8443/api/storage/v2/"; @@ -97,18 +95,32 @@ public abstract class TestUtils { return mergedURL.toString(); } - public static void assertRecordVersion(ClientResponse response, Long expectedVersion) { - assertEquals(HttpStatus.SC_OK, response.getStatus()); + public static void assertRecordVersion(CloseableHttpResponse response, Long expectedVersion) { + assertEquals(HttpStatus.SC_OK, response.getCode()); - String responseBody = response.getEntity(String.class); + String responseBody; + try { + responseBody = EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } DummyRecordsHelper.RecordResultMock result = gson.fromJson(responseBody, DummyRecordsHelper.RecordResultMock.class); assertEquals(expectedVersion.longValue(), Long.parseLong(result.version)); } - public static String assertRecordVersionAndReturnResponseBody(ClientResponse response, Long expectedVersion) { - assertEquals(HttpStatus.SC_OK, response.getStatus()); + public static String assertRecordVersionAndReturnResponseBody(CloseableHttpResponse response, Long expectedVersion) { + assertEquals(HttpStatus.SC_OK, response.getCode()); - String responseBody = response.getEntity(String.class); + String responseBody; + try { + responseBody = EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } DummyRecordsHelper.RecordResultMock result = gson.fromJson(responseBody, DummyRecordsHelper.RecordResultMock.class); assertEquals(expectedVersion.longValue(), Long.parseLong(result.version)); return responseBody; @@ -122,45 +134,46 @@ public abstract class TestUtils { throw new NotImplementedException(); } - public static ClientResponse sendWithCustomMediaType(String path, String httpMethod, Map<String, String> headers, String contentType, String requestBody, - String query) throws Exception { + public static CloseableHttpResponse sendWithCustomMediaType(String path, String httpMethod, Map<String, String> headers, String contentType, String requestBody, + String query) throws Exception { log(httpMethod, TestUtils.getApiPath(path + query), headers, requestBody); - Client client = TestUtils.getClient(); + BasicHttpClientConnectionManager cm = createBasicHttpClientConnectionManager(); + headers.put("Content-Type", contentType); + ClassicHttpRequest httpRequest = createHttpRequest(TestUtils.getApiPath(path + query), httpMethod, requestBody, headers); - WebResource webResource = client.resource(TestUtils.getApiPath(path + query)); - - WebResource.Builder builder = webResource.accept(MediaType.APPLICATION_JSON).type(contentType); - headers.forEach(builder::header); - - return builder.method(httpMethod, ClientResponse.class, requestBody); + try (CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(cm).build()) { + return httpClient.execute(httpRequest, new CustomHttpClientResponseHandler()); + } } - public static ClientResponse send(String path, String httpMethod, Map<String, String> headers, String requestBody, - String query) throws Exception { + public static CloseableHttpResponse send(String path, String httpMethod, Map<String, String> headers, String requestBody, + String query) throws Exception { log(httpMethod, TestUtils.getApiPath(path + query), headers, requestBody); - Client client = TestUtils.getClient(); - WebResource webResource = client.resource(TestUtils.getApiPath(path + query)); + BasicHttpClientConnectionManager cm = createBasicHttpClientConnectionManager(); + headers.put("Content-Type", MediaType.APPLICATION_JSON); + headers.put("Accept-Charset","utf-8"); + ClassicHttpRequest httpRequest = createHttpRequest(TestUtils.getApiPath(path + query), httpMethod, requestBody, headers); - WebResource.Builder builder = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON); - headers.forEach(builder::header); - - return builder.method(httpMethod, ClientResponse.class, requestBody); + try (CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(cm).build()) { + return httpClient.execute(httpRequest, new CustomHttpClientResponseHandler()); + } } - public static ClientResponse send(String url, String path, String httpMethod, Map<String, String> headers, - String requestBody, String query) throws Exception { + public static CloseableHttpResponse send(String url, String path, String httpMethod, Map<String, String> headers, + String requestBody, String query) throws Exception { log(httpMethod, url + path, headers, requestBody); - Client client = TestUtils.getClient(); - WebResource webResource = client.resource(url + path); - WebResource.Builder builder = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON); - headers.forEach(builder::header); + BasicHttpClientConnectionManager cm = createBasicHttpClientConnectionManager(); + headers.put("Content-Type", MediaType.APPLICATION_JSON); + ClassicHttpRequest httpRequest = createHttpRequest(url + path, httpMethod, requestBody, headers); - return builder.method(httpMethod, ClientResponse.class, requestBody); + try (CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(cm).build()) { + return httpClient.execute(httpRequest, new CustomHttpClientResponseHandler()); + } } private static void log(String method, String url, Map<String, String> headers, String body) { @@ -169,78 +182,58 @@ public abstract class TestUtils { } @SuppressWarnings("unchecked") - public static <T> T getResult(ClientResponse response, int exepectedStatus, Class<T> classOfT) { - assertEquals(exepectedStatus, response.getStatus()); + public static <T> T getResult(CloseableHttpResponse response, int exepectedStatus, Class<T> classOfT) { + assertEquals(exepectedStatus, response.getCode()); if (exepectedStatus == 204) { return null; } - assertTrue(response.getType().toString().contains("application/json")); - String json = response.getEntity(String.class); + assertTrue(response.getEntity().getContentType().contains("application/json")); + String json; + try { + json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } if (classOfT == String.class) { return (T) json; } - return gson.fromJson(json, classOfT); } public static Long createRecordInCollaborationContext_AndReturnVersion(String recordId, String kind, String legaltag, String collaborationId, String applicationName, String tenant_name, String token) throws Exception { String jsonInput = RecordUtil.createDefaultJsonRecord(recordId, kind, legaltag); - ClientResponse response = TestUtils.send("records", "PUT", getHeadersWithxCollaboration(collaborationId, applicationName, tenant_name, token), jsonInput, ""); - assertEquals(SC_CREATED, response.getStatus()); - assertTrue(response.getType().toString().contains("application/json")); + CloseableHttpResponse response = TestUtils.send("records", "PUT", getHeadersWithxCollaboration(collaborationId, applicationName, tenant_name, token), jsonInput, ""); + assertEquals(SC_CREATED, response.getCode()); + assertTrue(response.getEntity().getContentType().contains("application/json")); - String responseBody = response.getEntity(String.class); + String responseBody = EntityUtils.toString(response.getEntity()); DummyRecordsHelper.CreateRecordResponse result = GSON.fromJson(responseBody, DummyRecordsHelper.CreateRecordResponse.class); return Long.parseLong(result.recordIdVersions[0].split(":")[3]); } - 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 ClassicHttpRequest createHttpRequest(String path, String httpMethod, String requestBody, + Map<String, String> headers) throws MalformedURLException { + ClassicRequestBuilder classicRequestBuilder = ClassicRequestBuilder.create(httpMethod) + .setUri(path) + .setEntity(requestBody, ContentType.APPLICATION_JSON); + headers.forEach(classicRequestBuilder::addHeader); + return classicRequestBuilder.build(); } - 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); + private static BasicHttpClientConnectionManager createBasicHttpClientConnectionManager() { + ConnectionConfig connConfig = ConnectionConfig.custom() + .setConnectTimeout(1500000, TimeUnit.MILLISECONDS) + .setSocketTimeout(1500000, TimeUnit.MILLISECONDS) + .build(); + BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(); + cm.setConnectionConfig(connConfig); + return cm; + } - 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/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/VersionInfoUtils.java b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/VersionInfoUtils.java index ded1f68d021d1d3b9b709cd2c72bf74e5b4420ae..0bee982cf47bd374758517acf0b4846db4cac613 100644 --- a/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/VersionInfoUtils.java +++ b/testing/storage-test-core/src/main/java/org/opengroup/osdu/storage/util/VersionInfoUtils.java @@ -1,15 +1,26 @@ package org.opengroup.osdu.storage.util; -import static org.junit.Assert.assertTrue; - import com.google.gson.Gson; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; + +import java.io.IOException; + +import static org.junit.Assert.assertTrue; public class VersionInfoUtils { - public VersionInfo getVersionInfoFromResponse(ClientResponse response) { - assertTrue(response.getType().toString().contains("application/json")); - String json = response.getEntity(String.class); + public VersionInfo getVersionInfoFromResponse(CloseableHttpResponse response) { + assertTrue(response.getEntity().getContentType().contains("application/json")); + String json = null; + try { + json = EntityUtils.toString(response.getEntity()); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } Gson gson = new Gson(); return gson.fromJson(json, VersionInfo.class); } diff --git a/testing/storage-test-gc/pom.xml b/testing/storage-test-gc/pom.xml index 3a1bea13118e789d166ae3e35f86f6ca7b8457c4..ffb4ba537dd7243e70b551a76e440f97c528918b 100644 --- a/testing/storage-test-gc/pom.xml +++ b/testing/storage-test-gc/pom.xml @@ -1,19 +1,20 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 2017-2019 Schlumberger - - 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. ---> + ~ 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. + --> <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"> <parent> @@ -31,8 +32,9 @@ <packaging>jar</packaging> <properties> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <java.version>17</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.main.basedir>${project.basedir}</project.main.basedir> </properties> @@ -72,7 +74,7 @@ <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> - <version>2.9.1</version> + <version>2.10.1</version> </dependency> <dependency> <groupId>com.google.auth</groupId> diff --git a/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java b/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java index a4d75e7a69ff1c34a4a15f7fcecf8ee27a0054a1..16a7bef5e8090c51858efed4007cad105b9a2af7 100644 --- a/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java +++ b/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/PubsubEndpoint/TestPubsubEndpoint.java @@ -14,21 +14,13 @@ package org.opengroup.osdu.storage.PubsubEndpoint; -import com.sun.jersey.api.client.ClientResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.http.HttpStatus; +import org.junit.*; +import org.opengroup.osdu.storage.util.*; + import java.util.ArrayList; import java.util.List; -import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.opengroup.osdu.storage.util.GCPTestUtils; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.LegalTagUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; public class TestPubsubEndpoint extends PubsubEndpointTest { @@ -65,10 +57,10 @@ public class TestPubsubEndpoint extends PubsubEndpointTest { List<String> legalTagNames = new ArrayList<>(); legalTagNames.add(LEGAL_TAG_1); legalTagNames.add(LEGAL_TAG_2); - ClientResponse responseRecordQuery = + CloseableHttpResponse responseRecordQuery = TestUtils.send("records/" + RECORD_ID, "GET", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); - Assert.assertEquals(HttpStatus.SC_NOT_FOUND, responseRecordQuery.getStatus()); + Assert.assertEquals(HttpStatus.SC_NOT_FOUND, responseRecordQuery.getCode()); long now = System.currentTimeMillis(); long later = now + 2000L; @@ -78,13 +70,13 @@ public class TestPubsubEndpoint extends PubsubEndpointTest { String recordIdTemp2 = TenantUtils.getTenantName() + ":endtoend:1.1." + later; String recordTemp2 = RecordUtil.createDefaultJsonRecord(recordIdTemp2, kindTemp, LEGAL_TAG_2); - ClientResponse responseInvalid = + CloseableHttpResponse responseInvalid = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp1, ""); - Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, responseInvalid.getStatus()); + Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, responseInvalid.getCode()); Assert.assertEquals("Invalid legal tags", this.getResponseReasonFromRecordIngestResponse(responseInvalid)); - ClientResponse responseValid3 = + CloseableHttpResponse responseValid3 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), recordTemp2, ""); - Assert.assertEquals(HttpStatus.SC_CREATED, responseValid3.getStatus()); + Assert.assertEquals(HttpStatus.SC_CREATED, responseValid3.getCode()); TestUtils.send("records/" + recordIdTemp2, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", ""); } } diff --git a/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java b/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java index 2d02c7184d0487a2ebe223c2ca979252473c99d0..4bb4ecb0ce7e3767278ae4ceea84290b856e4696 100644 --- a/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java +++ b/testing/storage-test-gc/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java @@ -14,23 +14,20 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; - import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; -import java.util.Map; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import org.opengroup.osdu.storage.util.ConfigUtils; -import org.opengroup.osdu.storage.util.GCPTestUtils; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; +import org.opengroup.osdu.storage.util.*; + +import java.util.Map; + +import static org.junit.Assert.assertEquals; public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTests { @@ -70,11 +67,11 @@ public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTest Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records", "PUT", headers, + CloseableHttpResponse response = TestUtils.send("records", "PUT", headers, RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), ""); - assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatus()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode()); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); assertEquals(401, json.get("code").getAsInt()); assertEquals("Error from compliance service", json.get("reason").getAsString()); assertEquals("Legal response 401 {\"code\":401,\"reason\":\"Unauthorized\",\"message\":\"The user is not authorized to perform this action\"}", json.get("message").getAsString()); diff --git a/testing/storage-test-ibm/pom.xml b/testing/storage-test-ibm/pom.xml index ad17b02491f891e5044d39496adf7c949c6b2645..a46cf9c044cc8aca3fd0e3737aa37c98e1ad5962 100644 --- a/testing/storage-test-ibm/pom.xml +++ b/testing/storage-test-ibm/pom.xml @@ -30,8 +30,9 @@ <packaging>jar</packaging> <properties> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <java.version>17</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.main.basedir>${project.basedir}</project.main.basedir> <MY_TENANT>opendes</MY_TENANT> @@ -76,7 +77,7 @@ <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> - <version>2.9.1</version> + <version>2.10.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> diff --git a/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java b/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java index 41f5c2dc453280ca8d85fd28d7a7fdd15030a36f..b5d6122bdb495f70fcb5d8161feb8c4e19658b6b 100644 --- a/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java +++ b/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestIngestRecordNotFound.java @@ -14,20 +14,10 @@ package org.opengroup.osdu.storage.records; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.opengroup.osdu.storage.util.HeaderUtils; -import org.opengroup.osdu.storage.util.IBMTestUtils; -import org.opengroup.osdu.storage.util.RecordUtil; -import org.opengroup.osdu.storage.util.TenantUtils; -import org.opengroup.osdu.storage.util.TestUtils; - -import com.sun.jersey.api.client.ClientResponse; +import org.junit.*; +import org.opengroup.osdu.storage.util.*; public class TestIngestRecordNotFound extends IngestRecordNotFoundTest { @@ -65,7 +55,7 @@ public class TestIngestRecordNotFound extends IngestRecordNotFoundTest { String record = RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG).replace(TestUtils.getAcl(), group); - ClientResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); + CloseableHttpResponse response = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), record, ""); // it's a much simpler implementation to just check if the user is in the group that is being saved and if not to skip // per previous integration test requirements TestUtils.getResult(response, HttpStatus.SC_FORBIDDEN, String.class); diff --git a/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java b/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java index 97f45deb8c03ede2e599826cc3f7aa44d7ee0a45..e93aa0c00b5bbc849ca3b7d0433cdcb607d91bc2 100644 --- a/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java +++ b/testing/storage-test-ibm/src/test/java/org/opengroup/osdu/storage/records/TestRecordAccessAuthorization.java @@ -14,18 +14,18 @@ package org.opengroup.osdu.storage.records; -import static org.junit.Assert.assertEquals; - -import java.util.Map; - import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; import org.junit.*; import org.opengroup.osdu.storage.util.*; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.sun.jersey.api.client.ClientResponse; +import java.util.Map; + +import static org.junit.Assert.assertEquals; public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTests { @@ -58,11 +58,11 @@ public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTest Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records", "PUT", headers, + CloseableHttpResponse response = TestUtils.send("records", "PUT", headers, RecordUtil.createDefaultJsonRecord(RECORD_ID, KIND, LEGAL_TAG), ""); - assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatus()); - JsonObject json = new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); + assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode()); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); assertEquals(401, json.get("code").getAsInt()); assertEquals("Access denied", json.get("reason").getAsString()); assertEquals("The user is not authorized to perform this action", json.get("message").getAsString()); @@ -71,23 +71,17 @@ public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTest @Override public void should_receiveHttp403_when_userIsNotAuthorizedToGetLatestVersionOfARecord() throws Exception { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), this.testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "GET", headers, "", ""); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "GET", headers, "", ""); this.assertNotAuthorized(response); } - protected void assertNotAuthorized(ClientResponse response) { - Assert.assertEquals(401L, (long)response.getStatus()); - JsonObject json = (new JsonParser()).parse((String)response.getEntity(String.class)).getAsJsonObject(); - Assert.assertEquals(401L, (long)json.get("code").getAsInt()); - Assert.assertEquals("Access denied", json.get("reason").getAsString()); - Assert.assertEquals("The user is not authorized to perform this action", json.get("message").getAsString()); - } + @Test public void should_receiveHttp403_when_userIsNotAuthorizedToPurgeRecord() throws Exception { Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), this.testUtils.getNoDataAccessToken()); - ClientResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", headers, "", ""); - Assert.assertEquals(401L, (long)response.getStatus()); - JsonObject json = (new JsonParser()).parse((String)response.getEntity(String.class)).getAsJsonObject(); - Assert.assertEquals(401L, (long)json.get("code").getAsInt()); + CloseableHttpResponse response = TestUtils.send("records/" + RECORD_ID, "DELETE", headers, "", ""); + Assert.assertEquals(401, response.getCode()); + JsonObject json = JsonParser.parseString(EntityUtils.toString(response.getEntity())).getAsJsonObject(); + Assert.assertEquals(401, json.get("code").getAsInt()); Assert.assertEquals("Access denied", json.get("reason").getAsString()); } @@ -101,10 +95,10 @@ public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTest Map<String, String> headersWithValidAccessToken = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()); - ClientResponse response = TestUtils.send("records", "PUT", headersWithValidAccessToken, + CloseableHttpResponse response = TestUtils.send("records", "PUT", headersWithValidAccessToken, RecordUtil.createDefaultJsonRecord(newRecordId, KIND, LEGAL_TAG), ""); - assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + assertEquals(HttpStatus.SC_CREATED, response.getCode()); // Query for original record (no access) and recently created record (with // access) @@ -119,7 +113,7 @@ public class TestRecordAccessAuthorization extends RecordAccessAuthorizationTest body.add("records", records); response = TestUtils.send("query/records", "POST", headersWithNoDataAccessToken, body.toString(), ""); - assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatus()); + assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getCode()); TestUtils.send("records/" + newRecordId, "DELETE", headersWithNoDataAccessToken, "", ""); diff --git a/testing/storage-test-ibm/src/test/resources/logback-test.xml b/testing/storage-test-ibm/src/test/resources/logback-test.xml new file mode 100644 index 0000000000000000000000000000000000000000..22c6175d45f368b69c4006deb9ebf3ff5084579a --- /dev/null +++ b/testing/storage-test-ibm/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/defaults.xml"/> + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) %n</pattern> + <charset>utf8</charset> + </encoder> + </appender> + <root level="INFO"> + <appender-ref ref="CONSOLE" /> + </root> +</configuration>