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 | */ |
---|
17 | package eu.clarin.fcs.tester; |
---|
18 | |
---|
19 | import java.util.List; |
---|
20 | import java.util.logging.LogRecord; |
---|
21 | |
---|
22 | |
---|
23 | import eu.clarin.sru.client.SRUClientException; |
---|
24 | import eu.clarin.sru.client.SRUSimpleClient; |
---|
25 | |
---|
26 | |
---|
27 | public abstract class FCSTest { |
---|
28 | public abstract String getName(); |
---|
29 | |
---|
30 | |
---|
31 | public abstract String getDescription(); |
---|
32 | |
---|
33 | |
---|
34 | public abstract String getExpected(); |
---|
35 | |
---|
36 | |
---|
37 | public abstract FCSTestResult perform(FCSTestContext context, |
---|
38 | SRUSimpleClient client, FCSTestHandler handler) |
---|
39 | throws SRUClientException; |
---|
40 | |
---|
41 | |
---|
42 | protected String escapeCQL(String q) { |
---|
43 | if (q.contains(" ")) { |
---|
44 | return "\"" + q + "\""; |
---|
45 | } else { |
---|
46 | return q; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | protected String escapeFCS(String q) { |
---|
52 | StringBuilder sb = new StringBuilder(); |
---|
53 | sb.append("\""); |
---|
54 | for (int i = 0; i < q.length(); i++) { |
---|
55 | final char ch = q.charAt(i); |
---|
56 | switch (ch) { |
---|
57 | case '\\': |
---|
58 | sb.append("\\\\"); |
---|
59 | break; |
---|
60 | case '\'': |
---|
61 | sb.append("\\'"); |
---|
62 | break; |
---|
63 | default: |
---|
64 | sb.append(ch); |
---|
65 | } |
---|
66 | } |
---|
67 | sb.append("\""); |
---|
68 | return sb.toString(); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | protected FCSTestResult makeSuccess() { |
---|
73 | return new FCSTestResult(this, FCSTestResult.Code.SUCCESS, |
---|
74 | "The test case was processed successfully"); |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | protected FCSTestResult makeWarning(String message) { |
---|
79 | return new FCSTestResult(this, FCSTestResult.Code.WARNING, message); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | protected FCSTestResult makeWarningUnexpectedDiagnostics() { |
---|
84 | return new FCSTestResult(this, FCSTestResult.Code.WARNING, |
---|
85 | "One or more unexpected diagnostic reported by endpoint"); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | protected FCSTestResult makeGenericError() { |
---|
90 | return new FCSTestResult(this, FCSTestResult.Code.ERROR, |
---|
91 | "Something went wrong"); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | protected FCSTestResult makeError(String message) { |
---|
96 | return new FCSTestResult(this, FCSTestResult.Code.ERROR, message); |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | protected FCSTestResult makeError(List<LogRecord> records) { |
---|
101 | return new FCSTestResult(this, FCSTestResult.Code.ERROR, |
---|
102 | "An error occurred while processing the test case", records); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | protected FCSTestResult makeErrorNoDiagnostic(String diagnostic) { |
---|
107 | return new FCSTestResult(this, FCSTestResult.Code.ERROR, String.format( |
---|
108 | "Endpoint did not report expected diagnostic: %s", diagnostic)); |
---|
109 | } |
---|
110 | |
---|
111 | } // class FCSTest |
---|