|
| 1 | +package io.securecodebox.persistence.defectdojo.service; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 4 | +import io.securecodebox.persistence.defectdojo.config.Config; |
| 5 | +import io.securecodebox.persistence.defectdojo.model.User; |
| 6 | +import lombok.Getter; |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.net.URISyntaxException; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import static com.github.tomakehurst.wiremock.client.WireMock.*; |
| 14 | +import static org.junit.jupiter.api.Assertions.*; |
| 15 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 16 | +import static org.hamcrest.Matchers.*; |
| 17 | + |
| 18 | +/** |
| 19 | + * Tests for {@link UserService} |
| 20 | + */ |
| 21 | +final class UserServiceTest extends WireMockBaseTestCase{ |
| 22 | + private final UserService sut = new UserService(conf()); |
| 23 | + |
| 24 | + @Test |
| 25 | + void search() throws URISyntaxException, IOException { |
| 26 | + stubFor( |
| 27 | + get("/api/v2/users/?offset=0&limit=100") |
| 28 | + .willReturn( |
| 29 | + ok() |
| 30 | + .withBody(readResponseBodyFromFixture("io/securecodebox/persistence/defectdojo/service/fixture_UserService.json")) |
| 31 | + ) |
| 32 | + ); |
| 33 | + |
| 34 | + final var result = sut.search(); |
| 35 | + |
| 36 | + assertAll( |
| 37 | + () -> assertThat(result, hasSize(3)), |
| 38 | + () -> assertThat(result, containsInAnyOrder( |
| 39 | + User.builder() |
| 40 | + .id(1) |
| 41 | + .username("admin") |
| 42 | + .firstName("Admin") |
| 43 | + .lastName("User") |
| 44 | + .build(), |
| 45 | + User.builder() |
| 46 | + .id(2) |
| 47 | + .username("JannikHollenbach") |
| 48 | + .firstName("Jannik") |
| 49 | + .lastName("Hollenbach") |
| 50 | + .build(), |
| 51 | + User.builder() |
| 52 | + .id(3) |
| 53 | + .username("SvenStrittmatter") |
| 54 | + .firstName("Sven") |
| 55 | + .lastName("Strittmatter") |
| 56 | + .build() |
| 57 | + )) |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
0 commit comments