diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 804b6d5..dc8d4bf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,13 +3,14 @@ spring.datasource.url=jdbc:postgresql://${POSTGRES_HOST}:5432/${POSTGRES_DB}?cur spring.datasource.username=${POSTGRES_USER} spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver + server.port=80 dashboard.columns={abbreviation:'Abbreviation',name:'Name',clinvars:'Clinical Variables'} dashboard.column-order=abbreviation,name,clinvars dashboard.nonmeta-columns=abbreviation,name dashboard.enable.extra_details=true -dashboard.enable.bdc_hack=true -dashboard.layout.type= +dashboard.enable.bdc_hack=false +dashboard.layout.type=default filtering.unfilterable_concepts=stigmatized diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerControllerTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerControllerTest.java new file mode 100644 index 0000000..da82739 --- /dev/null +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerControllerTest.java @@ -0,0 +1,47 @@ +package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; + +import org.junit.jupiter.api.Tag; +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.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@Tag("unit") +@WebMvcTest(DashboardDrawerController.class) +class DashboardDrawerControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private DashboardDrawerService dashboardDrawerService; + + @Test + void testFindAll() throws Exception { + DashboardDrawerList mockList = new DashboardDrawerList(new ArrayList<>()); // Populate mock data if needed + when(dashboardDrawerService.findAll()).thenReturn(mockList); + + mockMvc.perform(get("/dashboard-drawer").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); + } + + @Test + void testFindByDatasetId() throws Exception { + DashboardDrawer mockDrawer = + new DashboardDrawer(1, "Full Name", "Abbreviation", List.of("Consent 1"), "Summary", List.of("Focus 1"), "Design", "Sponsor"); + + when(dashboardDrawerService.findByDatasetId(1)).thenReturn(mockDrawer); + + mockMvc.perform(get("/dashboard-drawer/1").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); + } +} diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRepositoryTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRepositoryTest.java new file mode 100644 index 0000000..20c69c7 --- /dev/null +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRepositoryTest.java @@ -0,0 +1,72 @@ +package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; + +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +@Tag("unit") +@ExtendWith(MockitoExtension.class) +class DashboardDrawerRepositoryTest { + + @Mock + private NamedParameterJdbcTemplate template; + + @InjectMocks + private DashboardDrawerRepository repository; + + @Test + void testGetDashboardDrawerRowsWithoutDatasetId_Success() { + DashboardDrawer mockDashboardDrawer = new DashboardDrawer( + 1, // datasetId + "Study Full Name", // studyFullname + "Study Abbreviation", // studyAbbreviation + List.of("Consent Group 1"), // consentGroups + "Study Summary", // studySummary + List.of("Study Focus 1"), // studyFocus + "Study Design", // studyDesign + "Sponsor" // sponsor + ); + + List expectedRows = Collections.singletonList(mockDashboardDrawer); + when(template.query(anyString(), any(DashboardDrawerRowMapper.class))).thenReturn(expectedRows); + + List result = repository.getDashboardDrawerRows(); + + assertEquals(expectedRows, result); + verify(template, times(1)).query(anyString(), any(DashboardDrawerRowMapper.class)); + } + + @Test + void testGetDashboardDrawerRowsWithDatasetId_Success() { + DashboardDrawer mockDashboardDrawer = new DashboardDrawer( + 1, // datasetId + "Study Full Name", // studyFullname + "Study Abbreviation", // studyAbbreviation + List.of("Consent Group 1"), // consentGroups + "Study Summary", // studySummary + List.of("Study Focus 1"), // studyFocus + "Study Design", // studyDesign + "Sponsor" // sponsor + ); + + List expectedRows = Collections.singletonList(mockDashboardDrawer); + when(template.query(anyString(), any(MapSqlParameterSource.class), any(DashboardDrawerRowMapper.class))).thenReturn(expectedRows); + + List result = repository.getDashboardDrawerRows(1); + + assertEquals(expectedRows, result); + verify(template, times(1)).query(anyString(), any(MapSqlParameterSource.class), any(DashboardDrawerRowMapper.class)); + } +} diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerServiceTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerServiceTest.java new file mode 100644 index 0000000..6d69549 --- /dev/null +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerServiceTest.java @@ -0,0 +1,49 @@ +package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.*; + +@Tag("unit") +@ExtendWith(MockitoExtension.class) +class DashboardDrawerServiceTest { + + @Mock + private DashboardDrawerRepository repository; + + private static final String DASHBOARD_LAYOUT_BDC = "bdc"; + private static final String DASHBOARD_LAYOUT_OTHER = "other"; + + @Test + void testFindAll_WithBDCLayout() { + List mockRecords = List.of( + new DashboardDrawer(1, "Full Name", "Abbreviation", List.of("Consent 1"), "Summary", List.of("Focus 1"), "Design", "Sponsor") + ); + when(repository.getDashboardDrawerRows()).thenReturn(mockRecords); + + DashboardDrawerService serviceWithBDCLayout = new DashboardDrawerService(repository, DASHBOARD_LAYOUT_BDC); + + DashboardDrawerList result = serviceWithBDCLayout.findAll(); + + assertEquals(mockRecords, result.dashboardDrawerList()); + verify(repository, times(1)).getDashboardDrawerRows(); + } + + @Test + void testFindAll_WithNonBDCLayout() { + DashboardDrawerService serviceWithOtherLayout = new DashboardDrawerService(repository, DASHBOARD_LAYOUT_OTHER); + + DashboardDrawerList result = serviceWithOtherLayout.findAll(); + + assertEquals(0, result.dashboardDrawerList().size()); + verifyNoInteractions(repository); + } +} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 8fb1863..697f376 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -7,8 +7,8 @@ spring.datasource.driver-class-name=org.postgresql.Driver dashboard.columns={abbreviation:'Abbreviation',melast:'This one goes last',name:'Name',clinvars:'Clinical Variables',participants:'Participants'} dashboard.column-order=abbreviation,name,clinvars dashboard.nonmeta-columns=abbreviation,name - dashboard.enable.extra_details=true dashboard.enable.bdc_hack=false +dashboard.layout.type=default filtering.unfilterable_concepts=stigmatized