1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package com.gisgraphy.domain.geoloc.service.fulltextsearch;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.fail;
27 import net.sf.jstester.JsTester;
28
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 import com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor;
34 import com.gisgraphy.domain.valueobject.Output.OutputFormat;
35 import com.gisgraphy.test.FeedChecker;
36
37
38 public class FulltextErrorVisitorTest {
39
40 private String errorMessage = "My Message";
41 IoutputFormatVisitor FulltextErrorVisitor;
42
43
44 @Before
45 public void onSetUp() throws Exception {
46 FulltextErrorVisitor = new FulltextErrorVisitor(errorMessage);
47 }
48
49
50 @Test
51 public void fulltextErrorVisitorString() {
52 IoutputFormatVisitor FulltextErrorVisitor = new FulltextErrorVisitor(errorMessage);
53 Assert.assertEquals("The error message is not well set ",errorMessage, FulltextErrorVisitor.getErrorMessage());
54 }
55
56 @Test
57 public void fulltextErrorVisitor() {
58 IoutputFormatVisitor FulltextErrorVisitor = new FulltextErrorVisitor();
59 Assert.assertEquals("An error message should be provided when no message is specified ",IoutputFormatVisitor.DEFAULT_ERROR_MESSAGE, FulltextErrorVisitor.getErrorMessage());
60 }
61
62 @Test
63 public void visitXML() {
64 String result = FulltextErrorVisitor.visitXML(OutputFormat.XML);
65 FeedChecker.checkFulltextErrorXML(result,errorMessage);
66 }
67
68
69 @Test
70 public void visitJSON() {
71 JsTester jsTester = null;
72 IoutputFormatVisitor FulltextErrorVisitor = new FulltextErrorVisitor(errorMessage);
73 String result = FulltextErrorVisitor.visitJSON(OutputFormat.JSON);
74 try {
75 jsTester = new JsTester();
76 jsTester.onSetUp();
77
78
79 jsTester.eval("evalresult= eval(" + result + ");");
80 String error = jsTester.eval("evalresult.responseHeader.error")
81 .toString();
82
83 assertEquals(errorMessage, error);
84
85 error = jsTester.eval("evalresult.responseHeader.status")
86 .toString();
87 Assert.assertEquals("-1.0", error);
88
89
90 } catch (Exception e) {
91 fail("An exception has occured " + e.getMessage());
92 } finally {
93 if (jsTester != null) {
94 jsTester.onTearDown();
95 }
96
97 }
98
99 }
100
101 @Test
102 public void visitPYTHON() {
103 String result = FulltextErrorVisitor.visitPYTHON(OutputFormat.PYTHON);
104 checkErrorMessageIsPresentInOutputStream(result);
105 }
106
107
108
109
110 @Test
111 public void visitRUBY() {
112 String result = FulltextErrorVisitor.visitRUBY(OutputFormat.RUBY);
113 checkErrorMessageIsPresentInOutputStream(result);
114 }
115
116 @Test
117 public void visitPHP() {
118 String result = FulltextErrorVisitor.visitPHP(OutputFormat.PHP);
119 checkErrorMessageIsPresentInOutputStream(result);
120
121 }
122
123 @Test
124 public void visitATOM() {
125 String result = FulltextErrorVisitor.visitATOM(OutputFormat.ATOM);
126
127 FeedChecker.checkFulltextErrorXML(result,errorMessage);
128 }
129
130 @Test
131 public void visitGEORSS() {
132 String result = FulltextErrorVisitor.visitGEORSS(OutputFormat.GEORSS);
133
134 FeedChecker.checkFulltextErrorXML(result,errorMessage);
135 }
136
137 private void checkErrorMessageIsPresentInOutputStream(String result) {
138 Assert.assertTrue("the error Message should contains the error Message", result.contains(errorMessage));
139 }
140
141
142
143
144
145 }