From 5cc19a89be68181278996cb591bcb03667766a65 Mon Sep 17 00:00:00 2001 From: Mahmud Ali <95893226+jissan95@users.noreply.github.com> Date: Wed, 3 May 2023 11:26:50 -0400 Subject: [PATCH] 30710:Creation of SeqSumissionOpenApi (#220) --- .../seqdb/api/openapi/OpenAPIConstants.java | 1 - .../api/openapi/SeqSubmissionOpenApiIT.java | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/test/java/ca/gc/aafc/seqdb/api/openapi/SeqSubmissionOpenApiIT.java diff --git a/src/test/java/ca/gc/aafc/seqdb/api/openapi/OpenAPIConstants.java b/src/test/java/ca/gc/aafc/seqdb/api/openapi/OpenAPIConstants.java index f79cd3eb..9af7cfac 100644 --- a/src/test/java/ca/gc/aafc/seqdb/api/openapi/OpenAPIConstants.java +++ b/src/test/java/ca/gc/aafc/seqdb/api/openapi/OpenAPIConstants.java @@ -10,7 +10,6 @@ public class OpenAPIConstants { private static final String SCHEME = "https"; static final String SPEC_HOST = "raw.githubusercontent.com"; static final String SPEC_PATH = "DINA-Web/sequence-specs/master/schema/sequence.yml"; - public static final URL SEQDB_API_SPECS_URL = buildOpenAPISpecsURL(); private OpenAPIConstants() { diff --git a/src/test/java/ca/gc/aafc/seqdb/api/openapi/SeqSubmissionOpenApiIT.java b/src/test/java/ca/gc/aafc/seqdb/api/openapi/SeqSubmissionOpenApiIT.java new file mode 100644 index 00000000..ef202221 --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/openapi/SeqSubmissionOpenApiIT.java @@ -0,0 +1,54 @@ +package ca.gc.aafc.seqdb.api.openapi; + +import ca.gc.aafc.dina.testsupport.BaseRestAssuredTest; +import ca.gc.aafc.dina.testsupport.PostgresTestContainerInitializer; +import ca.gc.aafc.dina.testsupport.jsonapi.JsonAPIRelationship; +import ca.gc.aafc.dina.testsupport.jsonapi.JsonAPITestHelper; +import ca.gc.aafc.dina.testsupport.specs.OpenAPI3Assertions; +import ca.gc.aafc.dina.testsupport.specs.ValidationRestrictionOptions; +import ca.gc.aafc.seqdb.api.SeqdbApiLauncher; +import ca.gc.aafc.seqdb.api.dto.SeqBatchDto; +import ca.gc.aafc.seqdb.api.dto.SeqSubmissionDto; +import ca.gc.aafc.seqdb.api.testsupport.fixtures.*; +import lombok.SneakyThrows; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; + +import java.util.List; +import java.util.UUID; + +@SpringBootTest( + classes = SeqdbApiLauncher.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT +) +@TestPropertySource(properties = "spring.config.additional-location=classpath:application-test.yml") +@ContextConfiguration(initializers = {PostgresTestContainerInitializer.class}) +public class SeqSubmissionOpenApiIT extends BaseRestAssuredTest{ + protected SeqSubmissionOpenApiIT(){super("/api");} + @SneakyThrows + @Test + void seqSubmission_SpecValid() { + + SeqBatchDto seqBatchDto = SeqBatchTestFixture.newSeqBatch(); + seqBatchDto.setExperimenters(null); + String seqBatchDtoUuid = JsonAPITestHelper.extractId( + sendPost(SeqBatchDto.TYPENAME, + JsonAPITestHelper.toJsonAPIMap(SeqBatchDto.TYPENAME, JsonAPITestHelper.toAttributeMap(seqBatchDto)))); + + + SeqSubmissionDto seqSubmissionDto = SeqSubmissionTestFixture.newSeqSubmission(); + seqSubmissionDto.setSubmittedBy(null); + + OpenAPI3Assertions.assertRemoteSchema(OpenAPIConstants.SEQDB_API_SPECS_URL, "SeqSubmission", + sendPost(SeqSubmissionDto.TYPENAME, JsonAPITestHelper.toJsonAPIMap(SeqSubmissionDto.TYPENAME, JsonAPITestHelper.toAttributeMap(seqSubmissionDto), + JsonAPITestHelper.toRelationshipMap( + List.of(JsonAPIRelationship.of("seqBatch", SeqBatchDto.TYPENAME, seqBatchDtoUuid), + JsonAPIRelationship.of("submittedBy", "person", UUID.randomUUID().toString()) + )), + null) + ).extract().asString(), + ValidationRestrictionOptions.builder().build()); + } +}