Search in sources :

Example 11 with Operation

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

the class OperationResourceIntTest method createOperation.

@Test
@Transactional
public void createOperation() throws Exception {
    int databaseSizeBeforeCreate = operationRepository.findAll().size();
    // Create the Operation
    restOperationMockMvc.perform(post("/api/operations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(operation))).andExpect(status().isCreated());
    // Validate the Operation in the database
    List<Operation> operationList = operationRepository.findAll();
    assertThat(operationList).hasSize(databaseSizeBeforeCreate + 1);
    Operation testOperation = operationList.get(operationList.size() - 1);
    assertThat(testOperation.getDate()).isEqualTo(DEFAULT_DATE);
    assertThat(testOperation.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
    assertThat(testOperation.getAmount()).isEqualTo(DEFAULT_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)

Example 12 with Operation

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

the class OperationResource method updateOperation.

/**
 * PUT  /operations : Updates an existing operation.
 *
 * @param operation the operation to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated operation,
 * or with status 400 (Bad Request) if the operation is not valid,
 * or with status 500 (Internal Server Error) if the operation couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/operations")
@Timed
public ResponseEntity<Operation> updateOperation(@Valid @RequestBody Operation operation) throws URISyntaxException {
    log.debug("REST request to update Operation : {}", operation);
    if (operation.getId() == null) {
        return createOperation(operation);
    }
    Operation result = operationRepository.save(operation);
    operationSearchRepository.save(result);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, operation.getId().toString())).body(result);
}
Also used : Operation(io.github.jhipster.sample.domain.Operation) Timed(com.codahale.metrics.annotation.Timed)

Example 13 with Operation

use of io.github.jhipster.sample.domain.Operation in project jhipster-sample-app-elasticsearch 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);
    // Validate the Operation in Elasticsearch
    verify(mockOperationSearchRepository, times(1)).save(testOperation);
}
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)

Example 14 with Operation

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

the class OperationResourceIntTest method createEntity.

/**
 * Create an entity for this test.
 *
 * This is a static method, as tests for other entities might also need it,
 * if they test an entity which requires the current entity.
 */
public static Operation createEntity(EntityManager em) {
    Operation operation = new Operation();
    operation.setDate(DEFAULT_DATE);
    operation.setDescription(DEFAULT_DESCRIPTION);
    operation.setAmount(DEFAULT_AMOUNT);
    return operation;
}
Also used : Operation(io.github.jhipster.sample.domain.Operation)

Example 15 with Operation

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

the class OperationResourceIntTest method equalsVerifier.

@Test
@Transactional
public void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Operation.class);
    Operation operation1 = new Operation();
    operation1.setId(1L);
    Operation operation2 = new Operation();
    operation2.setId(operation1.getId());
    assertThat(operation1).isEqualTo(operation2);
    operation2.setId(2L);
    assertThat(operation1).isNotEqualTo(operation2);
    operation1.setId(null);
    assertThat(operation1).isNotEqualTo(operation2);
}
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