From e3e08268f54274262e89241c9212ef6c05ebf140 Mon Sep 17 00:00:00 2001 From: Alessia Bardi Date: Fri, 20 Oct 2023 16:40:45 +0200 Subject: [PATCH] #9103: db_load_date available from the Info API --- .../eu/dnetlib/openaire/info/JdbcInfoDao.java | 1 + .../openaire/info/InfoControllerTest.java | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/info/JdbcInfoDao.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/info/JdbcInfoDao.java index 0898d85e..be1fe66a 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/info/JdbcInfoDao.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/info/JdbcInfoDao.java @@ -8,6 +8,7 @@ public interface JdbcInfoDao { claim_load_date, oaf_load_date, odf_load_date, + db_load_date, inference_date, stats_update_date, crossref_update_date, diff --git a/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/info/InfoControllerTest.java b/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/info/InfoControllerTest.java index 746fa144..5763637b 100644 --- a/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/info/InfoControllerTest.java +++ b/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/info/InfoControllerTest.java @@ -7,6 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Arrays; @@ -17,19 +18,18 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; -@SpringBootTest + @WebMvcTest(InfoController.class) public class InfoControllerTest { public static final MediaType APPLICATION_JSON_UTF8 = new MediaType( MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), - Charset.forName("utf8")); + StandardCharsets.UTF_8); @Autowired private MockMvc mvc; @@ -37,18 +37,18 @@ public class InfoControllerTest { @MockBean private InfoController infoController; - private LocalDate expectedDate; private String formattedDate; @BeforeEach public void setup() { - expectedDate = LocalDate.now(); + LocalDate expectedDate = LocalDate.now(); formattedDate = expectedDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); given(infoController.getDate(JdbcInfoDao.DATE_INFO.claim_load_date.name())).willReturn(expectedDate); given(infoController.getDate(JdbcInfoDao.DATE_INFO.oaf_load_date.name())).willReturn(expectedDate); given(infoController.getDate(JdbcInfoDao.DATE_INFO.odf_load_date.name())).willReturn(expectedDate); given(infoController.getDate(JdbcInfoDao.DATE_INFO.inference_date.name())).willReturn(expectedDate); given(infoController.getDate(JdbcInfoDao.DATE_INFO.stats_update_date.name())).willReturn(expectedDate); + given(infoController.getDate(JdbcInfoDao.DATE_INFO.db_load_date.name())).willReturn(expectedDate); given(infoController.listInfo()).willReturn(Maps.newHashMap(JdbcInfoDao.DATE_INFO.inference_date.name(), LocalDate.now())); given(infoController.listInfoKeys()) .willReturn(Arrays.stream(JdbcInfoDao.DATE_INFO.values()).map(JdbcInfoDao.DATE_INFO::name).collect(Collectors.toList())); @@ -116,4 +116,12 @@ public class InfoControllerTest { .getContentAsString()); } + @Test + public void testGetDbLoadDate() throws Exception { + mvc.perform(get("/info/db_load_date") + .contentType(APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", is(formattedDate))); + } + }