From 9062fa060f9fa00e4a486e347251e964e30177a2 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Tue, 17 Dec 2024 10:10:42 +0100 Subject: [PATCH] fixed openaireId + test --- .../service/DirectIndexService.java | 2 +- .../controllers/LegacyApiControllerTest.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/test/java/eu/dnetlib/app/directindex/controllers/LegacyApiControllerTest.java diff --git a/src/main/java/eu/dnetlib/app/directindex/service/DirectIndexService.java b/src/main/java/eu/dnetlib/app/directindex/service/DirectIndexService.java index 93710c8..be14087 100644 --- a/src/main/java/eu/dnetlib/app/directindex/service/DirectIndexService.java +++ b/src/main/java/eu/dnetlib/app/directindex/service/DirectIndexService.java @@ -87,7 +87,7 @@ public class DirectIndexService { private void fixOpenaireId(final ResultEntry r) throws DirectIndexApiException { final DatasourceEntry ds = StringUtils.isNotBlank(r.getCollectedFromId()) ? dsmClient.findDatasource(r.getCollectedFromId()) : UNKNOWN_REPO; - final String openaireId = ds.getPrefix() + "::" + DigestUtils.md5Hex(r.getOpenaireId()); + final String openaireId = ds.getPrefix() + "::" + DigestUtils.md5Hex(r.getOriginalId()); r.setOpenaireId(openaireId); } diff --git a/src/test/java/eu/dnetlib/app/directindex/controllers/LegacyApiControllerTest.java b/src/test/java/eu/dnetlib/app/directindex/controllers/LegacyApiControllerTest.java new file mode 100644 index 0000000..803c1fb --- /dev/null +++ b/src/test/java/eu/dnetlib/app/directindex/controllers/LegacyApiControllerTest.java @@ -0,0 +1,55 @@ +package eu.dnetlib.app.directindex.controllers; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.lenient; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import eu.dnetlib.app.directindex.input.ResultEntry; +import eu.dnetlib.app.directindex.tasks.ScheduledActions; + +@SpringBootTest +@Disabled +public class LegacyApiControllerTest { + + @Autowired + private LegacyApiController controller; + + @Autowired + private ScheduledActions actions; + + @Test + public void contextLoads() throws Exception { + assertThat(controller).isNotNull(); + assertThat(actions).isNotNull(); + } + + @Test + public void stressFeedResult() throws Exception { + + actions.setEnabled(false); + final ResultEntry result = new ObjectMapper().readValue(getClass().getResourceAsStream("/samples/sample-result-01.json"), ResultEntry.class); + + final HttpServletRequest req = Mockito.mock(HttpServletRequest.class); + lenient().when(req.getRemoteAddr()).thenReturn("127.0.0.1"); + + for (int i = 0; i < 10000; i++) { + result.setOpenaireId(null); + result.setOriginalId("test::" + i); + final String openaireId = controller.feedResult(result, req); + System.out.println(openaireId); + } + + actions.setEnabled(true); + actions.indexRecords(); + } + +}