Skip to content

Commit

Permalink
MODEUS-189: Add keywords search (label, description, aggregator name)…
Browse files Browse the repository at this point in the history
  • Loading branch information
julianladisch committed Nov 7, 2024
1 parent 89e4bfb commit 434cebf
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
"fromModuleVersion": "mod-erm-usage-4.0.0",
"withMetadata": true,
"fullTextIndex": [
{
"fieldName": "keywords",
"multiFieldNames": "label,description,harvestingConfig.aggregator.name"
},
{
"fieldName": "harvestingConfig.harvestingStatus",
"tOps": "ADD"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.parsing.Parser;
import io.restassured.response.Response;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.json.Json;
Expand All @@ -20,6 +22,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

import org.folio.postgres.testing.PostgresTesterContainer;
import org.folio.rest.RestVerticle;
import org.folio.rest.client.TenantClient;
Expand All @@ -28,7 +32,6 @@
import org.folio.rest.jaxrs.model.TenantAttributes;
import org.folio.rest.jaxrs.model.UsageDataProvider;
import org.folio.rest.jaxrs.model.UsageDataProvider.HasFailedReport;
import org.folio.rest.jaxrs.model.UsageDataProviders;
import org.folio.rest.persist.PostgresClient;
import org.folio.rest.tools.utils.ModuleName;
import org.folio.rest.tools.utils.NetworkUtils;
Expand Down Expand Up @@ -265,46 +268,38 @@ public void checkThatWeCanAddGetPutAndDeleteUsageDataProviders() {

@Test
public void checkThatWeCanSearchByCQL() {
String mockedOkapiUrl = "http://localhost:" + wireMockRule.port();
var udproviders = List.of(udprovider, udprovider2);

// POST provider without aggregator
UsageDataProvider udp =
given()
.body(Json.encode(udprovider))
.header("X-Okapi-Tenant", TENANT)
.header("X-Okapi-Url", mockedOkapiUrl)
.header("content-type", APPLICATION_JSON)
.header("accept", APPLICATION_JSON)
.request()
.post(BASE_URI)
.thenReturn()
.as(UsageDataProvider.class);
assertThat(udp.getLabel()).isEqualTo(udprovider.getLabel());
assertThat(udp.getId()).isNotEmpty();
// POST two providers
udproviders.forEach(this::postUdp);

String cqlLabel = "?query=(label=\"" + udprovider.getLabel() + "\")";
UsageDataProviders queryResult =
given()
.header("X-Okapi-Tenant", TENANT)
.header("content-type", APPLICATION_JSON)
.header("accept", APPLICATION_JSON)
.when()
.get(BASE_URI + cqlLabel)
.thenReturn()
.as(UsageDataProviders.class);
assertThat(queryResult.getUsageDataProviders().size()).isEqualTo(1);
assertThat(queryResult.getUsageDataProviders().get(0).getLabel()).isEqualTo(udp.getLabel());
assertThat(queryResult.getUsageDataProviders().get(0).getId()).isEqualTo(udp.getId());
// GET by CQL: search for label
get("""
label="%s"
""".formatted(udprovider.getLabel()))
.then()
.statusCode(200)
.body("usageDataProviders.label", is(List.of(udprovider.getLabel())))
.body("usageDataProviders.id", is(List.of(udprovider.getId())));

// DELETE
given()
.header("X-Okapi-Tenant", TENANT)
.header("content-type", APPLICATION_JSON)
.header("accept", "text/plain")
.when()
.delete(BASE_URI + "/" + udprovider.getId())
// GET by CQL: search for a word from aggregator name, description, and label
get("""
keywords all "digital meeting with"
""")
.then()
.statusCode(204);
.statusCode(200)
.body("usageDataProviders.id", is(List.of(udprovider2.getId())));

// DELETE
udproviders.forEach(udp ->
given()
.header("X-Okapi-Tenant", TENANT)
.header("content-type", APPLICATION_JSON)
.header("accept", "text/plain")
.when()
.delete(BASE_URI + "/" + udp.getId())
.then()
.statusCode(204));
}

@Test
Expand Down Expand Up @@ -346,4 +341,35 @@ public void checkThatDefaultValueForHasFailedReportsIsNo() {
.then()
.statusCode(204);
}

private UsageDataProvider postUdp(UsageDataProvider udprovider) {
String mockedOkapiUrl = "http://localhost:" + wireMockRule.port();

UsageDataProvider udp =
given()
.body(Json.encode(udprovider))
.header("X-Okapi-Tenant", TENANT)
.header("X-Okapi-Url", mockedOkapiUrl)
.header("content-type", APPLICATION_JSON)
.header("accept", APPLICATION_JSON)
.request()
.post(BASE_URI)
.thenReturn()
.as(UsageDataProvider.class);
assertThat(udp.getLabel()).isEqualTo(udprovider.getLabel());
assertThat(udp.getId()).isNotEmpty();

return udp;
}

private Response get(String cql) {
return
given()
.header("X-Okapi-Tenant", TENANT)
.header("content-type", APPLICATION_JSON)
.header("accept", APPLICATION_JSON)
.when()
.param("query", cql)
.get(BASE_URI);
}
}
1 change: 1 addition & 0 deletions ramls/examples/udproviders.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "bf6c9ddc-ff82-40c4-be64-dd2414bdcd72",
"label": "Data provider without aggregator",
"description": "maintained by Betty",
"harvestingConfig": {
"harvestingStatus": "active",
"harvestVia": "sushi",
Expand Down
2 changes: 2 additions & 0 deletions ramls/examples/udproviders2.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "bf6c9ddc-ff82-40c4-be64-dd2414bdcd73",
"label": "Data provider with aggregator",
"description": "See meeting notes 2023-10-05",
"harvestingConfig": {
"harvestingStatus": "active",
"harvestVia": "aggregator",
Expand All @@ -10,6 +11,7 @@
},
"aggregator": {
"id": "4c66b956-23a8-4418-aef6-1c35dcdaccc4",
"name": "ACM Digital Library",
"vendorCode": "ACMDL"
},
"reportRelease": "4",
Expand Down

0 comments on commit 434cebf

Please sign in to comment.