28
28
import org .antlr .runtime .RecognitionException ;
29
29
import org .junit .Before ;
30
30
import org .junit .Test ;
31
+ import org .metafacture .commons .reflection .ReflectionException ;
31
32
import org .metafacture .flux .parser .FluxProgramm ;
32
- import org .metafacture .framework .MetafactureException ;
33
33
34
34
/**
35
35
* Tests for the Flux grammar.
@@ -91,7 +91,7 @@ public void shouldReplaceJavaEscapeSequences()
91
91
}
92
92
93
93
@ Test (expected = FluxParseException .class )
94
- public void issue421_shouldThrowRuntimeExceptionWhenSemicolonInFlowIsMissing ()
94
+ public void issue421_shouldThrowFluxParseExceptionWhenSemicolonInFlowIsMissing ()
95
95
throws RecognitionException , IOException {
96
96
final String script = "\" test\" |print" ;
97
97
try {
@@ -102,18 +102,91 @@ public void issue421_shouldThrowRuntimeExceptionWhenSemicolonInFlowIsMissing()
102
102
}
103
103
}
104
104
105
- @ Test (expected = RuntimeException .class )
106
- public void issue421_shouldThrowRuntimeExceptionWhenSemicolonInVarDefIsMissing ()
105
+ @ Test (expected = FluxParseException .class )
106
+ public void issue421_shouldThrowFluxParseExceptionWhenSemicolonInVarDefIsMissing ()
107
107
throws RecognitionException , IOException {
108
108
final String script = "foo=42" ;
109
109
try {
110
110
FluxCompiler .compile (createInputStream (script ), emptyMap ());
111
- } catch (RuntimeException re ) {
111
+ } catch (FluxParseException re ) {
112
112
assertEquals ("mismatched input '<EOF>' expecting ';' in Flux" , re .getMessage ());
113
113
throw re ;
114
114
}
115
115
}
116
116
117
+ @ Test (expected = ReflectionException .class )
118
+ public void issue421_shouldThrowReflectionExceptionWhenCommandIsNotFound ()
119
+ throws RecognitionException , IOException {
120
+ final String script = "\" test\" |prin;" ;
121
+ try {
122
+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
123
+ } catch (ReflectionException re ) {
124
+ assertEquals ("Class not found: prin" , re .getMessage ());
125
+ throw re ;
126
+ }
127
+ }
128
+
129
+ @ Test (expected = FluxParseException .class )
130
+ public void issue421_shouldThrowFluxParseExceptionWhenInputIsMissingAfterPipe1 ()
131
+ throws RecognitionException , IOException {
132
+ final String script = "\" test\" |" ;
133
+ try {
134
+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
135
+ } catch (FluxParseException re ) {
136
+ assertEquals ("no viable alternative at input '<EOF>' in Flux" , re .getMessage ());
137
+ throw re ;
138
+ }
139
+ }
140
+
141
+ @ Test (expected = FluxParseException .class )
142
+ public void issue421_shouldThrowFluxParseExceptionWhenInputIsMissingAfterPipe2 ()
143
+ throws RecognitionException , IOException {
144
+ final String script = "\" test\" |;" ;
145
+ try {
146
+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
147
+ } catch (FluxParseException re ) {
148
+ assertEquals ("no viable alternative at input ';' in Flux" , re .getMessage ());
149
+ throw re ;
150
+ }
151
+ }
152
+
153
+ @ Test (expected = FluxParseException .class )
154
+ public void issue421_shouldThrowFluxParseExceptionWhenTeeStructureOccursWithouATeeCommand ()
155
+ throws RecognitionException , IOException {
156
+ final String script = "\" test\" |{print}{print} ;" ;
157
+ try {
158
+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
159
+ } catch (FluxParseException re ) {
160
+ assertEquals ("Flow cannot be split without a tee-element." , re .getMessage ());
161
+ throw re ;
162
+ }
163
+ }
164
+
165
+ @ Test (expected = FluxParseException .class )
166
+ public void issue421_shouldThrowFluxParseExceptionWhenTeeIsNotASender ()
167
+ throws RecognitionException , IOException {
168
+ final String script = "\" test\" |print|object-tee|{print}{print} ;" ;
169
+ try {
170
+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
171
+ } catch (FluxParseException re ) {
172
+ assertEquals ("org.metafacture.io.ObjectStdoutWriter is not a sender" , re .getMessage ());
173
+ throw re ;
174
+ }
175
+ }
176
+
177
+ @ Test (expected = FluxParseException .class )
178
+ public void issue421_shouldInsertMissingSymbolsWhenTeeIsStructurallyInvalid ()
179
+ throws RecognitionException , IOException {
180
+ final String script = "\" test\" |object-tee|{object-tee{print{print} ;" ;
181
+ try {
182
+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
183
+ String tmp =stdoutBuffer .toString ();
184
+ } catch (FluxParseException re ) {
185
+ assertEquals ("missing '}' at '{' in Flux" , re .getMessage ());
186
+ throw re ;
187
+ }
188
+ }
189
+
117
190
private ByteArrayInputStream createInputStream (String script ) {
118
191
return new ByteArrayInputStream (script .getBytes (StandardCharsets .UTF_8 ));
119
192
}
0 commit comments