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 |
|
---|
15 | package de.ugoe.cs.autoquest.usability.rules.patterns.visitors.contains;
|
---|
16 |
|
---|
17 | import static de.ugoe.cs.autoquest.usability.tasktree.filters.EventTypeFilter.TEXT_INPUT;
|
---|
18 | import static de.ugoe.cs.autoquest.usability.tasktree.filters.TaskTypeFilter.SELECTION;
|
---|
19 | import static de.ugoe.cs.autoquest.usability.tasktree.filters.TaskTypeFilter.SEQUENCE;
|
---|
20 | import static org.fest.assertions.api.Assertions.assertThat;
|
---|
21 |
|
---|
22 | import org.junit.Test;
|
---|
23 |
|
---|
24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
25 | import de.ugoe.cs.autoquest.usability.rules.patterns.UsagePattern;
|
---|
26 | import de.ugoe.cs.autoquest.usability.rules.patterns.UsagePatternBuilder;
|
---|
27 | import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskModelUtil;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * <p>
|
---|
31 | * TODO comment
|
---|
32 | * </p>
|
---|
33 | *
|
---|
34 | * @author Alexander Deicke
|
---|
35 | */
|
---|
36 | public class ContainsPatternTest {
|
---|
37 |
|
---|
38 | @Test
|
---|
39 | public void contains_pattern_positive() {
|
---|
40 | // Given
|
---|
41 | String spec = "UserSession {" +
|
---|
42 | " Sequence seq1 {" +
|
---|
43 | " Selection sel1 {" +
|
---|
44 | " TextInput t1 {}" +
|
---|
45 | " }" +
|
---|
46 | " Selection sel1 {" +
|
---|
47 | " MouseClick t2 {}" +
|
---|
48 | " }" +
|
---|
49 | " }" +
|
---|
50 | "}";
|
---|
51 | ITaskModel taskTree = GenerateTaskModelUtil.getTaskModelFromSpec(spec);
|
---|
52 | UsagePatternBuilder patternBuilder = new UsagePatternBuilder();
|
---|
53 | UsagePattern containsPattern = patternBuilder.concernedNode(SELECTION).startsWith(TEXT_INPUT).endsWith(TEXT_INPUT).build();
|
---|
54 | UsagePattern pattern = patternBuilder.concernedNode(SEQUENCE).contains(containsPattern).build();
|
---|
55 | // When
|
---|
56 | boolean patternContained = pattern.containedIn(taskTree);
|
---|
57 | // Then
|
---|
58 | assertThat(patternContained).isTrue();
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Test
|
---|
62 | public void contains_pattern_negative() {
|
---|
63 | // Given
|
---|
64 | String spec = "UserSession {" +
|
---|
65 | " Iteration it1 {" +
|
---|
66 | " Selection sel1 {" +
|
---|
67 | " Sequence seq1 {" +
|
---|
68 | " EventTask t1 {}" +
|
---|
69 | " EventTask t2 {}" +
|
---|
70 | " }" +
|
---|
71 | " }" +
|
---|
72 | " Selection sel1 {" +
|
---|
73 | " Sequence seq2 {" +
|
---|
74 | " EventTask t2 {}" +
|
---|
75 | " EventTask t1 {}" +
|
---|
76 | " }" +
|
---|
77 | " }" +
|
---|
78 | " }" +
|
---|
79 | "}";
|
---|
80 | ITaskModel taskTree = GenerateTaskModelUtil.getTaskModelFromSpec(spec);
|
---|
81 | UsagePattern pattern = new UsagePatternBuilder().concernedNode(SELECTION).contains(TEXT_INPUT).build();
|
---|
82 | // When
|
---|
83 | boolean patternContained = pattern.containedIn(taskTree);
|
---|
84 | // Then
|
---|
85 | assertThat(patternContained).isFalse();
|
---|
86 | }
|
---|
87 |
|
---|
88 | }
|
---|