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