|
8 | 8 | package org.dspace.discovery;
|
9 | 9 |
|
10 | 10 | import static org.dspace.discovery.SolrServiceWorkspaceWorkflowRestrictionPlugin.DISCOVER_WORKSPACE_CONFIGURATION_NAME;
|
| 11 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 12 | +import static org.hamcrest.Matchers.hasItem; |
| 13 | +import static org.hamcrest.Matchers.not; |
| 14 | +import static org.hamcrest.Matchers.startsWith; |
11 | 15 | import static org.junit.Assert.assertEquals;
|
12 | 16 | import static org.junit.Assert.assertFalse;
|
13 | 17 | import static org.junit.Assert.assertTrue;
|
|
21 | 25 | import java.util.stream.Collectors;
|
22 | 26 | import javax.servlet.http.HttpServletRequest;
|
23 | 27 |
|
| 28 | +import org.apache.solr.client.solrj.SolrQuery; |
| 29 | +import org.apache.solr.client.solrj.SolrServerException; |
| 30 | +import org.apache.solr.client.solrj.response.QueryResponse; |
| 31 | +import org.apache.solr.common.SolrDocument; |
24 | 32 | import org.dspace.AbstractIntegrationTestWithDatabase;
|
25 | 33 | import org.dspace.app.launcher.ScriptLauncher;
|
26 | 34 | import org.dspace.app.scripts.handler.impl.TestDSpaceRunnableHandler;
|
@@ -99,6 +107,9 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
|
99 | 107 | MetadataAuthorityService metadataAuthorityService = ContentAuthorityServiceFactory.getInstance()
|
100 | 108 | .getMetadataAuthorityService();
|
101 | 109 |
|
| 110 | + SolrSearchCore solrSearchCore = DSpaceServicesFactory.getInstance().getServiceManager() |
| 111 | + .getServicesByType(SolrSearchCore.class).get(0); |
| 112 | + |
102 | 113 | @Override
|
103 | 114 | @Before
|
104 | 115 | public void setUp() throws Exception {
|
@@ -799,6 +810,108 @@ public void searchWithDefaultSortServiceTest() throws SearchServiceException {
|
799 | 810 | }
|
800 | 811 | }
|
801 | 812 |
|
| 813 | + /** |
| 814 | + * Test designed to check if metadatavalues with securitylevel are indexed. |
| 815 | + * @throws SearchServiceException |
| 816 | + */ |
| 817 | + @Test |
| 818 | + public void searchWithMaxSecurityLevelSetTest() throws SearchServiceException { |
| 819 | + |
| 820 | + configurationService.setProperty("discovery.index.securitylevel.maxlevel", 0); |
| 821 | + DiscoveryConfiguration defaultConf = SearchUtils.getDiscoveryConfiguration(context, "default", null); |
| 822 | + |
| 823 | + // Populate the testing objects: create items in eperson's workspace and perform search in it |
| 824 | + int numberItems = 10; |
| 825 | + context.turnOffAuthorisationSystem(); |
| 826 | + EPerson submitter = null; |
| 827 | + try { |
| 828 | + submitter = EPersonBuilder. createEPerson( context). withEmail( "[email protected]") |
| 829 | + .withNameInMetadata("Peter", "Funny").build(); |
| 830 | + } catch (SQLException e) { |
| 831 | + throw new RuntimeException(e); |
| 832 | + } |
| 833 | + context.setCurrentUser(submitter); |
| 834 | + Community community = CommunityBuilder.createCommunity(context).build(); |
| 835 | + Collection collection = CollectionBuilder.createCollection(context, community).build(); |
| 836 | + for (int i = 0; i < numberItems; i++) { |
| 837 | + ItemBuilder.createItem(context, collection) |
| 838 | + .withTitle("item " + i) |
| 839 | + .withSecuredMetadata("dc", "description", "abstract", "secured" + i + ".", 1) |
| 840 | + .withSecuredMetadata("dc", "description", "abstract", "secured" + i + ".", 2) |
| 841 | + .withSecuredMetadata("dc", "description", "abstract", "nonsecured" + i + ".", 0) |
| 842 | + .build(); |
| 843 | + } |
| 844 | + context.restoreAuthSystemState(); |
| 845 | + |
| 846 | + // Build query with default parameters (except for workspaceConf) |
| 847 | + QueryResponse result = null; |
| 848 | + try { |
| 849 | + result = solrSearchCore.getSolr().query(new SolrQuery(String.format( |
| 850 | + "search.resourcetype:\"Item\""))); |
| 851 | + } catch (SolrServerException e) { |
| 852 | + throw new RuntimeException(e); |
| 853 | + } catch (IOException e) { |
| 854 | + throw new RuntimeException(e); |
| 855 | + } |
| 856 | + assertEquals(result.getResults().size(), numberItems); |
| 857 | + for (SolrDocument doc : result.getResults()) { |
| 858 | + assertThat(doc.getFieldNames(), hasItem("dc.description.abstract")); |
| 859 | + assertThat(doc.getFieldValues("dc.description.abstract"), not(hasItem(startsWith("secured")))); |
| 860 | + assertThat(doc.getFieldValues("dc.description.abstract"), hasItem(startsWith("nonsecured"))); |
| 861 | + } |
| 862 | + } |
| 863 | + |
| 864 | + /** |
| 865 | + * Test designed to check if metadatavalues with securitylevel greater than 0 are indexed. |
| 866 | + * @throws SearchServiceException |
| 867 | + */ |
| 868 | + @Test |
| 869 | + public void searchWithMaxSecurityLevelGreater1SetTest() throws SearchServiceException { |
| 870 | + |
| 871 | + configurationService.setProperty("discovery.index.securitylevel.maxlevel", 1); |
| 872 | + DiscoveryConfiguration defaultConf = SearchUtils.getDiscoveryConfiguration(context, "default", null); |
| 873 | + |
| 874 | + // Populate the testing objects: create items in eperson's workspace and perform search in it |
| 875 | + int numberItems = 10; |
| 876 | + context.turnOffAuthorisationSystem(); |
| 877 | + EPerson submitter = null; |
| 878 | + try { |
| 879 | + submitter = EPersonBuilder. createEPerson( context). withEmail( "[email protected]") |
| 880 | + .withNameInMetadata("Peter", "Funny").build(); |
| 881 | + } catch (SQLException e) { |
| 882 | + throw new RuntimeException(e); |
| 883 | + } |
| 884 | + context.setCurrentUser(submitter); |
| 885 | + Community community = CommunityBuilder.createCommunity(context).build(); |
| 886 | + Collection collection = CollectionBuilder.createCollection(context, community).build(); |
| 887 | + for (int i = 0; i < numberItems; i++) { |
| 888 | + ItemBuilder.createItem(context, collection) |
| 889 | + .withTitle("item " + i) |
| 890 | + .withSecuredMetadata("dc", "description", "abstract", "nonsecured" + i + ".", 1) |
| 891 | + .withSecuredMetadata("dc", "description", "abstract", "secured" + i + ".", 2) |
| 892 | + .withSecuredMetadata("dc", "description", "abstract", "nonsecured" + i + ".", 0) |
| 893 | + .build(); |
| 894 | + } |
| 895 | + context.restoreAuthSystemState(); |
| 896 | + |
| 897 | + // Build query with default parameters (except for workspaceConf) |
| 898 | + QueryResponse result = null; |
| 899 | + try { |
| 900 | + result = solrSearchCore.getSolr().query(new SolrQuery(String.format( |
| 901 | + "search.resourcetype:\"Item\""))); |
| 902 | + } catch (SolrServerException e) { |
| 903 | + throw new RuntimeException(e); |
| 904 | + } catch (IOException e) { |
| 905 | + throw new RuntimeException(e); |
| 906 | + } |
| 907 | + assertEquals(result.getResults().size(), numberItems); |
| 908 | + for (SolrDocument doc : result.getResults()) { |
| 909 | + assertThat(doc.getFieldNames(), hasItem("dc.description.abstract")); |
| 910 | + assertThat(doc.getFieldValues("dc.description.abstract"), not(hasItem(startsWith("secured")))); |
| 911 | + assertThat(doc.getFieldValues("dc.description.abstract"), hasItem(startsWith("nonsecured"))); |
| 912 | + } |
| 913 | + } |
| 914 | + |
802 | 915 | private void assertSearchQuery(String resourceType, int size) throws SearchServiceException {
|
803 | 916 | assertSearchQuery(resourceType, size, size, 0, -1);
|
804 | 917 | }
|
|
0 commit comments