-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cn-browse): handle deletes/updates of call-numbers
Closes: MSEARCH-940
- Loading branch information
Showing
11 changed files
with
164 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
src/test/java/org/folio/search/controller/IndexingInstanceCallNumberIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package org.folio.search.controller; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.entry; | ||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
import static org.folio.search.model.types.ResourceType.INSTANCE_CALL_NUMBER; | ||
import static org.folio.search.service.reindex.ReindexConstants.CALL_NUMBER_TABLE; | ||
import static org.folio.search.service.reindex.ReindexConstants.INSTANCE_CALL_NUMBER_TABLE; | ||
import static org.folio.search.service.reindex.ReindexConstants.ITEM_TABLE; | ||
import static org.folio.search.utils.TestConstants.TENANT_ID; | ||
import static org.folio.search.utils.TestUtils.randomId; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import org.folio.search.domain.dto.Instance; | ||
import org.folio.search.domain.dto.Item; | ||
import org.folio.search.domain.dto.ItemEffectiveCallNumberComponents; | ||
import org.folio.search.support.base.BaseIntegrationTest; | ||
import org.folio.spring.testing.extension.DatabaseCleanup; | ||
import org.folio.spring.testing.type.IntegrationTest; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@IntegrationTest | ||
@DatabaseCleanup(tenants = TENANT_ID, tables = {CALL_NUMBER_TABLE, INSTANCE_CALL_NUMBER_TABLE, ITEM_TABLE}) | ||
class IndexingInstanceCallNumberIT extends BaseIntegrationTest { | ||
|
||
private static final String INSTANCE_ID_1 = randomId(); | ||
private static final String INSTANCE_ID_2 = randomId(); | ||
|
||
@BeforeAll | ||
static void prepare() { | ||
var instance1 = new Instance().id(INSTANCE_ID_1).title("test"); | ||
var instance2 = new Instance().id(INSTANCE_ID_2).title("test"); | ||
setUpTenant(instance1, instance2); | ||
} | ||
|
||
@AfterAll | ||
static void cleanUp() { | ||
removeTenant(); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
deleteAllDocuments(INSTANCE_CALL_NUMBER, TENANT_ID); | ||
} | ||
|
||
@Test | ||
void shouldIndexInstanceCallNumber_createNewDocument_onItemCreate() { | ||
// given | ||
// create items with the same call number | ||
var item1 = getItem(randomId()); | ||
var item2 = getItem(randomId()); | ||
inventoryApi.createItem(TENANT_ID, INSTANCE_ID_1, item1); | ||
inventoryApi.createItem(TENANT_ID, INSTANCE_ID_2, item2); | ||
awaitAssertion(() -> assertThat(fetchAllDocuments(INSTANCE_CALL_NUMBER, TENANT_ID)).hasSize(1)); | ||
|
||
// when | ||
// fetch all documents from search index | ||
var hits = fetchAllDocuments(INSTANCE_CALL_NUMBER, TENANT_ID); | ||
|
||
// then | ||
var sourceAsMap = hits[0].getSourceAsMap(); | ||
// assert that the document contains the expected fields | ||
assertThat(sourceAsMap) | ||
.contains( | ||
entry("callNumber", "NS 1 .B5"), | ||
entry("fullCallNumber", "NS 1 .B5"), | ||
entry("callNumberTypeId", "2b94c631-fca9-4892-a730-03ee529ff6c3"), | ||
entry("defaultShelvingOrder", "NS 1 .B5"), | ||
entry("deweyShelvingOrder", "NS 11 B 15"), | ||
entry("lcShelvingOrder", "NS 11 B5"), | ||
entry("sudocShelvingOrder", "!NS 11 !B 15"), | ||
entry("nlmShelvingOrder", "NS 11 B5") | ||
); | ||
|
||
// assert that the document contains the expected instances object with count 2 | ||
@SuppressWarnings("unchecked") | ||
var instances = (List<Map<String, Object>>) sourceAsMap.get("instances"); | ||
assertThat(instances) | ||
.hasSize(1) | ||
.allSatisfy(map -> assertThat(map).containsEntry("shared", false)) | ||
.allSatisfy(map -> assertThat(map).containsEntry("tenantId", TENANT_ID)) | ||
.allSatisfy(map -> assertThat(map).containsEntry("count", 2)); | ||
} | ||
|
||
@Test | ||
void shouldIndexInstanceCallNumber_deleteDocument_onItemUpdate() { | ||
// given | ||
// create item with call number | ||
var item = getItem(randomId()); | ||
inventoryApi.createItem(TENANT_ID, INSTANCE_ID_1, item); | ||
awaitAssertion(() -> assertThat(fetchAllDocuments(INSTANCE_CALL_NUMBER, TENANT_ID)).hasSize(1)); | ||
|
||
// when update item with null call number | ||
item.setEffectiveCallNumberComponents(null); | ||
inventoryApi.updateItem(TENANT_ID, INSTANCE_ID_1, item); | ||
|
||
// then | ||
awaitAssertion(() -> assertThat(fetchAllDocuments(INSTANCE_CALL_NUMBER, TENANT_ID)).isEmpty()); | ||
} | ||
|
||
@Test | ||
void shouldIndexInstanceCallNumber_deleteDocument_onItemDelete() { | ||
// given | ||
// create item with call number | ||
var itemId = randomId(); | ||
var item = getItem(itemId); | ||
inventoryApi.createItem(TENANT_ID, INSTANCE_ID_1, item); | ||
awaitAssertion(() -> assertThat(fetchAllDocuments(INSTANCE_CALL_NUMBER, TENANT_ID)).hasSize(1)); | ||
|
||
// when | ||
inventoryApi.deleteItem(TENANT_ID, itemId); | ||
|
||
// then | ||
awaitAssertion(() -> assertThat(fetchAllDocuments(INSTANCE_CALL_NUMBER, TENANT_ID)).isEmpty()); | ||
} | ||
|
||
private Item getItem(String itemId) { | ||
return new Item().id(itemId).holdingsRecordId(randomId()).effectiveCallNumberComponents(callNumberComponents()); | ||
} | ||
|
||
private ItemEffectiveCallNumberComponents callNumberComponents() { | ||
var callNumberTypeId = "2b94c631-fca9-4892-a730-03ee529ff6c3"; | ||
var callNumber = "NS 1 .B5"; | ||
return new ItemEffectiveCallNumberComponents().callNumber(callNumber).typeId(callNumberTypeId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters