55
66import com .fasterxml .jackson .core .JsonProcessingException ;
77import io .securecodebox .persistence .defectdojo .model .ProductGroup ;
8- import org .junit .jupiter .api .Disabled ;
98import org .junit .jupiter .api .Test ;
109
1110import java .io .IOException ;
2423final 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}
0 commit comments