Search in sources :

Example 6 with Operation

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

the class OperationResourceIntTest method updateOperation.

@Test
@Transactional
public void updateOperation() throws Exception {
    // Initialize the database
    operationRepository.saveAndFlush(operation);
    int databaseSizeBeforeUpdate = operationRepository.findAll().size();
    // Update the operation
    Operation updatedOperation = operationRepository.findById(operation.getId()).get();
    // Disconnect from session so that the updates on updatedOperation are not directly saved in db
    em.detach(updatedOperation);
    updatedOperation.setDate(UPDATED_DATE);
    updatedOperation.setDescription(UPDATED_DESCRIPTION);
    updatedOperation.setAmount(UPDATED_AMOUNT);
    OperationDTO operationDTO = operationMapper.toDto(updatedOperation);
    restOperationMockMvc.perform(put("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operationDTO))).andExpect(status().isOk());
    // Validate the Operation in the database
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeUpdate);
    Operation testOperation = operationList.get(operationList.size() - 1);
    assertThat(testOperation.getDate()).isEqualTo(UPDATED_DATE);
    assertThat(testOperation.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testOperation.getAmount()).isEqualTo(UPDATED_AMOUNT);
}
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 7 with Operation

use of io.github.jhipster.sample.domain.Operation 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 Operation

use of io.github.jhipster.sample.domain.Operation in project jhipster-sample-app-hazelcast by jhipster.

the class OperationResource method getAllOperations.

/**
 * GET  /operations : get all the operations.
 *
 * @param pageable the pagination information
 * @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many)
 * @return the ResponseEntity with status 200 (OK) and the list of operations in body
 */
@GetMapping("/operations")
@Timed
public ResponseEntity<List<Operation>> getAllOperations(Pageable pageable, @RequestParam(required = false, defaultValue = "false") boolean eagerload) {
    log.debug("REST request to get a page of Operations");
    Page<Operation> page;
    if (eagerload) {
        page = operationRepository.findAllWithEagerRelationships(pageable);
    } else {
        page = operationRepository.findAll(pageable);
    }
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, String.format("/api/operations?eagerload=%b", eagerload));
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Operation(io.github.jhipster.sample.domain.Operation) Timed(com.codahale.metrics.annotation.Timed)

Example 9 with Operation

use of io.github.jhipster.sample.domain.Operation in project jhipster-sample-app-hazelcast by jhipster.

the class OperationResource method createOperation.

/**
 * POST  /operations : Create a new operation.
 *
 * @param operation the operation to create
 * @return the ResponseEntity with status 201 (Created) and with body the new operation, 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<Operation> createOperation(@Valid @RequestBody Operation operation) throws URISyntaxException {
    log.debug("REST request to save Operation : {}", operation);
    if (operation.getId() != null) {
        throw new BadRequestAlertException("A new operation cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Operation result = operationRepository.save(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) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 10 with Operation

use of io.github.jhipster.sample.domain.Operation in project jhipster-sample-app-hazelcast by jhipster.

the class OperationResourceIntTest method updateOperation.

@Test
@Transactional
public void updateOperation() throws Exception {
    // Initialize the database
    operationRepository.saveAndFlush(operation);
    int databaseSizeBeforeUpdate = operationRepository.findAll().size();
    // Update the operation
    Operation updatedOperation = operationRepository.findById(operation.getId()).get();
    // Disconnect from session so that the updates on updatedOperation are not directly saved in db
    em.detach(updatedOperation);
    updatedOperation.setDate(UPDATED_DATE);
    updatedOperation.setDescription(UPDATED_DESCRIPTION);
    updatedOperation.setAmount(UPDATED_AMOUNT);
    restOperationMockMvc.perform(put("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedOperation))).andExpect(status().isOk());
    // Validate the Operation in the database
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeUpdate);
    Operation testOperation = operationList.get(operationList.size() - 1);
    assertThat(testOperation.getDate()).isEqualTo(UPDATED_DATE);
    assertThat(testOperation.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testOperation.getAmount()).isEqualTo(UPDATED_AMOUNT);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

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