mirror of
https://github.com/pcvolkmer/mv64e-onkostar-data.git
synced 2025-09-14 00:12:52 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package dev.pcvolkmer.onco.datamapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.MtbDiagnosis;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class KpaDiagnosisDataMapperTest {
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
KpaDiagnosisDataMapper dataMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(@Mock JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.dataMapper = new KpaDiagnosisDataMapper(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateDataMapper(@Mock DataSource dataSource) {
|
||||
assertThat(MtbDataMapper.create(dataSource)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseKpaProcedureId(@Mock ResultSet resultSet) throws SQLException {
|
||||
doAnswer(invocationOnMock -> {
|
||||
var columnName = invocationOnMock.getArgument(0, String.class);
|
||||
switch (columnName) {
|
||||
case "id":
|
||||
return "1";
|
||||
case "icd10":
|
||||
return "F79.9";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}).when(resultSet).getString(anyString());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(resultSet))
|
||||
.when(jdbcTemplate)
|
||||
.query(anyString(), any(RowMapper.class), anyInt());
|
||||
|
||||
var actual = this.dataMapper.getById(1);
|
||||
assertThat(actual).isInstanceOf(MtbDiagnosis.class);
|
||||
assertThat(actual.getId()).isEqualTo("1");
|
||||
assertThat(actual.getCode().getCode()).isEqualTo("F79.9");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package dev.pcvolkmer.onco.datamapper;
|
||||
|
||||
import dev.pcvolkmer.mv64e.mtb.Mtb;
|
||||
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MtbDataMapperTest {
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
MtbDataMapper mtbDataMapper;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(@Mock JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.mtbDataMapper = new MtbDataMapper(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateDataMapper(@Mock DataSource dataSource) {
|
||||
assertThat(MtbDataMapper.create(dataSource)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseKpaProcedureId() {
|
||||
doAnswer(invocationOnMock -> List.of(1))
|
||||
.when(jdbcTemplate)
|
||||
.query(anyString(), any(RowMapper.class), anyString());
|
||||
|
||||
var actual = this.mtbDataMapper.getByCaseId("16000123");
|
||||
assertThat(actual).isInstanceOf(Mtb.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionIfNoKpaProcedureFound() {
|
||||
var ex = assertThrows(DataAccessException.class, () -> {
|
||||
this.mtbDataMapper.getByCaseId("16000123");
|
||||
});
|
||||
assertThat(ex).hasMessage("No record found for case: 16000123");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionIfMultipleKpaProceduresFound() {
|
||||
doAnswer(invocationOnMock -> List.of(1, 2))
|
||||
.when(jdbcTemplate)
|
||||
.query(anyString(), any(RowMapper.class), anyString());
|
||||
|
||||
var ex = assertThrows(DataAccessException.class, () -> {
|
||||
this.mtbDataMapper.getByCaseId("16000123");
|
||||
});
|
||||
assertThat(ex).hasMessage("Multiple records found for case: 16000123");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user