From 52a406649666773fe7c41a42d96baa2e3b1eba44 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Wed, 3 Jan 2024 12:15:03 +0100 Subject: [PATCH 1/6] created two intermediate classes for the return object --- .../model/IngestionResultEntity.java | 38 +++++++++++++++++++ .../evaseqcol/model/InsertedSeqColEntity.java | 19 ++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/model/InsertedSeqColEntity.java diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java new file mode 100644 index 0000000..2ce59cf --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java @@ -0,0 +1,38 @@ +package uk.ac.ebi.eva.evaseqcol.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +/** + * This Entity will hold the information that should be returned + * upon ingestion of seqcol objects (given the assembly accession)*/ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class IngestionResultEntity { + + @JsonProperty("assembly_accession") + private String assemblyAccession; + @JsonProperty("numberOfInsertedSeqcols") + private Integer numberOfInsertedSeqcols = 0; + @JsonProperty("inserted_seqcols") + private List insertedSeqcols = new ArrayList<>(); + @JsonProperty("error_message") + private String errorMessage = null; + + + public void addInsertedSeqCol(InsertedSeqColEntity insertedSeqCol) { + this.insertedSeqcols.add(insertedSeqCol); + } + + /** + * Increment the numberOfInsertedSeqcols by one*/ + public void incrementNumberOfInsertedSeqCols() { + this.numberOfInsertedSeqcols += 1; + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/model/InsertedSeqColEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/model/InsertedSeqColEntity.java new file mode 100644 index 0000000..4b66265 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/model/InsertedSeqColEntity.java @@ -0,0 +1,19 @@ +package uk.ac.ebi.eva.evaseqcol.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * This entity will hold minimal seqcol information that will be returned + * to the user upon ingestion*/ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class InsertedSeqColEntity { + + private String digest; // Level 0 digest + @JsonProperty("naming_convention") + private String namingConvention; +} From d34b57f06c20316b4885badcc086359ebecf8b03 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Wed, 3 Jan 2024 12:15:46 +0100 Subject: [PATCH 2/6] changed the return object/type of the ingestion endpoint into a more standardized one --- .../controller/admin/AdminController.java | 7 ++-- .../entities/SeqColExtendedDataEntity.java | 1 + .../eva/evaseqcol/service/SeqColService.java | 36 ++++++++++++------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java index 94cff87..3c3b74b 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java @@ -15,6 +15,7 @@ import uk.ac.ebi.eva.evaseqcol.exception.AssemblyNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException; import uk.ac.ebi.eva.evaseqcol.exception.IncorrectAccessionException; +import uk.ac.ebi.eva.evaseqcol.model.IngestionResultEntity; import uk.ac.ebi.eva.evaseqcol.service.SeqColService; import java.io.IOException; @@ -54,10 +55,8 @@ public ResponseEntity fetchAndInsertSeqColByAssemblyAccession( example = "GCA_000146045.2", required = true) @PathVariable String asmAccession) { try { - List level0Digests = seqColService.fetchAndInsertAllSeqColByAssemblyAccession(asmAccession); - return new ResponseEntity<>( - "Successfully inserted seqCol object(s) for assembly accession " + asmAccession + "\nSeqCol digests=" + level0Digests - , HttpStatus.OK); + IngestionResultEntity ingestionResult = seqColService.fetchAndInsertAllSeqColByAssemblyAccession(asmAccession); + return ResponseEntity.ok(ingestionResult); } catch (IncorrectAccessionException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } catch (IllegalArgumentException e) { diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColExtendedDataEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColExtendedDataEntity.java index 256463f..811b144 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColExtendedDataEntity.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColExtendedDataEntity.java @@ -49,6 +49,7 @@ public class SeqColExtendedDataEntity { @Transient // This is needed when constructing multiple seqCol objects from the datasource to // identify the naming convention used for the sequences. + // Note: This will probably be required by the namesAttributeList and might be null for the others private SeqColEntity.NamingConvention namingConvention; public enum AttributeType { diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java index 1456d7b..3343069 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java @@ -18,6 +18,8 @@ import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException; import uk.ac.ebi.eva.evaseqcol.exception.SeqColNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.UnableToLoadServiceInfoException; +import uk.ac.ebi.eva.evaseqcol.model.IngestionResultEntity; +import uk.ac.ebi.eva.evaseqcol.model.InsertedSeqColEntity; import uk.ac.ebi.eva.evaseqcol.utils.JSONExtData; import uk.ac.ebi.eva.evaseqcol.utils.JSONIntegerListExtData; import uk.ac.ebi.eva.evaseqcol.utils.JSONStringListExtData; @@ -155,14 +157,16 @@ public void removeAllSeqCol() { * NOTE: All possible seqCol objects means with all possible/provided naming conventions that could be found in the * assembly report. * Return the list of level 0 digests of the inserted seqcol objects*/ - public List fetchAndInsertAllSeqColByAssemblyAccession( + public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession( String assemblyAccession) throws IOException, DuplicateSeqColException { - List insertedSeqColDigests = new ArrayList<>(); + IngestionResultEntity ingestionResultEntity = new IngestionResultEntity(); + ingestionResultEntity.setAssemblyAccession(assemblyAccession); Optional> seqColDataMap = ncbiSeqColDataSource .getAllPossibleSeqColExtendedData(assemblyAccession); if (!seqColDataMap.isPresent()) { logger.warn("No seqCol data corresponding to assemblyAccession " + assemblyAccession + " could be found on NCBI datasource"); - return insertedSeqColDigests; + ingestionResultEntity.setErrorMessage("No seqCol data corresponding to assemblyAccession " + assemblyAccession + " could be found on NCBI datasource"); + return ingestionResultEntity; } // Retrieving the Map's data @@ -199,17 +203,25 @@ public List fetchAndInsertAllSeqColByAssemblyAccession( seqColStringListExtDataEntities, seqColIntegerListExtDataEntities, extendedNamesEntity.getNamingConvention() ); - Optional seqColDigest = insertSeqColL1AndL2( // TODO: Check for possible self invocation problem - levelOneEntity, seqColStringListExtDataEntities, seqColIntegerListExtDataEntities); - if (seqColDigest.isPresent()) { - logger.info( - "Successfully inserted seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention()); - insertedSeqColDigests.add(seqColDigest.get()); - } else { - logger.warn("Could not insert seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention()); + try { + Optional seqColDigest = insertSeqColL1AndL2( // TODO: Check for possible self invocation problem + levelOneEntity, seqColStringListExtDataEntities, seqColIntegerListExtDataEntities); + if (seqColDigest.isPresent()) { + logger.info( + "Successfully inserted seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention()); + InsertedSeqColEntity insertedSeqCol = new InsertedSeqColEntity(seqColDigest.get(), extendedNamesEntity.getNamingConvention().toString()); + ingestionResultEntity.addInsertedSeqCol(insertedSeqCol); + ingestionResultEntity.incrementNumberOfInsertedSeqCols(); + } else { + logger.warn("Could not insert seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention()); + } + } catch (DuplicateSeqColException e) { + logger.info("Seqcol for " + assemblyAccession + " and naming convention " + extendedNamesEntity.getNamingConvention() + + " already exists. Skipping."); + continue; } } - return insertedSeqColDigests; + return ingestionResultEntity; } /** From c762c3e27bf3cec094a372da9e7dbbe381dec4c4 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Sat, 6 Jan 2024 12:03:39 +0100 Subject: [PATCH 3/6] used underscore for multi-word attributes --- .../uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java index 2ce59cf..4ba3b93 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/model/IngestionResultEntity.java @@ -18,7 +18,7 @@ public class IngestionResultEntity { @JsonProperty("assembly_accession") private String assemblyAccession; - @JsonProperty("numberOfInsertedSeqcols") + @JsonProperty("num_inserted_seqcols") private Integer numberOfInsertedSeqcols = 0; @JsonProperty("inserted_seqcols") private List insertedSeqcols = new ArrayList<>(); From 6b5917d8695361ee039fb6622b1bb7dc6d24f58f Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Sat, 13 Jan 2024 15:49:49 +0100 Subject: [PATCH 4/6] removed unnecessary json response for some ingestion cases and set the right response status codes --- .../controller/admin/AdminController.java | 7 ++- .../AssemblyAlreadyIngestedException.java | 7 +++ .../eva/evaseqcol/service/SeqColService.java | 37 ++++++---------- .../AdminControllerIntegrationTest.java | 44 +++++++++++++++++++ 4 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java index 3c3b74b..adef458 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import uk.ac.ebi.eva.evaseqcol.exception.AssemblyAlreadyIngestedException; import uk.ac.ebi.eva.evaseqcol.exception.AssemblyNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException; import uk.ac.ebi.eva.evaseqcol.exception.IncorrectAccessionException; @@ -42,7 +43,7 @@ public AdminController(SeqColService seqColService) { "contained in the assembly report) and eventually save these seqCol objects into the database. " + "This is an authenticated endpoint, so it requires admin privileges to run it.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "seqCol object(s) successfully inserted"), + @ApiResponse(responseCode = "201", description = "seqCol object(s) successfully inserted"), @ApiResponse(responseCode = "409", description = "seqCol object(s) already exist(s)"), @ApiResponse(responseCode = "404", description = "Assembly not found"), @ApiResponse(responseCode = "400", description = "Bad request. (It can be a bad accession value)"), @@ -56,7 +57,7 @@ public ResponseEntity fetchAndInsertSeqColByAssemblyAccession( required = true) @PathVariable String asmAccession) { try { IngestionResultEntity ingestionResult = seqColService.fetchAndInsertAllSeqColByAssemblyAccession(asmAccession); - return ResponseEntity.ok(ingestionResult); + return new ResponseEntity<>(ingestionResult, HttpStatus.CREATED); } catch (IncorrectAccessionException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } catch (IllegalArgumentException e) { @@ -69,6 +70,8 @@ public ResponseEntity fetchAndInsertSeqColByAssemblyAccession( return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT); } catch (AssemblyNotFoundException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND); + } catch (AssemblyAlreadyIngestedException e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT); } } } diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java new file mode 100644 index 0000000..74b7360 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java @@ -0,0 +1,7 @@ +package uk.ac.ebi.eva.evaseqcol.exception; + +public class AssemblyAlreadyIngestedException extends RuntimeException{ + public AssemblyAlreadyIngestedException(String assemblyAccession) { + super("Seqcol objects for assembly " + assemblyAccession + " has been already ingested"); + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java index 3343069..a733350 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java @@ -14,6 +14,8 @@ import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColExtendedDataEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity; +import uk.ac.ebi.eva.evaseqcol.exception.AssemblyAlreadyIngestedException; +import uk.ac.ebi.eva.evaseqcol.exception.AssemblyNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.AttributeNotDefinedException; import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException; import uk.ac.ebi.eva.evaseqcol.exception.SeqColNotFoundException; @@ -158,17 +160,17 @@ public void removeAllSeqCol() { * assembly report. * Return the list of level 0 digests of the inserted seqcol objects*/ public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession( - String assemblyAccession) throws IOException, DuplicateSeqColException { - IngestionResultEntity ingestionResultEntity = new IngestionResultEntity(); - ingestionResultEntity.setAssemblyAccession(assemblyAccession); + String assemblyAccession) throws IOException, DuplicateSeqColException, AssemblyNotFoundException, + AssemblyAlreadyIngestedException{ Optional> seqColDataMap = ncbiSeqColDataSource .getAllPossibleSeqColExtendedData(assemblyAccession); if (!seqColDataMap.isPresent()) { logger.warn("No seqCol data corresponding to assemblyAccession " + assemblyAccession + " could be found on NCBI datasource"); - ingestionResultEntity.setErrorMessage("No seqCol data corresponding to assemblyAccession " + assemblyAccession + " could be found on NCBI datasource"); - return ingestionResultEntity; + throw new AssemblyNotFoundException(assemblyAccession); } + IngestionResultEntity ingestionResultEntity = new IngestionResultEntity(); + ingestionResultEntity.setAssemblyAccession(assemblyAccession); // Retrieving the Map's data List>> possibleSequencesNamesList = (List>>) seqColDataMap.get().get("namesAttributes"); @@ -185,10 +187,6 @@ public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession( SeqColExtendedDataEntity> extendedSortedNameLengthPair = SeqColExtendedDataEntity. constructSeqColSortedNameLengthPairs(extendedNamesEntity, extendedLengthsEntity); - -// seqColExtendedDataEntities.add(extendedNamesEntity); -// seqColExtendedDataEntities.add(seqColSortedNameLengthPairEntity); - // Constructing a list of seqColExtData that has the type List List>> seqColStringListExtDataEntities = levelOneService.constructStringListExtDataEntities(sameValueAttributesMap, extendedNamesEntity, @@ -218,23 +216,16 @@ public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession( } catch (DuplicateSeqColException e) { logger.info("Seqcol for " + assemblyAccession + " and naming convention " + extendedNamesEntity.getNamingConvention() + " already exists. Skipping."); - continue; } } - return ingestionResultEntity; - } - - /** - * Return the extended data entity that corresponds to the seqCol lengths attribute*/ - // TODO: REFACTOR - /*public SeqColExtendedDataEntity retrieveExtendedLengthEntity(List extendedDataEntities) { - for (SeqColExtendedDataEntity entity: extendedDataEntities) { - if (entity.getAttributeType() == SeqColExtendedDataEntity.AttributeType.lengths) { - return entity; - } + if (ingestionResultEntity.getNumberOfInsertedSeqcols() == 0) { + logger.warn("Seqcol objects for assembly " + assemblyAccession + " has been already ingested"); + throw new AssemblyAlreadyIngestedException(assemblyAccession); + } else { + return ingestionResultEntity; } - return null; - }*/ + + } @Transactional /** diff --git a/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java b/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java index ecbef5b..0dbd088 100644 --- a/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java +++ b/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java @@ -1,15 +1,22 @@ package uk.ac.ebi.eva.evaseqcol.controller; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.http.client.support.BasicAuthenticationInterceptor; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; @@ -17,6 +24,7 @@ import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity; +import uk.ac.ebi.eva.evaseqcol.exception.AssemblyAlreadyIngestedException; import uk.ac.ebi.eva.evaseqcol.service.SeqColService; import java.util.Optional; @@ -72,6 +80,11 @@ void setUp() { baseUrl = baseUrl + ":" + port + contextPath + ADMIN_PATH; } + @AfterEach + void tearDown() { + seqColService.removeAllSeqCol(); + } + @Test @Transactional /** @@ -89,4 +102,35 @@ void ingestSeqColsTest() { assertNotNull(levelTwoEntity.get().getLengths()); } + @Test + /** + * Testing the response for the ingestion endpoint for + * different kind of ingestion cases: + * 1. Not existed + * 2. Already existed + * 3. Invalid assembly accession + * 4. Not found assembly accession + * Note: the order of execution is important */ + void ingestionResponseTest() { + // 1. Testing Valid Non-Existing Accession + String finalRequest1 = baseUrl + "/" + ASM_ACCESSION; + ResponseEntity putResponse1 = restTemplate.exchange(finalRequest1, HttpMethod.PUT, null, String.class); + assertEquals(HttpStatus.CREATED, putResponse1.getStatusCode()); + + // 2. Testing Valid Existing Accession + final String finalRequest2 = baseUrl + "/" + ASM_ACCESSION; // Same as above + assertThrows(HttpClientErrorException.Conflict.class, + () -> restTemplate.exchange(finalRequest2, HttpMethod.PUT, null, String.class)); + + // 3. Testing Invalid Assembly Accession + final String finalRequest3 = baseUrl + "/" + ASM_ACCESSION.substring(0, ASM_ACCESSION.length()-4); // Less than 15 characters + assertThrows(HttpClientErrorException.BadRequest.class, + () -> restTemplate.exchange(finalRequest3, HttpMethod.PUT, null, String.class)); + + // 4. Testing Assembly Not Found + final String finalRequest4 = baseUrl + "/" + ASM_ACCESSION + "55"; // Accession doesn't correspond to any assembly + assertThrows(HttpClientErrorException.NotFound.class, + () -> restTemplate.exchange(finalRequest4, HttpMethod.PUT, null, String.class)); + } + } From 2c73c66e99e74a4c67754e356762a3f78d8a4190 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Sat, 13 Jan 2024 17:01:24 +0100 Subject: [PATCH 5/6] fixed a failed test using the @Order method --- .../AdminControllerIntegrationTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java b/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java index 0dbd088..32025fe 100644 --- a/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java +++ b/src/test/java/uk/ac/ebi/eva/evaseqcol/controller/AdminControllerIntegrationTest.java @@ -1,10 +1,11 @@ package uk.ac.ebi.eva.evaseqcol.controller; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -13,6 +14,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.client.support.BasicAuthenticationInterceptor; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.transaction.annotation.Transactional; @@ -24,15 +26,18 @@ import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity; -import uk.ac.ebi.eva.evaseqcol.exception.AssemblyAlreadyIngestedException; import uk.ac.ebi.eva.evaseqcol.service.SeqColService; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Testcontainers +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class AdminControllerIntegrationTest { @LocalServerPort @@ -82,10 +87,11 @@ void setUp() { @AfterEach void tearDown() { - seqColService.removeAllSeqCol(); + seqColService.removeAllSeqCol(); // TODO Fix: This operation is rolled back for some reason @see 'https://www.baeldung.com/hibernate-initialize-proxy-exception' (might help) } @Test + @Order(2) @Transactional /** * Ingest all possible seqCol objects given the assembly accession*/ @@ -103,6 +109,7 @@ void ingestSeqColsTest() { } @Test + @Order(1) /** * Testing the response for the ingestion endpoint for * different kind of ingestion cases: From 5c231c2a40cfb0ccffebd8d1bf6466a9b25a38aa Mon Sep 17 00:00:00 2001 From: Haroune Hassine Date: Mon, 15 Jan 2024 23:01:26 +0100 Subject: [PATCH 6/6] Update src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java Co-authored-by: Timothee Cezard --- .../evaseqcol/exception/AssemblyAlreadyIngestedException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java index 74b7360..3753957 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/AssemblyAlreadyIngestedException.java @@ -2,6 +2,6 @@ public class AssemblyAlreadyIngestedException extends RuntimeException{ public AssemblyAlreadyIngestedException(String assemblyAccession) { - super("Seqcol objects for assembly " + assemblyAccession + " has been already ingested"); + super("Seqcol objects for assembly " + assemblyAccession + " have already been ingested"); } }