Skip to content

Commit

Permalink
[MSEARCH-770]. Add campus update integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
BKadirkhodjaev committed Jun 14, 2024
1 parent c4db32e commit d366f08
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.With;
import lombok.extern.jackson.Jacksonized;

/**
* Describes Campus object that comes from external channels.
*/
@Data
@With
@Builder
@Jacksonized
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
import static org.folio.search.domain.dto.ResourceEventType.CREATE;
import static org.folio.search.domain.dto.ResourceEventType.DELETE;
import static org.folio.search.domain.dto.ResourceEventType.DELETE_ALL;
import static org.folio.search.domain.dto.ResourceEventType.UPDATE;
import static org.folio.search.utils.SearchUtils.CAMPUS_RESOURCE;
import static org.folio.search.utils.SearchUtils.getIndexName;
import static org.folio.search.utils.TestConstants.CENTRAL_TENANT_ID;
import static org.folio.search.utils.TestConstants.MEMBER_TENANT_ID;
import static org.folio.search.utils.TestConstants.inventoryCampusTopic;
import static org.folio.search.utils.TestUtils.kafkaResourceEvent;
import static org.folio.search.utils.TestUtils.randomId;
import static org.folio.search.utils.TestUtils.toMap;
import static org.opensearch.index.query.QueryBuilders.boolQuery;
import static org.opensearch.search.builder.SearchSourceBuilder.searchSource;

import java.io.IOException;
import lombok.extern.log4j.Log4j2;
import org.folio.search.domain.dto.ResourceEvent;
import org.folio.search.model.dto.locationunit.CampusDto;
import org.folio.search.support.base.BaseConsortiumIntegrationTest;
Expand All @@ -24,7 +29,11 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.client.RequestOptions;
import org.opensearch.index.query.QueryBuilders;

@Log4j2
@IntegrationTest
class CampusesIndexingConsortiumIT extends BaseConsortiumIntegrationTest {

Expand Down Expand Up @@ -63,6 +72,25 @@ void shouldIndexAndRemoveCampus() {
awaitAssertCampusCount(0);
}

@Test
void shouldIndexAndUpdateCampus() {
var campusId = randomId();
var campus = CampusDto.builder().id(campusId)
.name("name")
.code("code")
.build();
var createEvent = kafkaResourceEvent(CENTRAL_TENANT_ID, CREATE, toMap(campus), null);
kafkaTemplate.send(inventoryCampusTopic(CENTRAL_TENANT_ID), createEvent);

awaitAssertCampusCount(1);

var campusUpdated = campus.withName("nameUpdated");
var updateEvent = kafkaResourceEvent(CENTRAL_TENANT_ID, UPDATE, toMap(campusUpdated), toMap(campus));
kafkaTemplate.send(inventoryCampusTopic(CENTRAL_TENANT_ID), updateEvent);

awaitAssertCampusCountAfterUpdate(1, campusUpdated);
}

@Test
void shouldIndexSameCampusFromDifferentTenantsAsSeparateDocs() {
var campusId = randomId();
Expand Down Expand Up @@ -108,4 +136,19 @@ public static void awaitAssertCampusCount(int expected) {
});
}

public static void awaitAssertCampusCountAfterUpdate(int expected, CampusDto campusUpdated) {
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).untilAsserted(() -> {
var idQuery = QueryBuilders.matchQuery("id", campusUpdated.getId());
var nameQuery = QueryBuilders.matchQuery("name", campusUpdated.getName());

var searchRequest = new SearchRequest()
.source(searchSource().query(boolQuery().must(idQuery).must(nameQuery))
.trackTotalHits(true).from(0).size(1))
.indices(getIndexName(CAMPUS_RESOURCE, CENTRAL_TENANT_ID));
var searchResponse = elasticClient.search(searchRequest, RequestOptions.DEFAULT);
var hitCount = searchResponse.getHits().getTotalHits().value;

assertThat(hitCount).isEqualTo(expected);
});
}
}

0 comments on commit d366f08

Please sign in to comment.