Skip to content

Tests for rest calls #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7a4f074
Enable debug logging in test code
Weltraumschaf Mar 7, 2024
f7c9186
Disable example test
Weltraumschaf Mar 7, 2024
3f01dfd
Implement first capture replay test for ProductTypeService
Weltraumschaf Mar 7, 2024
f8972c7
Debul log requested URL to know what URI path to mock in tests
Weltraumschaf Mar 7, 2024
766c57d
Extract Common Logic for WireMock Test Setup to Share Across Test Cases
Weltraumschaf Mar 8, 2024
ddb62e3
Capture & Replay Integration Test for UserService
Weltraumschaf Mar 8, 2024
6660d1a
Add Integration Test Stubs for all Services
Weltraumschaf Mar 8, 2024
ab94dd8
Capture & Replay Integration Test for EndpointService
Weltraumschaf Mar 8, 2024
5577076
Simplify Fixture Loading
Weltraumschaf Mar 8, 2024
db808e5
Capture & Replay Integration Test for EngagementService
Weltraumschaf Mar 8, 2024
57f11ab
No Integration Test for Base Service Implementation
Weltraumschaf Mar 8, 2024
13f2635
Capture & Replay Integration Test for GroupMemberService
Weltraumschaf Mar 8, 2024
fb6d745
Capture & Replay Integration Test for GroupService
Weltraumschaf Mar 8, 2024
79ef531
Capture & Replay Integration Test for ProductGroupService
Weltraumschaf Mar 8, 2024
c2a2991
Capture & Replay Integration Test for ProductService
Weltraumschaf Mar 8, 2024
d511791
Capture & Replay Integration Test for TestService
Weltraumschaf Mar 8, 2024
5d89d5b
Capture & Replay Integration Test for TestTypeService
Weltraumschaf Mar 8, 2024
2dcae1d
Capture & Replay Integration Test for ToolConfigService
Weltraumschaf Mar 8, 2024
3083557
Capture & Replay Integration Test for ToolTypeService
Weltraumschaf Mar 8, 2024
1d759f8
Remove Example WireMock Test Case
Weltraumschaf Mar 8, 2024
1738067
Port FindingServiceTest To WireMock
Weltraumschaf Mar 8, 2024
c8fa2b1
Add Missing SPDX Headers
Weltraumschaf Mar 8, 2024
9eec68f
Port UserProfileServiceTest To WireMock
Weltraumschaf Mar 8, 2024
6b38ec9
Contains Only Tests for Interface
Weltraumschaf Mar 8, 2024
ae22d59
This Is Not a Typical Service
Weltraumschaf Mar 8, 2024
87d0c0c
Extract generic service interface to derive missin integration test m…
Weltraumschaf Mar 8, 2024
58ceeae
Add Test Method Stubs for Whole Interface
Weltraumschaf Mar 8, 2024
21b6a5a
Implement test for search with query params
Weltraumschaf Mar 9, 2024
4062e91
Simulate the DefectDojo Response Headers
Weltraumschaf Mar 9, 2024
75de015
Implement Test Case for Single Endpoint
Weltraumschaf Mar 9, 2024
4e27239
Even More Integration Tests for EndpointService
Weltraumschaf Mar 9, 2024
214d5fd
Set Log Level in Tests to Warn Level
Weltraumschaf Mar 9, 2024
eccab28
Port Test Cases from EndpointService to Other Services
Weltraumschaf Mar 10, 2024
155345f
Add Missing TEsts and Fixtures for ProductGroupService
Weltraumschaf Mar 14, 2024
2af85fa
Add Missing Fixture
Weltraumschaf Mar 14, 2024
9bdce96
Fix Assertions for Special Implementation of UserProfileService
Weltraumschaf Mar 14, 2024
f793401
Move Public API to top of Class
Weltraumschaf Mar 14, 2024
37931fc
Update dependencies
Weltraumschaf Mar 14, 2024
b9835b8
Update plugins
Weltraumschaf Mar 14, 2024
e4b6e3f
Add Missing Interface Doc and Null Checks
Weltraumschaf Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Missing TEsts and Fixtures for ProductGroupService
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
  • Loading branch information
