source: trunk/autoquest-plugin-usability2-test/src/main/java/de/ugoe/cs/autoquest/usability/rules/patterns/visitors/startswith/StartsAndEndsWithPatternTest.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).

  • Property svn:mime-type set to text/plain
File size: 4.8 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.usability.rules.patterns.visitors.startswith;
16
17import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter.MOUSE_CLICK;
18import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter.TEXT_INPUT;
19import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskTypeFilter.ITERATION;
20import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskTypeFilter.SELECTION;
21import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskTypeFilter.SEQUENCE;
22import static org.fest.assertions.api.Assertions.assertThat;
23
24import org.junit.Test;
25
26import de.ugoe.cs.autoquest.usability.rules.patterns.InteractionPattern;
27import de.ugoe.cs.autoquest.usability.rules.patterns.InteractionPatternBuilder;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
29import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskModelUtil;
30
31/**
32 * <p>
33 * TODO comment
34 * </p>
35 *
36 * @author Alexander Deicke
37 */
38public class StartsAndEndsWithPatternTest {
39
40    @Test
41    public void starts_and_ends_with_pattern_positive() {
42        // Given
43        String spec = "UserSession {" +
44                              "  Sequence seq1 {" +
45                      "    Iteration iter1 {" +
46                      "      MouseClick t1 {}" +
47                      "    }" +
48                      "  }" +
49                      "  TextInput () {}" +
50                      "  Selection sel1 {" +
51                      "    MouseClick t2 {}" +
52                      "  }" +
53                      "  Selection sel1 {" +
54                      "    Sequence seq3 {" +
55                      "      TextInput t3 {}" +
56                      "      MouseClick t1 {}" +
57                      "    }" +
58                      "  }" +
59                      "}";
60        ITaskModel taskTree = GenerateTaskModelUtil.getTaskModelFromSpec(spec);
61        InteractionPattern startsWithPattern = InteractionPatternBuilder.newPattern().rootTask(ITERATION).containsEvent(MOUSE_CLICK).patternFinished().build();
62        InteractionPattern endsWithPattern = InteractionPatternBuilder.newPattern().rootTask(SELECTION).startsWithEvent(TEXT_INPUT).endsWithEvent(MOUSE_CLICK).patternFinished().build();
63        InteractionPattern pattern = InteractionPatternBuilder.newPattern().rootTask(SEQUENCE).startsWithPattern(startsWithPattern).endsWithPattern(endsWithPattern).patternFinished().build();
64        // When
65        boolean patternContained = pattern.containedIn(taskTree);
66        // Then
67        assertThat(patternContained).isTrue();
68    }
69   
70    @Test
71    public void starts_and_ends_with_pattern_negative() {
72        // Given
73        String spec = "UserSession {" +
74                              "  Sequence seq1 {" +
75                      "    Iteration iter1 {" +
76                      "      MouseClick t1 {}" +
77                      "    }" +
78                      "    TextInput t2 {}" +
79                      "    Selection sel1 {" +
80                      "      MouseClick t3 {}" +
81                      "    }" +
82                      "    Selection sel1 {" +
83                      "      Sequence seq2 {" +
84                      "        TextInput t3 {}" +
85                      "        MouseClick t1 {}" +
86                      "      }" +
87                      "    }" +
88                      "  }" +
89                      "}";
90        ITaskModel taskTree = GenerateTaskModelUtil.getTaskModelFromSpec(spec);
91        InteractionPattern startsWithPattern = InteractionPatternBuilder.newPattern().rootTask(ITERATION).containsEvent(MOUSE_CLICK).patternFinished().build();
92        InteractionPattern endsWithPattern = InteractionPatternBuilder.newPattern().rootTask(SELECTION).startsWithEvent(TEXT_INPUT).endsWithEvent(MOUSE_CLICK).patternFinished().build();
93        InteractionPattern pattern = InteractionPatternBuilder.newPattern().rootTask(ITERATION).startsWithPattern(endsWithPattern).endsWithPattern(startsWithPattern).patternFinished().build();
94        // When
95        boolean patternContained = pattern.containedIn(taskTree);
96        // Then
97        assertThat(patternContained).isFalse();
98    }
99   
100}
Note: See TracBrowser for help on using the repository browser.