Search in sources :

Example 1 with BankAccount

use of io.github.jhipster.sample.domain.BankAccount 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);
}
Also used : BankAccountDTO(io.github.jhipster.sample.service.dto.BankAccountDTO) BankAccount(io.github.jhipster.sample.domain.BankAccount) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with BankAccount

use of io.github.jhipster.sample.domain.BankAccount 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);
}
Also used : BankAccountDTO(io.github.jhipster.sample.service.dto.BankAccountDTO) BankAccount(io.github.jhipster.sample.domain.BankAccount) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with BankAccount

use of io.github.jhipster.sample.domain.BankAccount 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);
}
Also used : BankAccountDTO(io.github.jhipster.sample.service.dto.BankAccountDTO) BankAccount(io.github.jhipster.sample.domain.BankAccount) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BankAccount

use of io.github.jhipster.sample.domain.BankAccount in project jhipster-sample-app-dto by jhipster.

the class BankAccountResourceIntTest method equalsVerifier.

@Test
@Transactional
public void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(BankAccount.class);
    BankAccount bankAccount1 = new BankAccount();
    bankAccount1.setId(1L);
    BankAccount bankAccount2 = new BankAccount();
    bankAccount2.setId(bankAccount1.getId());
    assertThat(bankAccount1).isEqualTo(bankAccount2);
    bankAccount2.setId(2L);
    assertThat(bankAccount1).isNotEqualTo(bankAccount2);
    bankAccount1.setId(null);
    assertThat(bankAccount1).isNotEqualTo(bankAccount2);
}
Also used : BankAccount(io.github.jhipster.sample.domain.BankAccount) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with BankAccount

use of io.github.jhipster.sample.domain.BankAccount 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);
}
Also used : BankAccountDTO(io.github.jhipster.sample.service.dto.BankAccountDTO) BankAccount(io.github.jhipster.sample.domain.BankAccount) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BankAccount (io.github.jhipster.sample.domain.BankAccount)28 Test (org.junit.Test)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 Transactional (org.springframework.transaction.annotation.Transactional)13 Timed (com.codahale.metrics.annotation.Timed)8 BankAccountDTO (io.github.jhipster.sample.service.dto.BankAccountDTO)8 BadRequestAlertException (io.github.jhipster.sample.web.rest.errors.BadRequestAlertException)4 URI (java.net.URI)4