tmf: Enable the ctfadaptor and statistics unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderFilterTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 *******************************************************************************/
12 package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import junit.framework.Test;
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline;
22 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage;
23 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.Criteria;
24 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
25 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
26
27 /**
28 * Filter test cases.
29 *
30 * @author Bernd Hufmann
31 *
32 */
33 @SuppressWarnings("nls")
34 public class TmfUml2SDSyncLoaderFilterTest extends TestCase {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39 private Uml2SDTestFacility fFacility;
40
41 // ------------------------------------------------------------------------
42 // Static methods
43 // ------------------------------------------------------------------------
44
45 /**
46 * Returns test setup used when executing test case stand-alone.
47 * @return Test setup class
48 */
49 public static Test suite() {
50 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderFilterTest.class));
51 }
52
53 // ------------------------------------------------------------------------
54 // Constructors
55 // ------------------------------------------------------------------------
56 /**
57 * Constructor
58 */
59 public TmfUml2SDSyncLoaderFilterTest() {
60 }
61
62 // ------------------------------------------------------------------------
63 // Operations
64 // ------------------------------------------------------------------------
65 @Override
66 public void setUp() throws Exception {
67 super.setUp();
68 fFacility = Uml2SDTestFacility.getInstance();
69 fFacility.selectExperiment();
70 }
71
72
73 @Override
74 public void tearDown() throws Exception {
75 fFacility.disposeExperiment();
76 fFacility = null;
77 super.tearDown();
78 }
79
80 /**
81 * Main method with test cases.
82 */
83 public void testFilterHandling() {
84
85 // Create Filter Criteria
86 List<FilterCriteria> filterToSave = new ArrayList<FilterCriteria>();
87 Criteria criteria = new Criteria();
88 criteria.setLifeLineSelected(true);
89 criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
90 filterToSave.add(new FilterCriteria(criteria, true, false));
91
92 criteria = new Criteria();
93 criteria.setLifeLineSelected(true);
94 criteria.setExpression(IUml2SDTestConstants.MASTER_PLAYER_NAME);
95 filterToSave.add(new FilterCriteria(criteria, false, false));
96
97 criteria = new Criteria();
98 criteria.setSyncMessageSelected(true);
99 criteria.setExpression("BALL_.*"); //$NON-NLS-1$
100 filterToSave.add(new FilterCriteria(criteria, false, false));
101
102 /*
103 * Test Case: 001
104 * Description: Verify the filter lifelines (1 out of 2 is hidden)
105 * Verified Methods: loader.filter()
106 * Expected result: Only one lifeline is visible with no messages
107 */
108 fFacility.getLoader().filter(filterToSave);
109 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
110
111 assertEquals("filter", 1, fFacility.getSdView().getFrame().lifeLinesCount());
112 assertEquals("filter", IUml2SDTestConstants.MASTER_PLAYER_NAME, fFacility.getSdView().getFrame().getLifeline(0).getName());
113 assertEquals("filter", 0, fFacility.getSdView().getFrame().syncMessageCount());
114
115
116 /*
117 * Test Case: 002
118 * Description: Verify the filter lifelines (2 out of 2 are hidden)
119 * Verified Methods: loader.filter(), loader.fillCurrentPage()
120 * Expected result: Neiter liflines nor messages are visible
121 */
122 filterToSave.get(1).setActive(true);
123 fFacility.getLoader().filter(filterToSave);
124 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
125
126 assertEquals("filter", 0, fFacility.getSdView().getFrame().lifeLinesCount());
127 assertEquals("filter", 0, fFacility.getSdView().getFrame().syncMessageCount());
128
129 /*
130 * Test Case: 003
131 * Description: Verify removal of all filters
132 * Verified Methods: loader.filter(), loader.fillCurrentPage()
133 * Expected result: Everything is shown
134 */
135 filterToSave.get(0).setActive(false);
136 filterToSave.get(1).setActive(false);
137 fFacility.getLoader().filter(filterToSave);
138 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
139
140 assertEquals("filter", 2, fFacility.getSdView().getFrame().lifeLinesCount());
141 assertEquals("filter", IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, fFacility.getSdView().getFrame().syncMessageCount());
142
143 /*
144 * Test Case: 004
145 * Description: Verify filter of messages
146 * Verified Methods: loader.filter(), loader.fillCurrentPage()
147 * Expected result: Only particular messages are shown
148 */
149 filterToSave.get(2).setActive(true);
150 fFacility.getLoader().filter(filterToSave);
151 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
152
153 assertEquals("filter", 2, fFacility.getSdView().getFrame().lifeLinesCount());
154 assertEquals("filter", 6, fFacility.getSdView().getFrame().syncMessageCount());
155
156 String messages[] = { "REGISTER_PLAYER_REQUEST", "REGISTER_PLAYER_REPLY", "GAME_REQUEST", "GAME_REPLY", "START_GAME_REQUEST", "START_GAME_REPLY" };
157
158 for (int i = 0; i < messages.length; i++) {
159 SyncMessage msg = fFacility.getSdView().getFrame().getSyncMessage(i);
160 assertTrue("filter", msg instanceof TmfSyncMessage);
161 assertEquals("filter", messages[i], msg.getName());
162 }
163
164 /*
165 * Test Case: 005
166 * Description: Verify filter lifeline (1 out of three lifelines).
167 * Note that filter was set during change of page.
168 * Verified Methods: loader.filter(), loader.fillCurrentPage()
169 * Expected result: Only 2 lifelines and their interactions are shown
170 */
171 filterToSave.get(0).setActive(true);
172 filterToSave.get(2).setActive(false);
173 fFacility.setPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES);
174
175 assertEquals("filter", 2, fFacility.getSdView().getFrame().lifeLinesCount());
176 String lifelines[] = { IUml2SDTestConstants.MASTER_PLAYER_NAME, IUml2SDTestConstants.SECOND_PLAYER_NAME };
177
178 for (int i = 0; i < lifelines.length; i++) {
179 Lifeline line = fFacility.getSdView().getFrame().getLifeline(i);
180 assertEquals("filter", lifelines[i], line.getName());
181 }
182
183 assertTrue(fFacility.getSdView().getFrame().syncMessageCount() > 0);
184
185 filterToSave.get(2).setActive(false);
186 }
187 }
This page took 0.038909 seconds and 5 git commands to generate.