Search in sources :

Example 1 with Vote

use of com.icthh.xm.ms.entity.domain.Vote in project xm-ms-entity by xm-online.

the class VoteService method save.

/**
 * Save a vote.
 *
 * @param vote the entity to save
 * @return the persisted entity
 */
public Vote save(Vote vote) {
    startUpdateDateGenerationStrategy.preProcessStartDate(vote, vote.getId(), voteRepository, Vote::setEntryDate, Vote::getEntryDate);
    Vote result = voteRepository.save(vote);
    voteSearchRepository.save(result);
    return result;
}
Also used : Vote(com.icthh.xm.ms.entity.domain.Vote)

Example 2 with Vote

use of com.icthh.xm.ms.entity.domain.Vote in project xm-ms-entity by xm-online.

the class VoteResource method searchVotes.

/**
 * SEARCH  /_search/votes?query=:query : search for the vote corresponding
 * to the query.
 *
 * @param query the query of the vote search
 * @param pageable the pagination information
 * @return the result of the search
 */
@GetMapping("/_search/votes")
@Timed
public ResponseEntity<List<Vote>> searchVotes(@RequestParam String query, @ApiParam Pageable pageable) {
    Page<Vote> page = voteService.search(query, pageable, null);
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/votes");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Vote(com.icthh.xm.ms.entity.domain.Vote) ResponseEntity(org.springframework.http.ResponseEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with Vote

use of com.icthh.xm.ms.entity.domain.Vote in project xm-ms-entity by xm-online.

the class VoteResourceExtendedIntTest method createVoteWithEntryDate.

@Test
@Transactional
public void createVoteWithEntryDate() throws Exception {
    int databaseSizeBeforeCreate = voteRepository.findAll().size();
    // Create the Vote
    restVoteMockMvc.perform(post("/api/votes").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(vote))).andExpect(status().isCreated()).andExpect(jsonPath("$.entryDate").value(MOCKED_ENTRY_DATE.toString()));
    // Validate the Vote in the database
    List<Vote> voteList = voteRepository.findAll();
    assertThat(voteList).hasSize(databaseSizeBeforeCreate + 1);
    Vote testVote = voteList.get(voteList.size() - 1);
    assertThat(testVote.getEntryDate()).isEqualTo(MOCKED_ENTRY_DATE);
    // Validate the Vote in Elasticsearch
    Vote voteEs = voteSearchRepository.findOne(testVote.getId());
    assertThat(voteEs).isEqualToComparingFieldByField(testVote);
}
Also used : Vote(com.icthh.xm.ms.entity.domain.Vote) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Vote

use of com.icthh.xm.ms.entity.domain.Vote in project xm-ms-entity by xm-online.

the class VoteResourceExtendedIntTest method checkStartDateIsRequiredInDb.

@Test
@Transactional
public void checkStartDateIsRequiredInDb() throws Exception {
    Vote o = voteService.save(vote);
    // set the field null
    when(startUpdateDateGenerationStrategy.generateStartDate()).thenReturn(null);
    o.setEntryDate(null);
    voteService.save(o);
    try {
        voteRepository.flush();
        fail("DataIntegrityViolationException exception was expected!");
    } catch (DataIntegrityViolationException e) {
        assertThat(e.getMostSpecificCause().getMessage()).containsIgnoringCase("NULL not allowed for column \"ENTRY_DATE\"");
    }
}
Also used : Vote(com.icthh.xm.ms.entity.domain.Vote) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Vote

use of com.icthh.xm.ms.entity.domain.Vote in project xm-ms-entity by xm-online.

the class VoteResourceIntTest method createVote.

@Test
@Transactional
public void createVote() throws Exception {
    int databaseSizeBeforeCreate = voteRepository.findAll().size();
    // Create the Vote
    restVoteMockMvc.perform(post("/api/votes").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(vote))).andExpect(status().isCreated());
    // Validate the Vote in the database
    List<Vote> voteList = voteRepository.findAll();
    assertThat(voteList).hasSize(databaseSizeBeforeCreate + 1);
    Vote testVote = voteList.get(voteList.size() - 1);
    assertThat(testVote.getUserKey()).isEqualTo(DEFAULT_USER_KEY);
    assertThat(testVote.getValue()).isEqualTo(DEFAULT_VALUE);
    assertThat(testVote.getMessage()).isEqualTo(DEFAULT_MESSAGE);
    assertThat(testVote.getEntryDate()).isEqualTo(UPDATED_ENTRY_DATE);
    // Validate the Vote in Elasticsearch
    Vote voteEs = voteSearchRepository.findOne(testVote.getId());
    assertThat(voteEs).isEqualToComparingFieldByField(testVote);
}
Also used : Vote(com.icthh.xm.ms.entity.domain.Vote) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Vote (com.icthh.xm.ms.entity.domain.Vote)12 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Rating (com.icthh.xm.ms.entity.domain.Rating)3 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)3 Timed (com.codahale.metrics.annotation.Timed)2 Attachment (com.icthh.xm.ms.entity.domain.Attachment)2 Calendar (com.icthh.xm.ms.entity.domain.Calendar)2 Comment (com.icthh.xm.ms.entity.domain.Comment)2 Location (com.icthh.xm.ms.entity.domain.Location)2 Tag (com.icthh.xm.ms.entity.domain.Tag)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 Event (com.icthh.xm.ms.entity.domain.Event)1 FunctionContext (com.icthh.xm.ms.entity.domain.FunctionContext)1 Link (com.icthh.xm.ms.entity.domain.Link)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1