11package org .folio .api ;
22
3+ import static java .lang .Boolean .TRUE ;
34import static org .assertj .core .api .Assertions .assertThat ;
45import static org .folio .rspec .domain .entity .Field .FIELD_TABLE_NAME ;
56import static org .folio .support .ApiEndpoints .fieldIndicatorsPath ;
2021import static org .hamcrest .Matchers .hasItems ;
2122import static org .hamcrest .Matchers .is ;
2223import static org .hamcrest .Matchers .notNullValue ;
24+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
2325import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
2426import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
2527
2628import com .jayway .jsonpath .JsonPath ;
29+ import java .util .Arrays ;
2730import java .util .UUID ;
2831import org .folio .rspec .domain .dto .ErrorCode ;
2932import org .folio .rspec .domain .dto .Scope ;
3336import org .folio .rspec .exception .ResourceNotFoundException ;
3437import org .folio .spring .testing .extension .DatabaseCleanup ;
3538import org .folio .spring .testing .type .IntegrationTest ;
39+ import org .folio .support .ApiEndpoints ;
3640import org .folio .support .QueryParams ;
3741import org .folio .support .SpecificationITBase ;
3842import org .junit .jupiter .api .BeforeAll ;
3943import org .junit .jupiter .api .Test ;
4044import org .springframework .dao .DataIntegrityViolationException ;
45+ import org .springframework .test .web .servlet .ResultActions ;
4146import org .springframework .web .bind .MethodArgumentNotValidException ;
4247
4348@ IntegrationTest
4449@ DatabaseCleanup (tables = FIELD_TABLE_NAME , tenants = TENANT_ID )
4550class SpecificationStorageApiIT extends SpecificationITBase {
4651
52+ private static final UUID [] DISABLED_RULES = new UUID [] {
53+ UUID .fromString ("eaaa6357-7a95-460e-960d-73f5f6863ffe" ),
54+ UUID .fromString ("7c843a14-4c87-4c7d-9ad6-5c7654bff9b5" ),
55+ UUID .fromString ("0a769f6a-fe60-4ef1-bfa6-bcdd88908d04" ),
56+ UUID .fromString ("108ca421-24ba-4dc2-8d0f-661c00667e9a" )
57+ };
58+
4759 @ BeforeAll
4860 static void beforeAll () {
4961 setUpTenant ();
@@ -227,7 +239,7 @@ void getSpecification_shouldReturn200AndSpecificationWithRequiredFields() throws
227239
228240 @ Test
229241 void getSpecificationRules_shouldReturn200AndCollectionOfRules () throws Exception {
230- doGet (specificationRulesPath (BIBLIOGRAPHIC_SPECIFICATION_ID ))
242+ var specificationRules = getSpecificationRules ( doGet (specificationRulesPath (BIBLIOGRAPHIC_SPECIFICATION_ID ))
231243 .andExpect (jsonPath ("totalRecords" , is (15 )))
232244 .andExpect (jsonPath ("rules.size()" , is (15 )))
233245 .andExpect (jsonPath ("rules[0].id" , notNullValue ()))
@@ -239,7 +251,12 @@ void getSpecificationRules_shouldReturn200AndCollectionOfRules() throws Exceptio
239251 .andExpect (jsonPath ("rules[0].metadata.createdDate" , notNullValue ()))
240252 .andExpect (jsonPath ("rules[0].metadata.updatedDate" , notNullValue ()))
241253 .andExpect (jsonPath ("rules[0].metadata.createdByUserId" , notNullValue ()))
242- .andExpect (jsonPath ("rules[0].metadata.updatedByUserId" , notNullValue ()));
254+ .andExpect (jsonPath ("rules[0].metadata.updatedByUserId" , notNullValue ())));
255+
256+ // Assert expected rules disabled
257+ assertSpecificationRulesEnabled (false , true , specificationRules , DISABLED_RULES );
258+ // Assert all other rules enabled
259+ assertSpecificationRulesEnabled (true , false , specificationRules , DISABLED_RULES );
243260 }
244261
245262 @ Test
@@ -253,21 +270,21 @@ void getSpecificationRules_shouldReturn404WhenSpecificationNotExist() throws Exc
253270
254271 @ Test
255272 void toggleSpecificationRule_shouldReturn204AndToggleSpecificationRule () {
256- var specificationRules = getSpecificationRules (BIBLIOGRAPHIC_SPECIFICATION_ID );
273+ var specificationRules = getSpecificationRules (
274+ doGet (ApiEndpoints .specificationRulesPath (BIBLIOGRAPHIC_SPECIFICATION_ID )));
257275 var specificationRuleToToggle = specificationRules .getRules ().getFirst ();
258276 var stateBeforeToggle = specificationRuleToToggle .getEnabled ();
259277
260- var specificationRuleId = specificationRuleToToggle .getId ();
278+ var ruleId = specificationRuleToToggle .getId ();
261279
262280 var stateAfterToggle = Boolean .FALSE .equals (stateBeforeToggle );
263281 var toggleDto = new ToggleSpecificationRuleDto (stateAfterToggle );
264- doPatch (specificationRulePath (BIBLIOGRAPHIC_SPECIFICATION_ID , specificationRuleId ), toggleDto );
265- assertSpecificationRuleEnabled (specificationRuleId , BIBLIOGRAPHIC_SPECIFICATION_ID , stateAfterToggle );
282+ doPatch (specificationRulePath (BIBLIOGRAPHIC_SPECIFICATION_ID , ruleId ), toggleDto );
283+ assertSpecificationRuleEnabled (BIBLIOGRAPHIC_SPECIFICATION_ID , stateAfterToggle , ruleId );
266284
267285 toggleDto = toggleDto .enabled (stateBeforeToggle );
268- doPatch (specificationRulePath (BIBLIOGRAPHIC_SPECIFICATION_ID , specificationRuleId ), toggleDto );
269- assertSpecificationRuleEnabled (specificationRuleId , BIBLIOGRAPHIC_SPECIFICATION_ID ,
270- Boolean .TRUE .equals (stateBeforeToggle ));
286+ doPatch (specificationRulePath (BIBLIOGRAPHIC_SPECIFICATION_ID , ruleId ), toggleDto );
287+ assertSpecificationRuleEnabled (BIBLIOGRAPHIC_SPECIFICATION_ID , TRUE .equals (stateBeforeToggle ), ruleId );
271288
272289 assertSpecificationUpdatedEvents (2 );
273290 }
@@ -372,17 +389,24 @@ void createSpecificationLocalField_shouldReturn400WhenFieldTagIsNotAlphabetical(
372389 .andExpect (errorParameterMatch ("tag" ));
373390 }
374391
375- private SpecificationRuleDtoCollection getSpecificationRules (UUID specificationId ) {
392+ private SpecificationRuleDtoCollection getSpecificationRules (ResultActions resultActions ) {
376393 return contentAsObj (
377- doGet ( specificationRulesPath ( specificationId )) .andReturn (),
394+ resultActions .andReturn (),
378395 SpecificationRuleDtoCollection .class
379396 );
380397 }
381398
382- private void assertSpecificationRuleEnabled (UUID ruleId , UUID specificationId , boolean expected ) {
383- var specificationRulesAfterUpdate = getSpecificationRules (specificationId );
384- for (SpecificationRuleDto rule : specificationRulesAfterUpdate .getRules ()) {
385- if (rule .getId ().equals (ruleId )) {
399+ private void assertSpecificationRuleEnabled (UUID specificationId , boolean expected , UUID ruleId ) {
400+ var specificationRulesAfterUpdate = getSpecificationRules (doGet (specificationRulesPath (specificationId )));
401+ assertSpecificationRulesEnabled (expected , true , specificationRulesAfterUpdate , ruleId );
402+ }
403+
404+ private void assertSpecificationRulesEnabled (boolean expected , boolean including ,
405+ SpecificationRuleDtoCollection collection ,
406+ UUID ... ruleIds ) {
407+ for (SpecificationRuleDto rule : collection .getRules ()) {
408+ assertNotNull (rule .getId ());
409+ if (including ? Arrays .asList (ruleIds ).contains (rule .getId ()) : !Arrays .asList (ruleIds ).contains (rule .getId ())) {
386410 assertThat (rule .getEnabled ()).isEqualTo (expected );
387411 }
388412 }
0 commit comments