Skip to content
Snippets Groups Projects
Commit 11a12d92 authored by Lukas Karsch's avatar Lukas Karsch
Browse files

#29 first test for plant service

parent 7d97e727
No related branches found
No related tags found
1 merge request!15#29 Pagination for Plants endpoint w/ CustomPageDTO
### Get all plants
GET http://localhost:8080/api/v1/plants?page=0
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJsdWthcy5rYXJzY2hAZ214LmRlIiwiaWF0IjoxNzAxMjc4MzkzLCJleHAiOjE3MDEzNjQ3OTN9.TVQlG3yAl_zJddPoWDndY9Xj-9EaR0P__x3aGU3sdBA
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJsdWthcy5rYXJzY2hAZ214LmRlIiwiaWF0IjoxNzAxMzcyNTIxLCJleHAiOjE3MDE0NTg5MjF9.8_rTh-5s4A6D1t_bdRdQFbM5RdNl2fpCLETpTQzInuc
### Get garden entries
GET http://localhost:8080/api/v1/garden
......
package hdm.mi.growbros.service;
import hdm.mi.growbros.models.dto.CustomPageDto;
import hdm.mi.growbros.models.plant.Plant;
import hdm.mi.growbros.repositories.PlantRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@SpringBootTest
@ActiveProfiles("test")
class PlantsServiceTest {
@MockBean
private PlantRepository plantRepository;
@Autowired
private PlantsService plantsService;
@Test
void getPlants_withPageEmpty() {
final PageRequest pageable = PageRequest.of(0, 10);
PageImpl<Plant> page = new PageImpl<>(List.of());
final CustomPageDto<Plant> expected = new CustomPageDto<>(0, 0, page.getContent());
when(plantRepository.findAll(pageable))
.thenReturn(page);
CustomPageDto<Plant> actual = plantsService.getPlants(0, 10);
verify(plantRepository).findAll(pageable);
assertEquals(actual.currentPage(), expected.currentPage());
assertEquals(actual.pageSize(), 0);
assertEquals(actual.content(), expected.content());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment