Search in sources :

Example 6 with ProductDTO

use of com.rafaelvieira.letmebuy.dto.ProductDTO in project letmebuy by rafaelrok.

the class ProductServicesTests method findByIdShouldReturnProductDTOWhenIdExists.

@Test
public void findByIdShouldReturnProductDTOWhenIdExists() {
    ProductDTO result = service.findById(existingId);
    Assertions.assertNotNull(result);
}
Also used : ProductDTO(com.rafaelvieira.letmebuy.dto.ProductDTO) Test(org.junit.jupiter.api.Test)

Example 7 with ProductDTO

use of com.rafaelvieira.letmebuy.dto.ProductDTO in project letmebuy by rafaelrok.

the class ProductControllerIT method updateShouldReturnNotFoundWhenIdDoesNotExist.

@Test
public void updateShouldReturnNotFoundWhenIdDoesNotExist() throws Exception {
    String accessToken = tokenUtil.obtainAccessToken(mockMvc, username, password);
    ProductDTO productDTO = Factory.createProductDTO();
    String jsonBody = objectMapper.writeValueAsString(productDTO);
    ResultActions result = mockMvc.perform(put("/products/{id}", nonExistingId).header("Authorization", "Bearer " + accessToken).content(jsonBody).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON));
    result.andExpect(status().isNotFound());
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions) ProductDTO(com.rafaelvieira.letmebuy.dto.ProductDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ProductDTO

use of com.rafaelvieira.letmebuy.dto.ProductDTO in project letmebuy by rafaelrok.

the class ProductServiceIT method findAllPagedShouldReturnPageWhenPage0Size10.

@Test
public void findAllPagedShouldReturnPageWhenPage0Size10() {
    PageRequest pageRequest = PageRequest.of(0, 10);
    Page<ProductDTO> result = service.findAllPaged(0L, "", pageRequest);
    Assertions.assertFalse(result.isEmpty());
    Assertions.assertEquals(0, result.getNumber());
    Assertions.assertEquals(10, result.getSize());
    Assertions.assertEquals(countTotalProducts, result.getTotalElements());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) ProductDTO(com.rafaelvieira.letmebuy.dto.ProductDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with ProductDTO

use of com.rafaelvieira.letmebuy.dto.ProductDTO in project letmebuy by rafaelrok.

the class ProductServiceIT method findAllPagedShouldReturnSortedPageWhenSortByName.

@Test
public void findAllPagedShouldReturnSortedPageWhenSortByName() {
    PageRequest pageRequest = PageRequest.of(0, 10, Sort.by("name"));
    Page<ProductDTO> result = service.findAllPaged(0L, "", pageRequest);
    Assertions.assertFalse(result.isEmpty());
    Assertions.assertEquals("Macbook Pro", result.getContent().get(0).getName());
    Assertions.assertEquals("PC Gamer", result.getContent().get(1).getName());
    Assertions.assertEquals("PC Gamer Alfa", result.getContent().get(2).getName());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) ProductDTO(com.rafaelvieira.letmebuy.dto.ProductDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ProductDTO

use of com.rafaelvieira.letmebuy.dto.ProductDTO in project letmebuy by rafaelrok.

the class ProductServicesTests method findAllPagedShouldReturnPage.

@Test
public void findAllPagedShouldReturnPage() {
    Pageable pageable = PageRequest.of(0, 12);
    Page<ProductDTO> result = service.findAllPaged(0L, "", pageable);
    Assertions.assertNotNull(result);
// Mockito.verify(repositories, times(1)).find(pageable);
}
Also used : Pageable(org.springframework.data.domain.Pageable) ProductDTO(com.rafaelvieira.letmebuy.dto.ProductDTO) Test(org.junit.jupiter.api.Test)

Aggregations

ProductDTO (com.rafaelvieira.letmebuy.dto.ProductDTO)11 Test (org.junit.jupiter.api.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Product (com.rafaelvieira.letmebuy.entities.Product)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PageRequest (org.springframework.data.domain.PageRequest)3 ResourceNotFoundException (com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 Category (com.rafaelvieira.letmebuy.entities.Category)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 Pageable (org.springframework.data.domain.Pageable)1