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 testWhenInternalServerError_thenReturnHttp500() throws Exception { | |
String mockPhoneNum = "542*******"; | |
this.mockServer.expect(ExpectedCount.once(), requestTo(invoiceUrl | |
+ mockPhoneNum)) | |
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) | |
.andRespond((response) -> { throw new RuntimeException(); }); |
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
{ | |
"success": false, | |
"responseMsg": "No invoice data found for given phone number", | |
"statusCode": "204", | |
"response": "NO_CONTENT", | |
"data": {} | |
} |
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 testWhenPhoneNumEnteredAndNoDataFound_thenReturnHttp204() throws Exception { | |
String mockPhoneNum = "542*******"; | |
final FileInputStream fileInputStream = new FileInputStream(ResourceUtils.getFile("classpath:response_http204.json")); | |
final String staticResponse = StreamUtils.copyToString(fileInputStream, Charset.defaultCharset()); | |
InvoiceResponse mockInvoiceResponse = mapper.readValue(staticResponse, InvoiceResponse.class); | |
this.mockServer.expect(ExpectedCount.once(), requestTo(invoiceUrl |
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 |
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 testWhenPhoneNumEnteredAndNoDataFound_thenReturnHttp204() throws Exception { | |
final String mockPhoneNumber = "542*******"; | |
final FileInputStream fileInputStream = new FileInputStream(ResourceUtils.getFile("classpath:response_http204.json")); | |
final String staticResponse = StreamUtils.copyToString(fileInputStream, Charset.defaultCharset()); | |
InvoiceResponse mockInvoiceResponse = mapper.readValue(staticResponse, InvoiceResponse.class); |
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 { | |
final String mockPhoneNumber = "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 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
@RunWith(SpringRunner.class) | |
@RestClientTest(InvoiceServiceImp.class) | |
@PropertySource("classpath:application-test.properties") | |
public class InvoiceServiceTest { | |
@Autowired | |
private MockRestServiceServer mockServer; | |
@Autowired |
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
@RunWith(SpringRunner.class) | |
@WebMvcTest(InvoiceController.class) | |
public class InvoiceControllerTest { | |
@Autowired | |
private MockMvc mockMvc; | |
@MockBean | |
private InvoiceService invoiceService; |
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
{ | |
"success": true, | |
"responseMsg": "Successfully returned invoice list", | |
"statusCode": "200", | |
"response": "Success", | |
"data": { | |
"InvoiceList": [ | |
{ | |
"Id": "35011", | |
"Name": "Bonus Demand Tariff Package", |
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
public InvoiceQueryInfo getInvoiceInfo(String phoneNumber) { | |
try { | |
MultiValueMap<String, String> body = new LinkedMultiValueMap<>(); | |
HttpHeaders requestHeaders = new HttpHeaders(); | |
final String uuid = UUID.randomUUID().toString(); | |
requestHeaders.add("id", uuid); | |
HttpEntity<?> httpEntity = new HttpEntity<>(body, requestHeaders); | |
requestHeaders.setContentType(MediaType.APPLICATION_JSON); |
NewerOlder