Commit | Line | Data |
---|---|---|
73005152 | 1 | /******************************************************************************* |
df0b8ff4 | 2 | * Copyright (c) 2011, 2012 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 | |
11 | *******************************************************************************/ | |
df0b8ff4 | 12 | package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader; |
73005152 BH |
13 | |
14 | import java.util.ArrayList; | |
15 | import java.util.List; | |
16 | ||
4f5d9f9b | 17 | import junit.framework.Test; |
73005152 | 18 | import junit.framework.TestCase; |
4f5d9f9b | 19 | import junit.framework.TestSuite; |
73005152 BH |
20 | |
21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline; | |
22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage; | |
df0b8ff4 BH |
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; | |
73005152 | 26 | |
64636df8 BH |
27 | /** |
28 | * Filter test cases. | |
29 | * | |
30 | * @author Bernd Hufmann | |
31 | * | |
32 | */ | |
33 | @SuppressWarnings("nls") | |
73005152 BH |
34 | public class TmfUml2SDSyncLoaderFilterTest extends TestCase { |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Attributes | |
38 | // ------------------------------------------------------------------------ | |
39 | private Uml2SDTestFacility fFacility; | |
40 | ||
4f5d9f9b BH |
41 | // ------------------------------------------------------------------------ |
42 | // Static methods | |
64636df8 | 43 | // ------------------------------------------------------------------------ |
4f5d9f9b BH |
44 | |
45 | /** | |
46 | * Returns test setup used when executing test case stand-alone. | |
64636df8 | 47 | * @return Test setup class |
4f5d9f9b BH |
48 | */ |
49 | public static Test suite() { | |
50 | return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderFilterTest.class)); | |
51 | } | |
52 | ||
73005152 BH |
53 | // ------------------------------------------------------------------------ |
54 | // Constructors | |
55 | // ------------------------------------------------------------------------ | |
64636df8 BH |
56 | /** |
57 | * Constructor | |
58 | */ | |
73005152 BH |
59 | public TmfUml2SDSyncLoaderFilterTest() { |
60 | } | |
61 | ||
62 | // ------------------------------------------------------------------------ | |
63 | // Operations | |
64 | // ------------------------------------------------------------------------ | |
65 | @Override | |
66 | public void setUp() throws Exception { | |
67 | super.setUp(); | |
68 | fFacility = Uml2SDTestFacility.getInstance(); | |
73005152 BH |
69 | fFacility.selectExperiment(); |
70 | } | |
71 | ||
72 | ||
73 | @Override | |
74 | public void tearDown() throws Exception { | |
75 | fFacility.disposeExperiment(); | |
73005152 BH |
76 | fFacility = null; |
77 | super.tearDown(); | |
78 | } | |
64636df8 BH |
79 | |
80 | /** | |
81 | * Main method with test cases. | |
82 | */ | |
73005152 BH |
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)); | |
64636df8 | 91 | |
73005152 BH |
92 | criteria = new Criteria(); |
93 | criteria.setLifeLineSelected(true); | |
94 | criteria.setExpression(IUml2SDTestConstants.MASTER_PLAYER_NAME); | |
95 | filterToSave.add(new FilterCriteria(criteria, false, false)); | |
64636df8 | 96 | |
73005152 BH |
97 | criteria = new Criteria(); |
98 | criteria.setSyncMessageSelected(true); | |
99 | criteria.setExpression("BALL_.*"); //$NON-NLS-1$ | |
100 | filterToSave.add(new FilterCriteria(criteria, false, false)); | |
64636df8 | 101 | |
73005152 BH |
102 | /* |
103 | * Test Case: 001 | |
64636df8 BH |
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 | |
73005152 BH |
107 | */ |
108 | fFacility.getLoader().filter(filterToSave); | |
109 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); | |
64636df8 | 110 | |
73005152 BH |
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()); | |
64636df8 BH |
114 | |
115 | ||
73005152 BH |
116 | /* |
117 | * Test Case: 002 | |
64636df8 | 118 | * Description: Verify the filter lifelines (2 out of 2 are hidden) |
73005152 | 119 | * Verified Methods: loader.filter(), loader.fillCurrentPage() |
64636df8 | 120 | * Expected result: Neiter liflines nor messages are visible |
73005152 BH |
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()); | |
64636df8 | 128 | |
73005152 BH |
129 | /* |
130 | * Test Case: 003 | |
64636df8 BH |
131 | * Description: Verify removal of all filters |
132 | * Verified Methods: loader.filter(), loader.fillCurrentPage() | |
133 | * Expected result: Everything is shown | |
73005152 BH |
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); | |
64636df8 | 139 | |
73005152 BH |
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 | |
64636df8 BH |
145 | * Description: Verify filter of messages |
146 | * Verified Methods: loader.filter(), loader.fillCurrentPage() | |
73005152 BH |
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); | |
64636df8 | 152 | |
73005152 BH |
153 | assertEquals("filter", 2, fFacility.getSdView().getFrame().lifeLinesCount()); |
154 | assertEquals("filter", 6, fFacility.getSdView().getFrame().syncMessageCount()); | |
64636df8 | 155 | |
73005152 | 156 | String messages[] = { "REGISTER_PLAYER_REQUEST", "REGISTER_PLAYER_REPLY", "GAME_REQUEST", "GAME_REPLY", "START_GAME_REQUEST", "START_GAME_REPLY" }; |
64636df8 | 157 | |
73005152 BH |
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 | } | |
64636df8 | 163 | |
73005152 BH |
164 | /* |
165 | * Test Case: 005 | |
64636df8 BH |
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() | |
73005152 BH |
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 }; | |
64636df8 | 177 | |
73005152 BH |
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 | } | |
64636df8 | 182 | |
73005152 | 183 | assertTrue(fFacility.getSdView().getFrame().syncMessageCount() > 0); |
64636df8 | 184 | |
73005152 BH |
185 | filterToSave.get(2).setActive(false); |
186 | } | |
187 | } |