Skip to content

Commit

Permalink
Capture & Replay Integration Test for UserService
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strittmatter <[email protected]>
  • Loading branch information
Weltraumschaf committed Mar 8, 2024
1 parent 56d4eb4 commit 9006546
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
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()
))
);
}
}
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": []
}
]
}

0 comments on commit 9006546

Please sign in to comment.