From 470e8e726d3a7c6739ce1042918c90668328994a Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Thu, 22 Nov 2018 01:50:09 +0100 Subject: [PATCH] Made WireMock adjustments for Jenkins. --- .../org/dhis2/fhir/adapter/AbstractAppTest.java | 15 +++++++-------- .../org/dhis2/fhir/adapter/TestConfiguration.java | 5 +++++ ...rackedEntityInstanceTransformationAppTest.java | 13 ++++++------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/test/java/org/dhis2/fhir/adapter/AbstractAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/AbstractAppTest.java index 9bc5bc89..5d74c3f2 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/AbstractAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/AbstractAppTest.java @@ -165,19 +165,17 @@ protected void notifyResource( @Nonnull FhirResourceType resourceType, @Nullable final UrlPattern urlPattern = urlMatching( TestConfiguration.BASE_DSTU3_CONTEXT + "/" + resourceType.getResourceTypeName() + "\\?_sort=_lastUpdated&_count=10000&_lastUpdated=ge[^&]+&_elements=meta\\%2[cC]id" ); - final StubMapping stubMapping = stubFor( WireMock.get( urlPattern ).willReturn( aResponse() + previousResourceSearchStubMapping = fhirMockServer.stubFor( + WireMock.get( urlPattern ).willReturn( aResponse() .withHeader( "Content-Type", "application/fhir+json" ) .withBody( resourceSearchResponse ) ) ); - fhirMockServer.addStubMapping( stubMapping ); - previousResourceSearchStubMapping = stubMapping; } if ( StringUtils.isNotBlank( resourceId ) && StringUtils.isNotBlank( resourceResponse ) ) { - final StubMapping stubMapping = stubFor( WireMock.get( urlEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + + fhirMockServer.stubFor( WireMock.get( urlEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + "/" + resourceType.getResourceTypeName() + "/" + resourceId ) ).willReturn( aResponse() .withHeader( "Content-Type", "application/fhir+json" ) .withBody( resourceResponse ) ) ); - fhirMockServer.addStubMapping( stubMapping ); } mockMvc.perform( post( "/remote-fhir-rest-hook/{subscriptionId}/{subscriptionResourceId}", @@ -240,15 +238,16 @@ private long getQueueMessageCount( @Nonnull JmsTemplate jmsTemplate, @Nullable S public void beforeAbstractAppTest() throws Exception { fhirMockServer.resetAll(); + WireMock.configureFor( fhirMockServer.port() ); previousResourceSearchStubMapping = null; systemDhis2Server = MockRestServiceServer.bindTo( systemDhis2RestTemplate ).ignoreExpectOrder( true ).build(); userDhis2Server = MockRestServiceServer.bindTo( userDhis2RestTemplate ).build(); - fhirMockServer.addStubMapping( - stubFor( WireMock.get( urlPathEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + "/metadata" ) ).willReturn( aResponse() + fhirMockServer.stubFor( + WireMock.get( urlPathEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + "/metadata" ) ).willReturn( aResponse() .withHeader( "Content-Type", "application/fhir+json" ) - .withBody( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/dstu3/metadata.json", StandardCharsets.UTF_8 ) ) ) ) ); + .withBody( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/dstu3/metadata.json", StandardCharsets.UTF_8 ) ) ) ); clearCache( metadataCacheManager ); clearCache( dhisCacheManager ); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/TestConfiguration.java b/app/src/test/java/org/dhis2/fhir/adapter/TestConfiguration.java index 2a49c821..0bdd9cc6 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/TestConfiguration.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/TestConfiguration.java @@ -38,6 +38,8 @@ import org.dhis2.fhir.adapter.setup.SetupResult; import org.dhis2.fhir.adapter.setup.SetupService; import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -67,6 +69,8 @@ @AutoConfigureAfter( HibernateJpaAutoConfiguration.class ) public class TestConfiguration { + private final Logger logger = LoggerFactory.getLogger( getClass() ); + public static final String ADAPTER_AUTHORIZATION = "Bearer 836ef9274abc828728746"; public static final String DHIS2_USERNAME = "fhir_user"; @@ -142,6 +146,7 @@ protected void postConstruct() { fhirMockServer = new WireMockServer( wireMockConfig().dynamicPort() ); fhirMockServer.start(); + logger.info( "Started WireMock server for FHIR requests on port {}.", fhirMockServer.port() ); final Setup setup = new Setup(); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java index ec572fc8..4fbcdb48 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java @@ -39,7 +39,8 @@ import java.nio.charset.StandardCharsets; -import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -55,17 +56,15 @@ public class PatientToTrackedEntityInstanceTransformationAppTest public void createPatient() throws Exception { expectTrackedEntityMetadataRequests(); - fhirMockServer.addStubMapping( - stubFor( WireMock.get( urlPathEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + "/Organization/19" ) ).willReturn( aResponse() + fhirMockServer.stubFor( WireMock.get( urlPathEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + "/Organization/19" ) ).willReturn( aResponse() .withHeader( "Content-Type", "application/fhir+json" ) - .withBody( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/dstu3/get-organization-19.json", StandardCharsets.UTF_8 ) ) ) ) ); + .withBody( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/dstu3/get-organization-19.json", StandardCharsets.UTF_8 ) ) ) ); systemDhis2Server.expect( ExpectedCount.once(), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/organisationUnits.json?paging=false&fields=id,code&filter=code:eq:OU_U_7777" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-org-unit-empty.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); - fhirMockServer.addStubMapping( - stubFor( WireMock.get( urlPathEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + "/Organization/18" ) ).willReturn( aResponse() + fhirMockServer.stubFor( WireMock.get( urlPathEqualTo( TestConfiguration.BASE_DSTU3_CONTEXT + "/Organization/18" ) ).willReturn( aResponse() .withHeader( "Content-Type", "application/fhir+json" ) - .withBody( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/dstu3/get-organization-18.json", StandardCharsets.UTF_8 ) ) ) ) ); + .withBody( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/fhir/test/dstu3/get-organization-18.json", StandardCharsets.UTF_8 ) ) ) ); systemDhis2Server.expect( ExpectedCount.once(), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/organisationUnits.json?paging=false&fields=id,code&filter=code:eq:OU_1234" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-org-unit-OU_1234.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );