Search in sources :

Example 26 with BankAccount

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

the class BankAccountResourceIntTest method createBankAccount.

@Test
@Transactional
public void createBankAccount() throws Exception {
    int databaseSizeBeforeCreate = bankAccountRepository.findAll().size();
    // Create the BankAccount
    BankAccountDTO bankAccountDTO = bankAccountMapper.toDto(bankAccount);
    restBankAccountMockMvc.perform(post("/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(databaseSizeBeforeCreate + 1);
    BankAccount testBankAccount = bankAccountList.get(bankAccountList.size() - 1);
    assertThat(testBankAccount.getName()).isEqualTo(DEFAULT_NAME);
    assertThat(testBankAccount.getBalance()).isEqualTo(DEFAULT_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)

Example 27 with BankAccount

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

the class BankAccountResourceIntTest method checkNameIsRequired.

@Test
@Transactional
public void checkNameIsRequired() throws Exception {
    int databaseSizeBeforeTest = bankAccountRepository.findAll().size();
    // set the field null
    bankAccount.setName(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 28 with BankAccount

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

the class BankAccountResource method createBankAccount.

/**
 * POST  /bank-accounts : Create a new bankAccount.
 *
 * @param bankAccountDTO the bankAccountDTO to create
 * @return the ResponseEntity with status 201 (Created) and with body the new bankAccountDTO, or with status 400 (Bad Request) if the bankAccount has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/bank-accounts")
@Timed
public ResponseEntity<BankAccountDTO> createBankAccount(@Valid @RequestBody BankAccountDTO bankAccountDTO) throws URISyntaxException {
    log.debug("REST request to save BankAccount : {}", bankAccountDTO);
    if (bankAccountDTO.getId() != null) {
        throw new BadRequestAlertException("A new bankAccount cannot already have an ID", ENTITY_NAME, "idexists");
    }
    BankAccount bankAccount = bankAccountMapper.toEntity(bankAccountDTO);
    bankAccount = bankAccountRepository.save(bankAccount);
    BankAccountDTO result = bankAccountMapper.toDto(bankAccount);
    return ResponseEntity.created(new URI("/api/bank-accounts/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(io.github.jhipster.sample.web.rest.errors.BadRequestAlertException) BankAccountDTO(io.github.jhipster.sample.service.dto.BankAccountDTO) BankAccount(io.github.jhipster.sample.domain.BankAccount) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

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