Search in sources :

Example 11 with Label

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

the class LabelResource method updateLabel.

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

Example 12 with Label

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

the class LabelResourceIntTest method equalsVerifier.

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

Example 13 with Label

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

the class LabelResourceIntTest 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 Label createEntity(EntityManager em) {
    Label label = new Label();
    label.setLabel(DEFAULT_LABEL);
    return label;
}
Also used : Label(io.github.jhipster.sample.domain.Label)

Example 14 with Label

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

the class LabelResourceIntTest method updateLabel.

@Test
@Transactional
public void updateLabel() throws Exception {
    // Initialize the database
    labelRepository.saveAndFlush(label);
    int databaseSizeBeforeUpdate = labelRepository.findAll().size();
    // Update the label
    Label updatedLabel = labelRepository.findById(label.getId()).get();
    // Disconnect from session so that the updates on updatedLabel are not directly saved in db
    em.detach(updatedLabel);
    updatedLabel.setLabel(UPDATED_LABEL);
    restLabelMockMvc.perform(put("/api/labels").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedLabel))).andExpect(status().isOk());
    // Validate the Label in the database
    List<Label> labelList = labelRepository.findAll();
    assertThat(labelList).hasSize(databaseSizeBeforeUpdate);
    Label testLabel = labelList.get(labelList.size() - 1);
    assertThat(testLabel.getLabel()).isEqualTo(UPDATED_LABEL);
    // Validate the Label in Elasticsearch
    verify(mockLabelSearchRepository, times(1)).save(testLabel);
}
Also used : Label(io.github.jhipster.sample.domain.Label) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Label

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

the class LabelResourceIntTest method createLabel.

@Test
@Transactional
public void createLabel() throws Exception {
    int databaseSizeBeforeCreate = labelRepository.findAll().size();
    // Create the Label
    restLabelMockMvc.perform(post("/api/labels").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(label))).andExpect(status().isCreated());
    // Validate the Label in the database
    List<Label> labelList = labelRepository.findAll();
    assertThat(labelList).hasSize(databaseSizeBeforeCreate + 1);
    Label testLabel = labelList.get(labelList.size() - 1);
    assertThat(testLabel.getLabel()).isEqualTo(DEFAULT_LABEL);
    // Validate the Label in Elasticsearch
    verify(mockLabelSearchRepository, times(1)).save(testLabel);
}
Also used : Label(io.github.jhipster.sample.domain.Label) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Label (io.github.jhipster.sample.domain.Label)21 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 Transactional (org.springframework.transaction.annotation.Transactional)12 LabelDTO (io.github.jhipster.sample.service.dto.LabelDTO)7 Timed (com.codahale.metrics.annotation.Timed)6 BadRequestAlertException (io.github.jhipster.sample.web.rest.errors.BadRequestAlertException)3 URI (java.net.URI)3