Search in sources :

Example 1 with LabelDTO

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

the class LabelResource method updateLabel.

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

Example 2 with LabelDTO

use of io.github.jhipster.sample.service.dto.LabelDTO in project jhipster-sample-app-dto 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);
    LabelDTO labelDTO = labelMapper.toDto(updatedLabel);
    restLabelMockMvc.perform(put("/api/labels").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(labelDTO))).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);
}
Also used : Label(io.github.jhipster.sample.domain.Label) LabelDTO(io.github.jhipster.sample.service.dto.LabelDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with LabelDTO

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

the class LabelResourceIntTest method checkLabelIsRequired.

@Test
@Transactional
public void checkLabelIsRequired() throws Exception {
    int databaseSizeBeforeTest = labelRepository.findAll().size();
    // set the field null
    label.setLabel(null);
    // Create the Label, which fails.
    LabelDTO labelDTO = labelMapper.toDto(label);
    restLabelMockMvc.perform(post("/api/labels").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(labelDTO))).andExpect(status().isBadRequest());
    List<Label> labelList = labelRepository.findAll();
    assertThat(labelList).hasSize(databaseSizeBeforeTest);
}
Also used : Label(io.github.jhipster.sample.domain.Label) LabelDTO(io.github.jhipster.sample.service.dto.LabelDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with LabelDTO

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

the class LabelResourceIntTest method updateNonExistingLabel.

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

Example 5 with LabelDTO

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

the class LabelResourceIntTest method createLabelWithExistingId.

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

Aggregations

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