From 4e1aed1a555648fd7440c99241c7b157e7ba026c Mon Sep 17 00:00:00 2001 From: supun Date: Tue, 15 Oct 2024 11:42:57 +0100 Subject: [PATCH 1/5] add request class --- .../UniRefToUniProtKBDownloadRequest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java new file mode 100644 index 000000000..1cea83784 --- /dev/null +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java @@ -0,0 +1,65 @@ +package org.uniprot.api.async.download.model.request.mapto; + +import io.swagger.v3.oas.annotations.Parameter; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springdoc.api.annotations.ParameterObject; +import org.uniprot.api.async.download.model.request.ValidDownloadRequest; +import org.uniprot.api.rest.request.UniProtKBRequestUtil; +import org.uniprot.api.rest.validation.CustomConstraintGroup; +import org.uniprot.api.rest.validation.ValidAsyncDownloadFormats; +import org.uniprot.api.rest.validation.ValidReturnFields; +import org.uniprot.api.rest.validation.ValidTSVAndXLSFormatOnlyFields; +import org.uniprot.api.uniref.common.service.light.request.UniRefStreamRequest; +import org.uniprot.store.config.UniProtDataType; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.uniprot.api.rest.openapi.OpenAPIConstants.*; +import static org.uniprot.api.rest.output.UniProtMediaType.*; + +@Data +@EqualsAndHashCode(callSuper = true) +@ValidDownloadRequest(groups = CustomConstraintGroup.class) +@ParameterObject +public class UniRefToUniProtKBDownloadRequest extends UniRefStreamRequest + implements MapToDownloadRequest { + + @ValidAsyncDownloadFormats( + formats = { + FASTA_MEDIA_TYPE_VALUE, + TSV_MEDIA_TYPE_VALUE, + APPLICATION_JSON_VALUE, + XLS_MEDIA_TYPE_VALUE, + LIST_MEDIA_TYPE_VALUE, + RDF_MEDIA_TYPE_VALUE, + TURTLE_MEDIA_TYPE_VALUE, + N_TRIPLES_MEDIA_TYPE_VALUE + }) + @Parameter(description = FORMAT_UNIPARC_DESCRIPTION, example = FORMAT_UNIREF_EXAMPLE) + private String format; + + private boolean force; + + @Parameter(description = FORMAT_UNIPROTKB_DESCRIPTION, example = FIELDS_UNIPROTKB_EXAMPLE) + @ValidReturnFields(uniProtDataType = UniProtDataType.UNIPROTKB) + @ValidTSVAndXLSFormatOnlyFields(fieldPattern = "xref_.*_full") + private String fields; + + @Parameter(hidden = true) + private String downloadJobId; + + @Override + public String getTo() { + return "UniProtKB"; + } + + @Override + public String getFrom() { + return "UniRef"; + } + + @Override + public void setFormat(String format) { + this.format = UniProtKBRequestUtil.parseFormat(format); + } +} From a96a551dc64f60f51f8a11acf0367da71f719729 Mon Sep 17 00:00:00 2001 From: supun Date: Wed, 16 Oct 2024 16:04:49 +0100 Subject: [PATCH 2/5] added new classes --- .../config/mapto/MapToRabbitMQConfig.java | 9 +++++- ...iProtKBToUniRefProducerMessageService.java | 2 +- .../UniRefToUniProtKBJobSubmissionRules.java | 17 +++++++++++ ...iRefToUniProtKBProducerMessageService.java | 30 +++++++++++++++++++ ...tKBToUniRefProducerMessageServiceTest.java | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRules.java create mode 100644 async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/config/mapto/MapToRabbitMQConfig.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/config/mapto/MapToRabbitMQConfig.java index 76e52211f..3aef2f77d 100644 --- a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/config/mapto/MapToRabbitMQConfig.java +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/config/mapto/MapToRabbitMQConfig.java @@ -10,6 +10,7 @@ import org.uniprot.api.async.download.messaging.consumer.mapto.MapToMessageConsumer; import org.uniprot.api.async.download.model.request.MapToDownloadRequestToArrayConverter; import org.uniprot.api.async.download.model.request.mapto.UniProtKBToUniRefDownloadRequest; +import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; import org.uniprot.api.rest.request.HashGenerator; /** @@ -93,7 +94,13 @@ public MessageListenerContainer mapMessageListenerContainer( } @Bean - public HashGenerator mapDownloadHashGenerator( + public HashGenerator uniProtKbToUniRefMapDownloadHashGenerator( + @Value("${async.download.mapto.hash.salt}") String hashSalt) { + return new HashGenerator<>(new MapToDownloadRequestToArrayConverter<>(), hashSalt); + } + + @Bean + public HashGenerator unirefToUniProtKBMapDownloadHashGenerator( @Value("${async.download.mapto.hash.salt}") String hashSalt) { return new HashGenerator<>(new MapToDownloadRequestToArrayConverter<>(), hashSalt); } diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageService.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageService.java index 919beb80c..385e4815c 100644 --- a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageService.java +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageService.java @@ -17,7 +17,7 @@ public UniProtKBToUniRefProducerMessageService( MapToMessagingService messagingService, HashGenerator hashGenerator, MapToFileHandler asyncDownloadFileHandler, - MapToJobSubmissionRules + UniProtKBToUniRefJobSubmissionRules asyncDownloadSubmissionRules) { super( jobService, diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRules.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRules.java new file mode 100644 index 000000000..e9cb02db8 --- /dev/null +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRules.java @@ -0,0 +1,17 @@ +package org.uniprot.api.async.download.messaging.producer.mapto; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; +import org.uniprot.api.async.download.service.mapto.MapToJobService; + +@Component +public class UniRefToUniProtKBJobSubmissionRules + extends MapToJobSubmissionRules { + protected UniRefToUniProtKBJobSubmissionRules( + @Value("${async.download.mapto.retryMaxCount}") int maxRetryCount, + @Value("${async.download.mapto.waitingMaxTime}") int maxWaitingTime, + MapToJobService jobService) { + super(maxRetryCount, maxWaitingTime, jobService); + } +} diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java new file mode 100644 index 000000000..ecc0767c8 --- /dev/null +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java @@ -0,0 +1,30 @@ +package org.uniprot.api.async.download.messaging.producer.mapto; + +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.stereotype.Component; +import org.uniprot.api.async.download.messaging.result.mapto.MapToFileHandler; +import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; +import org.uniprot.api.async.download.mq.mapto.MapToMessagingService; +import org.uniprot.api.async.download.service.mapto.MapToJobService; +import org.uniprot.api.rest.request.HashGenerator; + +@Component +public class UniRefToUniProtKBProducerMessageService + extends MapToProducerMessageService { + public UniRefToUniProtKBProducerMessageService( + MapToJobService jobService, + MessageConverter messageConverter, + MapToMessagingService messagingService, + HashGenerator hashGenerator, + MapToFileHandler asyncDownloadFileHandler, + UniRefToUniProtKBJobSubmissionRules + asyncDownloadSubmissionRules) { + super( + jobService, + messageConverter, + messagingService, + hashGenerator, + asyncDownloadFileHandler, + asyncDownloadSubmissionRules); + } +} diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageServiceTest.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageServiceTest.java index a35c121f0..06ff1e0d2 100644 --- a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageServiceTest.java +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUniRefProducerMessageServiceTest.java @@ -30,7 +30,7 @@ public class UniProtKBToUniRefProducerMessageServiceTest uniProtKBMapDownloadRequestHashGenerator; @Mock - private MapToJobSubmissionRules + private UniProtKBToUniRefJobSubmissionRules uniProtKBMapDownloadRequestMapToJobSubmissionRules; @BeforeEach From 3160f37afdd3ad8dcc7ed0ef46222ffcca96b1e9 Mon Sep 17 00:00:00 2001 From: supun Date: Thu, 31 Oct 2024 14:53:06 +0000 Subject: [PATCH 3/5] fixed field descriptions --- .../model/request/mapto/UniProtKBToUniRefDownloadRequest.java | 2 +- .../model/request/mapto/UniRefToUniProtKBDownloadRequest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequest.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequest.java index 384682fda..41a6142c0 100644 --- a/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequest.java +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequest.java @@ -36,7 +36,7 @@ public class UniProtKBToUniRefDownloadRequest extends UniProtKBStreamRequest TURTLE_MEDIA_TYPE_VALUE, N_TRIPLES_MEDIA_TYPE_VALUE }) - @Parameter(description = FORMAT_UNIPARC_DESCRIPTION, example = FORMAT_UNIREF_EXAMPLE) + @Parameter(description = FORMAT_UNIREF_DESCRIPTION, example = FORMAT_UNIREF_EXAMPLE) private String format; private boolean force; diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java index 1cea83784..c0e8a6b8d 100644 --- a/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java @@ -35,12 +35,12 @@ public class UniRefToUniProtKBDownloadRequest extends UniRefStreamRequest TURTLE_MEDIA_TYPE_VALUE, N_TRIPLES_MEDIA_TYPE_VALUE }) - @Parameter(description = FORMAT_UNIPARC_DESCRIPTION, example = FORMAT_UNIREF_EXAMPLE) + @Parameter(description = FORMAT_UNIPROTKB_DESCRIPTION, example = FORMAT_UNIPROTKB_EXAMPLE) private String format; private boolean force; - @Parameter(description = FORMAT_UNIPROTKB_DESCRIPTION, example = FIELDS_UNIPROTKB_EXAMPLE) + @Parameter(description = FIELDS_UNIPROTKB_DESCRIPTION, example = FIELDS_UNIPROTKB_EXAMPLE) @ValidReturnFields(uniProtDataType = UniProtDataType.UNIPROTKB) @ValidTSVAndXLSFormatOnlyFields(fieldPattern = "xref_.*_full") private String fields; From 72510eb3b08a3e9778e58a92bf7ed0c6232185f5 Mon Sep 17 00:00:00 2001 From: supun Date: Thu, 31 Oct 2024 15:00:44 +0000 Subject: [PATCH 4/5] add tests, used common constant for from and to types --- .../UniRefToUniProtKBDownloadRequest.java | 6 +- .../UniProtKBToUniRefDownloadRequestTest.java | 72 +++++++++++++++++++ .../UniRefToUniProtKBDownloadRequestTest.java | 72 +++++++++++++++++++ 3 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequestTest.java create mode 100644 async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequestTest.java diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java index c0e8a6b8d..ee77471dc 100644 --- a/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequest.java @@ -16,6 +16,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.uniprot.api.rest.openapi.OpenAPIConstants.*; import static org.uniprot.api.rest.output.UniProtMediaType.*; +import static org.uniprot.store.search.SolrCollection.uniprot; +import static org.uniprot.store.search.SolrCollection.uniref; @Data @EqualsAndHashCode(callSuper = true) @@ -50,12 +52,12 @@ public class UniRefToUniProtKBDownloadRequest extends UniRefStreamRequest @Override public String getTo() { - return "UniProtKB"; + return uniprot.name(); } @Override public String getFrom() { - return "UniRef"; + return uniref.name(); } @Override diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequestTest.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequestTest.java new file mode 100644 index 000000000..8419d2202 --- /dev/null +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniProtKBToUniRefDownloadRequestTest.java @@ -0,0 +1,72 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.uniprot.api.async.download.model.request.mapto.UniProtKBToUniRefDownloadRequest; +import org.uniprot.api.rest.request.UniProtKBRequestUtil; +import org.uniprot.store.search.SolrCollection; + +import static org.junit.jupiter.api.Assertions.*; + +class UniProtKBToUniRefDownloadRequestTest { + + private UniProtKBToUniRefDownloadRequest request; + + @BeforeEach + void setUp() { + request = new UniProtKBToUniRefDownloadRequest(); + } + + @Test + void testInitialFieldValues() { + // Default values should be null or false + assertNull(request.getFormat()); + assertNull(request.getFields()); + assertNull(request.getDownloadJobId()); + assertFalse(request.isForce()); + } + + @Test + void testSetAndGetFormat() { + // Set the format + String format = "json"; + request.setFormat(format); + + // Verify that the format is parsed using UniProtKBRequestUtil + String expectedFormat = UniProtKBRequestUtil.parseFormat(format); + assertEquals(expectedFormat, request.getFormat()); + } + + @Test + void testSetAndGetFields() { + // Set and get fields + String fields = "xref_full_name, protein_name"; + request.setFields(fields); + assertEquals(fields, request.getFields()); + } + + @Test + void testSetAndGetDownloadJobId() { + // Set and get downloadJobId + String downloadJobId = "12345"; + request.setDownloadJobId(downloadJobId); + assertEquals(downloadJobId, request.getDownloadJobId()); + } + + @Test + void testSetAndIsForce() { + // Set and check the force flag + request.setForce(true); + assertTrue(request.isForce()); + } + + @Test + void testGetFromMethod() { + // Verify that getFrom returns the name of the uniprot SolrCollection + assertEquals(SolrCollection.uniprot.name(), request.getFrom()); + } + + @Test + void testGetToMethod() { + // Verify that getTo returns the name of the uniref SolrCollection + assertEquals(SolrCollection.uniref.name(), request.getTo()); + } +} diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequestTest.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequestTest.java new file mode 100644 index 000000000..2dda1071b --- /dev/null +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/model/request/mapto/UniRefToUniProtKBDownloadRequestTest.java @@ -0,0 +1,72 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; +import org.uniprot.api.rest.request.UniProtKBRequestUtil; +import org.uniprot.store.search.SolrCollection; + +import static org.junit.jupiter.api.Assertions.*; + +class UniRefToUniProtKBDownloadRequestTest { + + private UniRefToUniProtKBDownloadRequest request; + + @BeforeEach + void setUp() { + request = new UniRefToUniProtKBDownloadRequest(); + } + + @Test + void testInitialFieldValues() { + // Default values should be null or false + assertNull(request.getFormat()); + assertNull(request.getFields()); + assertNull(request.getDownloadJobId()); + assertFalse(request.isForce()); + } + + @Test + void testSetAndGetFormat() { + // Set the format + String format = "json"; + request.setFormat(format); + + // Verify that the format is parsed using UniProtKBRequestUtil + String expectedFormat = UniProtKBRequestUtil.parseFormat(format); + assertEquals(expectedFormat, request.getFormat()); + } + + @Test + void testSetAndGetFields() { + // Set and get fields + String fields = "gene_name,protein_name"; + request.setFields(fields); + assertEquals(fields, request.getFields()); + } + + @Test + void testSetAndGetDownloadJobId() { + // Set and get downloadJobId + String downloadJobId = "12345"; + request.setDownloadJobId(downloadJobId); + assertEquals(downloadJobId, request.getDownloadJobId()); + } + + @Test + void testSetAndIsForce() { + // Set and check the force flag + request.setForce(true); + assertTrue(request.isForce()); + } + + @Test + void testGetToMethod() { + // Verify that getTo returns the name of the uniprot SolrCollection + assertEquals(SolrCollection.uniprot.name(), request.getTo()); + } + + @Test + void testGetFromMethod() { + // Verify that getFrom returns the name of the uniref SolrCollection + assertEquals(SolrCollection.uniref.name(), request.getFrom()); + } +} From 785a234b9ca3f97614f951777e377f6217738646 Mon Sep 17 00:00:00 2001 From: supun Date: Thu, 31 Oct 2024 15:38:18 +0000 Subject: [PATCH 5/5] add tests for producer --- ...iRefToUniProtKBProducerMessageService.java | 2 +- .../mapto/MapToProducerMessageServiceIT.java | 20 ---- ...KBToUnRefMapProducerMessageServiceIT.java} | 23 +++- ...iRefToUniProtKBJobSubmissionRulesTest.java | 23 ++++ ...ToUniProtKBProducerMessageServiceTest.java | 86 ++++++++++++++ ...efToProtKBMapProducerMessageServiceIT.java | 112 ++++++++++++++++++ 6 files changed, 244 insertions(+), 22 deletions(-) rename async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/{UniProtKToUnRefMapProducerMessageServiceIT.java => UniProtKBToUnRefMapProducerMessageServiceIT.java} (83%) create mode 100644 async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRulesTest.java create mode 100644 async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageServiceTest.java create mode 100644 async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniUnRefToProtKBMapProducerMessageServiceIT.java diff --git a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java index ecc0767c8..013ea5119 100644 --- a/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java +++ b/async-download-rest/src/main/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageService.java @@ -3,8 +3,8 @@ import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.stereotype.Component; import org.uniprot.api.async.download.messaging.result.mapto.MapToFileHandler; +import org.uniprot.api.async.download.messaging.service.mapto.MapToMessagingService; import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; -import org.uniprot.api.async.download.mq.mapto.MapToMessagingService; import org.uniprot.api.async.download.service.mapto.MapToJobService; import org.uniprot.api.rest.request.HashGenerator; diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/MapToProducerMessageServiceIT.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/MapToProducerMessageServiceIT.java index cc4cd0897..1ffc70df1 100644 --- a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/MapToProducerMessageServiceIT.java +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/MapToProducerMessageServiceIT.java @@ -58,24 +58,4 @@ protected DownloadConfigProperties getDownloadConfigProperties() { "org.uniprot.api.async.download.messaging.producer.mapto" }) static class MapProducerTestConfig {} - - @Override - protected @NotNull String getJobHashForSuccess() { - return "e01159046a85cbd920622f34511d9e4c198c6ca4"; - } - - @Override - protected @NotNull String getJobHashForSuccessForceAndIdleJobAllowedAndCleanResources() { - return "7a5b14e8b59dd20dcbd27ba8cad1fb45c4806575"; - } - - @Override - protected @NotNull String getJobHashForWithoutFormatDefaultToJson() { - return "964a9c6154896d88132b6082d397dc6ca9d9f733"; - } - - @Override - protected @NotNull String getJobHashForAlreadyRunning() { - return "ab3f9709a8a59b7241901f13167686bf124fdd81"; - } } diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKToUnRefMapProducerMessageServiceIT.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUnRefMapProducerMessageServiceIT.java similarity index 83% rename from async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKToUnRefMapProducerMessageServiceIT.java rename to async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUnRefMapProducerMessageServiceIT.java index f31264a61..a1020bacc 100644 --- a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKToUnRefMapProducerMessageServiceIT.java +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniProtKBToUnRefMapProducerMessageServiceIT.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -23,7 +24,7 @@ RedisConfigTest.class }) @EnableConfigurationProperties({MapToDownloadConfigProperties.class}) -public class UniProtKToUnRefMapProducerMessageServiceIT +public class UniProtKBToUnRefMapProducerMessageServiceIT extends MapToProducerMessageServiceIT { @Autowired private UniProtKBToUniRefProducerMessageService service; @@ -88,4 +89,24 @@ protected UniProtKBToUniRefDownloadRequest getWithoutFormatRequest() { getService() { return service; } + + @Override + protected @NotNull String getJobHashForWithoutFormatDefaultToJson() { + return "964a9c6154896d88132b6082d397dc6ca9d9f733"; + } + + @Override + protected @NotNull String getJobHashForSuccess() { + return "e01159046a85cbd920622f34511d9e4c198c6ca4"; + } + + @Override + protected @NotNull String getJobHashForSuccessForceAndIdleJobAllowedAndCleanResources() { + return "7a5b14e8b59dd20dcbd27ba8cad1fb45c4806575"; + } + + @Override + protected @NotNull String getJobHashForAlreadyRunning() { + return "ab3f9709a8a59b7241901f13167686bf124fdd81"; + } } diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRulesTest.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRulesTest.java new file mode 100644 index 000000000..ad088d916 --- /dev/null +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBJobSubmissionRulesTest.java @@ -0,0 +1,23 @@ +package org.uniprot.api.async.download.messaging.producer.mapto; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; + +@ExtendWith(MockitoExtension.class) +class UniRefToUniProtKBJobSubmissionRulesTest + extends MapToJobSubmissionRulesTest { + @Mock private UniRefToUniProtKBDownloadRequest mapDownloadRequest; + + @BeforeEach + void setUp() { + init(); + downloadRequest = mapDownloadRequest; + jobSubmissionRules = + new UniRefToUniProtKBJobSubmissionRules( + MAX_RETRY_COUNT, MAX_WAITING_TIME, mapToJobService); + mock(); + } +} diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageServiceTest.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageServiceTest.java new file mode 100644 index 000000000..a168de267 --- /dev/null +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniRefToUniProtKBProducerMessageServiceTest.java @@ -0,0 +1,86 @@ +package org.uniprot.api.async.download.messaging.producer.mapto; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.uniprot.api.async.download.messaging.producer.ProducerMessageService; +import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; +import org.uniprot.api.rest.request.HashGenerator; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.uniprot.api.rest.download.model.JobStatus.NEW; + +@ExtendWith(MockitoExtension.class) +public class UniRefToUniProtKBProducerMessageServiceTest + extends MapToProducerMessageServiceTest { + public static final String UNIREF_MAP_FIELDS = "uniRefMapFields"; + public static final String UNIREF_MAP_SORT = "uniRefMapSort"; + public static final String UNIREF_MAP_FORMAT = "uniRefMapFormat"; + protected final String UNIREF_MAP_QUERY = "uniRefMapQuery"; + @Mock private UniRefToUniProtKBDownloadRequest mapDownloadRequest; + + @Mock + private HashGenerator + uniProtKBMapDownloadRequestHashGenerator; + + @Mock + private UniRefToUniProtKBJobSubmissionRules + uniRefToUniProtKBJobSubmissionRules; + + @BeforeEach + void setUp() { + init(); + this.downloadRequest = mapDownloadRequest; + this.hashGenerator = uniProtKBMapDownloadRequestHashGenerator; + this.jobSubmissionRules = uniRefToUniProtKBJobSubmissionRules; + this.producerMessageService = + new UniRefToUniProtKBProducerMessageService( + mapToJobService, + mapMessageConverter, + mapToMessagingService, + hashGenerator, + mapDownloadFileHandler, + uniRefToUniProtKBJobSubmissionRules); + } + + @Override + protected void mockDownloadRequest() { + mockDownloadRequestWithoutFormat(); + when(downloadRequest.getFormat()).thenReturn(UNIREF_MAP_FORMAT); + } + + @Override + protected void mockDownloadRequestWithoutFormat() { + when(messageConverter.toMessage( + same(downloadRequest), + argThat(mh -> JOB_ID.equals(mh.getHeader(ProducerMessageService.JOB_ID))))) + .thenReturn(message); + when(downloadRequest.getQuery()).thenReturn(UNIREF_MAP_QUERY); + when(downloadRequest.getFields()).thenReturn(UNIREF_MAP_FIELDS); + when(downloadRequest.getSort()).thenReturn(UNIREF_MAP_SORT); + } + + @Override + protected void verifyDownloadJob(UniRefToUniProtKBDownloadRequest request) { + verify(jobService) + .save( + argThat( + job -> { + assertSame(JOB_ID, job.getId()); + assertSame(NEW, job.getStatus()); + assertNotNull(job.getCreated()); + assertNotNull(job.getUpdated()); + assertSame(request.getQuery(), job.getQuery()); + assertSame(request.getFields(), job.getFields()); + assertSame(request.getSort(), job.getSort()); + assertSame(request.getFormat(), job.getFormat()); + return true; + })); + } +} diff --git a/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniUnRefToProtKBMapProducerMessageServiceIT.java b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniUnRefToProtKBMapProducerMessageServiceIT.java new file mode 100644 index 000000000..0be50d058 --- /dev/null +++ b/async-download-rest/src/test/java/org/uniprot/api/async/download/messaging/producer/mapto/UniUnRefToProtKBMapProducerMessageServiceIT.java @@ -0,0 +1,112 @@ +package org.uniprot.api.async.download.messaging.producer.mapto; + +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.uniprot.api.async.download.common.RedisConfigTest; +import org.uniprot.api.async.download.messaging.config.mapto.MapToDownloadConfigProperties; +import org.uniprot.api.async.download.messaging.config.mapto.MapToRabbitMQConfig; +import org.uniprot.api.async.download.messaging.producer.SolrProducerMessageService; +import org.uniprot.api.async.download.model.job.mapto.MapToDownloadJob; +import org.uniprot.api.async.download.model.request.mapto.UniRefToUniProtKBDownloadRequest; +import org.uniprot.api.rest.download.model.JobStatus; + +import java.time.LocalDateTime; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration( + classes = { + MapToProducerMessageServiceIT.MapProducerTestConfig.class, + MapToRabbitMQConfig.class, + RedisConfigTest.class + }) +@EnableConfigurationProperties({MapToDownloadConfigProperties.class}) +public class UniUnRefToProtKBMapProducerMessageServiceIT + extends MapToProducerMessageServiceIT { + @Autowired private UniRefToUniProtKBProducerMessageService service; + + @Override + protected MapToDownloadJob getDownloadJob( + String jobId, LocalDateTime idleSince, UniRefToUniProtKBDownloadRequest request) { + return new MapToDownloadJob( + jobId, + JobStatus.RUNNING, + null, + idleSince, + null, + 0, + request.getQuery(), + request.getFields(), + request.getSort(), + null, + request.getFormat(), + 100, + 10, + 1); + } + + @Override + protected UniRefToUniProtKBDownloadRequest getSuccessDownloadRequest() { + UniRefToUniProtKBDownloadRequest request = new UniRefToUniProtKBDownloadRequest(); + request.setQuery("query2 value"); + request.setSort("accession2 asc"); + request.setFormat("json"); + request.setFields("accession,gene"); + return request; + } + + @Override + protected UniRefToUniProtKBDownloadRequest getSuccessDownloadRequestWithForce() { + UniRefToUniProtKBDownloadRequest request = new UniRefToUniProtKBDownloadRequest(); + request.setQuery("query value"); + request.setSort("accession asc"); + request.setFormat("json"); + request.setFields("accession,gene"); + request.setForce(true); + return request; + } + + @Override + protected UniRefToUniProtKBDownloadRequest getAlreadyRunningRequest() { + UniRefToUniProtKBDownloadRequest request = new UniRefToUniProtKBDownloadRequest(); + request.setQuery("AlreadyExist"); + request.setFormat("json"); + return request; + } + + @Override + protected UniRefToUniProtKBDownloadRequest getWithoutFormatRequest() { + UniRefToUniProtKBDownloadRequest request = new UniRefToUniProtKBDownloadRequest(); + request.setQuery("Not using format"); + return request; + } + + @Override + protected SolrProducerMessageService + getService() { + return service; + } + + @Override + protected @NotNull String getJobHashForWithoutFormatDefaultToJson() { + return "eb87fbe32a6dca5cd8677996aa9ec81bb3def1e9"; + } + + @Override + protected @NotNull String getJobHashForSuccess() { + return "4398ed2e180af6776b54212800cb55d6884bc988"; + } + + @Override + protected @NotNull String getJobHashForSuccessForceAndIdleJobAllowedAndCleanResources() { + return "98571776721c70f42c7f4999c7e39229e76df76d"; + } + + @Override + protected @NotNull String getJobHashForAlreadyRunning() { + return "408f3c5d6fa78854e2e7b6ccec0c7c5675bcc0d6"; + } +}