Search in sources :

Example 6 with LabelDTO

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

the class LabelResourceIntTest method createLabel.

@Test
@Transactional
public void createLabel() throws Exception {
    int databaseSizeBeforeCreate = labelRepository.findAll().size();
    // Create the Label
    LabelDTO labelDTO = labelMapper.toDto(label);
    restLabelMockMvc.perform(post("/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(databaseSizeBeforeCreate + 1);
    Label testLabel = labelList.get(labelList.size() - 1);
    assertThat(testLabel.getLabel()).isEqualTo(DEFAULT_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 7 with LabelDTO

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

the class LabelResourceIntTest method dtoEqualsVerifier.

@Test
@Transactional
public void dtoEqualsVerifier() throws Exception {
    TestUtil.equalsVerifier(LabelDTO.class);
    LabelDTO labelDTO1 = new LabelDTO();
    labelDTO1.setId(1L);
    LabelDTO labelDTO2 = new LabelDTO();
    assertThat(labelDTO1).isNotEqualTo(labelDTO2);
    labelDTO2.setId(labelDTO1.getId());
    assertThat(labelDTO1).isEqualTo(labelDTO2);
    labelDTO2.setId(2L);
    assertThat(labelDTO1).isNotEqualTo(labelDTO2);
    labelDTO1.setId(null);
    assertThat(labelDTO1).isNotEqualTo(labelDTO2);
}
Also used : 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 8 with LabelDTO

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

the class LabelResource method createLabel.

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

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