Skip to content

Commit 3f9c39f

Browse files
authored
feat: add v2.1 changelog and default data updates to disable undefined rules (#171)
Closes: MRSPECS-102
1 parent ec039d4 commit 3f9c39f

5 files changed

Lines changed: 75 additions & 15 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Features
1010
* Refactor specification sync from URL to local copy ([MRSPECS-87](https://folio-org.atlassian.net/browse/MRSPECS-87))
11+
* Default specification data updates to disable undefined rules ([MRSPECS-102](https://folio-org.atlassian.net/browse/MRSPECS-102))
1112

1213
### Bug fixes
1314
* Fix non-obsolete subfield choosing logic ([MRSPECS-95](https://folio-org.atlassian.net/browse/MRSPECS-95))

mod-record-specifications-server/src/main/resources/db/changelog/changelog-master.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
66

77
<include file="changes/changelog-v1.0.xml" relativeToChangelogFile="true"/>
8+
<include file="changes/changelog-v2.1.xml" relativeToChangelogFile="true"/>
89

910
</databaseChangeLog>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
5+
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
6+
7+
<include file="v2.1/update-default-data.xml" relativeToChangelogFile="true"/>
8+
9+
</databaseChangeLog>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
5+
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
6+
7+
<changeSet id="MRSPECS-102@@default-data:disable-undefined-rules" labels="default-data" author="pavlo_smahin">
8+
<preConditions>
9+
<tableExists tableName="specification_rule"/>
10+
</preConditions>
11+
12+
<comment>Disable undefined-* code rules</comment>
13+
14+
<update tableName="specification_rule">
15+
<column name="enabled" valueBoolean="false"/>
16+
<where>rule_id IN (
17+
'7c843a14-4c87-4c7d-9ad6-5c7654bff9b5',
18+
'eaaa6357-7a95-460e-960d-73f5f6863ffe',
19+
'108ca421-24ba-4dc2-8d0f-661c00667e9a'
20+
)
21+
</where>
22+
</update>
23+
</changeSet>
24+
25+
</databaseChangeLog>

mod-record-specifications-server/src/test/java/org/folio/api/SpecificationStorageApiIT.java

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.folio.api;
22

3+
import static java.lang.Boolean.TRUE;
34
import static org.assertj.core.api.Assertions.assertThat;
45
import static org.folio.rspec.domain.entity.Field.FIELD_TABLE_NAME;
56
import static org.folio.support.ApiEndpoints.fieldIndicatorsPath;
@@ -20,10 +21,12 @@
2021
import static org.hamcrest.Matchers.hasItems;
2122
import static org.hamcrest.Matchers.is;
2223
import static org.hamcrest.Matchers.notNullValue;
24+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2325
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
2426
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2527

2628
import com.jayway.jsonpath.JsonPath;
29+
import java.util.Arrays;
2730
import java.util.UUID;
2831
import org.folio.rspec.domain.dto.ErrorCode;
2932
import org.folio.rspec.domain.dto.Scope;
@@ -33,17 +36,26 @@
3336
import org.folio.rspec.exception.ResourceNotFoundException;
3437
import org.folio.spring.testing.extension.DatabaseCleanup;
3538
import org.folio.spring.testing.type.IntegrationTest;
39+
import org.folio.support.ApiEndpoints;
3640
import org.folio.support.QueryParams;
3741
import org.folio.support.SpecificationITBase;
3842
import org.junit.jupiter.api.BeforeAll;
3943
import org.junit.jupiter.api.Test;
4044
import org.springframework.dao.DataIntegrityViolationException;
45+
import org.springframework.test.web.servlet.ResultActions;
4146
import org.springframework.web.bind.MethodArgumentNotValidException;
4247

4348
@IntegrationTest
4449
@DatabaseCleanup(tables = FIELD_TABLE_NAME, tenants = TENANT_ID)
4550
class 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

Comments
 (0)