source: trunk/autoquest-plugin-usability2-test/src/main/java/de/ugoe/cs/autoquest/plugin/usability2/rules/operator/FollowedByTest.java @ 1326

Last change on this file since 1326 was 1326, checked in by khartmann, 10 years ago

Moved alexanders code into a new plugin project.
First commit of my experimental code (needs a lot of cleanup).

File size: 4.4 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.usability2.rules.operator;
16
17import static org.fest.assertions.api.Assertions.assertThat;
18
19import java.util.Collection;
20
21import org.junit.Test;
22
23import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.Follows;
24import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.IFilter;
25import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.Label;
26import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.filter.AnyFilter;
27import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.filter.EventTypeFilter;
28import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.visitors.Contains;
29import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.visitors.FindContained;
30import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.AbstractTaskEntryVisitor;
31import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.FollowedByUtil;
32import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.ITaskEntry;
33import de.ugoe.cs.autoquest.plugin.usability2.rules.results.IMatch;
34import de.ugoe.cs.autoquest.plugin.usability2.rules.results.IResult;
35import de.ugoe.cs.autoquest.plugin.usability2.tools.TaskUtilities;
36import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
37import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
38import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskModelUtil;
39
40/**
41 * <p>
42 * Test of the FollowedBy Operator
43 * </p>
44 *
45 * @author Konni Hartmann
46 */
47public class FollowedByTest {
48
49    static class TestVisitor extends AbstractTaskEntryVisitor {
50        int indentionLevel = 0;
51
52        @Override
53        public void visitEntry(ITaskEntry value) {
54            StringBuilder indent = new StringBuilder((indentionLevel - 1) * 2);
55            for (int i = 1; i < indentionLevel; i++)
56                indent.append("  ");
57            System.out.printf("%s%s %s %s %s\n", indent, value, value.getReference(),
58                              value.getParent(), value.getNext());
59        }
60
61        @Override
62        public void visit(ITaskEntry value) {
63            indentionLevel++;
64            super.visit(value);
65            indentionLevel--;
66        }
67    }
68   
69    @Test
70    public void contains_event_positive() {
71        // Given
72        String spec =
73                "UserSession {" +
74                "  Sequence seq1 {" +
75                "    TextInput t3 { aaa }" +
76                "    MouseClick c3 { }" +
77                "    Iteration it {" +
78                "        Sequence c0 {" +
79                "            TextInput t2 {b}" +
80                "            MouseClick c1 { }" +
81                "        }" +
82                "    }" +
83                "  }" +
84                "}";
85
86        ITaskModel taskTree = GenerateTaskModelUtil.getTaskModelFromSpec(spec);
87        Collection<ITask> tasks = TaskUtilities.findRootTasks(taskTree.getTasks());
88
89        assertThat(tasks.size()).isEqualTo(1);
90        ITask root = tasks.iterator().next();
91
92        // When
93        ITaskEntry followTree = FollowedByUtil.generateFollowList(root);
94        TestVisitor v = new TestVisitor();
95        v.visit(followTree);
96       
97        System.out.println();
98       
99        IFilter f = new Follows(new FindContained(new Label("X", EventTypeFilter.MOUSE_CLICK)),
100                                new Contains(new Label("Y", AnyFilter.ANY))
101        );
102
103        //f = new Contains(new Label("X", AnyFilter.ANY));
104       
105        IResult result = f.match(root);
106       
107        System.out.println("\n>>RESULTS:");
108        System.out.println(result.isPresent());
109        for (IMatch m : result) {
110            System.out.println(">"+m.getLabeledResults());
111        }
112       
113        // Then
114        assertThat(result.isPresent()).isTrue();
115    }
116}
Note: See TracBrowser for help on using the repository browser.