-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture & Replay Integration Test for UserService
Signed-off-by: Sven Strittmatter <[email protected]>
- Loading branch information
1 parent
56d4eb4
commit 9006546
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/test/java/io/securecodebox/persistence/defectdojo/service/UserServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.securecodebox.persistence.defectdojo.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import io.securecodebox.persistence.defectdojo.config.Config; | ||
import io.securecodebox.persistence.defectdojo.model.User; | ||
import lombok.Getter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
* Tests for {@link UserService} | ||
*/ | ||
final class UserServiceTest extends WireMockBaseTestCase{ | ||
private final UserService sut = new UserService(conf()); | ||
|
||
@Test | ||
void search() throws URISyntaxException, IOException { | ||
stubFor( | ||
get("/api/v2/users/?offset=0&limit=100") | ||
.willReturn( | ||
ok() | ||
.withBody(readResponseBodyFromFixture("io/securecodebox/persistence/defectdojo/service/fixture_UserService.json")) | ||
) | ||
); | ||
|
||
final var result = sut.search(); | ||
|
||
assertAll( | ||
() -> assertThat(result, hasSize(3)), | ||
() -> assertThat(result, containsInAnyOrder( | ||
User.builder() | ||
.id(1) | ||
.username("admin") | ||
.firstName("Admin") | ||
.lastName("User") | ||
.build(), | ||
User.builder() | ||
.id(2) | ||
.username("JannikHollenbach") | ||
.firstName("Jannik") | ||
.lastName("Hollenbach") | ||
.build(), | ||
User.builder() | ||
.id(3) | ||
.username("SvenStrittmatter") | ||
.firstName("Sven") | ||
.lastName("Strittmatter") | ||
.build() | ||
)) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/resources/io/securecodebox/persistence/defectdojo/service/fixture_UserService.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"count": 7, | ||
"next": null, | ||
"previous": null, | ||
"results": [ | ||
{ | ||
"id": 1, | ||
"username": "admin", | ||
"first_name": "Admin", | ||
"last_name": "User", | ||
"email": "[email protected]", | ||
"last_login": "2024-03-01T14:53:58.920659Z", | ||
"is_active": true, | ||
"is_superuser": true, | ||
"configuration_permissions": [] | ||
}, | ||
{ | ||
"id": 2, | ||
"username": "JannikHollenbach", | ||
"first_name": "Jannik", | ||
"last_name": "Hollenbach", | ||
"email": "[email protected]", | ||
"last_login": "2024-03-01T15:02:06.007669Z", | ||
"is_active": true, | ||
"is_superuser": true, | ||
"configuration_permissions": [] | ||
}, | ||
{ | ||
"id": 3, | ||
"username": "SvenStrittmatter", | ||
"first_name": "Sven", | ||
"last_name": "Strittmatter", | ||
"email": "[email protected]", | ||
"last_login": null, | ||
"is_active": true, | ||
"is_superuser": true, | ||
"configuration_permissions": [] | ||
} | ||
] | ||
} |