0

I am using srping framework for API testing. For negative test cases where API returns error codes like 400,401,403. feign always throws an exception

Is there any way I can catch Actual API response instead of feign exception and assert it.

@FeignClient(name = "StockTransferProxy", url = "${app.url}")
public interface `StockTransferProxy` {

@PutMapping(value = "${api.scanItems}")
ScannedItemResponse scanItems(@RequestHeader(HttpHeaders.AUTHORIZATION)String auth,
                              @RequestParam("transferId") String transferId,
                              @RequestBody ScannedItemRequest body);
 }

Testcase file

@EnableWebTests
public class StockTransfer extends CoreTest {

private static final Logger log = LoggerFactory.getLogger(StockTransfer.class);

private String auth = "...";

@Autowired
private StockTransferProxy stockTransferProxy;


@Test
public void stockTransfer_1() {
ScannedItemResponse scannedItem = stockTransferProxy.scanItems(auth, transferId, new ScannedItemRequest("010001707340051"));}

Any help on getting the actual http status code and message

Poornima Hegde
  • 163
  • 1
  • 10
  • I don't think Feign is arbitrarily remapping a 409 to a 400. Something else is might be happening with the application. Is there a fallback mechanism (Hystrix?) that's making another service call under the cover? E.g., scanItems returns a 409 but in response another call is being invoked and that one is returning the 400 you see? – peekay Apr 30 '19 at 09:18
  • Thanks @peekay. Even api is throwing 400 – Poornima Hegde Apr 30 '19 at 09:24

0 Answers0