use of io.github.jhipster.sample.service.dto.BankAccountDTO in project jhipster-sample-app-dto by jhipster.
the class BankAccountResource method updateBankAccount.
/**
* PUT /bank-accounts : Updates an existing bankAccount.
*
* @param bankAccountDTO the bankAccountDTO to update
* @return the ResponseEntity with status 200 (OK) and with body the updated bankAccountDTO,
* or with status 400 (Bad Request) if the bankAccountDTO is not valid,
* or with status 500 (Internal Server Error) if the bankAccountDTO couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/bank-accounts")
@Timed
public ResponseEntity<BankAccountDTO> updateBankAccount(@Valid @RequestBody BankAccountDTO bankAccountDTO) throws URISyntaxException {
log.debug("REST request to update BankAccount : {}", bankAccountDTO);
if (bankAccountDTO.getId() == null) {
return createBankAccount(bankAccountDTO);
}
BankAccount bankAccount = bankAccountMapper.toEntity(bankAccountDTO);
bankAccount = bankAccountRepository.save(bankAccount);
BankAccountDTO result = bankAccountMapper.toDto(bankAccount);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, bankAccountDTO.getId().toString())).body(result);
}
use of io.github.jhipster.sample.service.dto.BankAccountDTO in project jhipster-sample-app-dto by jhipster.
the class BankAccountResourceIntTest method checkBalanceIsRequired.
@Test
@Transactional
public void checkBalanceIsRequired() throws Exception {
int databaseSizeBeforeTest = bankAccountRepository.findAll().size();
// set the field null
bankAccount.setBalance(null);
// Create the BankAccount, which fails.
BankAccountDTO bankAccountDTO = bankAccountMapper.toDto(bankAccount);
restBankAccountMockMvc.perform(post("/api/bank-accounts").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(bankAccountDTO))).andExpect(status().isBadRequest());
List<BankAccount> bankAccountList = bankAccountRepository.findAll();
assertThat(bankAccountList).hasSize(databaseSizeBeforeTest);
}
use of io.github.jhipster.sample.service.dto.BankAccountDTO in project jhipster-sample-app-dto by jhipster.
the class BankAccountResourceIntTest method createBankAccountWithExistingId.
@Test
@Transactional
public void createBankAccountWithExistingId() throws Exception {
int databaseSizeBeforeCreate = bankAccountRepository.findAll().size();
// Create the BankAccount with an existing ID
bankAccount.setId(1L);
BankAccountDTO bankAccountDTO = bankAccountMapper.toDto(bankAccount);
// An entity with an existing ID cannot be created, so this API call must fail
restBankAccountMockMvc.perform(post("/api/bank-accounts").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(bankAccountDTO))).andExpect(status().isBadRequest());
// Validate the BankAccount in the database
List<BankAccount> bankAccountList = bankAccountRepository.findAll();
assertThat(bankAccountList).hasSize(databaseSizeBeforeCreate);
}
use of io.github.jhipster.sample.service.dto.BankAccountDTO in project jhipster-sample-app-dto by jhipster.
the class BankAccountResourceIntTest method updateBankAccount.
@Test
@Transactional
public void updateBankAccount() throws Exception {
// Initialize the database
bankAccountRepository.saveAndFlush(bankAccount);
int databaseSizeBeforeUpdate = bankAccountRepository.findAll().size();
// Update the bankAccount
BankAccount updatedBankAccount = bankAccountRepository.findById(bankAccount.getId()).get();
// Disconnect from session so that the updates on updatedBankAccount are not directly saved in db
em.detach(updatedBankAccount);
updatedBankAccount.setName(UPDATED_NAME);
updatedBankAccount.setBalance(UPDATED_BALANCE);
BankAccountDTO bankAccountDTO = bankAccountMapper.toDto(updatedBankAccount);
restBankAccountMockMvc.perform(put("/api/bank-accounts").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(bankAccountDTO))).andExpect(status().isOk());
// Validate the BankAccount in the database
List<BankAccount> bankAccountList = bankAccountRepository.findAll();
assertThat(bankAccountList).hasSize(databaseSizeBeforeUpdate);
BankAccount testBankAccount = bankAccountList.get(bankAccountList.size() - 1);
assertThat(testBankAccount.getName()).isEqualTo(UPDATED_NAME);
assertThat(testBankAccount.getBalance()).isEqualTo(UPDATED_BALANCE);
}
use of io.github.jhipster.sample.service.dto.BankAccountDTO in project jhipster-sample-app-dto by jhipster.
the class BankAccountResourceIntTest method updateNonExistingBankAccount.
@Test
@Transactional
public void updateNonExistingBankAccount() throws Exception {
int databaseSizeBeforeUpdate = bankAccountRepository.findAll().size();
// Create the BankAccount
BankAccountDTO bankAccountDTO = bankAccountMapper.toDto(bankAccount);
// If the entity doesn't have an ID, it will be created instead of just being updated
restBankAccountMockMvc.perform(put("/api/bank-accounts").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(bankAccountDTO))).andExpect(status().isCreated());
// Validate the BankAccount in the database
List<BankAccount> bankAccountList = bankAccountRepository.findAll();
assertThat(bankAccountList).hasSize(databaseSizeBeforeUpdate + 1);
}
Aggregations