Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/FCSTest.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/FCSTest.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/FCSTest.java	(revision 7172)
@@ -38,4 +38,34 @@
             SRUSimpleClient client, FCSTestHandler handler)
             throws SRUClientException;
+
+
+    protected String escapeCQL(String q) {
+        if (q.contains(" ")) {
+            return "\"" + q + "\"";
+        } else {
+            return q;
+        }
+    }
+
+    
+    protected String escapeFCS(String q) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("\"");
+        for (int i = 0; i < q.length(); i++) {
+            final char ch = q.charAt(i);
+            switch (ch) {
+            case '\\':
+                sb.append("\\\\");
+                break;
+            case '\'':
+                sb.append("\\'");
+                break;
+            default:
+                sb.append(ch);
+            }
+        }
+        sb.append("\"");
+        return sb.toString();
+    }
 
 
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch1.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch1.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch1.java	(revision 7172)
@@ -58,5 +58,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         client.searchRetrieve(req, handler);
         return handler.getDiagnosticCount() == 0
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch10.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch10.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch10.java	(revision 7172)
@@ -58,5 +58,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         req.setStartRecord(Integer.MAX_VALUE);
         client.searchRetrieve(req, handler);
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch11.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch11.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch11.java	(revision 7172)
@@ -58,5 +58,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getUnicodeSearchTerm());
+                escapeCQL(context.getUnicodeSearchTerm()));
         client.searchRetrieve(req, handler);
         return handler.getDiagnosticCount() == 0
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch12.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch12.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch12.java	(revision 7172)
@@ -71,5 +71,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getUserSearchTerm());
+                escapeCQL(context.getUserSearchTerm()));
         req.setRecordSchema(FCS_RECORD_SCHEMA);
         req.setMaximumRecords(5);
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch13.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch13.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch13.java	(revision 7172)
@@ -24,5 +24,4 @@
 import eu.clarin.fcs.tester.FCSTestHandler.SurrogateDiagnostic;
 import eu.clarin.fcs.tester.FCSTestResult;
-import eu.clarin.sru.client.SRUClientConstants;
 import eu.clarin.sru.client.SRUClientException;
 import eu.clarin.sru.client.SRUDiagnostic;
@@ -30,4 +29,5 @@
 import eu.clarin.sru.client.SRUSimpleClient;
 import eu.clarin.sru.client.SRUSurrogateRecordData;
+import eu.clarin.sru.client.fcs.ClarinFCSConstants;
 import eu.clarin.sru.client.fcs.ClarinFCSRecordData;
 import eu.clarin.sru.client.fcs.DataView;
