View Javadoc
1   package de.fhdw.wtf.walker.tasks.test;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import java.util.concurrent.ExecutionException;
6   
7   import org.junit.Before;
8   import org.junit.Test;
9   
10  import de.fhdw.wtf.common.ast.Model;
11  import de.fhdw.wtf.common.stream.FilteredTokenStream;
12  import de.fhdw.wtf.common.stream.SimpleScannerInput;
13  import de.fhdw.wtf.common.stream.TokenStream;
14  import de.fhdw.wtf.core.integration.testutil.AssertOperations;
15  import de.fhdw.wtf.dsl.scanner.common.Scanner;
16  import de.fhdw.wtf.dsl.scanner.modelScanner.ModelDslScanner;
17  import de.fhdw.wtf.parser.Parser;
18  import de.fhdw.wtf.walker.tasks.util.ConstructorReferencerTestReturnValue;
19  
20  /**
21   * Test the functions of the referencer: - Finding the right constructor for a given name in {@link Model}. - Create
22   * anything.
23   */
24  public class TestConstructorReferencer {
25  	
26  	/**
27  	 * Contains different functions to check the results of referencing.
28  	 */
29  	private AssertOperations assertOperations;
30  	
31  	/**
32  	 * Sets up the {@link AssertOperations} for each testcase.
33  	 */
34  	@Before
35  	public void setUp() {
36  		this.assertOperations = new AssertOperations();
37  	}
38  	
39  	/**
40  	 * Test the referencing of:Group:group=[ A:class={ (x:Integer); }; B:class=A+{ ()=A(Integer); }; ];.
41  	 * 
42  	 * @throws Exception
43  	 *             {@link de.fhdw.wtf.common.exception.parser.NoValidTokenStreamException}, {@link InterruptedException}
44  	 *             , {@link ExecutionException}.
45  	 */
46  	@Test
47  	public void testSuperConstructorWorking() throws Exception {
48  		final Scanner scanner = ModelDslScanner.create();
49  		final SimpleScannerInput input =
50  				new SimpleScannerInput("Group:group=[A:class={(x:Integer);};B:class=A+{()=A(Integer);};];");
51  		final TokenStream output = FilteredTokenStream.create();
52  		scanner.scan(input, output);
53  		final Parser parser = Parser.create(output);
54  		final Model result = parser.parse();
55  		
56  		final ConstructorReferencerTestReturnValue v = new ConstructorReferencerTestReturnValue(result);
57  		
58  		assertEquals(0, v.getFailResult().size());
59  		assertEquals(2, v.getOkResult().size());
60  	}
61  	
62  	/**
63  	 * Test the referencing of:Group:group=[ A:class={ (x:Integer); }; B:class=A+{ ()=A(String); }; ];.
64  	 * 
65  	 * @throws Exception
66  	 *             {@link de.fhdw.wtf.common.exception.parser.NoValidTokenStreamException}, {@link InterruptedException}
67  	 *             , {@link ExecutionException}.
68  	 */
69  	@Test
70  	public void testSuperConstructorFailing() throws Exception {
71  		final Scanner scanner = ModelDslScanner.create();
72  		final SimpleScannerInput input =
73  				new SimpleScannerInput("Group:group=[A:class={(x:Integer);};B:class=A+{()=A(String);};];");
74  		final TokenStream output = FilteredTokenStream.create();
75  		scanner.scan(input, output);
76  		final Parser parser = Parser.create(output);
77  		final Model result = parser.parse();
78  		
79  		final ConstructorReferencerTestReturnValue v = new ConstructorReferencerTestReturnValue(result);
80  		
81  		assertEquals(1, v.getFailResult().size());
82  		assertEquals(1, v.getOkResult().size());
83  	}
84  	
85  }