|
| 1 | +package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Tag; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 6 | +import org.mockito.InjectMocks; |
| 7 | +import org.mockito.Mock; |
| 8 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 9 | +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; |
| 10 | +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; |
| 11 | + |
| 12 | +import java.util.Collections; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 16 | +import static org.mockito.ArgumentMatchers.*; |
| 17 | +import static org.mockito.Mockito.*; |
| 18 | + |
| 19 | +@Tag("unit") |
| 20 | +@ExtendWith(MockitoExtension.class) |
| 21 | +class DashboardDrawerRepositoryTest { |
| 22 | + |
| 23 | + @Mock |
| 24 | + private NamedParameterJdbcTemplate template; |
| 25 | + |
| 26 | + @InjectMocks |
| 27 | + private DashboardDrawerRepository repository; |
| 28 | + |
| 29 | + @Test |
| 30 | + void testGetDashboardDrawerRowsWithoutDatasetId_Success() { |
| 31 | + DashboardDrawer mockDashboardDrawer = new DashboardDrawer( |
| 32 | + 1, // datasetId |
| 33 | + "Study Full Name", // studyFullname |
| 34 | + "Study Abbreviation", // studyAbbreviation |
| 35 | + List.of("Consent Group 1"), // consentGroups |
| 36 | + "Study Summary", // studySummary |
| 37 | + List.of("Study Focus 1"), // studyFocus |
| 38 | + "Study Design", // studyDesign |
| 39 | + "Sponsor" // sponsor |
| 40 | + ); |
| 41 | + |
| 42 | + List<DashboardDrawer> expectedRows = Collections.singletonList(mockDashboardDrawer); |
| 43 | + when(template.query(anyString(), any(DashboardDrawerRowMapper.class))).thenReturn(expectedRows); |
| 44 | + |
| 45 | + List<DashboardDrawer> result = repository.getDashboardDrawerRows(); |
| 46 | + |
| 47 | + assertEquals(expectedRows, result); |
| 48 | + verify(template, times(1)).query(anyString(), any(DashboardDrawerRowMapper.class)); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + void testGetDashboardDrawerRowsWithDatasetId_Success() { |
| 53 | + DashboardDrawer mockDashboardDrawer = new DashboardDrawer( |
| 54 | + 1, // datasetId |
| 55 | + "Study Full Name", // studyFullname |
| 56 | + "Study Abbreviation", // studyAbbreviation |
| 57 | + List.of("Consent Group 1"), // consentGroups |
| 58 | + "Study Summary", // studySummary |
| 59 | + List.of("Study Focus 1"), // studyFocus |
| 60 | + "Study Design", // studyDesign |
| 61 | + "Sponsor" // sponsor |
| 62 | + ); |
| 63 | + |
| 64 | + List<DashboardDrawer> expectedRows = Collections.singletonList(mockDashboardDrawer); |
| 65 | + when(template.query(anyString(), any(MapSqlParameterSource.class), any(DashboardDrawerRowMapper.class))).thenReturn(expectedRows); |
| 66 | + |
| 67 | + List<DashboardDrawer> result = repository.getDashboardDrawerRows(1); |
| 68 | + |
| 69 | + assertEquals(expectedRows, result); |
| 70 | + verify(template, times(1)).query(anyString(), any(MapSqlParameterSource.class), any(DashboardDrawerRowMapper.class)); |
| 71 | + } |
| 72 | +} |
0 commit comments