Search in sources :

Example 6 with Task

use of lunigorn.task_book_service.persistence.domain.Task in project task-book by Lunigorn.

the class TaskRepositoryTests method taskDeleteSuccess.

@Test
public void taskDeleteSuccess() {
    // arrange
    Task task = new Task();
    String randomName = RandomStringUtils.randomAlphabetic(10);
    String randomDescription = RandomStringUtils.randomAlphabetic(1000);
    task.setName(randomName);
    task.setDescription(randomDescription);
    tasks.save(task);
    Task toDelete = tasks.findOneByName(randomName);
    // act
    tasks.delete(toDelete);
    // assert
    assertNotNull(toDelete);
    assertNull(tasks.findOneByName(randomName));
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with Task

use of lunigorn.task_book_service.persistence.domain.Task in project task-book by Lunigorn.

the class TaskRepositoryTests method taskSaveSucces.

@Test
public void taskSaveSucces() {
    // arrange
    Task task = new Task();
    String randomName = RandomStringUtils.randomAlphabetic(10);
    String randomDescription = RandomStringUtils.randomAlphabetic(1000);
    task.setName(randomName);
    task.setDescription(randomDescription);
    // act
    tasks.save(task);
    // assert
    Task found = tasks.findOneByName(randomName);
    assertEquals(task, found);
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 8 with Task

use of lunigorn.task_book_service.persistence.domain.Task in project task-book by Lunigorn.

the class TaskController method deleteById.

@RequestMapping(path = "/tasks/{id}", method = RequestMethod.DELETE)
public Task deleteById(@PathVariable Long id) {
    Task found = tasks.findOne(id);
    if (found.equals(null))
        return null;
    tasks.delete(id);
    return found;
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Task

use of lunigorn.task_book_service.persistence.domain.Task in project task-book by Lunigorn.

the class TaskControllerTests method taskUpdateSucces.

@Test
@SneakyThrows({ Exception.class })
public void taskUpdateSucces() {
    // arrange
    Task task = new Task();
    String randomName = RandomStringUtils.randomAlphabetic(10);
    String randomDescription = RandomStringUtils.randomAlphabetic(1000);
    task.setName(randomName);
    task.setDescription(randomDescription);
    tasks.save(task);
    String newRandomName = RandomStringUtils.randomAlphabetic(10);
    String newRandomDescription = RandomStringUtils.randomAlphabetic(1000);
    // assert name saved in database is correct
    assertEquals(tasks.findOne(task.getId()).getName(), randomName);
    assertEquals(tasks.findOne(task.getId()).getDescription(), randomDescription);
    // act
    mockMvc.perform(put("/tasks/").content("{\"id\":\"" + task.getId() + "\",\"name\":\"" + newRandomName + "\",\"description\":\"" + newRandomDescription + "\"}").contentType(contentType)).andDo(print()).andExpect(status().is2xxSuccessful()).andExpect(jsonPath("$.id", anything())).andExpect(jsonPath("$.name", is(newRandomName))).andExpect(jsonPath("$.description", is(newRandomDescription)));
    // assert name saved in database is changed
    assertEquals(tasks.findOne(task.getId()).getName(), newRandomName);
    assertEquals(tasks.findOne(task.getId()).getDescription(), newRandomDescription);
    assertNotEquals(tasks.findOne(task.getId()).getName(), randomName);
    assertNotEquals(tasks.findOne(task.getId()).getDescription(), randomDescription);
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Aggregations

Task (lunigorn.task_book_service.persistence.domain.Task)9 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 SneakyThrows (lombok.SneakyThrows)6 MvcResult (org.springframework.test.web.servlet.MvcResult)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Random (java.util.Random)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1