[1326] | 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.plugin.usability2.rules.operator;
|
---|
| 16 |
|
---|
| 17 | import static org.fest.assertions.api.Assertions.assertThat;
|
---|
| 18 |
|
---|
| 19 | import java.util.Collection;
|
---|
| 20 |
|
---|
| 21 | import org.junit.Test;
|
---|
| 22 |
|
---|
| 23 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.Follows;
|
---|
| 24 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.IFilter;
|
---|
| 25 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.Label;
|
---|
| 26 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.filter.AnyFilter;
|
---|
| 27 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.filter.EventTypeFilter;
|
---|
| 28 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.visitors.Contains;
|
---|
| 29 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.visitors.FindContained;
|
---|
| 30 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.AbstractTaskEntryVisitor;
|
---|
| 31 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.FollowedByUtil;
|
---|
| 32 | import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.ITaskEntry;
|
---|
| 33 | import de.ugoe.cs.autoquest.plugin.usability2.rules.results.IMatch;
|
---|
| 34 | import de.ugoe.cs.autoquest.plugin.usability2.rules.results.IResult;
|
---|
| 35 | import de.ugoe.cs.autoquest.plugin.usability2.tools.TaskUtilities;
|
---|
| 36 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
| 37 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
| 38 | import 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 | */
|
---|
| 47 | public 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 | }
|
---|