Skip to content

Commit

Permalink
Made WireMock adjustments for Jenkins.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Nov 22, 2018
1 parent 116a4a3 commit 470e8e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
15 changes: 7 additions & 8 deletions app/src/test/java/org/dhis2/fhir/adapter/AbstractAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 ) );
Expand Down

0 comments on commit 470e8e7

Please sign in to comment.