Skip to content

Commit 114b820

Browse files
committed
Add Missing TEsts and Fixtures for ProductGroupService
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent b1e00db commit 114b820

File tree

2 files changed

+99
-11
lines changed

2 files changed

+99
-11
lines changed

src/test/java/io/securecodebox/persistence/defectdojo/service/ProductGroupServiceTest.java

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import com.fasterxml.jackson.core.JsonProcessingException;
77
import io.securecodebox.persistence.defectdojo.model.ProductGroup;
8-
import org.junit.jupiter.api.Disabled;
98
import org.junit.jupiter.api.Test;
109

1110
import java.io.IOException;
@@ -24,10 +23,28 @@
2423
final class ProductGroupServiceTest extends WireMockBaseTestCase {
2524
private static final String RESPONSE_LIST_FIXTURE_JSON = "ProductGroupService_response_list_fixture.json";
2625
private final ProductGroupService sut = new ProductGroupService(conf());
27-
private final ProductGroup expectedFromSearch = ProductGroup.builder().build();
26+
private final ProductGroup[] expectedFromSearch = new ProductGroup[]{
27+
ProductGroup.builder()
28+
.id(1)
29+
.product(2)
30+
.group(3)
31+
.role(4)
32+
.build(),
33+
ProductGroup.builder()
34+
.id(5)
35+
.product(6)
36+
.group(7)
37+
.role(8)
38+
.build(),
39+
ProductGroup.builder()
40+
.id(9)
41+
.product(10)
42+
.group(11)
43+
.role(12)
44+
.build()
45+
};
2846

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

4360
assertAll(
44-
() -> assertThat(result, hasSize(0)),
61+
() -> assertThat(result, hasSize(3)),
4562
() -> assertThat(result, containsInAnyOrder(expectedFromSearch))
4663
);
4764
}
4865

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

6884
assertAll(
69-
() -> assertThat(result, hasSize(0)),
85+
() -> assertThat(result, hasSize(3)),
7086
() -> assertThat(result, containsInAnyOrder(expectedFromSearch))
7187
);
7288
}
7389

7490
@Test
75-
@Disabled("TODO: Ad JSON fixture.")
7691
void get_byId() {
7792
final var response = """
7893
{
94+
"id": 42,
95+
"product": 2,
96+
"group": 3,
97+
"role": 4
7998
}
8099
""";
81100
stubFor(get(urlPathEqualTo("/api/v2/product_groups/42"))
@@ -85,6 +104,9 @@ void get_byId() {
85104
));
86105
final var expected = ProductGroup.builder()
87106
.id(42)
107+
.product(2)
108+
.group(3)
109+
.role(4)
88110
.build();
89111

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

145167
@Test
146-
@Disabled("TODO: Implement test.")
147168
void create() {
169+
final var json = """
170+
{
171+
"id": 42,
172+
"product": 285,
173+
"group": 23,
174+
"role": 47
175+
}
176+
""";
177+
stubFor(post(urlPathEqualTo("/api/v2/product_groups/"))
178+
.withRequestBody(equalToJson(json))
179+
.willReturn(created()
180+
.withHeaders(responseHeaders(json.length()))
181+
.withBody(json) // Typically the entity with new assigned id is returned, but we ignore this here.
182+
));
183+
final var toCreate = ProductGroup.builder()
184+
.id(42)
185+
.product(285)
186+
.group(23)
187+
.role(47)
188+
.build();
189+
190+
final var result = sut.create(toCreate);
191+
192+
assertThat(result, is(toCreate));
148193
}
149194

150195
@Test
@@ -158,7 +203,31 @@ void delete_byId() {
158203
}
159204

160205
@Test
161-
@Disabled("TODO: Implement test.")
162206
void update() {
207+
final var json = """
208+
{
209+
"id": 42,
210+
"product": 285,
211+
"group": 23,
212+
"role": 47
213+
}
214+
""";
215+
stubFor(put(urlPathEqualTo("/api/v2/product_groups/42/"))
216+
.withRequestBody(equalToJson(json))
217+
.willReturn(ok()
218+
.withHeaders(responseHeaders(json.length()))
219+
.withBody(json)
220+
));
221+
222+
final var toUpdate = ProductGroup.builder()
223+
.id(42)
224+
.product(285)
225+
.group(23)
226+
.role(47)
227+
.build();
228+
229+
final var result = sut.update(toUpdate, 42L);
230+
231+
assertThat(result, is(toUpdate));
163232
}
164233
}
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
{
2-
"count": 0,
2+
"count": 3,
33
"next": null,
44
"previous": null,
5-
"results": [],
5+
"results": [
6+
{
7+
"id": 1,
8+
"product": 2,
9+
"group": 3,
10+
"role": 4
11+
},
12+
{
13+
"id": 5,
14+
"product": 6,
15+
"group": 7,
16+
"role": 8
17+
},
18+
{
19+
"id": 9,
20+
"product": 10,
21+
"group": 11,
22+
"role": 12
23+
}
24+
],
625
"prefetch": {}
726
}

0 commit comments

Comments
 (0)