diff --git a/partition-acceptance-test/pom.xml b/partition-acceptance-test/pom.xml index 53e4307afe0250a3831421faa52f35f58b14466c..d40d532781f46e22dad37abeeabc3e8b6eab1726 100644 --- a/partition-acceptance-test/pom.xml +++ b/partition-acceptance-test/pom.xml @@ -14,57 +14,63 @@ 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"> - <modelVersion>4.0.0</modelVersion> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <groupId>org.opengroup.osdu.partition</groupId> - <artifactId>partition-acceptance-test</artifactId> - <version>0.28.0-SNAPSHOT</version> - <packaging>jar</packaging> + <groupId>org.opengroup.osdu.partition</groupId> + <artifactId>partition-acceptance-test</artifactId> + <version>0.28.0-SNAPSHOT</version> + <packaging>jar</packaging> - <properties> - <java.version>17</java.version> - <maven.compiler.target>17</maven.compiler.target> - <maven.compiler.source>17</maven.compiler.source> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> + <properties> + <java.version>17</java.version> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> - <dependencies> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>1.18.24</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-client</artifactId> - <version>1.19.4</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13.2</version> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.10.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>5.2.7.RELEASE</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents.client5</groupId> - <artifactId>httpclient5</artifactId> - <version>5.2.1</version> - </dependency> - <dependency> - <groupId>com.nimbusds</groupId> - <artifactId>oauth2-oidc-sdk</artifactId> - <version>9.15</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.24</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-client</artifactId> + <version>1.19.4</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13.2</version> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.10.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>5.2.7.RELEASE</version> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents.client5</groupId> + <artifactId>httpclient5</artifactId> + <version>5.2.1</version> + </dependency> + <dependency> + <groupId>com.nimbusds</groupId> + <artifactId>oauth2-oidc-sdk</artifactId> + <version>9.15</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>2.15.2</version> + </dependency> + </dependencies> </project> diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/CreatePartitionTest.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/CreatePartitionTest.java index 3bf113825964dee7dbad419881892c1869a87481..b43ed23eae16132d5d9eea6ad8721d5de048c68e 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/CreatePartitionTest.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/CreatePartitionTest.java @@ -16,18 +16,15 @@ package org.opengroup.osdu.partition.api; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.junit.After; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.opengroup.osdu.partition.api.descriptor.CreatePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor; -import org.opengroup.osdu.partition.api.util.AuthorizationTestUtil; import org.opengroup.osdu.partition.util.BaseTestTemplate; import org.opengroup.osdu.partition.util.TestTokenUtils; import org.springframework.http.HttpStatus; import static org.junit.Assert.assertEquals; -import static org.opengroup.osdu.partition.util.Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS; public final class CreatePartitionTest extends BaseTestTemplate { @@ -37,7 +34,6 @@ public final class CreatePartitionTest extends BaseTestTemplate { @Before public void setup() { this.testUtils = new TestTokenUtils(); - this.authorizationTestUtil = new AuthorizationTestUtil(this.descriptor, this.testUtils); } @Override @@ -45,7 +41,6 @@ public final class CreatePartitionTest extends BaseTestTemplate { public void tearDown() throws Exception { deleteResource(); this.testUtils = null; - this.authorizationTestUtil = null; } @Override @@ -80,7 +75,6 @@ public final class CreatePartitionTest extends BaseTestTemplate { CloseableHttpResponse response2 = this.descriptor.run(this.getId(), testUtils.getAccessToken()); assertEquals(this.error(""), HttpStatus.CONFLICT.value(), response2.getCode()); - deleteResource(); } @Test @@ -89,25 +83,4 @@ public final class CreatePartitionTest extends BaseTestTemplate { CloseableHttpResponse response = descriptor.runWithCustomPayload(getId(), invalidPayload, testUtils.getAccessToken()); assertEquals(400, response.getCode()); } - - @Override - @Test - public void should_return401_when_noAccessToken() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_noAccessToken(getId()); - } - - @Override - @Test - public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId()); - } - - @Override - @Test - public void should_return401_when_makingHttpRequestWithoutToken() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId()); - } } diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/DeletePartitionTest.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/DeletePartitionTest.java index 3ed57040380195e8d8b90542303938dca49f428f..cc2c728924e67230353fd63410bb38a81b2b27df 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/DeletePartitionTest.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/DeletePartitionTest.java @@ -14,25 +14,30 @@ package org.opengroup.osdu.partition.api; +import com.fasterxml.jackson.databind.JsonNode; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.io.entity.EntityUtils; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.opengroup.osdu.partition.api.descriptor.CreatePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor; -import org.opengroup.osdu.partition.api.util.AuthorizationTestUtil; +import org.opengroup.osdu.partition.api.descriptor.GetPartitionDescriptor; import org.opengroup.osdu.partition.util.BaseTestTemplate; -import org.opengroup.osdu.partition.util.Constants; import org.opengroup.osdu.partition.util.RestDescriptor; import org.opengroup.osdu.partition.util.TestTokenUtils; +import org.opengroup.osdu.partition.util.TestUtils; import org.springframework.http.HttpStatus; -import static org.opengroup.osdu.partition.util.Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS; +import java.util.Map; public final class DeletePartitionTest extends BaseTestTemplate { private String partitionId; private static String integrationTestPrefix = getIntegrationTestPrefix(); + private GetPartitionDescriptor getDescriptor = new GetPartitionDescriptor(); public DeletePartitionTest() { super(createDeleteDescriptor(integrationTestPrefix + System.currentTimeMillis())); @@ -43,7 +48,6 @@ public final class DeletePartitionTest extends BaseTestTemplate { @Override public void setup() throws Exception { this.testUtils = new TestTokenUtils(); - this.authorizationTestUtil = new AuthorizationTestUtil(descriptor, testUtils); } @After @@ -51,7 +55,6 @@ public final class DeletePartitionTest extends BaseTestTemplate { public void tearDown() throws Exception { deleteResource(); this.testUtils = null; - this.authorizationTestUtil = null; } private static DeletePartitionDescriptor createDeleteDescriptor(String id) { @@ -95,25 +98,23 @@ public final class DeletePartitionTest extends BaseTestTemplate { Assert.assertEquals(this.error(""), HttpStatus.NOT_FOUND.value(), response1.getCode()); } - @Override @Test - public void should_return401_when_noAccessToken() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_noAccessToken(getId()); - } + public void create_and_delete_partition() throws Exception { + //create Resource + createResource(); - @Override - @Test - public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId()); - } + //get partition + CloseableHttpResponse getPartitionResponse = getDescriptor.run(this.getId(), this.testUtils.getAccessToken()); + Map<String, JsonNode> partitionProperties = TestUtils.parseResponse(getPartitionResponse); + Assert.assertEquals(HttpStatus.OK.value(), getPartitionResponse.getCode()); + Assert.assertNotNull(partitionProperties); - @Override - @Test - public void should_return401_when_makingHttpRequestWithoutToken() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId()); + //delete partition + deleteResource(); + + //get deleted Partition + CloseableHttpResponse postDeleteResponse = getDescriptor.run(this.getId(), this.testUtils.getAccessToken()); + Assert.assertEquals(HttpStatus.NOT_FOUND.value(), postDeleteResponse.getCode()); } @Override diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/GetPartitionByIdApiTest.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/GetPartitionByIdApiTest.java index 141d874258b9c81ccb71c139d7df8e5940f8a332..c66aac452c912efe77a1a427a74258d57fce22ea 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/GetPartitionByIdApiTest.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/GetPartitionByIdApiTest.java @@ -14,22 +14,24 @@ package org.opengroup.osdu.partition.api; +import com.fasterxml.jackson.databind.JsonNode; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.junit.After; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.opengroup.osdu.partition.api.descriptor.CreatePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.GetPartitionDescriptor; -import org.opengroup.osdu.partition.api.util.AuthorizationTestUtil; import org.opengroup.osdu.partition.util.BaseTestTemplate; -import org.opengroup.osdu.partition.util.Constants; import org.opengroup.osdu.partition.util.TestTokenUtils; +import org.opengroup.osdu.partition.util.TestUtils; import org.springframework.http.HttpStatus; +import java.util.Map; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; public final class GetPartitionByIdApiTest extends BaseTestTemplate { @@ -37,9 +39,8 @@ public final class GetPartitionByIdApiTest extends BaseTestTemplate { @Override @Before - public void setup() throws Exception { + public void setup() { this.testUtils = new TestTokenUtils(); - this.authorizationTestUtil = new AuthorizationTestUtil(this.descriptor, this.testUtils); } @Override @@ -47,7 +48,6 @@ public final class GetPartitionByIdApiTest extends BaseTestTemplate { public void tearDown() throws Exception { deleteResource(); this.testUtils = null; - this.authorizationTestUtil = null; } @Override @@ -59,7 +59,7 @@ public final class GetPartitionByIdApiTest extends BaseTestTemplate { protected void deleteResource() throws Exception { DeletePartitionDescriptor deletePartitionDes = new DeletePartitionDescriptor(); deletePartitionDes.setPartitionId(partitionId); - CloseableHttpResponse response = deletePartitionDes.run(this.getId(), this.testUtils.getAccessToken()); + deletePartitionDes.run(this.getId(), this.testUtils.getAccessToken()); } @Override @@ -81,25 +81,15 @@ public final class GetPartitionByIdApiTest extends BaseTestTemplate { return HttpStatus.OK.value(); } - @Override @Test - public void should_return401_when_noAccessToken() throws Exception { - Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_noAccessToken(getId()); - } + public void create_and_read_partition() throws Exception { + createResource(); - @Override - @Test - public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception { - Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId()); - } + //get partition + CloseableHttpResponse response = this.descriptor.run(this.getId(), this.testUtils.getAccessToken()); + Map<String, JsonNode> partitionProperties = TestUtils.parseResponse(response); - @Override - @Test - public void should_return401_when_makingHttpRequestWithoutToken() throws Exception { - Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId()); + assertNotNull(partitionProperties); + assertEquals(partitionProperties.size(), CreatePartitionDescriptor.getDefaultProperties().size()); // While creating partition, properties are added in CreatePartitionDescriptor#getValidBody } - } diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/ListPartitionsApiTest.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/ListPartitionsApiTest.java index 6c5a58f4695fa1cc58ae8b9340cac580a1599465..f94e8c97130cd911e5b8dd3fde86b9decb2693f3 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/ListPartitionsApiTest.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/ListPartitionsApiTest.java @@ -17,19 +17,21 @@ package org.opengroup.osdu.partition.api; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.junit.After; -import org.junit.Assume; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.opengroup.osdu.partition.api.descriptor.CreatePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.ListPartitionDescriptor; -import org.opengroup.osdu.partition.api.util.AuthorizationTestUtil; import org.opengroup.osdu.partition.util.BaseTestTemplate; -import org.opengroup.osdu.partition.util.Constants; import org.opengroup.osdu.partition.util.TestTokenUtils; +import org.opengroup.osdu.partition.util.TestUtils; import org.springframework.http.HttpStatus; +import java.util.List; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public final class ListPartitionsApiTest extends BaseTestTemplate { @@ -39,7 +41,6 @@ public final class ListPartitionsApiTest extends BaseTestTemplate { @Before public void setup() { this.testUtils = new TestTokenUtils(); - this.authorizationTestUtil = new AuthorizationTestUtil(this.descriptor, this.testUtils); } @Override @@ -47,7 +48,6 @@ public final class ListPartitionsApiTest extends BaseTestTemplate { public void tearDown() throws Exception { deleteResource(); this.testUtils = null; - this.authorizationTestUtil = null; } @Override @@ -57,21 +57,29 @@ public final class ListPartitionsApiTest extends BaseTestTemplate { @Override protected void deleteResource() throws Exception { - DeletePartitionDescriptor deletePartitionDes = new DeletePartitionDescriptor(); - deletePartitionDes.setPartitionId(partitionId); - CloseableHttpResponse response = deletePartitionDes.run(this.getId(), this.testUtils.getAccessToken()); + deleteResource(partitionId); } @Override protected void createResource() throws Exception { + createResource(partitionId); + } + + private void createResource(String partitionId) throws Exception { CreatePartitionDescriptor createPartitionDescriptor = new CreatePartitionDescriptor(); createPartitionDescriptor.setPartitionId(partitionId); - CloseableHttpResponse createResponse = createPartitionDescriptor.run(this.getId(), this.testUtils.getAccessToken()); + CloseableHttpResponse createResponse = createPartitionDescriptor.run(partitionId, this.testUtils.getAccessToken()); assertEquals(this.error(EntityUtils.toString(createResponse.getEntity())), HttpStatus.CREATED.value(), createResponse.getCode()); } + private void deleteResource(String partitionId) throws Exception { + DeletePartitionDescriptor deletePartitionDes = new DeletePartitionDescriptor(); + deletePartitionDes.setPartitionId(partitionId); + CloseableHttpResponse response = deletePartitionDes.run(partitionId, this.testUtils.getAccessToken()); + } + public ListPartitionsApiTest() { super(new ListPartitionDescriptor()); } @@ -81,24 +89,22 @@ public final class ListPartitionsApiTest extends BaseTestTemplate { return HttpStatus.OK.value(); } - @Override @Test - public void should_return401_when_noAccessToken() throws Exception { - Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_noAccessToken(getId()); - } + public void create_multiple_partitions_and_retrieve_them() throws Exception { + String partitionId1 = partitionId + "_1"; + String partitionId2 = partitionId + "_2"; - @Override - @Test - public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception { - Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId()); - } + createResource(partitionId1); + createResource(partitionId2); - @Override - @Test - public void should_return401_when_makingHttpRequestWithoutToken() throws Exception { - Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId()); + CloseableHttpResponse response = this.descriptor.run(null, this.testUtils.getAccessToken()); + List<String> partitionIds = TestUtils.parseResponse(response); + + deleteResource(partitionId1); + deleteResource(partitionId2); + + Assert.assertNotNull(partitionIds); + assertTrue(partitionIds.contains(partitionId1)); + assertTrue(partitionIds.contains(partitionId2)); } } diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/UpdatePartitionTest.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/UpdatePartitionTest.java index 578728a417fab1d8af5445154529429a98c3e7b7..d3e3144d9fcd6092d078e64a3e78dfe6e61caafe 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/UpdatePartitionTest.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/UpdatePartitionTest.java @@ -2,32 +2,27 @@ package org.opengroup.osdu.partition.api; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.io.entity.EntityUtils; -import org.junit.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.opengroup.osdu.partition.api.descriptor.CreatePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor; import org.opengroup.osdu.partition.api.descriptor.UpdatePartitionDescriptor; -import org.opengroup.osdu.partition.api.util.AuthorizationTestUtil; import org.opengroup.osdu.partition.util.BaseTestTemplate; -import org.opengroup.osdu.partition.util.Constants; import org.opengroup.osdu.partition.util.TestTokenUtils; import org.springframework.http.HttpStatus; -import java.lang.constant.Constable; - import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.opengroup.osdu.partition.util.Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS; public final class UpdatePartitionTest extends BaseTestTemplate { String partitionId = getIntegrationTestPrefix() + System.currentTimeMillis(); - private String nonExistentPartitionId = "nonexistent-partition"+System.currentTimeMillis(); + private String nonExistentPartitionId = "nonexistent-partition" + System.currentTimeMillis(); @Override @Before public void setup() { this.testUtils = new TestTokenUtils(); - this.authorizationTestUtil = new AuthorizationTestUtil(this.descriptor, this.testUtils); } @Override @@ -35,7 +30,6 @@ public final class UpdatePartitionTest extends BaseTestTemplate { public void tearDown() throws Exception { deleteResource(); this.testUtils = null; - this.authorizationTestUtil = null; } public UpdatePartitionTest() { @@ -80,7 +74,6 @@ public final class UpdatePartitionTest extends BaseTestTemplate { createResource(); CloseableHttpResponse response = this.descriptor.runWithCustomPayload(this.getId(), getInvalidBodyForUpdatePartition(), this.testUtils.getAccessToken()); assertEquals(this.error(""), HttpStatus.BAD_REQUEST.value(), response.getCode()); - deleteResource(); } @Test @@ -88,19 +81,7 @@ public final class UpdatePartitionTest extends BaseTestTemplate { public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception { createResource(); CloseableHttpResponse response = this.descriptor.runWithCustomPayload(this.getId(), getValidBodyForUpdatePartition(), this.testUtils.getAccessToken()); - deleteResource(); assertEquals(HttpStatus.NO_CONTENT.value(), response.getCode()); - assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", response.getHeader("Access-Control-Allow-Methods").getValue()); - assertEquals("access-control-allow-origin, origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey", response.getHeader("Access-Control-Allow-Headers").getValue()); - assertEquals("*", response.getHeader("Access-Control-Allow-Origin").getValue()); - assertEquals("true", response.getHeader("Access-Control-Allow-Credentials").getValue()); - assertEquals("default-src 'self'", response.getHeader("Content-Security-Policy").getValue()); - assertEquals("max-age=31536000; includeSubDomains", response.getHeader("Strict-Transport-Security").getValue()); - assertEquals("0", response.getHeader("Expires").getValue()); - assertEquals("DENY", response.getHeader("X-Frame-Options").getValue()); - assertEquals("private, max-age=300", response.getHeader("Cache-Control").getValue()); - assertEquals("1; mode=block", response.getHeader("X-XSS-Protection").getValue()); - assertEquals("nosniff", response.getHeader("X-Content-Type-Options").getValue()); } private String getInvalidBodyForUpdatePartition() { @@ -127,25 +108,4 @@ public final class UpdatePartitionTest extends BaseTestTemplate { .append("}"); return sb.toString(); } - - @Override - @Test - public void should_return401_when_noAccessToken() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_noAccessToken(getId()); - } - - @Override - @Test - public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId()); - } - - @Override - @Test - public void should_return401_when_makingHttpRequestWithoutToken() throws Exception { - Assume.assumeTrue(EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); - authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId()); - } } diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java index fee0ffb55efd13fff7b7ee4fb0c12507f20f9804..f4d7a97e9baf7f135e6aa18d02fe19413b675544 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/api/descriptor/CreatePartitionDescriptor.java @@ -14,12 +14,19 @@ package org.opengroup.osdu.partition.api.descriptor; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.opengroup.osdu.partition.util.RestDescriptor; import org.springframework.web.bind.annotation.RequestMethod; +import java.util.HashMap; +import java.util.Map; + public class CreatePartitionDescriptor extends RestDescriptor { private String partitionId; + private static final ObjectMapper objectMapper = new ObjectMapper(); @Override public String getPath() { @@ -34,13 +41,12 @@ public class CreatePartitionDescriptor extends RestDescriptor { @Override public String getValidBody() { StringBuffer sb = new StringBuffer(); - sb.append("{\n"); - sb.append(" \"properties\": {") - .append("\"elasticPassword\": {\"sensitive\":true,\"value\":\"test-password\"},") - .append("\"serviceBusConnection\": {\"sensitive\":true,\"value\":\"test-service-bus-connection\"},") - .append("\"complianceRuleSet\": {\"value\":\"shared\"}") - .append("}\n") - .append("}"); + try { + sb = new StringBuffer(); + sb.append("{\"properties\":" + objectMapper.writeValueAsString(getDefaultProperties())) + .append("}"); + } catch (JsonProcessingException e) { + } return sb.toString(); } @@ -51,4 +57,13 @@ public class CreatePartitionDescriptor extends RestDescriptor { public void setPartitionId(String partitionId) { this.partitionId = partitionId; } + + public static Map<String, JsonNode> getDefaultProperties() throws JsonProcessingException { + Map<String, JsonNode> propertyMap = new HashMap<>(); + + propertyMap.put("elasticPassword", objectMapper.readTree("{\"sensitive\":true,\"value\":\"test-password\"}")); + propertyMap.put("serviceBusConnection", objectMapper.readTree("{\"sensitive\":true,\"value\":\"test-service-bus-connection\"}")); + propertyMap.put("complianceRuleSet", objectMapper.readTree("{\"value\":\"shared\"}")); + return propertyMap; + } } diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/BaseTestTemplate.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/BaseTestTemplate.java index 7941a2d40f4def9ff4d6b9cbd696681e3ac94d8d..1aaeb3f74e081e828b0634832a718475d9a879d2 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/BaseTestTemplate.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/BaseTestTemplate.java @@ -16,18 +16,16 @@ package org.opengroup.osdu.partition.util; -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.junit.Assume; import org.junit.Test; -import org.opengroup.osdu.partition.api.util.AuthorizationTestUtil; import static org.junit.Assert.assertEquals; public abstract class BaseTestTemplate extends TestBase { protected RestDescriptor descriptor; - protected AuthorizationTestUtil authorizationTestUtil; public BaseTestTemplate(RestDescriptor descriptor) { this.descriptor = descriptor; @@ -46,20 +44,14 @@ public abstract class BaseTestTemplate extends TestBase { } @Test - public void should_return401_when_noAccessToken() throws Exception { - CloseableHttpResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoAccessToken()); - assertEquals(error(EntityUtils.toString(response.getEntity())), 401, response.getCode()); - } - - @Test - public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception { - CloseableHttpResponse response = descriptor.run(getId(), testUtils.getNoAccessToken()); - assertEquals(error(EntityUtils.toString(response.getEntity())), 401, response.getCode()); + public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception { + should_return20X_when_usingCredentialsWithPermission(testUtils.getAccessToken()); } @Test - public void should_return20XResponseCode_when_makingValidHttpsRequest() throws Exception { - should_return20X_when_usingCredentialsWithPermission(testUtils.getAccessToken()); + public void should_return400_when_makingHttpRequestWithoutValidUrl() throws Exception { + CloseableHttpResponse response = descriptor.runWithInvalidPath(getId(), testUtils.getAccessToken()); + assertEquals(error(EntityUtils.toString(response.getEntity())), 400, response.getCode()); } public void should_return20X_when_usingCredentialsWithPermission(String token) throws Exception { @@ -67,17 +59,6 @@ public abstract class BaseTestTemplate extends TestBase { CloseableHttpResponse response = descriptor.run(getId(), token); deleteResource(); assertEquals(error(response.getCode() == 204 ? "" : EntityUtils.toString(response.getEntity())), expectedOkResponseCode(), response.getCode()); - assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", response.getHeader("Access-Control-Allow-Methods").getValue()); - assertEquals("access-control-allow-origin, origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey", response.getHeader("Access-Control-Allow-Headers").getValue()); - assertEquals("*", response.getHeader("Access-Control-Allow-Origin").getValue()); - assertEquals("true", response.getHeader("Access-Control-Allow-Credentials").getValue()); - assertEquals("default-src 'self'", response.getHeader("Content-Security-Policy").getValue()); - assertEquals("max-age=31536000; includeSubDomains", response.getHeader("Strict-Transport-Security").getValue()); - assertEquals("0", response.getHeader("Expires").getValue()); - assertEquals("DENY", response.getHeader("X-Frame-Options").getValue()); - assertEquals("private, max-age=300", response.getHeader("Cache-Control").getValue()); - assertEquals("1; mode=block", response.getHeader("X-XSS-Protection").getValue()); - assertEquals("nosniff", response.getHeader("X-Content-Type-Options").getValue()); } @Test @@ -90,13 +71,22 @@ public abstract class BaseTestTemplate extends TestBase { @Test public void should_return401_when_makingHttpRequestWithoutToken() throws Exception { + Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); CloseableHttpResponse response = descriptor.run(getId(), ""); assertEquals(error(EntityUtils.toString(response.getEntity())), 401, response.getCode()); } @Test - public void should_return400_when_makingHttpRequestWithoutValidUrl() throws Exception { - CloseableHttpResponse response = descriptor.runWithInvalidPath(getId(), testUtils.getAccessToken()); - assertEquals(error(EntityUtils.toString(response.getEntity())), 400, response.getCode()); + public void should_return401_when_noAccessToken() throws Exception { + Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); + CloseableHttpResponse response = descriptor.runOnCustomerTenant(getId(), testUtils.getNoAccessToken()); + assertEquals(error(EntityUtils.toString(response.getEntity())), 401, response.getCode()); + } + + @Test + public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception { + Assume.assumeTrue(Constants.EXECUTE_AUTHORIZATION_DEPENDENT_TESTS); + CloseableHttpResponse response = descriptor.run(getId(), testUtils.getNoAccessToken()); + assertEquals(error(EntityUtils.toString(response.getEntity())), 401, response.getCode()); } } diff --git a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/TestUtils.java b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/TestUtils.java index 3bad6430ec7cb2df76b7ceeb3a8714aaae0fa760..f5762d2b346e1bbd425ee3a2d652d8fd7679aca5 100644 --- a/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/TestUtils.java +++ b/partition-acceptance-test/src/test/java/org/opengroup/osdu/partition/util/TestUtils.java @@ -16,6 +16,8 @@ package org.opengroup.osdu.partition.util; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; 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; @@ -23,9 +25,10 @@ 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.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; -import java.io.Console; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -120,4 +123,17 @@ public abstract class TestUtils { return cm; } + public static <T> T parseResponse(CloseableHttpResponse response) throws IOException { + String jsonString; + try { + jsonString = EntityUtils.toString(response.getEntity()); + } catch (ParseException e) { + return null; + } + + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(jsonString, new TypeReference<>() { + }); + } + }