Search in sources :

Example 56 with SneakyThrows

use of lombok.SneakyThrows in project task-book by Lunigorn.

the class TaskControllerTests method taskDeleteByIdSucces.

@Test
@SneakyThrows({ Exception.class })
public void taskDeleteByIdSucces() {
    // arrange
    Task task = new Task();
    String randomName = RandomStringUtils.randomAlphabetic(10);
    task.setName(randomName);
    tasks.save(task);
    Task foundBeforeDelete = tasks.findOne(task.getId());
    assertNotNull(foundBeforeDelete);
    // act
    mockMvc.perform(delete("/tasks/" + task.getId()).contentType(contentType)).andDo(print()).andExpect(status().is2xxSuccessful()).andExpect(jsonPath("$.id", is(task.getId().intValue()))).andExpect(jsonPath("$.name", is(task.getName())));
    Task foundAfterDelete = tasks.findOne(task.getId());
    assertNull(foundAfterDelete);
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 57 with SneakyThrows

use of lombok.SneakyThrows in project task-book by Lunigorn.

the class TaskControllerTests method taskGetByIdSucces.

@Test
@SneakyThrows({ Exception.class })
public void taskGetByIdSucces() {
    // arrange
    Task task = new Task();
    String randomName = RandomStringUtils.randomAlphabetic(10);
    task.setName(randomName);
    tasks.save(task);
    // act
    mockMvc.perform(get("/tasks/" + task.getId()).contentType(contentType)).andDo(print()).andExpect(status().is2xxSuccessful()).andExpect(jsonPath("$.id", is(task.getId().intValue()))).andExpect(jsonPath("$.name", is(task.getName())));
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 58 with SneakyThrows

use of lombok.SneakyThrows in project task-book by Lunigorn.

the class TaskControllerTests method taskInsertSucces.

@Test
@SneakyThrows({ Exception.class })
public void taskInsertSucces() {
    // arrange
    String randomName = RandomStringUtils.randomAlphabetic(10);
    // act
    MvcResult result = mockMvc.perform(post("/tasks/").content("{\"name\":\"" + randomName + "\"}").contentType(contentType)).andDo(print()).andExpect(status().is2xxSuccessful()).andExpect(jsonPath("$.id", anything())).andExpect(jsonPath("$.name", is(randomName))).andReturn();
    String responseText = result.getResponse().getContentAsString();
    // assert returned task has id
    Integer savedTaskId = JsonPath.read(responseText, "$.id");
    assertNotNull(savedTaskId);
    // assert returned task is saved in database
    Task savedTask = tasks.findOne(savedTaskId.longValue());
    assertEquals(savedTask.getName(), randomName);
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 59 with SneakyThrows

use of lombok.SneakyThrows in project task-book by Lunigorn.

the class TaskControllerTests method taskInsertWithIdFail.

@Test
@SneakyThrows({ Exception.class })
public void taskInsertWithIdFail() {
    // arrange
    Integer randomId = new Random().nextInt();
    String randomName = RandomStringUtils.randomAlphabetic(10);
    Task foundByRandomId = tasks.findOne(randomId.longValue());
    if (foundByRandomId != null)
        assertNotEquals(randomName, foundByRandomId.getName());
    // act
    MvcResult result = mockMvc.perform(post("/tasks/").content("{\"id\":\"" + randomId + "\",\"name\":\"" + randomName + "\"}").contentType(contentType)).andDo(print()).andExpect(status().isBadRequest()).andReturn();
    Task foundByRandomIdAfterError = tasks.findOne(randomId.longValue());
    assertEquals(foundByRandomId, foundByRandomIdAfterError);
}
Also used : Task(lunigorn.task_book_service.persistence.domain.Task) Random(java.util.Random) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 60 with SneakyThrows

use of lombok.SneakyThrows in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityServiceBeanTest method testGetVesselDetailsAndContactPartiesForFishingTrip.

@Test
@SneakyThrows
public void testGetVesselDetailsAndContactPartiesForFishingTrip() {
    Map<String, List<String>> returnMap = new HashMap<>();
    returnMap.put("code", new ArrayList<String>());
    when(vesselTransportMeansDao.findLatestVesselByTripId("NOR-TRP-20160517234053706")).thenReturn(new VesselTransportMeansEntity());
    when(mdrModuleServiceBean.getAcronymFromMdr("FLUX_VESSEL_ID_TYPE", "*", new ArrayList<String>(), 9999999, "code")).thenReturn(returnMap);
    VesselDetailsDTO vesselDetailsDTO = fishingTripService.getVesselDetailsForFishingTrip("NOR-TRP-20160517234053706");
    assertNotNull(vesselDetailsDTO);
}
Also used : VesselTransportMeansEntity(eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity) HashMap(java.util.HashMap) VesselDetailsDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.details.VesselDetailsDTO) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)706 lombok.val (lombok.val)314 Test (org.junit.Test)91 ArrayList (java.util.ArrayList)75 HashMap (java.util.HashMap)63 List (java.util.List)53 Cleanup (lombok.Cleanup)38 Map (java.util.Map)35 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)34 Collectors (java.util.stream.Collectors)34 LinkedHashMap (java.util.LinkedHashMap)30 File (java.io.File)28 Path (java.nio.file.Path)28 IOException (java.io.IOException)26 InputStream (java.io.InputStream)24 Slf4j (lombok.extern.slf4j.Slf4j)24 URL (java.net.URL)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 Collection (java.util.Collection)18 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)17