source: FCSEndpointTester/tags/FCSEndpointTester-1.0.0/src/main/java/eu/clarin/fcs/tester/tests/TestSearch14.java @ 7180

Last change on this file since 7180 was 7180, checked in by Oliver Schonefeld, 6 years ago
  • tag version 1.0.0
File size: 7.8 KB
Line 
1/**
2 * This software is copyright (c) 2013 by
3 *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
4 * This is free software. You can redistribute it
5 * and/or modify it under the terms described in
6 * the GNU General Public License v3 of which you
7 * should have received a copy. Otherwise you can download
8 * it from
9 *
10 *   http://www.gnu.org/licenses/gpl-3.0.txt
11 *
12 * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
13 *
14 * @license http://www.gnu.org/licenses/gpl-3.0.txt
15 *  GNU General Public License v3
16 */
17package eu.clarin.fcs.tester.tests;
18
19import eu.clarin.fcs.tester.FCSTest;
20import eu.clarin.fcs.tester.FCSTestCase;
21import eu.clarin.fcs.tester.FCSTestContext;
22import eu.clarin.fcs.tester.FCSTestProfile;
23import eu.clarin.fcs.tester.FCSTestHandler;
24import eu.clarin.fcs.tester.FCSTestHandler.SurrogateDiagnostic;
25import eu.clarin.fcs.tester.FCSTestResult;
26import eu.clarin.sru.client.SRUClientException;
27import eu.clarin.sru.client.SRUDiagnostic;
28import eu.clarin.sru.client.SRUSearchRetrieveRequest;
29import eu.clarin.sru.client.SRUSimpleClient;
30import eu.clarin.sru.client.SRUSurrogateRecordData;
31import eu.clarin.sru.client.fcs.ClarinFCSConstants;
32import eu.clarin.sru.client.fcs.ClarinFCSRecordData;
33import eu.clarin.sru.client.fcs.DataView;
34import eu.clarin.sru.client.fcs.DataViewAdvanced;
35import eu.clarin.sru.client.fcs.DataViewHits;
36import eu.clarin.sru.client.fcs.Resource;
37import eu.clarin.sru.client.fcs.Resource.ResourceFragment;
38
39@FCSTestCase(priority=4100, profiles = {
40        FCSTestProfile.CLARIN_FCS_2_0
41})
42public class TestSearch14 extends FCSTest {
43    private static final String FCS_RECORD_SCHEMA =
44            ClarinFCSRecordData.RECORD_SCHEMA;
45
46    @Override
47    public String getName() {
48        return "SearchRetrieve";
49    }
50
51
52    @Override
53    public String getDescription() {
54        return "Advanced-Search for user specified search term and " +
55                "requesting endpoint to return results in CLARIN-FCS " +
56                "record schema '" + FCS_RECORD_SCHEMA + "'";
57    }
58
59
60    @Override
61    public String getExpected() {
62        return "Expecting at least one record in CLARIN-FCS record " +
63                "schema (without any surrogate diagnostics)";
64    }
65
66
67    @Override
68    public FCSTestResult perform(FCSTestContext context, SRUSimpleClient client,
69            FCSTestHandler handler) throws SRUClientException {
70        SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
71        req.setQuery(ClarinFCSConstants.QUERY_TYPE_FCS,
72                escapeFCS(context.getUserSearchTerm()));
73        req.setRecordSchema(FCS_RECORD_SCHEMA);
74        req.setMaximumRecords(5);
75        client.searchRetrieve(req, handler);
76        if (handler.findDiagnostic("info:srw/diagnostic/1/66")) {
77            return makeError("Endpoint claims to not " +
78                    "support FCS record schema (" + FCS_RECORD_SCHEMA + ")");
79        } else if (handler.getRecordCount() == 0) {
80            return makeWarning("Endpoint has no results " +"" +
81                    "for search term \"" + context.getUserSearchTerm() +
82                    "\". Please supply a different search term.");
83        } else {
84            for (FCSTestHandler.Record record : handler.getRecords()) {
85                String recordSchema = record.getData().getRecordSchema();
86                if (SRUSurrogateRecordData.RECORD_SCHEMA.equals(recordSchema)) {
87                    final SurrogateDiagnostic data =
88                            (SurrogateDiagnostic) record.getData();
89                    final SRUDiagnostic d = data.getDiagnostic();
90
91                    if (data.isDiagnostic("info:srw/diagnostic/1/67")) {
92                        return makeError("Endpoint cannot render record in " +
93                                "CLARIN-FCS record format and returned " +
94                                "surrogate diagnostic \"info:srw/diagnostic/1/67\" " +
95                                "instead.");
96                    } else if (data.isDiagnostic("info:clarin/sru/diagnostic/2")) {
97                        return makeError("Endpoint sent one or more records with record " +
98                                        "schema of '" + d.getDetails() +
99                                        "' instead of '" + FCS_RECORD_SCHEMA +
100                                        "'.");
101                    } else {
102                        StringBuilder sb = new StringBuilder();
103                        sb.append("Endpoint returned unexpected surrgogate ")
104                                .append("diagnostic \"")
105                                .append(d.getURI()).append("\"");
106                        if (d.getDetails() != null) {
107                            sb.append("; details = \"")
108                                .append(d.getDetails()).append("\"");
109                        }
110                        if (d.getMessage() != null) {
111                            sb.append("; message = \"")
112                                .append(d.getMessage()).append("\"");
113                        }
114                        return makeError(sb.toString());
115                    }
116                } else if (FCS_RECORD_SCHEMA.equals(recordSchema)) {
117                    final ClarinFCSRecordData data =
118                            (ClarinFCSRecordData) record.getData();
119                    final Resource resource = data.getResource();
120                    boolean foundHits = false;
121                    boolean foundAdv  = false;
122                    if (resource.hasDataViews()) {
123                        for (DataView dataView : resource.getDataViews()) {
124                            if (dataView.isMimeType(DataViewHits.TYPE)) {
125                                foundHits = true;
126                            }
127                            if (dataView.isMimeType(DataViewAdvanced.TYPE)) {
128                                foundAdv = true;
129                            }
130                        }
131                    }
132
133                    if (resource.hasResourceFragments()) {
134                        for (ResourceFragment fragment : resource.getResourceFragments()) {
135                            for (DataView dataView : fragment.getDataViews()) {
136                                if (dataView.isMimeType(DataViewHits.TYPE)) {
137                                    foundHits = true;
138                                }
139                                if (dataView.isMimeType(DataViewAdvanced.TYPE)) {
140                                    foundAdv = true;
141                                }
142                            }
143                        }
144                    }
145                    if (!(foundHits && foundAdv)) {
146                        return makeError("Endpoint did not provide mandatory HITS and Advanced (ADV) dataviews in results");
147                    } else if (!foundHits) {
148                        return makeError("Endpoint did not provide mandatory HITS dataview in results");
149                    } else if (!foundAdv) {
150                        return makeError("Endpoint did not provide mandatory Advanced (ADV) dataview in results");
151                    }
152                } else {
153                    return makeError("Endpoint does not supply results in FCS record schema (" + FCS_RECORD_SCHEMA + "\"");
154                }
155            }
156            if (handler.getRecordCount() > req.getMaximumRecords()) {
157                return makeError("Endpoint did not honor upper requested limit for " +
158                                "\"maximumRecords\" parameter (up to " +
159                                req.getMaximumRecords() +
160                                " records where requested and endpoint delivered " +
161                                handler.getRecordCount() + " results)");
162            }
163            return makeSuccess();
164        }
165    }
166
167}
Note: See TracBrowser for help on using the repository browser.