Skip to content

Commit 98a6eca

Browse files
Restore the CLARIN-only discovery facet tests to dtq-dev-9-base (#1427)
Source: origin/dtq-dev (a3627a6), ClarinDiscoveryRestControllerIT.java Nothing on this branch covered the two CLARIN customisations of the hierarchical subject facet, and one of them turned out to be broken. On DSpace 7 the fork kept a 6088-line copy of DiscoveryRestControllerIT, because that class hard-coded the vanilla facet list, failed under the CLARIN discovery.xml and was @ignore'd at class level. DSpace 9 builds the expected facets and filters from the live configuration instead (FacetEntryMatcher.defaultFacetMatchers, SearchFilterMatcher.searchFilterMatchers), so DiscoveryRestControllerIT runs here, unignored, against the CLARIN configuration -- 71 of the copy's 74 tests exist there by the same name and are green, and four tests the copy had to @ignore are active. Restoring the copy verbatim is impossible anyway: every FacetEntryMatcher call it makes carries a hasNext argument that v9 deleted, its four clarin*/dcType facet matchers and all seven clarin* search-filter matchers no longer exist, and v9 renamed the type facet to "itemtype". So this restores only what has no counterpart: - showFacetValuesWithSplitterInSearchPage (subject facet, "::" splitter) - doNotShowFacetValuesWithSplitterInHomePage (subjectFirstValue, homepage config) Both test bodies are the dtq-dev originals, unchanged; no assertion was dropped. The third test without a counterpart, discoverSearchSelfLinkKeepsScopeAndConfiguration Test, belongs to card BE-02 and lands there in DiscoveryRestControllerIT. Two configuration restores were needed to make them pass: - discovery.xml, searchFilterSubject: restore skipFirstNodeLevel=false, added by the fork in 46afa35 ("Show all values for the Subject facet in the search page", #569) and lost in the v9 squash -- the bean is byte-identical with vanilla 9.3 here, and HierarchicalSidebarFacetConfiguration defaults the flag to true. Without it the search-page subject facet indexes and lists only the leaf of an "A::B" value ("Jane" instead of "People" and "People::Jane"). This is a live regression, not only a test one. The flag is applied at index time (ItemIndexFactoryImpl), so a deployed instance needs `dspace index-discovery -b` before the facet changes. - test-discovery.xml: add the missing `homepage` entry. This file replaces the whole DiscoveryConfigurationService bean, so its map -- not the one in discovery.xml -- decides which ?configuration= names exist in ITs. The homepageConfiguration and searchFilterSubjectFirstValue beans already exist on this branch, so only the one map entry had to be merged. Card: X-01 (split off the test-parity branch, which carries the other three restored classes). Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 382360c commit 98a6eca

3 files changed

Lines changed: 153 additions & 0 deletions

File tree

dspace-server-webapp/src/test/data/dspaceFolder/config/spring/api/test-discovery.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<!-- Same as the "default" configuration, but does NOT filter out older versions of items -->
3535
<!-- Used to display related items on single-item pages, because a relationship does not always point to the latest version of the related item -->
3636
<entry key="default-relationships" value-ref="defaultRelationshipsConfiguration" />
37+
<!-- CLARIN: the home page uses its own configuration; this bean definition replaces the one in
38+
discovery.xml, so the entry has to be repeated here or ?configuration=homepage is unknown -->
39+
<entry key="homepage" value-ref="homepageConfiguration" />
3740
<!--<entry key="123456789/7621" value-ref="defaultConfiguration"/>-->
3841
<!-- Used to show filters and results on MyDSpace -->
3942
<!-- Do not change the id of special entries or else they won't work -->
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.app.rest;
9+
10+
import static org.hamcrest.Matchers.containsString;
11+
import static org.hamcrest.Matchers.emptyOrNullString;
12+
import static org.hamcrest.Matchers.is;
13+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
15+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16+
17+
import com.jayway.jsonpath.matchers.JsonPathMatchers;
18+
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
19+
import org.dspace.builder.CollectionBuilder;
20+
import org.dspace.builder.CommunityBuilder;
21+
import org.dspace.builder.ItemBuilder;
22+
import org.dspace.content.Collection;
23+
import org.hamcrest.Matchers;
24+
import org.junit.Test;
25+
26+
/**
27+
* Discovery tests for the CLARIN customisations that {@link DiscoveryRestControllerIT} does not cover: the
28+
* hierarchical {@code subject} facet with a {@code ::} splitter, and the {@code subjectFirstValue} facet of the
29+
* CLARIN {@code homepage} configuration, which collapses such values to their first node.
30+
*
31+
* <p>On DSpace 7 this class was a full copy of {@code DiscoveryRestControllerIT}, because that class hard-coded
32+
* the vanilla facet list and therefore failed against the CLARIN {@code discovery.xml}. DSpace 9 derives its
33+
* expected facets and filters from the live configuration instead ({@code FacetEntryMatcher.defaultFacetMatchers},
34+
* {@code SearchFilterMatcher.searchFilterMatchers}), so {@code DiscoveryRestControllerIT} runs green against the
35+
* CLARIN configuration and only the two tests below have no counterpart there.</p>
36+
*
37+
* @author Milan Majchrak (dspace at dataquest.sk)
38+
*/
39+
public class ClarinDiscoveryRestControllerIT extends AbstractControllerIntegrationTest {
40+
41+
@Test
42+
public void showFacetValuesWithSplitterInSearchPage() throws Exception {
43+
context.turnOffAuthorisationSystem();
44+
45+
parentCommunity = CommunityBuilder.createCommunity(context)
46+
.withName("Parent Community").build();
47+
48+
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
49+
.withName("Collection 1").build();
50+
51+
ItemBuilder.createItem(context, col1)
52+
.withTitle("Public item 1")
53+
.withIssueDate("2017-10-17")
54+
.withAuthor("Smith, Donald")
55+
.withSubject("People")
56+
.build();
57+
58+
ItemBuilder.createItem(context, col1)
59+
.withTitle("Public item 2")
60+
.withIssueDate("2020-02-13")
61+
.withAuthor("Doe, Jane")
62+
.withSubject("People::Jane")
63+
.build();
64+
65+
ItemBuilder.createItem(context, col1)
66+
.withTitle("Public item 2")
67+
.withIssueDate("2020-02-13")
68+
.withAuthor("Doe, Jane")
69+
.withSubject("People::Jane")
70+
.build();
71+
72+
context.restoreAuthSystemState();
73+
74+
getClient().perform(get("/api/discover/facets/subject"))
75+
.andExpect(status().isOk())
76+
.andExpect(jsonPath("$.type", is("discover")))
77+
.andExpect(jsonPath("$.name", is("subject")))
78+
.andExpect(jsonPath("$.facetType", is("hierarchical")))
79+
.andExpect(jsonPath("$.scope", is(emptyOrNullString())))
80+
.andExpect(jsonPath("$._links.self.href",
81+
containsString("api/discover/facets/subject")))
82+
.andExpect(jsonPath("$._embedded.values[0].label", is("People")))
83+
.andExpect(jsonPath("$._embedded.values[0].count", is(3)))
84+
.andExpect(jsonPath("$._embedded.values[1].label", is("People::Jane")))
85+
.andExpect(jsonPath("$._embedded.values[1].count", is(2)))
86+
.andExpect(jsonPath("$", JsonPathMatchers.hasNoJsonPath("_embedded.values[2].label")))
87+
.andExpect(jsonPath("$", JsonPathMatchers.hasNoJsonPath("_embedded.values[2].count")))
88+
.andExpect(jsonPath("$._embedded.values").value(Matchers.hasSize(2)));
89+
}
90+
91+
@Test
92+
public void doNotShowFacetValuesWithSplitterInHomePage() throws Exception {
93+
context.turnOffAuthorisationSystem();
94+
95+
parentCommunity = CommunityBuilder.createCommunity(context)
96+
.withName("Parent Community").build();
97+
98+
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
99+
.withName("Collection 1").build();
100+
101+
ItemBuilder.createItem(context, col1)
102+
.withTitle("Public item 1")
103+
.withIssueDate("2017-10-17")
104+
.withAuthor("Smith, Donald")
105+
.withSubject("People")
106+
.build();
107+
108+
ItemBuilder.createItem(context, col1)
109+
.withTitle("Public item 2")
110+
.withIssueDate("2020-02-13")
111+
.withAuthor("Doe, Jane")
112+
.withSubject("People::Jane")
113+
.build();
114+
115+
ItemBuilder.createItem(context, col1)
116+
.withTitle("Public item 2")
117+
.withIssueDate("2020-02-13")
118+
.withAuthor("Doe, Jane")
119+
.withSubject("People::Jane")
120+
.build();
121+
122+
ItemBuilder.createItem(context, col1)
123+
.withTitle("Public item 2")
124+
.withIssueDate("2020-02-13")
125+
.withAuthor("Doe, Jane")
126+
.withSubject("Another subject")
127+
.build();
128+
129+
context.restoreAuthSystemState();
130+
131+
getClient().perform(get("/api/discover/facets/subjectFirstValue")
132+
.param("configuration", "homepage"))
133+
.andExpect(status().isOk())
134+
.andExpect(jsonPath("$.type", is("discover")))
135+
.andExpect(jsonPath("$.name", is("subjectFirstValue")))
136+
.andExpect(jsonPath("$.facetType", is("hierarchical")))
137+
.andExpect(jsonPath("$.scope", is(emptyOrNullString())))
138+
.andExpect(jsonPath("$._links.self.href",
139+
containsString("api/discover/facets/subjectFirstValue")))
140+
.andExpect(jsonPath("$._embedded.values[0].label", is("People")))
141+
.andExpect(jsonPath("$._embedded.values[0].count", is(3)))
142+
.andExpect(jsonPath("$._embedded.values[1].label", is("Another subject")))
143+
.andExpect(jsonPath("$._embedded.values[1].count", is(1)))
144+
.andExpect(jsonPath("$", JsonPathMatchers.hasNoJsonPath("_embedded.values[2].label")))
145+
.andExpect(jsonPath("$", JsonPathMatchers.hasNoJsonPath("_embedded.values[2].count")))
146+
.andExpect(jsonPath("$._embedded.values").value(Matchers.hasSize(2)));
147+
}
148+
}

dspace/config/spring/api/discovery.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,8 @@
26822682
<property name="sortOrderSidebar" value="COUNT"/>
26832683
<property name="sortOrderFilterPage" value="COUNT"/>
26842684
<property name="splitter" value="::"/>
2685+
<!-- CLARIN: show the whole "A::B" value on the search page, not just its leaf -->
2686+
<property name="skipFirstNodeLevel" value="false"/>
26852687

26862688
</bean>
26872689

0 commit comments

Comments
 (0)