1
0
mirror of https://github.com/pcvolkmer/mv64e-etl-processor synced 2025-09-13 09:02:50 +00:00

test: added failing test

This commit is contained in:
Jakub Lidke
2025-09-05 15:58:31 +02:00
parent 88857cf201
commit ace5637ed8
2 changed files with 75 additions and 71 deletions

View File

@@ -24,14 +24,15 @@ import java.time.Instant;
import java.util.Date; import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError; import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
@ContextConfiguration(classes = {AppConfiguration.class, ObjectMapper.class}) @ContextConfiguration(classes = {AppConfiguration.class, ObjectMapper.class})
@TestPropertySource(properties = { @TestPropertySource(properties = {
"app.consent.service=gics", "app.consent.service=gics",
"app.consent.gics.uri=http://localhost:8090/ttp-fhir/fhir/gics" "app.consent.gics.uri=http://localhost:8090/ttp-fhir/fhir/gics"
}) })
@RestClientTest @RestClientTest
class GicsConsentServiceTest { class GicsConsentServiceTest {
@@ -46,8 +47,8 @@ class GicsConsentServiceTest {
@BeforeEach @BeforeEach
void setUp( void setUp(
@Autowired AppFhirConfig appFhirConfig, @Autowired AppFhirConfig appFhirConfig,
@Autowired GIcsConfigProperties gIcsConfigProperties @Autowired GIcsConfigProperties gIcsConfigProperties
) { ) {
this.appFhirConfig = appFhirConfig; this.appFhirConfig = appFhirConfig;
this.gIcsConfigProperties = gIcsConfigProperties; this.gIcsConfigProperties = gIcsConfigProperties;
@@ -56,33 +57,33 @@ class GicsConsentServiceTest {
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate); this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate);
this.gicsConsentService = new GicsConsentService( this.gicsConsentService = new GicsConsentService(
this.gIcsConfigProperties, this.gIcsConfigProperties,
RetryTemplate.builder().maxAttempts(1).build(), RetryTemplate.builder().maxAttempts(1).build(),
restTemplate, restTemplate,
this.appFhirConfig this.appFhirConfig
); );
} }
@Test @Test
void shouldReturnTtpBroadConsentStatus() { void shouldReturnTtpBroadConsentStatus() {
final Parameters consentedResponse = new Parameters() final Parameters consentedResponse = new Parameters()
.addParameter( .addParameter(
new ParametersParameterComponent() new ParametersParameterComponent()
.setName("consented") .setName("consented")
.setValue(new BooleanType().setValue(true)) .setValue(new BooleanType().setValue(true))
); );
mockRestServiceServer mockRestServiceServer
.expect( .expect(
requestTo( requestTo(
"http://localhost:8090/ttp-fhir/fhir/gics" + GicsConsentService.IS_CONSENTED_ENDPOINT) "http://localhost:8090/ttp-fhir/fhir/gics" + GicsConsentService.IS_CONSENTED_ENDPOINT)
)
.andRespond(
withSuccess(
appFhirConfig.fhirContext().newJsonParser().encodeResourceToString(consentedResponse),
MediaType.APPLICATION_JSON
) )
); .andRespond(
withSuccess(
appFhirConfig.fhirContext().newJsonParser().encodeResourceToString(consentedResponse),
MediaType.APPLICATION_JSON
)
);
var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456"); var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456");
assertThat(consentStatus).isEqualTo(TtpConsentStatus.BROAD_CONSENT_GIVEN); assertThat(consentStatus).isEqualTo(TtpConsentStatus.BROAD_CONSENT_GIVEN);
@@ -91,22 +92,22 @@ class GicsConsentServiceTest {
@Test @Test
void shouldReturnRevokedConsent() { void shouldReturnRevokedConsent() {
final Parameters revokedResponse = new Parameters() final Parameters revokedResponse = new Parameters()
.addParameter( .addParameter(
new ParametersParameterComponent() new ParametersParameterComponent()
.setName("consented") .setName("consented")
.setValue(new BooleanType().setValue(false)) .setValue(new BooleanType().setValue(false))
); );
mockRestServiceServer mockRestServiceServer
.expect( .expect(
requestTo( requestTo(
"http://localhost:8090/ttp-fhir/fhir/gics" + GicsConsentService.IS_CONSENTED_ENDPOINT) "http://localhost:8090/ttp-fhir/fhir/gics" + GicsConsentService.IS_CONSENTED_ENDPOINT)
) )
.andRespond( .andRespond(
withSuccess( withSuccess(
appFhirConfig.fhirContext().newJsonParser().encodeResourceToString(revokedResponse), appFhirConfig.fhirContext().newJsonParser().encodeResourceToString(revokedResponse),
MediaType.APPLICATION_JSON) MediaType.APPLICATION_JSON)
); );
var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456"); var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456");
assertThat(consentStatus).isEqualTo(TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED); assertThat(consentStatus).isEqualTo(TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED);
@@ -116,23 +117,23 @@ class GicsConsentServiceTest {
@Test @Test
void shouldReturnInvalidParameterResponse() { void shouldReturnInvalidParameterResponse() {
final OperationOutcome responseWithErrorOutcome = new OperationOutcome() final OperationOutcome responseWithErrorOutcome = new OperationOutcome()
.addIssue( .addIssue(
new OperationOutcomeIssueComponent() new OperationOutcomeIssueComponent()
.setSeverity(IssueSeverity.ERROR) .setSeverity(IssueSeverity.ERROR)
.setCode(IssueType.PROCESSING) .setCode(IssueType.PROCESSING)
.setDiagnostics("Invalid policy parameter...") .setDiagnostics("Invalid policy parameter...")
); );
mockRestServiceServer mockRestServiceServer
.expect( .expect(
requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT) requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT)
)
.andRespond(
withSuccess(
appFhirConfig.fhirContext().newJsonParser().encodeResourceToString(responseWithErrorOutcome),
MediaType.APPLICATION_JSON
) )
); .andRespond(
withSuccess(
appFhirConfig.fhirContext().newJsonParser().encodeResourceToString(responseWithErrorOutcome),
MediaType.APPLICATION_JSON
)
);
var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456"); var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456");
assertThat(consentStatus).isEqualTo(TtpConsentStatus.FAILED_TO_ASK); assertThat(consentStatus).isEqualTo(TtpConsentStatus.FAILED_TO_ASK);
@@ -141,12 +142,12 @@ class GicsConsentServiceTest {
@Test @Test
void shouldReturnRequestError() { void shouldReturnRequestError() {
mockRestServiceServer mockRestServiceServer
.expect( .expect(
requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT) requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT)
) )
.andRespond( .andRespond(
withServerError() withServerError()
); );
var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456"); var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456");
assertThat(consentStatus).isEqualTo(TtpConsentStatus.FAILED_TO_ASK); assertThat(consentStatus).isEqualTo(TtpConsentStatus.FAILED_TO_ASK);
@@ -156,26 +157,29 @@ class GicsConsentServiceTest {
void buildRequestParameterCurrentPolicyStatesForPersonTest() { void buildRequestParameterCurrentPolicyStatesForPersonTest() {
String pid = "12345678"; String pid = "12345678";
var result = gicsConsentService var result = gicsConsentService
.buildRequestParameterCurrentPolicyStatesForPerson( .buildRequestParameterCurrentPolicyStatesForPerson(
pid, pid,
Date.from(Instant.now()), Date.from(Instant.now()),
ConsentDomain.MODELLVORHABEN_64E ConsentDomain.MODELLVORHABEN_64E
); );
assertThat(result.getParameter()) assertThat(result.getParameter())
.as("should contain 3 parameter resources") .as("should contain 3 parameter resources")
.hasSize(3); .hasSize(3);
assertThat(((StringType) result.getParameter("domain").getValue()).getValue()) assertThat(((StringType) result.getParameter("domain").getValue()).getValue())
.isEqualTo( .isEqualTo(
gIcsConfigProperties.getGenomDeConsentDomainName() gIcsConfigProperties.getGenomDeConsentDomainName()
); );
assertThat(((Identifier) result.getParameter("personIdentifier").getValue()).getValue()) assertThat(((Identifier) result.getParameter("personIdentifier").getValue()).getValue())
.isEqualTo( .isEqualTo(
pid pid
); );
} }
@Test
public void convertGicsResultToMiiBroadConsent() {
fail("todo: implement Test gicsConsentService.convertGicsResultToMiiBroadConsent");
}
} }

View File

@@ -80,7 +80,7 @@ class ConsentProcessorTest {
val checkResult = consentProcessor.consentGatedCheckAndTryEmbedding(inputMtb) val checkResult = consentProcessor.consentGatedCheckAndTryEmbedding(inputMtb)
assertThat(checkResult).isTrue assertThat(checkResult).isTrue
assertThat(inputMtb.metadata.researchConsents).hasSize(26) assertThat(inputMtb.metadata.researchConsents).isNotEmpty
} }
companion object { companion object {