Method: testOclAnyInvoke()

1: /*******************************************************************************
2: * Copyright (c) 2009, 2012 Obeo.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * Obeo - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.acceleo.engine.tests.unit.environment;
12:
13: import static org.junit.Assert.assertEquals;
14: import static org.junit.Assert.fail;
15:
16: import java.util.Map;
17:
18: import org.eclipse.acceleo.engine.tests.unit.AbstractAcceleoTest;
19: import org.junit.Before;
20: import org.junit.Test;
21:
22: /**
23: * This will test the behavior of the Acceleo non standard library's operations when called from a parsed
24: * generator file.
25: *
26: * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
27: */
28: @SuppressWarnings("nls")
29: public class AcceleoNonStandardLibraryParsedTest extends AbstractAcceleoTest {
30:         /** This is the output we expect from each generated file. */
31:         private final static String OUTPUT = "\t\tconstant output" + System.getProperty("line.separator");
32:
33:         /** This will be generated from setup. */
34:         private Map<String, String> generatedPreview;
35:
36:         /**
37:          * {@inheritDoc}
38:          *
39:          * @see org.eclipse.acceleo.engine.tests.unit.AbstractAcceleoTest#getModuleLocation()
40:          */
41:         @Override
42:         public String getModuleLocation() {
43:                 return "data/Library/nonstdlib.mtl";
44:         }
45:
46:         /**
47:          * {@inheritDoc}
48:          *
49:          * @see org.eclipse.acceleo.engine.tests.unit.AbstractAcceleoTest#getReferencePath()
50:          */
51:         @Override
52:         public String getReferencePath() {
53:                 return "NonStandardLibrary";
54:         }
55:
56:         /**
57:          * Tests the behavior of the non standard "ancestors()" operation on OclAny.
58:          */
59:         @Test
60:         public void testOclAnyAncestors() {
61:                 assertFileContainsOutput("test_oclany_ancestors");
62:         }
63:
64:         /**
65:          * Tests the behavior of the non standard "eAllContents()" operation on OclAny.
66:          */
67:         @Test
68:         public void testOclAnyEAllContents() {
69:                 assertFileContainsOutput("test_oclany_eAllContents");
70:         }
71:
72:         /**
73:          * Tests the behavior of the non standard "eInverse()" operation on OclAny.
74:          */
75:         @Test
76:         public void testOclAnyEInverse() {
77:                 assertFileContainsOutput("test_oclany_eInverse");
78:         }
79:
80:         /**
81:          * Tests the behavior of the non standard "invoke()" operation on OclAny.
82:          */
83:         @Test
84:         public void testOclAnyInvoke() {
85:                 assertFileContainsOutput("test_oclany_invoke");
86:         }
87:
88:         /**
89:          * Tests the behavior of the non standard "siblings()" operation on OclAny.
90:          */
91:         @Test
92:         public void testOclAnySiblings() {
93:                 assertFileContainsOutput("test_oclany_siblings");
94:         }
95:
96:         /**
97:          * Tests the behavior of the non standard "toString()" operation on OclAny.
98:          */
99:         @Test
100:         public void testOclAnyToString() {
101:                 assertFileContainsOutput("test_oclany_toString");
102:         }
103:
104:         /**
105:          * Tests the behavior of the non standard "ancestors(OclAny)" operation on OclAny.
106:          */
107:         @Test
108:         public void testOclAnyTypedAncestors() {
109:                 assertFileContainsOutput("test_oclany_typed_eAllContents");
110:         }
111:
112:         /**
113:          * Tests the behavior of the non standard "eAllContents(OclAny)" operation on OclAny.
114:          */
115:         @Test
116:         public void testOclAnyTypedEAllContents() {
117:                 assertFileContainsOutput("test_oclany_typed_eAllContents");
118:         }
119:
120:         /**
121:          * Tests the behavior of the non standard "eInverse(OclAny)" operation on OclAny.
122:          */
123:         @Test
124:         public void testOclAnyTypedEInverse() {
125:                 assertFileContainsOutput("test_oclany_typed_eInverse");
126:         }
127:
128:         /**
129:          * Tests the behavior of the non standard "siblings(OclAny)" operation on OclAny.
130:          */
131:         @Test
132:         public void testOclAnyTypedSiblings() {
133:                 assertFileContainsOutput("test_oclany_typed_siblings");
134:         }
135:
136:         /**
137:          * Tests the behavior of the non standard "lineSeparator(OclAny)" operation on OclAny.
138:          */
139:         @Test
140:         public void testOclAnyLineSeparator() {
141:                 assertFileContainsOutput("test_oclany_line_separator");
142:         }
143:
144:         /**
145:          * Tests the behavior of the non standard "contains(String)" operation on Strings.
146:          */
147:         @Test
148:         public void testStringContains() {
149:                 assertFileContainsOutput("test_string_contains");
150:         }
151:
152:         /**
153:          * Tests the behavior of the non standard "endsWith(String)" operation on Strings.
154:          */
155:         @Test
156:         public void testStringEndsWith() {
157:                 assertFileContainsOutput("test_string_endsWith");
158:         }
159:
160:         /**
161:          * Tests the behavior of the non standard "replace(String, String)" operation on Strings.
162:          */
163:         @Test
164:         public void testStringReplace() {
165:                 assertFileContainsOutput("test_string_replace");
166:         }
167:
168:         /**
169:          * Tests the behavior of the non standard "replaceAll(String, String)" operation on Strings.
170:          */
171:         @Test
172:         public void testStringReplaceAll() {
173:                 assertFileContainsOutput("test_string_replaceAll");
174:         }
175:
176:         /**
177:          * Tests the behavior of the non standard "startsWith(String)" operation on Strings.
178:          */
179:         @Test
180:         public void testStringStartsWith() {
181:                 assertFileContainsOutput("test_string_startsWith");
182:         }
183:
184:         /**
185:          * Tests the behavior of the non standard "substituteAll(String, String)" operation on Strings.
186:          */
187:         @Test
188:         public void testStringSubstituteAll() {
189:                 assertFileContainsOutput("test_string_substituteAll");
190:         }
191:
192:         /**
193:          * Tests the behavior of the non standard "tokenize(String)" operation on Strings.
194:          */
195:         @Test
196:         public void testStringTokenize() {
197:                 assertFileContainsOutput("test_string_tokenize");
198:         }
199:
200:         /**
201:          * Tests the behavior of the non standard "trim()" operation on Strings.
202:          */
203:         @Test
204:         public void testStringTrim() {
205:                 assertFileContainsOutput("test_string_trim");
206:         }
207:
208:         /**
209:          * Tests the behavior of the non standard "index(String, Integer)" operation on Strings.
210:          */
211:         @Test
212:         public void testStringIndex() {
213:                 assertFileContainsOutput("test_string_index");
214:         }
215:
216:         /**
217:          * Tests the behavior of the non standard "lastIndex(String, Integer)" operation on Strings.
218:          */
219:         @Test
220:         public void testStringLastIndex() {
221:                 assertFileContainsOutput("test_string_last_index");
222:         }
223:
224:         /**
225:          * Tests the behavior of the non standard "tokenize()" operation on Strings.
226:          */
227:         @Test
228:         public void testStringTokenize_2() {
229:                 assertFileContainsOutput("test_string_tokenize_2");
230:         }
231:
232:         /**
233:          * Tests the behavior of the non standard "tokenizeLine()" operation on Strings.
234:          */
235:         @Test
236:         public void testStringTokenizeLine() {
237:                 assertFileContainsOutput("test_string_tokenize_line");
238:         }
239:
240:         /**
241:          * Tests the behavior of the non standard "sep(String, String, String)" operation on Collections.
242:          */
243:         @Test
244:         public void testCollectionSep() {
245:                 assertFileContainsOutput("test_collection_sep_3");
246:         }
247:
248:         /**
249:          * Tests the behavior of the non standard "addAll(Collection)" operation on Collections.
250:          */
251:         @Test
252:         public void testCollectionAddAll() {
253:                 assertFileContainsOutput("test_collection_add_all_sequence_1");
254:                 assertFileContainsOutput("test_collection_add_all_sequence_2");
255:                 assertFileContainsOutput("test_collection_add_all_sequence_3");
256:                 assertFileContainsOutput("test_collection_add_all_sequence_4");
257:
258:                 assertFileContainsOutput("test_collection_add_all_ordered_set_1");
259:                 assertFileContainsOutput("test_collection_add_all_ordered_set_2");
260:                 assertFileContainsOutput("test_collection_add_all_ordered_set_3");
261:                 assertFileContainsOutput("test_collection_add_all_ordered_set_4");
262:
263:                 assertFileContainsOutput("test_collection_add_all_set_1");
264:                 assertFileContainsOutput("test_collection_add_all_set_2");
265:                 assertFileContainsOutput("test_collection_add_all_set_3");
266:                 assertFileContainsOutput("test_collection_add_all_set_4");
267:
268:                 assertFileContainsOutput("test_collection_add_all_bag_1");
269:                 assertFileContainsOutput("test_collection_add_all_bag_2");
270:                 assertFileContainsOutput("test_collection_add_all_bag_3");
271:                 assertFileContainsOutput("test_collection_add_all_bag_4");
272:         }
273:
274:         /**
275:          * Tests the behavior of the non standard "removeAll(Collection)" operation on Collections.
276:          */
277:         public void testCollectionRemoveAll() {
278:                 assertFileContainsOutput("test_collection_remove_all_sequence_1");
279:                 assertFileContainsOutput("test_collection_remove_all_sequence_2");
280:                 assertFileContainsOutput("test_collection_remove_all_sequence_3");
281:                 assertFileContainsOutput("test_collection_remove_all_sequence_4");
282:
283:                 assertFileContainsOutput("test_collection_remove_all_ordered_set_1");
284:                 assertFileContainsOutput("test_collection_remove_all_ordered_set_2");
285:                 assertFileContainsOutput("test_collection_remove_all_ordered_set_3");
286:                 assertFileContainsOutput("test_collection_remove_all_ordered_set_4");
287:
288:                 assertFileContainsOutput("test_collection_remove_all_set_1");
289:                 assertFileContainsOutput("test_collection_remove_all_set_2");
290:                 assertFileContainsOutput("test_collection_remove_all_set_3");
291:                 assertFileContainsOutput("test_collection_remove_all_set_4");
292:
293:                 assertFileContainsOutput("test_collection_remove_all_bag_1");
294:                 assertFileContainsOutput("test_collection_remove_all_bag_2");
295:                 assertFileContainsOutput("test_collection_remove_all_bag_3");
296:                 assertFileContainsOutput("test_collection_remove_all_bag_4");
297:         }
298:
299:         /**
300:          * Tests the behavior of the non standard "drop(Integer)" operation on Sequence and OrderedSet.
301:          */
302:         @Test
303:         public void testCollectionDrop() {
304:                 assertFileContainsOutput("test_collection_drop");
305:         }
306:
307:         /**
308:          * Tests the behavior of the non standard "dropRight(Integer)" operation on Sequence and OrderedSet.
309:          */
310:         @Test
311:         public void testCollectionDropRight() {
312:                 assertFileContainsOutput("test_collection_drop_right");
313:         }
314:
315:         /**
316:          * Tests the behavior of the non standard "startsWith(Collection)" operation on Sequence and OrderedSet.
317:          */
318:         @Test
319:         public void testCollectionStartsWith() {
320:                 assertFileContainsOutput("test_collection_starts_with");
321:         }
322:
323:         /**
324:          * Tests the behavior of the non standard "endsWith(Collection)" operation on Sequence and OrderedSet.
325:          */
326:         @Test
327:         public void testCollectionEndsWith() {
328:                 assertFileContainsOutput("test_collection_ends_with");
329:         }
330:
331:         /**
332:          * Tests the behavior of the non standard "indexOfSlice(Collection)" operation on Sequence and OrderedSet.
333:          */
334:         @Test
335:         public void testCollectionIndexOfSlice() {
336:                 assertFileContainsOutput("test_collection_index_of_slice");
337:         }
338:
339:         /**
340:          * Tests the behavior of the non standard "lastIndexOfSlice(Collection)" operation on Sequence and
341:          * OrderedSet.
342:          */
343:         @Test
344:         public void testCollectionLastIndexOfSlice() {
345:                 assertFileContainsOutput("test_collection_last_index_of_slice");
346:         }
347:
348:         /**
349:          * {@inheritDoc}
350:          *
351:          * @see org.eclipse.acceleo.engine.tests.unit.AbstractAcceleoTest#setUp()
352:          */
353:         @Before
354:         @Override
355:         public void setUp() {
356:                 super.setUp();
357:                 this.init("NonStdLib");
358:                 generatedPreview = generate("test_nonstdlib", previewStrategy); //$NON-NLS-1$
359:         }
360:
361:         /**
362:          * This is the only assertion needed for each of the preview files.
363:          *
364:          * @param fileName
365:          * Name of the file on which to run the assertion.
366:          */
367:         private void assertFileContainsOutput(String fileName) {
368:                 boolean fileFound = false;
369:                 for (Map.Entry<String, String> filePreview : generatedPreview.entrySet()) {
370:                         if (filePreview.getKey().endsWith(fileName)) {
371:                                 assertEquals(OUTPUT.trim(), filePreview.getValue().toString().trim());
372:                                 fileFound = true;
373:                         }
374:                 }
375:                 if (!fileFound) {
376:                         fail("expected file hasn't been generated.");
377:                 }
378:         }
379: }