@Test public void test_create_error() throws IOException, Exception { when(instrumentService.create(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getInstruments()); mockMvc.perform(post("/instruments/_create") .content(resources.readRequest("instrument/instrument_create_invalid_field_value.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is5xxServerError()); }
@PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentResponse instrumentResponse = new InstrumentResponse(); instrumentResponse.setResponseInfo(getResponseInfo(instrumentRequest.getRequestInfo())); List<Instrument> instruments = new ArrayList<>(); Instrument instrument; List<InstrumentContract> instrumentContracts = new ArrayList<>(); InstrumentContract contract; instrumentRequest.getRequestInfo().setAction(ACTION_CREATE); for (InstrumentContract instrumentContract : instrumentRequest.getInstruments()) { instrument = mapper.toDomain(instrumentContract); instrument.setCreatedDate(new Date()); instrument.setCreatedBy(instrumentRequest.getRequestInfo().getUserInfo()); instrument.setLastModifiedBy(instrumentRequest.getRequestInfo().getUserInfo()); instruments.add(instrument); } instruments = instrumentService.create(instruments, errors, instrumentRequest.getRequestInfo()); for (Instrument i : instruments) { contract = mapper.toContract(i); instrumentContracts.add(contract); } instrumentResponse.setInstruments(instrumentContracts); return instrumentResponse; }
InstrumentController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentResponse instrumentResponse = new InstrumentResponse(); instrumentResponse.setResponseInfo(getResponseInfo(instrumentRequest.getRequestInfo())); List<Instrument> instruments = new ArrayList<>(); Instrument instrument; List<InstrumentContract> instrumentContracts = new ArrayList<>(); InstrumentContract contract; instrumentRequest.getRequestInfo().setAction(ACTION_CREATE); for (InstrumentContract instrumentContract : instrumentRequest.getInstruments()) { instrument = mapper.toDomain(instrumentContract); instrument.setCreatedDate(new Date()); instrument.setCreatedBy(instrumentRequest.getRequestInfo().getUserInfo()); instrument.setLastModifiedBy(instrumentRequest.getRequestInfo().getUserInfo()); instruments.add(instrument); } instruments = instrumentService.create(instruments, errors, instrumentRequest.getRequestInfo()); for (Instrument i : instruments) { contract = mapper.toContract(i); instrumentContracts.add(contract); } instrumentResponse.setInstruments(instrumentContracts); return instrumentResponse; } }
InstrumentController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentResponse instrumentResponse = new InstrumentResponse(); instrumentResponse.setResponseInfo(getResponseInfo(instrumentRequest.getRequestInfo())); List<Instrument> instruments = new ArrayList<>(); Instrument instrument; List<InstrumentContract> instrumentContracts = new ArrayList<>(); InstrumentContract contract; instrumentRequest.getRequestInfo().setAction(ACTION_CREATE); for (InstrumentContract instrumentContract : instrumentRequest.getInstruments()) { instrument = mapper.toDomain(instrumentContract); instrument.setCreatedDate(new Date()); instrument.setCreatedBy(instrumentRequest.getRequestInfo().getUserInfo()); instrument.setLastModifiedBy(instrumentRequest.getRequestInfo().getUserInfo()); instruments.add(instrument); } instruments = instrumentService.create(instruments, errors, instrumentRequest.getRequestInfo()); for (Instrument i : instruments) { contract = mapper.toContract(i); instrumentContracts.add(contract); } instrumentResponse.setInstruments(instrumentContracts); return instrumentResponse; }  }
InstrumentController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentResponse instrumentResponse = new InstrumentResponse(); instrumentResponse.setResponseInfo(getResponseInfo(instrumentRequest.getRequestInfo())); List<Instrument> instruments = new ArrayList<>(); Instrument instrument; List<InstrumentContract> instrumentContracts = new ArrayList<>(); InstrumentContract contract; instrumentRequest.getRequestInfo().setAction(ACTION_CREATE); for (InstrumentContract instrumentContract : instrumentRequest.getInstruments()) { instrument = mapper.toDomain(instrumentContract); instrument.setCreatedDate(new Date()); instrument.setCreatedBy(instrumentRequest.getRequestInfo().getUserInfo()); instrument.setLastModifiedBy(instrumentRequest.getRequestInfo().getUserInfo()); instruments.add(instrument); } instruments = instrumentService.create(instruments, errors, instrumentRequest.getRequestInfo()); for (Instrument i : instruments) { contract = mapper.toContract(i); instrumentContracts.add(contract); } instrumentResponse.setInstruments(instrumentContracts); return instrumentResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse update(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse delete(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract,
            RequestInfo requestInfo, BindingResult errors); @PostMapping("/_deposit") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse depositInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); @PostMapping("/_dishonor") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse dishonorInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); }
InstrumentController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentResponse instrumentResponse = new InstrumentResponse(); instrumentResponse.setResponseInfo(getResponseInfo(instrumentRequest.getRequestInfo())); List<Instrument> instruments = new ArrayList<>(); Instrument instrument; List<InstrumentContract> instrumentContracts = new ArrayList<>(); InstrumentContract contract; instrumentRequest.getRequestInfo().setAction(ACTION_CREATE); for (InstrumentContract instrumentContract : instrumentRequest.getInstruments()) { instrument = mapper.toDomain(instrumentContract); instrument.setCreatedDate(new Date()); instrument.setCreatedBy(instrumentRequest.getRequestInfo().getUserInfo()); instrument.setLastModifiedBy(instrumentRequest.getRequestInfo().getUserInfo()); instruments.add(instrument); } instruments = instrumentService.create(instruments, errors, instrumentRequest.getRequestInfo()); for (Instrument i : instruments) { contract = mapper.toContract(i); instrumentContracts.add(contract); } instrumentResponse.setInstruments(instrumentContracts); return instrumentResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse update(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse delete(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract,
            RequestInfo requestInfo, BindingResult errors); @PostMapping("/_deposit") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse depositInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); @PostMapping("/_dishonor") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse dishonorInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); static final String ACTION_CREATE; static final String ACTION_UPDATE; static final String ACTION_DELETE; static final String PLACEHOLDER; }