Search in sources :

Example 6 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResourceIntTest method dtoEqualsVerifier.

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

Example 7 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResourceIntTest method checkAmountIsRequired.

@Test
@Transactional
public void checkAmountIsRequired() throws Exception {
    int databaseSizeBeforeTest = operationRepository.findAll().size();
    // set the field null
    operation.setAmount(null);
    // Create the Operation, which fails.
    OperationDTO operationDTO = operationMapper.toDto(operation);
    restOperationMockMvc.perform(post("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operationDTO))).andExpect(status().isBadRequest());
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeTest);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResourceIntTest method createOperationWithExistingId.

@Test
@Transactional
public void createOperationWithExistingId() throws Exception {
    int databaseSizeBeforeCreate = operationRepository.findAll().size();
    // Create the Operation with an existing ID
    operation.setId(1L);
    OperationDTO operationDTO = operationMapper.toDto(operation);
    // An entity with an existing ID cannot be created, so this API call must fail
    restOperationMockMvc.perform(post("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operationDTO))).andExpect(status().isBadRequest());
    // Validate the Operation in the database
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeCreate);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResourceIntTest method updateNonExistingOperation.

@Test
@Transactional
public void updateNonExistingOperation() throws Exception {
    int databaseSizeBeforeUpdate = operationRepository.findAll().size();
    // Create the Operation
    OperationDTO operationDTO = operationMapper.toDto(operation);
    // If the entity doesn't have an ID, it will be created instead of just being updated
    restOperationMockMvc.perform(put("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operationDTO))).andExpect(status().isCreated());
    // Validate the Operation in the database
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeUpdate + 1);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) OperationDTO(io.github.jhipster.sample.service.dto.OperationDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with OperationDTO

use of io.github.jhipster.sample.service.dto.OperationDTO in project jhipster-sample-app-dto by jhipster.

the class OperationResource method createOperation.

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

Aggregations

OperationDTO (io.github.jhipster.sample.service.dto.OperationDTO)10 Operation (io.github.jhipster.sample.domain.Operation)8 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Timed (com.codahale.metrics.annotation.Timed)3 BadRequestAlertException (io.github.jhipster.sample.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1