1515import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
1616import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
1717
18+ import java .util .List ;
19+
20+ import org .dspace .app .bulkaccesscontrol .model .BulkAccessConditionConfiguration ;
21+ import org .dspace .app .bulkaccesscontrol .service .BulkAccessConditionConfigurationService ;
1822import org .dspace .app .rest .matcher .AccessConditionOptionMatcher ;
1923import org .dspace .app .rest .test .AbstractControllerIntegrationTest ;
2024import org .dspace .builder .CollectionBuilder ;
2125import org .dspace .builder .CommunityBuilder ;
2226import org .dspace .builder .ItemBuilder ;
2327import org .dspace .content .Collection ;
2428import org .dspace .content .Community ;
29+ import org .dspace .submit .model .AccessConditionOption ;
2530import org .hamcrest .Matchers ;
2631import org .junit .Test ;
32+ import org .springframework .beans .factory .annotation .Autowired ;
2733
2834/**
2935 * Integration test class for the bulkaccessconditionoptions endpoint.
3238 */
3339public class BulkAccessConditionRestRepositoryIT extends AbstractControllerIntegrationTest {
3440
41+ @ Autowired
42+ private BulkAccessConditionConfigurationService bulkAccessConditionConfigurationService ;
43+
3544 @ Test
3645 public void findAllByAdminUserTest () throws Exception {
3746 String authToken = getAuthToken (admin .getEmail (), password );
47+ String embargoLimit = getLimitForOption ("embargo" , "startDate" );
48+ String leaseLimit = getLimitForOption ("lease" , "endDate" );
49+
3850 getClient (authToken )
3951 .perform (get ("/api/config/bulkaccessconditionoptions" ))
4052 .andExpect (status ().isOk ())
4153 .andExpect (jsonPath ("$.page.totalElements" , greaterThanOrEqualTo (1 )))
4254 .andExpect (jsonPath ("$._embedded.bulkaccessconditionoptions" , containsInAnyOrder (allOf (
4355 hasJsonPath ("$.id" , is ("default" )),
4456 hasJsonPath ("$.itemAccessConditionOptions" , Matchers .containsInAnyOrder (
45- AccessConditionOptionMatcher .matchAccessConditionOption ("openaccess" , false , false , null , null ),
46- AccessConditionOptionMatcher .matchAccessConditionOption ("embargo" , true , false , "+36MONTHS" , null ),
47- AccessConditionOptionMatcher .matchAccessConditionOption ("administrator" , false , false , null , null ),
48- AccessConditionOptionMatcher .matchAccessConditionOption ("lease" , false , true , null , "+6MONTHS" ))
57+ AccessConditionOptionMatcher .matchAccessConditionOption (
58+ "openaccess" , false , false , null , null ),
59+ AccessConditionOptionMatcher .matchAccessConditionOption (
60+ "embargo" , true , false , embargoLimit , null ),
61+ AccessConditionOptionMatcher .matchAccessConditionOption (
62+ "administrator" , false , false , null , null ),
63+ AccessConditionOptionMatcher .matchAccessConditionOption (
64+ "lease" , false , true , null , leaseLimit ))
4965 ),
5066 hasJsonPath ("$.bitstreamAccessConditionOptions" , Matchers .containsInAnyOrder (
51- AccessConditionOptionMatcher .matchAccessConditionOption ("openaccess" , false , false , null , null ),
52- AccessConditionOptionMatcher .matchAccessConditionOption ("embargo" , true , false , "+36MONTHS" , null ),
53- AccessConditionOptionMatcher .matchAccessConditionOption ("administrator" , false , false , null , null ),
54- AccessConditionOptionMatcher .matchAccessConditionOption ("lease" , false , true , null , "+6MONTHS" ))
67+ AccessConditionOptionMatcher .matchAccessConditionOption (
68+ "openaccess" , false , false , null , null ),
69+ AccessConditionOptionMatcher .matchAccessConditionOption (
70+ "embargo" , true , false , embargoLimit , null ),
71+ AccessConditionOptionMatcher .matchAccessConditionOption (
72+ "administrator" , false , false , null , null ),
73+ AccessConditionOptionMatcher .matchAccessConditionOption (
74+ "lease" , false , true , null , leaseLimit ))
5575 )))));
5676 }
5777
@@ -140,21 +160,24 @@ public void findAllByAnonymousUserTest() throws Exception {
140160 @ Test
141161 public void findOneByAdminTest () throws Exception {
142162 String tokenAdmin = getAuthToken (admin .getEmail (), password );
163+ String embargoLimit = getLimitForOption ("embargo" , "startDate" );
164+ String leaseLimit = getLimitForOption ("lease" , "endDate" );
165+
143166 getClient (tokenAdmin )
144167 .perform (get ("/api/config/bulkaccessconditionoptions/default" ))
145168 .andExpect (status ().isOk ())
146169 .andExpect (jsonPath ("$.id" , is ("default" )))
147170 .andExpect (jsonPath ("$.itemAccessConditionOptions" , Matchers .containsInAnyOrder (
148171 AccessConditionOptionMatcher .matchAccessConditionOption ("openaccess" , false , false , null , null ),
149- AccessConditionOptionMatcher .matchAccessConditionOption ("embargo" , true , false , "+36MONTHS" , null ),
172+ AccessConditionOptionMatcher .matchAccessConditionOption ("embargo" , true , false , embargoLimit , null ),
150173 AccessConditionOptionMatcher .matchAccessConditionOption ("administrator" , false , false , null , null ),
151- AccessConditionOptionMatcher .matchAccessConditionOption ("lease" , false , true , null , "+6MONTHS" ))
174+ AccessConditionOptionMatcher .matchAccessConditionOption ("lease" , false , true , null , leaseLimit ))
152175 ))
153176 .andExpect (jsonPath ("$.bitstreamAccessConditionOptions" , Matchers .containsInAnyOrder (
154177 AccessConditionOptionMatcher .matchAccessConditionOption ("openaccess" , false , false , null , null ),
155- AccessConditionOptionMatcher .matchAccessConditionOption ("embargo" , true , false , "+36MONTHS" , null ),
178+ AccessConditionOptionMatcher .matchAccessConditionOption ("embargo" , true , false , embargoLimit , null ),
156179 AccessConditionOptionMatcher .matchAccessConditionOption ("administrator" , false , false , null , null ),
157- AccessConditionOptionMatcher .matchAccessConditionOption ("lease" , false , true , null , "+6MONTHS" ))
180+ AccessConditionOptionMatcher .matchAccessConditionOption ("lease" , false , true , null , leaseLimit ))
158181 ))
159182 .andExpect (jsonPath ("$.type" , is ("bulkaccessconditionoption" )));
160183 }
@@ -253,4 +276,26 @@ public void findOneNotFoundTest() throws Exception {
253276 .andExpect (status ().isNotFound ());
254277 }
255278
279+ /**
280+ * Helper method to extract limits from the current configuration dynamically.
281+ */
282+ private String getLimitForOption (String optionName , String limitType ) {
283+ BulkAccessConditionConfiguration config = bulkAccessConditionConfigurationService .
284+ getBulkAccessConditionConfiguration ("default" );
285+
286+ if (config != null ) {
287+ List <AccessConditionOption > options = config .getItemAccessConditionOptions ();
288+ for (AccessConditionOption option : options ) {
289+ if (option .getName ().equals (optionName )) {
290+ if ("startDate" .equals (limitType )) {
291+ return option .getStartDateLimit ();
292+ } else if ("endDate" .equals (limitType )) {
293+ return option .getEndDateLimit ();
294+ }
295+ }
296+ }
297+ }
298+ return null ;
299+ }
300+
256301}
0 commit comments