@SpringBootTest
@RunWith(SpringRunner.class)
public class OkHttpExaxeFileUploaderTest {
// Type under test
private OkHttpExaxeFileUploader uploader;
// Run WireMock on port 9999
@Rule
public WireMockRule wireMockRule = new WireMockRule(options().port(9999));
@Test
public void validFileUploadIsSuccess() throws Exception {
// Mock Exaxe API to return 200 and a success response
givenThat(
post(
urlEqualTo("/apex/UploadFile")
)
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody(readStringFromFile("uploadFileResponse_success.json"))
)
);
String rates = readStringFromFile("exchange-rates.csv");
boolean success = uploader.uploadToExaxe("ExchangeRate", "some.csv", rates);
assertThat(success).isTrue();
}
}