Skip to content

Commit

Permalink
MODLD-601: LCCN deduplication
Browse files Browse the repository at this point in the history
MODLD-601: LCCN deduplication test
  • Loading branch information
AndreiBordak committed Nov 29, 2024
1 parent ee4f166 commit 025e76d
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: CRUD operations on settings
Background:
* url baseUrl

@getSettings
Scenario: Get settings
Given path 'settings/entries'
And param query = query
When method GET
Then status 200
* def response = $

@putSetting
Scenario: Put a setting
Given path 'settings/entries/' + id
And request settingRequest
When method PUT
Then status 200
* def response = $
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Resource validation
Background:
* url baseUrl

@validationErrorWithCodeOnResourceCreation
Scenario: Get a resource
Given path 'linked-data/resource'
And request resource
When method POST
Then status 400
And match $.errors[0].code == code
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Feature: LCCN validation for duplicates.

Background:
* url baseUrl
* call login testUser
* def testUserHeaders = { 'Content-Type': 'application/json', 'x-okapi-token': '#(okapitoken)', 'Accept': '*/*' }
* configure headers = testUserHeaders

Scenario: Create a new resource in Linked Data, enable LCCN deduplication and try to create a resource with same LCCN.
# Step 1: Enable LCCN deduplication
* def settingsResponse = call getSettings { query: '(scope==ui-quick-marc.lccn-duplicate-check.manage and key==lccn-duplicate-check)'}
* def setting = postInstanceCall.response.items[0]
* karate.log('##setting##', setting)
* eval setting.value.duplicateLccnCheckingEnabled = true
* call putSetting { id : '#(setting.id)', settingRequest : '#(setting)'}

# Step 2: Create work and instance
* def workRequest = read('samples/work-request.json')
* def workResponse = call postResource { resourceRequest: '#(workRequest)' }
* def workId = workResponse.response.resource['http://bibfra.me/vocab/lite/Work'].id

* def instanceRequest = read('samples/instance-request.json')
* def instanceResponse = call postResource { resourceRequest: '#(instanceRequest)' }

# Step 3: Update the instance with same LCCN (here we check linked-data -> mod-search interaction and id exclusion)
* def instanceId = instanceResponse.response.resource['http://bibfra.me/vocab/lite/Instance'].id
* call putResource { id: '#(instanceId)' , resourceRequest: '#(instanceRequest)' }

# Step 4: Create new instance with existing LCCN, verify bad request
* eval workRequest.resource['http://bibfra.me/vocab/lite/Work']['http://bibfra.me/vocab/marc/title'][0]['http://bibfra.me/vocab/marc/Title']['http://bibfra.me/vocab/marc/mainTitle'] = ['new_title']
* def newWorkResponse = call postResource { resourceRequest: '#(workRequest)' }
* eval workId = newWorkResponse.response.resource['http://bibfra.me/vocab/lite/Work'].id
* def newInstanceRequest = read('samples/instance-request.json')
* eval newInstanceRequest.resource['http://bibfra.me/vocab/lite/Instance']['http://bibfra.me/vocab/marc/title'][0]['http://bibfra.me/vocab/marc/Title']['http://bibfra.me/vocab/marc/mainTitle'] = ['new_title']
* call validationErrorWithCodeOnResourceCreation { resource: '#(newInstanceRequest)', code: 'lccn_not_unique'}

# Step 5: Disable LCCN deduplication setting
* eval setting.value.duplicateLccnCheckingEnabled = false
* call putSetting { id : '#(setting.id)', settingRequest : '#(setting)'}

# Step 6: Create new instance with existing LCCN, verify success
* call postResource { resourceRequest: '#(newInstanceRequest)' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"resource":{
"http://bibfra.me/vocab/lite/Instance":{
"http://bibfra.me/vocab/marc/title":[
{
"http://bibfra.me/vocab/marc/Title":{
"http://bibfra.me/vocab/bflc/nonSortNum":[
"1"
],
"http://bibfra.me/vocab/marc/mainTitle":[
"deduplication_main_title"
]
}
}
],
"http://library.link/vocab/map":[
{
"http://library.link/identifier/LCCN":{
"http://bibfra.me/vocab/lite/name":[
"nn0987654321"
],
"http://bibfra.me/vocab/marc/status":[
{
"http://bibfra.me/vocab/lite/label":[
"current"
],
"http://bibfra.me/vocab/lite/link":[
"http://id.loc.gov/vocabulary/mstatus/current"
]
}
]
}
}
],
"_workReference":[
{
"id":"#(workId)"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"resource":{
"http://bibfra.me/vocab/lite/Work":{
"http://bibfra.me/vocab/marc/title":[
{
"http://bibfra.me/vocab/marc/Title":{
"http://bibfra.me/vocab/bflc/nonSortNum":[
"1"
],
"http://bibfra.me/vocab/marc/mainTitle":[
"deduplication_main_title"
],
"http://bibfra.me/vocab/marc/partNumber":[
"1"
],
"http://bibfra.me/vocab/marc/partName":[
"part 1"
]
}
}
],
"http://bibfra.me/vocab/marc/content":[
{
"http://bibfra.me/vocab/marc/term":[
"cartographic image"
],
"http://bibfra.me/vocab/lite/link":[
"http://id.loc.gov/vocabulary/contentTypes/cri"
]
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Feature: mod-linked-data integration tests
| 'specification-storage.specifications.collection.get' |
| 'specification-storage.specification.rules.collection.get' |
| 'specification-storage.specification.rules.item.patch' |
| 'ui-quick-marc.settings.lccn-duplicate-check.edit' |
| 'mod-settings.entries.collection.get' |
| 'mod-settings.entries.item.get' |
| 'mod-settings.entries.item.put' |

Scenario: create tenant and users for testing
Given call read('classpath:common/setup-users.feature')
3 changes: 3 additions & 0 deletions mod-linked-data/src/main/resources/karate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function fn() {
getResourceGraph: karate.read('classpath:citation/mod-linked-data/features/util/crud-resource.feature@getResourceGraph'),
getResourceSupportCheck: karate.read('classpath:citation/mod-linked-data/features/util/crud-resource.feature@getResourceSupportCheck'),
getResourcePreview: karate.read('classpath:citation/mod-linked-data/features/util/crud-resource.feature@getResourcePreview'),
validationErrorWithCodeOnResourceCreation: karate.read('classpath:citation/mod-linked-data/features/util/validation-resource.feature@validationErrorWithCodeOnResourceCreation'),
getSettings: karate.read('classpath:citation/mod-linked-data/features/util/crud-settings.feature@getSettings'),
getSetting: karate.read('classpath:citation/mod-linked-data/features/util/crud-settings.feature@getSetting'),
postImport: karate.read('classpath:citation/mod-linked-data/features/util/crud-resource.feature@postImport'),
getSpecifications: karate.read('classpath:citation/mod-linked-data/features/util/crud-specifications.feature@getSpecifications'),
getRules: karate.read('classpath:citation/mod-linked-data/features/util/crud-specifications.feature@getRules'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ void importBibRecordFromSrsToLinkedData() {
void lccnPatternValidation() {
runFeatureTest("lccn-pattern-validation/lccn-pattern-validation.feature");
}

@Test
void lccnDeduplication() {
runFeatureTest("validation/lccn/deduplication/lccn-deduplication.feature");
}
}

0 comments on commit 025e76d

Please sign in to comment.