TMF: Close sequence diagram view after sequence diagram tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderFilterTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertTrue;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Lifeline;
23 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.SyncMessage;
24 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.Criteria;
25 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
26 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
27 import org.junit.After;
28 import org.junit.AfterClass;
29 import org.junit.Before;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32
33 /**
34 * Filter test cases.
35 *
36 * @author Bernd Hufmann
37 */
38 public class TmfUml2SDSyncLoaderFilterTest {
39
40 private static Uml2SDTestFacility fFacility;
41 private static List<FilterCriteria> filterToSave;
42
43 /**
44 * Initialization
45 */
46 @BeforeClass
47 public static void setUpClass() {
48 fFacility = Uml2SDTestFacility.getInstance();
49 fFacility.init();
50 fFacility.selectExperiment();
51
52 /* Create Filter Criteria */
53 filterToSave = new ArrayList<>();
54 Criteria criteria = new Criteria();
55 criteria.setLifeLineSelected(true);
56 criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
57 filterToSave.add(new FilterCriteria(criteria, false, false));
58
59 criteria = new Criteria();
60 criteria.setLifeLineSelected(true);
61 criteria.setExpression(IUml2SDTestConstants.MASTER_PLAYER_NAME);
62 filterToSave.add(new FilterCriteria(criteria, false, false));
63
64 criteria = new Criteria();
65 criteria.setSyncMessageSelected(true);
66 criteria.setExpression("BALL_.*");
67 filterToSave.add(new FilterCriteria(criteria, false, false));
68 }
69
70 /**
71 * Cleanup
72 */
73 @AfterClass
74 public static void tearDownClass() {
75 fFacility.disposeExperiment();
76 fFacility.dispose();
77 fFacility = null;
78 }
79
80 /**
81 * Test Case set-up code.
82 */
83 @Before
84 public void beforeTest(){
85 // Make sure we are at the first page
86 fFacility.firstPage();
87 }
88
89 /**
90 * Test case clean-up code.
91 */
92 @After
93 public void afterTest() {
94 filterToSave.get(0).setActive(false);
95 filterToSave.get(1).setActive(false);
96 filterToSave.get(2).setActive(false);
97 fFacility.getLoader().filter(filterToSave);
98 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
99 }
100
101 /**
102 * Verify the filter lifelines (1 out of 2 is hidden)
103 *
104 * Verified Methods: loader.filter()
105 * Expected result: Only one lifeline is visible with no messages
106 */
107 @Test
108 public void verifyFilter1of2() {
109 // Initialize the filter
110 filterToSave.get(0).setActive(true);
111 // Run the filter
112 fFacility.getLoader().filter(filterToSave);
113 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
114
115 assertEquals("filter", 1, fFacility.getSdView().getFrame().lifeLinesCount());
116 assertEquals("filter", IUml2SDTestConstants.MASTER_PLAYER_NAME, fFacility.getSdView().getFrame().getLifeline(0).getName());
117 assertEquals("filter", 0, fFacility.getSdView().getFrame().syncMessageCount());
118 }
119
120
121 /**
122 * Verify the filter lifelines (2 out of 2 are hidden)
123 *
124 * Verified Methods: loader.filter(), loader.fillCurrentPage()
125 * Expected result: Neiter liflines nor messages are visible
126 */
127 @Test
128 public void verifyFilter2of2() {
129 // Initialize the filter
130 filterToSave.get(0).setActive(true);
131 filterToSave.get(1).setActive(true);
132 // Run the filter
133 fFacility.getLoader().filter(filterToSave);
134 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
135
136 assertEquals("filter", 0, fFacility.getSdView().getFrame().lifeLinesCount());
137 assertEquals("filter", 0, fFacility.getSdView().getFrame().syncMessageCount());
138 }
139
140 /**
141 * Verify removal of all filters
142 *
143 * Verified Methods: loader.filter(), loader.fillCurrentPage()
144 * Expected result: Everything is shown
145 */
146 @Test
147 public void verifyRemoval() {
148 // First set 2 filter
149 filterToSave.get(0).setActive(true);
150 filterToSave.get(1).setActive(true);
151 fFacility.getLoader().filter(filterToSave);
152 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
153
154 // Remove the filter
155 filterToSave.get(0).setActive(false);
156 filterToSave.get(1).setActive(false);
157 fFacility.getLoader().filter(filterToSave);
158 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
159
160 assertEquals("filter", 2, fFacility.getSdView().getFrame().lifeLinesCount());
161 assertEquals("filter", IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE,
162 fFacility.getSdView().getFrame().syncMessageCount());
163 }
164
165 /**
166 * Verify filter of messages
167 *
168 * Verified Methods: loader.filter(), loader.fillCurrentPage()
169 * Expected result: Only particular messages are shown
170 */
171 @Test
172 public void verifyMessageFilter() {
173 // Initialize the filter
174 filterToSave.get(2).setActive(true);
175 // Run the filter
176 fFacility.getLoader().filter(filterToSave);
177 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
178
179 assertEquals("filter", 2, fFacility.getSdView().getFrame().lifeLinesCount());
180 assertEquals("filter", 6, fFacility.getSdView().getFrame().syncMessageCount());
181
182 String messages[] = { "REGISTER_PLAYER_REQUEST", "REGISTER_PLAYER_REPLY",
183 "GAME_REQUEST", "GAME_REPLY", "START_GAME_REQUEST", "START_GAME_REPLY" };
184
185 for (int i = 0; i < messages.length; i++) {
186 SyncMessage msg = fFacility.getSdView().getFrame().getSyncMessage(i);
187 assertTrue("filter", msg instanceof TmfSyncMessage);
188 assertEquals("filter", messages[i], msg.getName());
189 }
190 }
191
192 /**
193 * Verify filter lifeline (1 out of three lifelines). Note that filter was
194 * set during change of page.
195 *
196 * Verified Methods: loader.filter(), loader.fillCurrentPage()
197 * Expected result: Only 2 lifelines and their interactions are shown
198 */
199 @Test
200 public void verifyFilter1of3() {
201 filterToSave.get(0).setActive(true);
202 fFacility.getLoader().filter(filterToSave);
203 fFacility.setPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES);
204
205 assertEquals("filter", 2, fFacility.getSdView().getFrame().lifeLinesCount());
206 String lifelines[] = { IUml2SDTestConstants.MASTER_PLAYER_NAME, IUml2SDTestConstants.SECOND_PLAYER_NAME };
207
208 for (int i = 0; i < lifelines.length; i++) {
209 Lifeline line = fFacility.getSdView().getFrame().getLifeline(i);
210 assertEquals("filter", lifelines[i], line.getName());
211 }
212
213 assertTrue(fFacility.getSdView().getFrame().syncMessageCount() > 0);
214 }
215 }
This page took 0.042212 seconds and 5 git commands to generate.