Last active
April 24, 2020 10:09
-
-
Save hakansander/1d92b1aa8a085ead86bb6c7dc0fcac9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testWhenPhoneNumEnteredAndDataExists_thenReturnHttp200() throws Exception { | |
String mockPhoneNum = "534*******"; | |
final FileInputStream fileInputStream = new FileInputStream(ResourceUtils.getFile("classpath:response_http200.json")); | |
final String staticResponse = StreamUtils.copyToString(fileInputStream, Charset.defaultCharset()); | |
InvoiceResponse mockInvoiceResponse = mapper.readValue(staticResponse, InvoiceResponse.class); | |
this.mockServer.expect(ExpectedCount.once(), requestTo(invoiceUrl | |
+ mockPhoneNum)) | |
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) | |
.andRespond(withStatus(HttpStatus.OK) | |
.contentType(MediaType.APPLICATION_JSON) | |
.body(mapper.writeValueAsString(mockInvoiceResponse))); | |
responseInvoiceResponseEntity = mockService.getInvoiceInfo(mockPhoneNum); | |
mockServer.verify(); | |
Assert.assertEquals("200", | |
responseInvoiceResponseEntity. | |
getStatusCode()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment