Skip to content

Commit

Permalink
Move tests/almafix tests/ (#1707)
Browse files Browse the repository at this point in the history
This gets rid of Aleph testing.
  • Loading branch information
dr0i committed Apr 25, 2023
1 parent 677daa0 commit 7f982c1
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 1,156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class AlmaMarcXmlFix2lobidJsonEs {
private static boolean updateDonotCreateIndex;
private static String fixFileName = "src/main/resources/alma/alma.fix";

private static final String INDEXCONFIG = "index-config.json";
private static final String INDEXCONFIG = "alma/index-config.json";
private static final HashMap<String, String> fixVariables = new HashMap<>();
private static String mailtoInfo = "localhost";
private static String mailtoError = "localhost";
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/alma/index-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,18 @@
"type" : "nested",
"include_in_parent" : "true",
"properties": {
"altLabel": {
"type": "text",
"analyzer" : "german_analyzer"
},
"componentList": {
"type" : "nested",
"include_in_parent" : "true",
"properties": {
"altLabel": {
"type": "text",
"analyzer" : "german_analyzer"
},
"id": {
"type" : "keyword"
},
Expand Down Expand Up @@ -585,6 +593,9 @@
}
}
},
"subjectslabels" : {
"type" : "keyword"
},
"corporateBodyForTitle" : {
"type" : "text"
},
Expand Down
54 changes: 27 additions & 27 deletions web/test/tests/AcceptIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Copyright 2014-2017 Fabian Steeg, hbz. Licensed under the EPL 2.0 */

package tests;

import static org.fest.assertions.Assertions.assertThat;
import static play.test.Helpers.GET;
import static play.test.Helpers.fakeApplication;
Expand All @@ -23,10 +22,9 @@

/**
* Integration tests for functionality provided by the {@link Accept} class.
*
*
* @author Fabian Steeg (fsteeg)
*/
@SuppressWarnings("javadoc")
@RunWith(Parameterized.class)
public class AcceptIntegrationTest extends LocalIndexSetup {

Expand All @@ -52,32 +50,32 @@ public static Collection<Object[]> data() {
{ fakeRequest(GET, "/resources/search?q=*").header("Accept", "text/html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/resources/search?q=*").header("Accept", "application/rss+xml"), /*->*/ "application/rss+xml" },
// get, default format: JSON
{ fakeRequest(GET, "/resources/HT018907266"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/HT018907266?format="), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/HT018907266?format=json"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/HT018907266?format=whatever"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "application/pdf"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/990210781980206441"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/990210781980206441?format="), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/990210781980206441?format=json"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/990210781980206441?format=whatever"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/pdf"), /*->*/ "application/json" },
// get, other formats as query param:
{ fakeRequest(GET, "/resources/HT018907266?format=html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/resources/HT018907266?format=rdf"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/HT018907266?format=ttl"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/HT018907266?format=nt"), /*->*/ "application/n-triples" },
{ fakeRequest(GET, "/resources/990210781980206441?format=html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/resources/990210781980206441?format=rdf"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/990210781980206441?format=ttl"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/990210781980206441?format=nt"), /*->*/ "application/n-triples" },
// get, formats as URL path elem:
{ fakeRequest(GET, "/resources/HT018907266.html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/resources/HT018907266.json"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/HT018907266.rdf"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/HT018907266.ttl"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/HT018907266.nt"), /*->*/ "application/n-triples" },
{ fakeRequest(GET, "/resources/990210781980206441.html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/resources/990210781980206441.json"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/990210781980206441.rdf"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/990210781980206441.ttl"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/990210781980206441.nt"), /*->*/ "application/n-triples" },
// get, others formats via header:
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "application/json"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "text/html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "text/xml"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "application/xml"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "application/rdf+xml"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "text/turtle"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "application/x-turtle"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "text/plain"), /*->*/ "application/n-triples" },
{ fakeRequest(GET, "/resources/HT018907266").header("Accept", "application/n-triples"), /*->*/ "application/n-triples" }});
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/json"), /*->*/ "application/json" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "text/html"), /*->*/ "text/html" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "text/xml"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/xml"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/rdf+xml"), /*->*/ "application/rdf+xml" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "text/turtle"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/x-turtle"), /*->*/ "text/turtle" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "text/plain"), /*->*/ "application/n-triples" },
{ fakeRequest(GET, "/resources/990210781980206441").header("Accept", "application/n-triples"), /*->*/ "application/n-triples" }});
} // @formatter:on

private Http.RequestBuilder fakeRequest;
Expand All @@ -92,7 +90,9 @@ public AcceptIntegrationTest(Http.RequestBuilder request,
@Test
public void test() {
running(fakeApplication(), () -> {
System.out.println(fakeRequest.path() +fakeRequest.body() );
Result result = route(fakeRequest);
System.out.println(result);
assertThat(result).isNotNull();
assertThat(result.contentType()).isEqualTo(contentType);
if (contentType.equals("application/json")) {
Expand All @@ -101,4 +101,4 @@ public void test() {
});
}

}
}
4 changes: 2 additions & 2 deletions web/test/tests/AcceptUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* Unit tests for functionality provided by the {@link Accept} class.
*
*
* @author Fabian Steeg (fsteeg)
*/
@SuppressWarnings("javadoc")
Expand Down Expand Up @@ -85,4 +85,4 @@ public void test() {
assertThat(result).as(description).startsWith(expectedFormat);
}

}
}
6 changes: 3 additions & 3 deletions web/test/tests/AggregationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

/**
* Test customizable aggregations.
*
*
* See https://github.com/hbz/lobid-resources/pull/243
*
*
* @author Fabian Steeg (fsteeg)
*/
@SuppressWarnings("javadoc")
Expand Down Expand Up @@ -89,4 +89,4 @@ public void test() {

}

}
}
87 changes: 40 additions & 47 deletions web/test/tests/IndexIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,62 +33,54 @@ public class IndexIntegrationTest extends LocalIndexSetup {
public static Collection<Object[]> data() {
// @formatter:off
return queries(new Object[][] {
{ "title:der", /*->*/ 27 },
{ "title:der", /*->*/ 12 },
{ "title:Westfalen", /*->*/ 6 },
{ "contribution.agent.label:Westfalen", /*->*/ 9 },
{ "contribution.agent.label:Westfälen", /*->*/ 9 },
{ "contribution.agent.id:\"https\\://d-nb.info/gnd/5265186-1\"", /*->*/ 1 },
{ "contribution.agent.label:Westfalen", /*->*/ 3 },
{ "contribution.agent.label:Westfälen", /*->*/ 3 },
{ "contribution.agent.id:\"https\\://d-nb.info/gnd/5253963-5\"", /*->*/ 1 },
{ "contribution.agent.id:5265186-1", /*->*/ 0 },
{ "contribution.agent.id:\"5265186-1\"", /*->*/ 0 },
{ "title:Westfalen AND contribution.agent.label:Westfalen", /*->*/ 3 },
{ "title:Westfalen OR title:Munsterland", /*->*/ 7 },
{ "(title:Westfalen OR title:Münsterland) AND contribution.agent.id:\"https\\://d-nb.info/gnd/2019209-5\"", /*->*/ 0 },
{ "subject.componentList.label:Münsterland", /*->*/ 2 },
{ "subject.componentList.label:Muensterland", /*->*/ 2 },
{ "subject.componentList.label:Munsterland", /*->*/ 2 },
{ "subject.componentList.label:Münsterländer", /*->*/ 2 },
{ "subject.componentList.label.unstemmed:Münsterländer", /*->*/ 0 },
{ "subjectAltLabel:Südwestfalen", /*->*/ 1 },
{ "subjectAltLabel:Suedwestfalen", /*->*/ 1 },
{ "subjectAltLabel:Sudwestfalen", /*->*/ 1 },
{ "subjectAltLabel:Südwestfale", /*->*/ 1 },
{ "subjectAltLabel.unstemmed:Südwestfale", /*->*/ 0 },
{ "subject.componentList.id:\"https\\://d-nb.info/gnd/4042570-8\"", /*->*/ 6 },
{ "(title:Westfalen OR title:Münsterland) AND NOT contribution.agent.id:\"https\\://d-nb.info/gnd/2019209-5\"", /*->*/ 7 },
{ "subject.componentList.label:Westfalen", /*->*/ 12 },
{ "subject.componentList.label:Westfälen", /*->*/ 12 },
{ "spatial.label:Westfalen", /*->*/ 14 },
{ "spatial.label:Westfälen", /*->*/ 14 },
{ "subject.componentList.id:\"https\\://d-nb.info/gnd/4042570-8\"", /*->*/ 6 },
{ "title:Westfalen AND contribution.agent.label:Prause", /*->*/ 1 },
{ "title:Westfalen OR title:Munsterland", /*->*/ 6 },
{ "(title:Westfalen OR title:Münsterland) AND contribution.agent.id:\"https\\://d-nb.info/gnd/5253963-5\"", /*->*/ 0 },
{ "subject.componentList.label:Düsseldorf", /*->*/ 1 },
{ "subject.componentList.label:Duesseldorf", /*->*/ 1 },
{ "subject.componentList.label:Dusseldorf", /*->*/ 1 },
{ "subject.componentList.label:Düsseldorfer", /*->*/ 1 },
{ "subject.componentList.label.unstemmed:Düsseldorfer", /*->*/ 0 },
{ "subject.componentList.id:\"https\\://d-nb.info/gnd/4042570-8\"", /*->*/ 2 },
{ "(title:Westfalen OR title:Münsterland) AND NOT contribution.agent.id:\"https\\://d-nb.info/gnd/2019209-5\"", /*->*/ 6 },
{ "subject.componentList.label:Westfalen", /*->*/ 6 },
{ "subject.componentList.label:Westfälen", /*->*/ 6 },
{ "spatial.label:Westfalen", /*->*/ 4 },
{ "spatial.label:Westfälen", /*->*/ 4 },
{ "subject.componentList.id:1113670827", /*->*/ 0 },
{ "subject.componentList.type:PlaceOrGeographicName", /*->*/ 38 },
{ "publication.location:Berlin", /*->*/ 19 },
{ "subject.notation:914.3", /*->*/ 5 },
{ "subject.componentList.type:PlaceOrGeographicName", /*->*/ 15 },
{ "publication.location:Berlin", /*->*/ 12 },
{ "subject.notation:914.3", /*->*/ 4 },
{ "subject.notation:914", /*->*/ 0 },
{ "subject.notation:914*", /*->*/ 5 },
{ "publication.location:Köln", /*->*/ 12 },
{ "publication.location:Koln", /*->*/ 12 },
{ "publication.startDate:1993", /*->*/ 3 },
{ "subject.notation:914*", /*->*/ 4 },
{ "publication.location:Köln", /*->*/ 5 },
{ "publication.location:Koln", /*->*/ 5 },
{ "publication.startDate:1993", /*->*/ 2 },
{ "publication.location:Berlin AND publication.startDate:1993", /*->*/ 1 },
{ "publication.location:Berlin AND publication.startDate:[1992 TO 2017]", /*->*/ 14 },
{ "inCollection.id:\"http\\://lobid.org/resources/HT014176012#\\!\"", /*->*/ 52 },
{ "publication.location:Berlin AND publication.startDate:[1992 TO 2017]", /*->*/ 6 },
{ "inCollection.id:\"http\\://lobid.org/organisations/DE-655#\\!\"", /*->*/ 112 },
{ "inCollection.id:NWBib", /*->*/ 0 },
{ "publication.publishedBy:Springer", /*->*/ 4 },
{ "publication.publishedBy:Spring", /*->*/ 4 },
{ "publication.publishedBy:DAG", /*->*/ 1 },
{ "publication.publishedBy:DÄG", /*->*/ 1 },
{ "hasItem.id:\"http\\://lobid.org/items/TT003059252\\:DE-5-58\\:9%2F041#\\!\"", /*->*/ 1 },
{ "hasItem.id:TT003059252\\:DE-5-58\\:9%2F041", /*->*/ 0 },
{ "coverage:99", /*->*/ 16},
{ "isbn:3454128013", /*->*/ 1},
{ "isbn:345-4128-013", /*->*/ 1},
{ "\"Studies in social and political theory\"", /*->*/ 1},
{ "(+Studies +in +social +and +political +theory)", /*->*/ 1},
{ "\"Zeitzeuge und Kleinod in Harsewinkel\"", /*->*/ 1},
{ "(+Zeitzeuge +und +Kleinod +in +Harsewinkel)", /*->*/ 1},
{ "publication.publishedBy:Quedenfeldt", /*->*/ 2 },
{ "publication.publishedBy:Quedenfeld", /*->*/ 2 },
{ "publication.publishedBy:Fidula", /*->*/ 1 },
{ "publication.publishedBy:Fidüla", /*->*/ 1 },
{ "hasItem.id:\"http\\://lobid.org/items/990021367710206441\\:DE-290\\:23198604440006445#\\!\"", /*->*/ 1 },
{ "hasItem.id:990021367710206441\\:DE-290\\:23198604440006445", /*->*/ 0 },
{ "isbn:9780702075551", /*->*/ 1},
{ "isbn:070-2075-558", /*->*/ 1},
{ "isbn:0702075558", /*->*/ 1},
{ "\"Handbook on policy, process and governing\"", /*->*/ 1},
{ "(+Handbook +on +policy +process +and +governing)", /*->*/ 1},
{ "\"Mülheim an der Ruhr\"", /*->*/ 1},
{ "(+Mülheim +an +der +Ruhr)", /*->*/ 1},
{ "\"Amtliche Publikation\"", /*->*/ 3}
{ "\"Amtliche Publikation\"", /*->*/ 1}
});
} // @formatter:on

Expand All @@ -106,6 +98,7 @@ private static List<Object[]> queries(Object[][] objects) {
private Search index;

public IndexIntegrationTest(Queries.Builder query, int resultCount) {
Logger.debug(query.build().toString());
this.expectedResultCount = resultCount;
this.index = new Search.Builder().query(query.build()).build();
}
Expand Down
2 changes: 1 addition & 1 deletion web/test/tests/InputStringsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Test nasty input strings using data from
* https://github.com/minimaxir/big-list-of-naughty-strings
*
*
* See http://www.playframework.com/documentation/2.3.x/JavaTest
*/
@SuppressWarnings("javadoc")
Expand Down
33 changes: 16 additions & 17 deletions web/test/tests/IntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import controllers.resources.Queries;
import controllers.resources.Search;
import play.api.Logger;
import play.libs.Json;
import play.mvc.Http;
import play.mvc.Result;
Expand Down Expand Up @@ -67,10 +68,9 @@ public void testFacets() {
terms.getBuckets().stream().map(Bucket::getKeyAsString);
Stream<Long> counts =
terms.getBuckets().stream().map(Bucket::getDocCount);
assertThat(values.collect(Collectors.toList())).contains(
"BibliographicResource", "Book", "Thesis", "Sonstige",
"Article");
assertThat(counts.collect(Collectors.toList())).excludes(0);
assertThat(values.collect(Collectors.toList())).contains("BibliographicResource", "Book", "Bibliography",
"EditedVolume", "Game", "Image", "Periodical", "Series");
assertThat(counts.collect(Collectors.toList())).excludes(0);
});
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public void bulkRequestCompatibility() {
private static void bulkRequestWith(String param) {
running(testServer(3333), () -> {
Result result =
route(fakeRequest(GET, "/resources/search?q=buch&format=" + param));
route(fakeRequest(GET, "/resources/search?q=theorie&format=" + param));
assertThat(result).isNotNull();
assertThat(result.contentType()).isEqualTo("application/x-jsonlines");
String text = Helpers.contentAsString(result);
Expand All @@ -115,30 +115,30 @@ private static void bulkRequestWith(String param) {
public void sizeRequest() {
running(testServer(3333), () -> {
Search index = new Search.Builder()
.query(new Queries.Builder().q("hbzId:TT050409948").build()).build();
.query(new Queries.Builder().q("hbzId:HT020202475").build()).build();
Long hits = index.totalHits();
assertThat(hits).isGreaterThan(0);
});
}

@Test
public void sizeRequestOwnerFull() {
ownerTest("http://lobid.org/organisations/DE-260#!");
ownerTest("http://lobid.org/organisations/DE-290#!");
}

@Test
public void sizeRequestOwnerAbout() {
ownerTest("http://lobid.org/organisations/DE-260");
ownerTest("http://lobid.org/organisations/DE-290");
}

@Test
public void sizeRequestOwnerShort() {
ownerTest("DE-260");
ownerTest("DE-290");
}

@Test
public void sizeRequestOwnerShortMulti() {
ownerTest("DE-260,DE-290");
ownerTest("DE-5,DE-290");
}

private static void ownerTest(String id) {
Expand All @@ -153,10 +153,9 @@ private static void ownerTest(String id) {
public void agentRequest() {
running(testServer(3333), () -> {
for (String s : Arrays.asList("Westfalen",
"https://d-nb.info/gnd/5265186-1", //
"Reulecke, Jürgen (1940-)", //
"Reiff, Johann J. (1793-1864)", //
"https://d-nb.info/gnd/5265186-1,https://d-nb.info/gnd/5265186-1,AND")) {
"120195364", //
"Breuer, Stefan (1948-)", //
"https://d-nb.info/gnd/120195364,AND")) {
assertThat(new Search.Builder()
.query(new Queries.Builder().agent(s).build()).build().totalHits())
.as(s).isGreaterThanOrEqualTo(1);
Expand All @@ -168,9 +167,9 @@ public void agentRequest() {
public void responseJsonFilterGet() {
running(testServer(3333), () -> {
Search index = new Search.Builder().build();
JsonNode hit = index.getResource("TT050409948").getResult();
JsonNode hit = index.getResource("990363946050206441").getResult();
assertThat(hit.isObject()).as("hit is an object").isTrue();
assertThat(hit.findValue("hbzId").asText()).isEqualTo("TT050409948");
assertThat(hit.findValue("hbzId").asText()).isEqualTo("HT020202475");
Search.HIDE_FIELDS.forEach(field -> assertThat(hit.get(field)).isNull());
});
}
Expand Down Expand Up @@ -205,7 +204,7 @@ public void queryFilter() {
.size(100).build().queryResources();
Search nwbib = new Search.Builder()
.query(new Queries.Builder().q("*")
.filter("inCollection.id:HT014176012").build())
.filter("inCollection.id:ZDB-197-MSE").build())
.size(100).build().queryResources();
assertThat(all.getTotal()).isGreaterThan(nwbib.getTotal());
});
Expand Down
Loading

0 comments on commit 7f982c1

Please sign in to comment.