fixed openaireId + test

This commit is contained in:
Michele Artini 2024-12-17 10:10:42 +01:00
parent ecf7f2ae33
commit 9062fa060f
2 changed files with 56 additions and 1 deletions

View File

@ -87,7 +87,7 @@ public class DirectIndexService {
private void fixOpenaireId(final ResultEntry r) throws DirectIndexApiException { private void fixOpenaireId(final ResultEntry r) throws DirectIndexApiException {
final DatasourceEntry ds = StringUtils.isNotBlank(r.getCollectedFromId()) ? dsmClient.findDatasource(r.getCollectedFromId()) : UNKNOWN_REPO; 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); r.setOpenaireId(openaireId);
} }

View File

@ -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();
}
}