View Javadoc
1   package de.fhdw.wtf.parser.testWithScanner;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.assertTrue;
5   import static org.junit.Assert.fail;
6   
7   import java.util.Iterator;
8   import java.util.Vector;
9   
10  import org.junit.Before;
11  import org.junit.Test;
12  
13  import de.fhdw.wtf.common.ast.Attribute;
14  import de.fhdw.wtf.common.ast.AttributeModifier;
15  import de.fhdw.wtf.common.ast.Constructor;
16  import de.fhdw.wtf.common.ast.Group;
17  import de.fhdw.wtf.common.ast.GroupElement;
18  import de.fhdw.wtf.common.ast.Model;
19  import de.fhdw.wtf.common.ast.Name;
20  import de.fhdw.wtf.common.ast.Operation;
21  import de.fhdw.wtf.common.ast.UnqualifiedName;
22  import de.fhdw.wtf.common.ast.type.ByNameState;
23  import de.fhdw.wtf.common.ast.type.ClassModifier;
24  import de.fhdw.wtf.common.ast.type.ClassModifierService;
25  import de.fhdw.wtf.common.ast.type.ClassModifierTransient;
26  import de.fhdw.wtf.common.ast.type.ClassType;
27  import de.fhdw.wtf.common.ast.type.MapType;
28  import de.fhdw.wtf.common.ast.type.ProductElementType;
29  import de.fhdw.wtf.common.ast.type.ProductType;
30  import de.fhdw.wtf.common.ast.type.RegularClassType;
31  import de.fhdw.wtf.common.ast.type.SumType;
32  import de.fhdw.wtf.common.ast.type.Type;
33  import de.fhdw.wtf.common.ast.type.TypeProxy;
34  import de.fhdw.wtf.common.exception.parser.AbstractParserException;
35  import de.fhdw.wtf.common.exception.parser.NoCurlyBracketCloseException;
36  import de.fhdw.wtf.common.exception.parser.NoValidTokenStreamException;
37  import de.fhdw.wtf.common.stream.FilteredTokenStream;
38  import de.fhdw.wtf.common.stream.SimpleScannerInput;
39  import de.fhdw.wtf.common.stream.TokenStream;
40  import de.fhdw.wtf.common.token.IdentifierToken;
41  import de.fhdw.wtf.common.token.Position;
42  import de.fhdw.wtf.common.token.keywords.AbstractToken;
43  import de.fhdw.wtf.common.token.keywords.GroupToken;
44  import de.fhdw.wtf.common.token.keywords.VisitableToken;
45  import de.fhdw.wtf.common.token.symbols.BracketOpenToken;
46  import de.fhdw.wtf.common.token.symbols.CurlyBracketOpenToken;
47  import de.fhdw.wtf.dsl.scanner.common.Scanner;
48  import de.fhdw.wtf.dsl.scanner.modelScanner.ModelDslScanner;
49  import de.fhdw.wtf.parser.Parser;
50  
51  /**
52   * Test the scanning an parsing of different Types.
53   */
54  public class TestTypes {
55  	
56  	private CurlyBracketOpenToken curlyBracketOpenToken;
57  	private BracketOpenToken bracketOpenToken;
58  	
59  	/**
60  	 * Creates the most important Tokens.
61  	 * 
62  	 * @throws Exception
63  	 */
64  	@Before
65  	public void setUp() throws Exception {
66  		this.bracketOpenToken = BracketOpenToken.create(Position.create("", 1, 1, 0));
67  		this.curlyBracketOpenToken = CurlyBracketOpenToken.create(Position.create("", 1, 1, 0));
68  	}
69  	
70  	/**
71  	 * group1 : group = [ class1 : class = {attribute : (int1:Integer, int2:Integer, sum1:{Integer, String, Test} ,
72  	 * sum2:{Integer, Test});} service transient;]; .
73  	 * 
74  	 * @throws Exception
75  	 */
76  	@Test
77  	public void testProductSum1() throws Exception {
78  		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
79  		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
80  		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
81  		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
82  		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
83  		final IdentifierToken testIdentifier = IdentifierToken.create("Test", Position.create("", 1, 1, 0));
84  		
85  		final String stringInput =
86  				"group1 : group = [ class1 : class = {attribute : (int1:Integer, int2:Integer, sum1:{Integer, String, Test} , sum2:{Integer, Test});} service transient;];";
87  		final SimpleScannerInput input = new SimpleScannerInput(stringInput);
88  		final TokenStream output = FilteredTokenStream.create();
89  		final Scanner scanner = ModelDslScanner.create();
90  		scanner.scan(input, output);
91  		
92  		final Parser parser = Parser.create(output);
93  		final Model model = parser.parse();
94  		
95  		final Vector<GroupElement> groupVector = new Vector<>();
96  		final Vector<Attribute> attributes = new Vector<>();
97  		final Vector<ClassModifier> modifiers = new Vector<>();
98  		
99  		final Name groupName = UnqualifiedName.create(groupIdentifier);
100 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
101 		
102 		final Name className = groupName.addName(classIdentifier);
103 		final ClassType clazz =
104 				RegularClassType.create(
105 						className,
106 						modifiers,
107 						attributes,
108 						new Vector<Type>(),
109 						new Vector<Operation>(),
110 						new Vector<Constructor>(),
111 						classIdentifier,
112 						
113 						new Vector<ClassType>());
114 		
115 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
116 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
117 		
118 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
119 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
120 		
121 		final ByNameState testByName = ByNameState.create(UnqualifiedName.create(testIdentifier));
122 		final TypeProxy typeProxyTest = TypeProxy.create(testIdentifier, testByName);
123 		
124 		final SumType sum1 = SumType.create(this.curlyBracketOpenToken);
125 		sum1.add(typeProxyInteger);
126 		sum1.add(typeProxyString);
127 		sum1.add(typeProxyTest);
128 		
129 		final SumType sum2 = SumType.create(this.curlyBracketOpenToken);
130 		sum2.add(typeProxyInteger);
131 		sum2.add(typeProxyTest);
132 		
133 		final ProductType product = ProductType.create(this.bracketOpenToken);
134 		final ProductElementType element1 =
135 				ProductElementType.create(
136 						"int1",
137 						typeProxyInteger,
138 						IdentifierToken.create("int1", Position.create("", 1, 1, 0)));
139 		final ProductElementType element2 =
140 				ProductElementType.create(
141 						"int2",
142 						typeProxyInteger,
143 						IdentifierToken.create("int2", Position.create("", 1, 1, 0)));
144 		final ProductElementType element3 =
145 				ProductElementType.create("sum1", sum1, IdentifierToken.create("sum1", Position.create("", 1, 1, 0)));
146 		final ProductElementType element4 =
147 				ProductElementType.create("sum2", sum2, IdentifierToken.create("sum2", Position.create("", 1, 1, 0)));
148 		product.addElement(element1);
149 		product.addElement(element2);
150 		product.addElement(element3);
151 		product.addElement(element4);
152 		
153 		final Attribute attribute =
154 				Attribute.create("attribute", product, new Vector<AttributeModifier>(), attributeIdentifier);
155 		attributes.add(attribute);
156 		
157 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
158 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
159 		groupVector.add(clazz);
160 		final Model expected = Model.create(groupIdentifier);
161 		expected.addGroup(group);
162 		assertEquals(expected, model);
163 	}
164 	
165 	/**
166 	 * group1 : group = [ class1 : class = {attribute : (int1:Integer, str:String) ;} service transient;]; .
167 	 * 
168 	 * @throws Exception
169 	 */
170 	@Test
171 	public void testProductSum2() throws Exception {
172 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
173 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
174 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
175 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
176 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
177 		
178 		final SimpleScannerInput input =
179 				new SimpleScannerInput(
180 						"group1 : group = [ class1 : class = {attribute : (int1:Integer, str:String) ;} service transient;];");
181 		final TokenStream output = FilteredTokenStream.create();
182 		final Scanner scanner = ModelDslScanner.create();
183 		scanner.scan(input, output);
184 		final Parser parser = Parser.create(output);
185 		final Model model = parser.parse();
186 		
187 		final Vector<GroupElement> groupVector = new Vector<>();
188 		final Vector<Attribute> attributes = new Vector<>();
189 		final Vector<ClassModifier> modifiers = new Vector<>();
190 		
191 		final Name groupName = UnqualifiedName.create(groupIdentifier);
192 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
193 		
194 		final Name className = groupName.addName(classIdentifier);
195 		final ClassType clazz =
196 				RegularClassType.create(
197 						className,
198 						modifiers,
199 						attributes,
200 						new Vector<Type>(),
201 						new Vector<Operation>(),
202 						new Vector<Constructor>(),
203 						classIdentifier,
204 						
205 						new Vector<ClassType>());
206 		
207 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
208 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
209 		
210 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
211 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
212 		
213 		final ProductType product = ProductType.create(this.bracketOpenToken);
214 		final ProductElementType element1 =
215 				ProductElementType.create(
216 						"int1",
217 						typeProxyInteger,
218 						IdentifierToken.create("int1", Position.create("", 1, 1, 0)));
219 		final ProductElementType element2 =
220 				ProductElementType.create(
221 						"str",
222 						typeProxyString,
223 						IdentifierToken.create("str", Position.create("", 1, 1, 0)));
224 		product.addElement(element1);
225 		product.addElement(element2);
226 		
227 		final Attribute attribute =
228 				Attribute.create("attribute", product, new Vector<AttributeModifier>(), attributeIdentifier);
229 		attributes.add(attribute);
230 		
231 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
232 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
233 		groupVector.add(clazz);
234 		final Model expected = Model.create(groupIdentifier);
235 		expected.addGroup(group);
236 		assertEquals(expected, model);
237 	}
238 	
239 	/**
240 	 * group1 : group = [ class1 : class = {attribute : {Integer, String} ;} service transient;]; .
241 	 * 
242 	 * @throws Exception
243 	 */
244 	@Test
245 	public void testProductSum3() throws Exception {
246 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
247 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
248 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
249 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
250 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
251 		
252 		final SimpleScannerInput input =
253 				new SimpleScannerInput(
254 						"group1 : group = [ class1 : class = {attribute : {Integer, String} ;} service transient;];");
255 		final TokenStream output = FilteredTokenStream.create();
256 		final Scanner scanner = ModelDslScanner.create();
257 		scanner.scan(input, output);
258 		final Parser parser = Parser.create(output);
259 		final Model model = parser.parse();
260 		
261 		final Vector<GroupElement> groupVector = new Vector<>();
262 		final Vector<Attribute> attributes = new Vector<>();
263 		final Vector<ClassModifier> modifiers = new Vector<>();
264 		
265 		final Name groupName = UnqualifiedName.create(groupIdentifier);
266 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
267 		
268 		final Name className = groupName.addName(classIdentifier);
269 		final ClassType clazz =
270 				RegularClassType.create(
271 						className,
272 						modifiers,
273 						attributes,
274 						new Vector<Type>(),
275 						new Vector<Operation>(),
276 						new Vector<Constructor>(),
277 						classIdentifier,
278 						
279 						new Vector<ClassType>());
280 		
281 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
282 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
283 		
284 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
285 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
286 		
287 		final SumType sum = SumType.create(this.curlyBracketOpenToken);
288 		sum.add(typeProxyInteger);
289 		sum.add(typeProxyString);
290 		
291 		final Attribute attribute =
292 				Attribute.create("attribute", sum, new Vector<AttributeModifier>(), attributeIdentifier);
293 		attributes.add(attribute);
294 		
295 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
296 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
297 		groupVector.add(clazz);
298 		final Model expected = Model.create(groupIdentifier);
299 		expected.addGroup(group);
300 		assertEquals(expected, model);
301 	}
302 	
303 	/**
304 	 * group1 : group = [ class1 : class = {attribute : {(int1:Integer,int2:Integer,int42:Integer), String,
305 	 * (int3:Integer,int4:Integer), Test} ;} service transient;]; .
306 	 * 
307 	 * @throws Exception
308 	 */
309 	@Test
310 	public void testProductSum4() throws Exception {
311 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
312 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
313 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
314 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
315 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
316 		final IdentifierToken testIdentifier = IdentifierToken.create("Test", Position.create("", 1, 1, 0));
317 		
318 		final SimpleScannerInput input =
319 				new SimpleScannerInput(
320 						"group1 : group = [ class1 : class = {attribute : {(int1:Integer,int2:Integer,int42:Integer), String, (int3:Integer,int4:Integer), Test} ;} service transient;];");
321 		final TokenStream output = FilteredTokenStream.create();
322 		final Scanner scanner = ModelDslScanner.create();
323 		scanner.scan(input, output);
324 		final Parser parser = Parser.create(output);
325 		final Model model = parser.parse();
326 		
327 		final Vector<GroupElement> groupVector = new Vector<>();
328 		final Vector<Attribute> attributes = new Vector<>();
329 		final Vector<ClassModifier> modifiers = new Vector<>();
330 		
331 		final Name groupName = UnqualifiedName.create(groupIdentifier);
332 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
333 		
334 		final Name className = groupName.addName(classIdentifier);
335 		final ClassType clazz =
336 				RegularClassType.create(
337 						className,
338 						modifiers,
339 						attributes,
340 						new Vector<Type>(),
341 						new Vector<Operation>(),
342 						new Vector<Constructor>(),
343 						classIdentifier,
344 						
345 						new Vector<ClassType>());
346 		
347 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
348 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
349 		
350 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
351 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
352 		
353 		final ByNameState testByName = ByNameState.create(UnqualifiedName.create(testIdentifier));
354 		final TypeProxy typeProxyTest = TypeProxy.create(testIdentifier, testByName);
355 		
356 		final ProductType product1 = ProductType.create(this.bracketOpenToken);
357 		final ProductElementType element11 =
358 				ProductElementType.create(
359 						"int1",
360 						typeProxyInteger,
361 						IdentifierToken.create("int1", Position.create("", 1, 1, 0)));
362 		final ProductElementType element12 =
363 				ProductElementType.create(
364 						"int2",
365 						typeProxyInteger,
366 						IdentifierToken.create("int2", Position.create("", 1, 1, 0)));
367 		final ProductElementType element13 =
368 				ProductElementType.create(
369 						"int42",
370 						typeProxyInteger,
371 						IdentifierToken.create("int42", Position.create("", 1, 1, 0)));
372 		product1.addElement(element11);
373 		product1.addElement(element12);
374 		product1.addElement(element13);
375 		
376 		final ProductType product2 = ProductType.create(this.bracketOpenToken);
377 		final ProductElementType element21 =
378 				ProductElementType.create(
379 						"int3",
380 						typeProxyInteger,
381 						IdentifierToken.create("int3", Position.create("", 1, 1, 0)));
382 		final ProductElementType element22 =
383 				ProductElementType.create(
384 						"int4",
385 						typeProxyInteger,
386 						IdentifierToken.create("int4", Position.create("", 1, 1, 0)));
387 		product2.addElement(element21);
388 		product2.addElement(element22);
389 		
390 		final SumType sum = SumType.create(this.curlyBracketOpenToken);
391 		sum.add(product1);
392 		sum.add(typeProxyString);
393 		sum.add(product2);
394 		sum.add(typeProxyTest);
395 		
396 		final Attribute attribute =
397 				Attribute.create("attribute", sum, new Vector<AttributeModifier>(), attributeIdentifier);
398 		attributes.add(attribute);
399 		
400 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
401 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
402 		groupVector.add(clazz);
403 		final Model expected = Model.create(groupIdentifier);
404 		expected.addGroup(group);
405 		assertEquals(expected, model);
406 	}
407 	
408 	/**
409 	 * group1 : group = [ class1 : class = {attribute : {(sum:{Integer, String}, int42:Integer), String,
410 	 * (int3:Integer,int4:Integer), Test} ;} service transient;]; .
411 	 * 
412 	 * @throws Exception
413 	 */
414 	@Test
415 	public void testProductSum5() throws Exception {
416 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
417 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
418 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
419 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
420 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
421 		final IdentifierToken testIdentifier = IdentifierToken.create("Test", Position.create("", 1, 1, 0));
422 		
423 		final SimpleScannerInput input =
424 				new SimpleScannerInput(
425 						"group1 : group = [ class1 : class = {attribute : {(sum:{Integer, String}, int42:Integer), String, (int3:Integer,int4:Integer), Test} ;} service transient;];");
426 		final TokenStream output = FilteredTokenStream.create();
427 		final Scanner scanner = ModelDslScanner.create();
428 		scanner.scan(input, output);
429 		final Parser parser = Parser.create(output);
430 		final Model model = parser.parse();
431 		
432 		final Vector<GroupElement> groupVector = new Vector<>();
433 		final Vector<Attribute> attributes = new Vector<>();
434 		final Vector<ClassModifier> modifiers = new Vector<>();
435 		
436 		final Name groupName = UnqualifiedName.create(groupIdentifier);
437 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
438 		
439 		final Name className = groupName.addName(classIdentifier);
440 		final ClassType clazz =
441 				RegularClassType.create(
442 						className,
443 						modifiers,
444 						attributes,
445 						new Vector<Type>(),
446 						new Vector<Operation>(),
447 						new Vector<Constructor>(),
448 						classIdentifier,
449 						
450 						new Vector<ClassType>());
451 		
452 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
453 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
454 		
455 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
456 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
457 		
458 		final ByNameState testByName = ByNameState.create(UnqualifiedName.create(testIdentifier));
459 		final TypeProxy typeProxyTest = TypeProxy.create(testIdentifier, testByName);
460 		
461 		final SumType sumP = SumType.create(this.curlyBracketOpenToken);
462 		sumP.add(typeProxyInteger);
463 		sumP.add(typeProxyString);
464 		
465 		final ProductType product1 = ProductType.create(this.bracketOpenToken);
466 		final ProductElementType element11 =
467 				ProductElementType.create("sum", sumP, IdentifierToken.create("sum", Position.create("", 1, 1, 0)));
468 		final ProductElementType element12 =
469 				ProductElementType.create(
470 						"int42",
471 						typeProxyInteger,
472 						IdentifierToken.create("int42", Position.create("", 1, 1, 0)));
473 		product1.addElement(element11);
474 		product1.addElement(element12);
475 		
476 		final ProductType product2 = ProductType.create(this.bracketOpenToken);
477 		final ProductElementType element21 =
478 				ProductElementType.create(
479 						"int3",
480 						typeProxyInteger,
481 						IdentifierToken.create("int3", Position.create("", 1, 1, 0)));
482 		final ProductElementType element22 =
483 				ProductElementType.create(
484 						"int4",
485 						typeProxyInteger,
486 						IdentifierToken.create("int4", Position.create("", 1, 1, 0)));
487 		product2.addElement(element21);
488 		product2.addElement(element22);
489 		
490 		final SumType sum = SumType.create(this.curlyBracketOpenToken);
491 		sum.add(product1);
492 		sum.add(typeProxyString);
493 		sum.add(product2);
494 		sum.add(typeProxyTest);
495 		
496 		final Attribute attribute =
497 				Attribute.create("attribute", sum, new Vector<AttributeModifier>(), attributeIdentifier);
498 		attributes.add(attribute);
499 		
500 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
501 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
502 		groupVector.add(clazz);
503 		final Model expected = Model.create(groupIdentifier);
504 		expected.addGroup(group);
505 		assertEquals(expected, model);
506 	}
507 	
508 	/**
509 	 * group1 : group = [ class1 : class = {attribute : (sum1:{Integer, Test}, sum2:{{Integer, String}, (int3:Integer,
510 	 * int4:Integer), Test}) ;} service transient;]; .
511 	 * 
512 	 * @throws Exception
513 	 */
514 	@Test
515 	public void testProductSum6() throws Exception {
516 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
517 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
518 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
519 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
520 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
521 		final IdentifierToken testIdentifier = IdentifierToken.create("Test", Position.create("", 1, 1, 0));
522 		
523 		final SimpleScannerInput input =
524 				new SimpleScannerInput(
525 						"group1 : group = [ class1 : class = {attribute : (sum1:{Integer, Test}, sum3:{{Integer, String}, (int3:Integer, int4:Integer), Test}) ;} service transient;];");
526 		final TokenStream output = FilteredTokenStream.create();
527 		final Scanner scanner = ModelDslScanner.create();
528 		scanner.scan(input, output);
529 		final Parser parser = Parser.create(output);
530 		final Model model = parser.parse();
531 		
532 		final Vector<GroupElement> groupVector = new Vector<>();
533 		final Vector<Attribute> attributes = new Vector<>();
534 		final Vector<ClassModifier> modifiers = new Vector<>();
535 		
536 		final Name groupName = UnqualifiedName.create(groupIdentifier);
537 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
538 		
539 		final Name className = groupName.addName(classIdentifier);
540 		final ClassType clazz =
541 				RegularClassType.create(
542 						className,
543 						modifiers,
544 						attributes,
545 						new Vector<Type>(),
546 						new Vector<Operation>(),
547 						new Vector<Constructor>(),
548 						classIdentifier,
549 						
550 						new Vector<ClassType>());
551 		
552 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
553 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
554 		
555 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
556 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
557 		
558 		final ByNameState testByName = ByNameState.create(UnqualifiedName.create(testIdentifier));
559 		final TypeProxy typeProxyTest = TypeProxy.create(testIdentifier, testByName);
560 		
561 		final SumType sum1 = SumType.create(this.curlyBracketOpenToken);
562 		sum1.add(typeProxyInteger);
563 		sum1.add(typeProxyTest);
564 		
565 		final ProductType product1 = ProductType.create(this.bracketOpenToken);
566 		final ProductElementType element11 =
567 				ProductElementType.create(
568 						"int3",
569 						typeProxyInteger,
570 						IdentifierToken.create("int3", Position.create("", 1, 1, 0)));
571 		final ProductElementType element12 =
572 				ProductElementType.create(
573 						"int4",
574 						typeProxyInteger,
575 						IdentifierToken.create("int4", Position.create("", 1, 1, 0)));
576 		product1.addElement(element11);
577 		product1.addElement(element12);
578 		
579 		final SumType sum3 = SumType.create(this.curlyBracketOpenToken);
580 		sum3.add(typeProxyInteger);
581 		sum3.add(typeProxyString);
582 		
583 		final SumType sum2 = SumType.create(this.curlyBracketOpenToken);
584 		sum2.add(sum3);
585 		sum2.add(product1);
586 		sum2.add(typeProxyTest);
587 		
588 		final ProductType product2 = ProductType.create(this.bracketOpenToken);
589 		final ProductElementType element21 =
590 				ProductElementType.create("sum1", sum1, IdentifierToken.create("sum1", Position.create("", 1, 1, 0)));
591 		final ProductElementType element22 =
592 				ProductElementType.create("sum3", sum2, IdentifierToken.create("sum3", Position.create("", 1, 1, 0)));
593 		product2.addElement(element21);
594 		product2.addElement(element22);
595 		
596 		final Attribute attribute =
597 				Attribute.create("attribute", product2, new Vector<AttributeModifier>(), attributeIdentifier);
598 		attributes.add(attribute);
599 		
600 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
601 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
602 		groupVector.add(clazz);
603 		final Model expected = Model.create(groupIdentifier);
604 		expected.addGroup(group);
605 		assertEquals(expected, model);
606 	}
607 	
608 	/**
609 	 * group1 : group = [ class1 : class = {attribute : (sum1:{Integer, Test}, sum2:{{Integer, (str1:String,
610 	 * str2:String)}, (int3:Integer, int4:Integer), Test}) ;} service transient;]; .
611 	 * 
612 	 * @throws Exception
613 	 */
614 	@Test
615 	public void testProductSum7() throws Exception {
616 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
617 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
618 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
619 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
620 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
621 		final IdentifierToken testIdentifier = IdentifierToken.create("Test", Position.create("", 1, 1, 0));
622 		
623 		final SimpleScannerInput input =
624 				new SimpleScannerInput(
625 						"group1 : group = [ class1 : class = {attribute : (sum1:{Integer, Test}, sum2:{{Integer, (str1:String, str2:String)}, (int3:Integer, int4:Integer), Test}) ;} service transient;];");
626 		
627 		final TokenStream output = FilteredTokenStream.create();
628 		final Scanner scanner = ModelDslScanner.create();
629 		scanner.scan(input, output);
630 		final Parser parser = Parser.create(output);
631 		final Model model = parser.parse();
632 		
633 		final Vector<GroupElement> groupVector = new Vector<>();
634 		final Vector<Attribute> attributes = new Vector<>();
635 		final Vector<ClassModifier> modifiers = new Vector<>();
636 		
637 		final Name groupName = UnqualifiedName.create(groupIdentifier);
638 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
639 		
640 		final Name className = groupName.addName(classIdentifier);
641 		final ClassType clazz =
642 				RegularClassType.create(
643 						className,
644 						modifiers,
645 						attributes,
646 						new Vector<Type>(),
647 						new Vector<Operation>(),
648 						new Vector<Constructor>(),
649 						classIdentifier,
650 						
651 						new Vector<ClassType>());
652 		
653 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
654 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
655 		
656 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
657 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
658 		
659 		final ByNameState testByName = ByNameState.create(UnqualifiedName.create(testIdentifier));
660 		final TypeProxy typeProxyTest = TypeProxy.create(testIdentifier, testByName);
661 		
662 		final SumType sum1 = SumType.create(IdentifierToken.create("sum1", Position.create("", 1, 1, 0)));
663 		sum1.add(typeProxyInteger);
664 		sum1.add(typeProxyTest);
665 		
666 		final ProductType product1 = ProductType.create(this.bracketOpenToken);
667 		final ProductElementType element1 =
668 				ProductElementType.create(
669 						"str1",
670 						typeProxyString,
671 						IdentifierToken.create("str1", Position.create("", 1, 1, 0)));
672 		final ProductElementType element2 =
673 				ProductElementType.create(
674 						"str2",
675 						typeProxyString,
676 						IdentifierToken.create("str2", Position.create("", 1, 1, 0)));
677 		product1.addElement(element1);
678 		product1.addElement(element2);
679 		
680 		final SumType sum2 = SumType.create(this.curlyBracketOpenToken);
681 		sum2.add(typeProxyInteger);
682 		sum2.add(product1);
683 		
684 		final ProductType product2 = ProductType.create(this.bracketOpenToken);
685 		final ProductElementType element3 =
686 				ProductElementType.create(
687 						"int3",
688 						typeProxyInteger,
689 						IdentifierToken.create("int3", Position.create("", 1, 1, 0)));
690 		final ProductElementType element4 =
691 				ProductElementType.create(
692 						"int4",
693 						typeProxyInteger,
694 						IdentifierToken.create("int4", Position.create("", 1, 1, 0)));
695 		product2.addElement(element3);
696 		product2.addElement(element4);
697 		
698 		final SumType sum3 = SumType.create(this.curlyBracketOpenToken);
699 		sum3.add(sum2);
700 		sum3.add(product2);
701 		sum3.add(typeProxyTest);
702 		
703 		final ProductType product3 = ProductType.create(this.bracketOpenToken);
704 		final ProductElementType element5 =
705 				ProductElementType.create("sum1", sum1, IdentifierToken.create("sum1", Position.create("", 1, 1, 0)));
706 		final ProductElementType element6 =
707 				ProductElementType.create("sum2", sum3, IdentifierToken.create("sum2", Position.create("", 1, 1, 0)));
708 		product3.addElement(element5);
709 		product3.addElement(element6);
710 		
711 		final Attribute attribute =
712 				Attribute.create("attribute", product3, new Vector<AttributeModifier>(), attributeIdentifier);
713 		attributes.add(attribute);
714 		
715 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
716 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
717 		groupVector.add(clazz);
718 		final Model expected = Model.create(groupIdentifier);
719 		expected.addGroup(group);
720 		assertEquals(expected, model);
721 		
722 	}
723 	
724 	/**
725 	 * group1 : group = [ class1 : class = {attribute : (sum1:{Integer, String}, sum2:{{Integer, String}, (int3:Integer,
726 	 * sum4: {Integer, Test})}) ;} service transient;]; .
727 	 * 
728 	 * @throws Exception
729 	 */
730 	@Test
731 	public void testProductSum8() throws Exception {
732 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
733 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
734 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
735 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
736 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
737 		final IdentifierToken testIdentifier = IdentifierToken.create("Test", Position.create("", 1, 1, 0));
738 		
739 		final SimpleScannerInput input =
740 				new SimpleScannerInput(
741 						"group1 : group = [ class1 : class = {attribute : (sum1:{Integer, String}, sum2:{{Integer, String}, (int3:Integer, sum4: {Integer, Test})}) ;} service transient;];");
742 		final TokenStream output = FilteredTokenStream.create();
743 		final Scanner scanner = ModelDslScanner.create();
744 		scanner.scan(input, output);
745 		final Parser parser = Parser.create(output);
746 		final Model model = parser.parse();
747 		
748 		final Vector<GroupElement> groupVector = new Vector<>();
749 		final Vector<Attribute> attributes = new Vector<>();
750 		final Vector<ClassModifier> modifiers = new Vector<>();
751 		
752 		final Name groupName = UnqualifiedName.create(groupIdentifier);
753 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
754 		final Name className = groupName.addName(classIdentifier);
755 		final ClassType clazz =
756 				RegularClassType.create(
757 						className,
758 						modifiers,
759 						attributes,
760 						new Vector<Type>(),
761 						new Vector<Operation>(),
762 						new Vector<Constructor>(),
763 						classIdentifier,
764 						
765 						new Vector<ClassType>());
766 		
767 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
768 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
769 		
770 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
771 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
772 		
773 		final ByNameState testByName = ByNameState.create(UnqualifiedName.create(testIdentifier));
774 		final TypeProxy typeProxyTest = TypeProxy.create(testIdentifier, testByName);
775 		
776 		final SumType sum1 = SumType.create(this.curlyBracketOpenToken);
777 		sum1.add(typeProxyInteger);
778 		sum1.add(typeProxyString);
779 		
780 		final SumType sum4 = SumType.create(this.curlyBracketOpenToken);
781 		sum4.add(typeProxyInteger);
782 		sum4.add(typeProxyTest);
783 		
784 		final ProductType product1 = ProductType.create(this.bracketOpenToken);
785 		final ProductElementType element11 =
786 				ProductElementType.create(
787 						"int3",
788 						typeProxyInteger,
789 						IdentifierToken.create("int3", Position.create("", 1, 1, 0)));
790 		final ProductElementType element12 =
791 				ProductElementType.create("sum4", sum4, IdentifierToken.create("sum4", Position.create("", 1, 1, 0)));
792 		product1.addElement(element11);
793 		product1.addElement(element12);
794 		
795 		final SumType sum2 = SumType.create(this.curlyBracketOpenToken);
796 		sum2.add(sum1);
797 		sum2.add(product1);
798 		
799 		final ProductType product2 = ProductType.create(this.bracketOpenToken);
800 		final ProductElementType element21 =
801 				ProductElementType.create("sum1", sum1, IdentifierToken.create("sum1", Position.create("", 1, 1, 0)));
802 		final ProductElementType element22 =
803 				ProductElementType.create("sum2", sum2, IdentifierToken.create("sum2", Position.create("", 1, 1, 0)));
804 		product2.addElement(element21);
805 		product2.addElement(element22);
806 		
807 		final Attribute attribute =
808 				Attribute.create("attribute", product2, new Vector<AttributeModifier>(), attributeIdentifier);
809 		attributes.add(attribute);
810 		
811 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
812 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
813 		groupVector.add(clazz);
814 		final Model expected = Model.create(groupIdentifier);
815 		expected.addGroup(group);
816 		assertEquals(expected, model);
817 	}
818 	
819 	/**
820 	 * group1 : group = [ class1 : class = {att1 :
821 	 * (prod1:{Integer1,Integer2},prod2:{Integer42,String},prod3:{Integer4,Test) ;} service transient;];" .
822 	 */
823 	@Test
824 	public void testProductSum9() {
825 		final SimpleScannerInput input =
826 				new SimpleScannerInput(
827 						"group1 : group = [ class1 : class = {attribute : (sum1:{Integer, String}, sum2:{Integer, String}, sum3:{Integer, Test) ;} service transient;];");
828 		final TokenStream output = FilteredTokenStream.create();
829 		final Scanner scanner = ModelDslScanner.create();
830 		scanner.scan(input, output);
831 		final Parser parser = Parser.create(output);
832 		boolean isRightException = false;
833 		try {
834 			parser.parse();
835 		} catch (final NoValidTokenStreamException e) {
836 			if (parser.getExceptions().size() != 1) {
837 				fail();
838 			}
839 			final Iterator<AbstractParserException> i = parser.getExceptions().iterator();
840 			while (i.hasNext()) {
841 				final AbstractParserException current = i.next();
842 				if (current instanceof NoCurlyBracketCloseException) {
843 					isRightException = true;
844 				}
845 			}
846 		}
847 		assertTrue(isRightException);
848 	}
849 	
850 	/**
851 	 * group1 : group = [ class1 : class = {attribute : [String->Integer];} service transient;]; .
852 	 * 
853 	 * @throws Exception
854 	 */
855 	@Test
856 	public void testMap() throws Exception {
857 		final IdentifierToken classIdentifier = IdentifierToken.create("class1", Position.create("", 1, 1, 0));
858 		final IdentifierToken groupIdentifier = IdentifierToken.create("group1", Position.create("", 1, 1, 0));
859 		final IdentifierToken attributeIdentifier = IdentifierToken.create("attribute", Position.create("", 1, 1, 0));
860 		final IdentifierToken integerIdentifier = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
861 		final IdentifierToken stringIdentifier = IdentifierToken.create("String", Position.create("", 1, 1, 0));
862 		
863 		final SimpleScannerInput input =
864 				new SimpleScannerInput(
865 						"group1 : group = [ class1 : class = {attribute : [String->Integer];} service transient;];");
866 		final TokenStream output = FilteredTokenStream.create();
867 		final Scanner scanner = ModelDslScanner.create();
868 		scanner.scan(input, output);
869 		final Parser parser = Parser.create(output);
870 		final Model model = parser.parse();
871 		
872 		final Vector<GroupElement> groupVector = new Vector<>();
873 		final Vector<Attribute> attributes = new Vector<>();
874 		final Vector<ClassModifier> modifiers = new Vector<>();
875 		
876 		final Name groupName = UnqualifiedName.create(groupIdentifier);
877 		final Group group = Group.create(groupName, groupVector, GroupToken.create(Position.create("", 1, 1, 0)));
878 		final Name className = groupName.addName(classIdentifier);
879 		final ClassType clazz =
880 				RegularClassType.create(
881 						className,
882 						modifiers,
883 						attributes,
884 						new Vector<Type>(),
885 						new Vector<Operation>(),
886 						new Vector<Constructor>(),
887 						classIdentifier,
888 						
889 						new Vector<ClassType>());
890 		
891 		final ByNameState integerByName = ByNameState.create(UnqualifiedName.create(integerIdentifier));
892 		final TypeProxy typeProxyInteger = TypeProxy.create(integerIdentifier, integerByName);
893 		
894 		final ByNameState stringByName = ByNameState.create(UnqualifiedName.create(stringIdentifier));
895 		final TypeProxy typeProxyString = TypeProxy.create(stringIdentifier, stringByName);
896 		
897 		final MapType map = MapType.create(stringIdentifier, typeProxyString, typeProxyInteger);
898 		
899 		final Attribute attribute =
900 				Attribute.create("attribute", map, new Vector<AttributeModifier>(), attributeIdentifier);
901 		attributes.add(attribute);
902 		
903 		modifiers.add(ClassModifierService.create(VisitableToken.create(Position.create("", 1, 1, 0))));
904 		modifiers.add(ClassModifierTransient.create(AbstractToken.create(Position.create("", 1, 1, 0))));
905 		groupVector.add(clazz);
906 		final Model expected = Model.create(groupIdentifier);
907 		expected.addGroup(group);
908 		assertEquals(expected, model);
909 	}
910 	
911 }