Weltraumschaf committed Mar 14, 2024
commit 155345fc874f0092ca112b755a9ff54768fa86dc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import io.securecodebox.persistence.defectdojo.model.ProductGroup;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -24,10 +23,28 @@
final class ProductGroupServiceTest extends WireMockBaseTestCase {
private static final String RESPONSE_LIST_FIXTURE_JSON = "ProductGroupService_response_list_fixture.json";
private final ProductGroupService sut = new ProductGroupService(conf());
private final ProductGroup expectedFromSearch = ProductGroup.builder().build();
private final ProductGroup[] expectedFromSearch = new ProductGroup[]{
ProductGroup.builder()
.id(1)
.product(2)
.group(3)
.role(4)
.build(),
ProductGroup.builder()
.id(5)
.product(6)
.group(7)
.role(8)
.build(),
ProductGroup.builder()
.id(9)
.product(10)
.group(11)
.role(12)
.build()
};

@Test
@Disabled("TODO: Add non-empty fixture for ProductGroupService.")
void search() throws URISyntaxException, IOException {
final var response = readFixtureFile(RESPONSE_LIST_FIXTURE_JSON);
stubFor(get(urlPathEqualTo("/api/v2/product_groups/"))
Expand All @@ -41,13 +58,12 @@ void search() throws URISyntaxException, IOException {
final var result = sut.search();

assertAll(
() -> assertThat(result, hasSize(0)),
() -> assertThat(result, hasSize(3)),
() -> assertThat(result, containsInAnyOrder(expectedFromSearch))
);
}

@Test
@Disabled("TODO: Add non-empty fixture for ProductGroupService.")
void search_withQueryParams() throws IOException, URISyntaxException {
final var response = readFixtureFile(RESPONSE_LIST_FIXTURE_JSON);
stubFor(get(urlPathEqualTo("/api/v2/product_groups/"))
Expand All @@ -66,16 +82,19 @@ void search_withQueryParams() throws IOException, URISyntaxException {
final var result = sut.search(params);

assertAll(
() -> assertThat(result, hasSize(0)),
() -> assertThat(result, hasSize(3)),
() -> assertThat(result, containsInAnyOrder(expectedFromSearch))
);
}

@Test
@Disabled("TODO: Ad JSON fixture.")
void get_byId() {
final var response = """
{
"id": 42,
"product": 2,
"group": 3,
"role": 4
}
""";
stubFor(get(urlPathEqualTo("/api/v2/product_groups/42"))
Expand All @@ -85,6 +104,9 @@ void get_byId() {
));
final var expected = ProductGroup.builder()
.id(42)
.product(2)
.group(3)
.role(4)
.build();

final var result = sut.get(42L);
Expand Down Expand Up @@ -143,8 +165,31 @@ void searchUnique_withQueryParams() throws URISyntaxException, JsonProcessingExc
}

@Test
@Disabled("TODO: Implement test.")
void create() {
final var json = """
{
"id": 42,
"product": 285,
"group": 23,
"role": 47
}
""";
stubFor(post(urlPathEqualTo("/api/v2/product_groups/"))
.withRequestBody(equalToJson(json))
.willReturn(created()
.withHeaders(responseHeaders(json.length()))
.withBody(json) // Typically the entity with new assigned id is returned, but we ignore this here.
));
final var toCreate = ProductGroup.builder()
.id(42)
.product(285)
.group(23)
.role(47)
.build();

final var result = sut.create(toCreate);

assertThat(result, is(toCreate));
}

@Test
Expand All @@ -158,7 +203,31 @@ void delete_byId() {
}

@Test
@Disabled("TODO: Implement test.")
void update() {
final var json = """
{
"id": 42,
"product": 285,
"group": 23,
"role": 47
}
""";
stubFor(put(urlPathEqualTo("/api/v2/product_groups/42/"))
.withRequestBody(equalToJson(json))
.willReturn(ok()
.withHeaders(responseHeaders(json.length()))
.withBody(json)
));

final var toUpdate = ProductGroup.builder()
.id(42)
.product(285)
.group(23)
.role(47)
.build();

final var result = sut.update(toUpdate, 42L);

assertThat(result, is(toUpdate));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
{
"count": 0,
"count": 3,
"next": null,
"previous": null,
"results": [],
"results": [
{
"id": 1,
"product": 2,
"group": 3,
"role": 4
},
{
"id": 5,
"product": 6,
"group": 7,
"role": 8
},
{
"id": 9,
"product": 10,
"group": 11,
"role": 12
}
],
"prefetch": {}
}