@@ -69,6 +69,6 @@
             FCSTestHandler handler) throws SRUClientException {
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
-        req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getUserSearchTerm());
+        req.setQuery(ClarinFCSConstants.QUERY_TYPE_CQL,
+                escapeCQL(context.getUserSearchTerm()));
         req.setRecordSchema(FCS_RECORD_SCHEMA);
         req.setMaximumRecords(5);
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch14.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch14.java	(revision 7172)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch14.java	(revision 7172)
@@ -0,0 +1,167 @@
+/**
+ * This software is copyright (c) 2013 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.fcs.tester.tests;
+
+import eu.clarin.fcs.tester.FCSTest;
+import eu.clarin.fcs.tester.FCSTestCase;
+import eu.clarin.fcs.tester.FCSTestContext;
+import eu.clarin.fcs.tester.FCSTestProfile;
+import eu.clarin.fcs.tester.FCSTestHandler;
+import eu.clarin.fcs.tester.FCSTestHandler.SurrogateDiagnostic;
+import eu.clarin.fcs.tester.FCSTestResult;
+import eu.clarin.sru.client.SRUClientException;
+import eu.clarin.sru.client.SRUDiagnostic;
+import eu.clarin.sru.client.SRUSearchRetrieveRequest;
+import eu.clarin.sru.client.SRUSimpleClient;
+import eu.clarin.sru.client.SRUSurrogateRecordData;
+import eu.clarin.sru.client.fcs.ClarinFCSConstants;
+import eu.clarin.sru.client.fcs.ClarinFCSRecordData;
+import eu.clarin.sru.client.fcs.DataView;
+import eu.clarin.sru.client.fcs.DataViewAdvanced;
+import eu.clarin.sru.client.fcs.DataViewHits;
+import eu.clarin.sru.client.fcs.Resource;
+import eu.clarin.sru.client.fcs.Resource.ResourceFragment;
+
+@FCSTestCase(priority=4100, profiles = {
+        FCSTestProfile.CLARIN_FCS_2_0
+})
+public class TestSearch14 extends FCSTest {
+    private static final String FCS_RECORD_SCHEMA =
+            ClarinFCSRecordData.RECORD_SCHEMA;
+
+    @Override
+    public String getName() {
+        return "SearchRetrieve";
+    }
+
+
+    @Override
+    public String getDescription() {
+        return "Advanced-Search for user specified search term and " +
+                "requesting endpoint to return results in CLARIN-FCS " +
+                "record schema '" + FCS_RECORD_SCHEMA + "'";
+    }
+
+
+    @Override
+    public String getExpected() {
+        return "Expecting at least one record in CLARIN-FCS record " +
+                "schema (without any surrogate diagnostics)";
+    }
+
+
+    @Override
+    public FCSTestResult perform(FCSTestContext context, SRUSimpleClient client,
+            FCSTestHandler handler) throws SRUClientException {
+        SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
+        req.setQuery(ClarinFCSConstants.QUERY_TYPE_FCS,
+                escapeFCS(context.getUserSearchTerm()));
+        req.setRecordSchema(FCS_RECORD_SCHEMA);
+        req.setMaximumRecords(5);
+        client.searchRetrieve(req, handler);
+        if (handler.findDiagnostic("info:srw/diagnostic/1/66")) {
+            return makeError("Endpoint claims to not " +
+                    "support FCS record schema (" + FCS_RECORD_SCHEMA + ")");
+        } else if (handler.getRecordCount() == 0) {
+            return makeWarning("Endpoint has no results " +"" +
+                    "for search term \"" + context.getUserSearchTerm() +
+                    "\". Please supply a different search term.");
+        } else {
+            for (FCSTestHandler.Record record : handler.getRecords()) {
+                String recordSchema = record.getData().getRecordSchema();
+                if (SRUSurrogateRecordData.RECORD_SCHEMA.equals(recordSchema)) {
+                    final SurrogateDiagnostic data =
+                            (SurrogateDiagnostic) record.getData();
+                    final SRUDiagnostic d = data.getDiagnostic();
+
+                    if (data.isDiagnostic("info:srw/diagnostic/1/67")) {
+                        return makeError("Endpoint cannot render record in " +
+                                "CLARIN-FCS record format and returned " +
+                                "surrogate diagnostic \"info:srw/diagnostic/1/67\" " +
+                                "instead.");
+                    } else if (data.isDiagnostic("info:clarin/sru/diagnostic/2")) {
+                        return makeError("Endpoint sent one or more records with record " +
+                                        "schema of '" + d.getDetails() +
+                                        "' instead of '" + FCS_RECORD_SCHEMA +
+                                        "'.");
+                    } else {
+                        StringBuilder sb = new StringBuilder();
+                        sb.append("Endpoint returned unexpected surrgogate ")
+                                .append("diagnostic \"")
+                                .append(d.getURI()).append("\"");
+                        if (d.getDetails() != null) {
+                            sb.append("; details = \"")
+                                .append(d.getDetails()).append("\"");
+                        }
+                        if (d.getMessage() != null) {
+                            sb.append("; message = \"")
+                                .append(d.getMessage()).append("\"");
+                        }
+                        return makeError(sb.toString());
+                    }
+                } else if (FCS_RECORD_SCHEMA.equals(recordSchema)) {
+                    final ClarinFCSRecordData data =
+                            (ClarinFCSRecordData) record.getData();
+                    final Resource resource = data.getResource();
+                    boolean foundHits = false;
+                    boolean foundAdv  = false;
+                    if (resource.hasDataViews()) {
+                        for (DataView dataView : resource.getDataViews()) {
+                            if (dataView.isMimeType(DataViewHits.TYPE)) {
+                                foundHits = true;
+                            }
+                            if (dataView.isMimeType(DataViewAdvanced.TYPE)) {
+                                foundAdv = true;
+                            }
+                        }
+                    }
+
+                    if (resource.hasResourceFragments()) {
+                        for (ResourceFragment fragment : resource.getResourceFragments()) {
+                            for (DataView dataView : fragment.getDataViews()) {
+                                if (dataView.isMimeType(DataViewHits.TYPE)) {
+                                    foundHits = true;
+                                }
+                                if (dataView.isMimeType(DataViewAdvanced.TYPE)) {
+                                    foundAdv = true;
+                                }
+                            }
+                        }
+                    }
+                    if (!(foundHits && foundAdv)) {
+                        return makeError("Endpoint did not provide mandatory HITS and Advanced (ADV) dataviews in results");
+                    } else if (!foundHits) {
+                        return makeError("Endpoint did not provide mandatory HITS dataview in results");
+                    } else if (!foundAdv) {
+                        return makeError("Endpoint did not provide mandatory Advanced (ADV) dataview in results");
+                    }
+                } else {
+                    return makeError("Endpoint does not supply results in FCS record schema (" + FCS_RECORD_SCHEMA + "\"");
+                }
+            }
+            if (handler.getRecordCount() > req.getMaximumRecords()) {
+                return makeError("Endpoint did not honor upper requested limit for " +
+                                "\"maximumRecords\" parameter (up to " +
+                                req.getMaximumRecords() +
+                                " records where requested and endpoint delivered " +
+                                handler.getRecordCount() + " results)");
+            }
+            return makeSuccess();
+        }
+    }
+
+}
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch2.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch2.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch2.java	(revision 7172)
@@ -60,5 +60,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         req.setRecordSchema(ClarinFCSRecordData.RECORD_SCHEMA);
         client.searchRetrieve(req, handler);
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch4.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch4.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch4.java	(revision 7172)
@@ -59,5 +59,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         req.setExtraRequestData(
                 SRUSearchRetrieveRequest.X_MALFORMED_RECORD_XML_ESCAPING, "invalid");
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch5.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch5.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch5.java	(revision 7172)
@@ -59,5 +59,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         req.setExtraRequestData(
                 SRUSearchRetrieveRequest.X_MALFORMED_START_RECORD, "invalid");
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch6.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch6.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch6.java	(revision 7172)
@@ -59,5 +59,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         req.setExtraRequestData(
                 SRUSearchRetrieveRequest.X_MALFORMED_START_RECORD, "0");
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch7.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch7.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch7.java	(revision 7172)
@@ -59,5 +59,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         req.setExtraRequestData(
                 SRUSearchRetrieveRequest.X_MALFORMED_MAXIMUM_RECORDS, "invalid");
Index: FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch8.java
===================================================================
--- FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch8.java	(revision 7170)
+++ FCSEndpointTester/trunk/src/main/java/eu/clarin/fcs/tester/tests/TestSearch8.java	(revision 7172)
@@ -59,5 +59,5 @@
         SRUSearchRetrieveRequest req = context.createSearchRetrieveRequest();
         req.setQuery(SRUClientConstants.QUERY_TYPE_CQL,
-                context.getRandomSearchTerm());
+                escapeCQL(context.getRandomSearchTerm()));
         req.setExtraRequestData(
                 SRUSearchRetrieveRequest.X_MALFORMED_MAXIMUM_RECORDS, "-1");
