8012eeba77034b8249804efdb206d130c1645ff2
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderExpTest.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.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.fail;
21
22 import java.util.List;
23
24 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
25 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
26 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.FilterListDialog;
27 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider;
28 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider;
29 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 /**
35 * Test cases for Experiment handling.
36 *
37 * @author Bernd Hufmann
38 */
39 public class TmfUml2SDSyncLoaderExpTest {
40
41 private static Uml2SDTestFacility fFacility;
42
43 /**
44 * Initialization
45 */
46 @BeforeClass
47 public static void setUpClass() {
48 fFacility = Uml2SDTestFacility.getInstance();
49 // create filter criteria (incl. save)
50 fFacility.createFilterCriteria();
51 fFacility.selectExperiment();
52 }
53
54 /**
55 * Cleanup
56 */
57 @AfterClass
58 public static void tearDownClass() {
59 fFacility.disposeExperiment();
60 fFacility = null;
61 }
62
63 /**
64 * Verify setup
65 *
66 * Verified Methods: loader.getTitleString()
67 * view.getPartName()
68 * view.getFrame()
69 * Expected result: Title, view name are set properly.
70 */
71 @Test
72 public void verifySetup() {
73 assertEquals("getTitleString", "Component Interactions", fFacility.getLoader().getTitleString());
74 assertEquals("getPartName", "Sequence Diagram", fFacility.getSdView().getPartName());
75 assertNotNull("getFrame", fFacility.getSdView().getFrame());
76
77 fFacility.disposeExperiment();
78
79 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
80 verifyPage(0, 0, false, false, 0);
81 }
82
83 /**
84 * Verify cancellation of ongoing indexing.
85 *
86 * Verified Methods: loader.experimentSelected(), loader.experimentDisposed(), loader.nextPage()
87 * Expected result: No exceptions during cancellation and nextPage() operation.
88 *
89 * Note this test is not sufficient to verify the concurrent access of the loader attributes
90 * by multiple threads. Contention might happen but it's not guaranteed.
91 */
92 @Test
93 public void verifyCancel() {
94 for(int i = 0; i < 5; i++) {
95 fFacility.selectExperiment(false);
96 fFacility.delay(IUml2SDTestConstants.INITIAL_INDEX_DELAY);
97
98 try {
99 fFacility.disposeExperiment();
100 fFacility.getLoader().nextPage(); // to test out of bounce
101 // Note: To actually create an out of bound exception remove
102 // safety-checks in nextPage/moveToPage of loader class
103 } catch (Exception e){
104 // No Exception expected
105 fail("exp.select/exp.dispose");
106 }
107 }
108 }
109
110 /**
111 * Verify disposed experiment.
112 *
113 * Verified Methods: loader.nextPage(),
114 * loader.pagesCount(), loader.hasNextPage(), loader.hasPrevPage(),
115 * frame.syncMessagesCount, frame.lifeLinesCount
116 * Expected result: Page values and filter are reset.
117 *
118 * Note this test is not sufficient to verify the concurrent access of the loader attributes
119 * by multiple threads. Contention might happen but it's not guaranteed.
120 */
121 @Test
122 public void verifyDispose() {
123 verifyPage(0, 0, false, false, 0);
124
125 // verify that all enable filters are disabled after disposal
126 List<FilterCriteria> filter = FilterListDialog.getGlobalFilters();
127
128 for (FilterCriteria filterCriteria : filter) {
129 assertFalse("exp.dispose", filterCriteria.isActive());
130 }
131 }
132
133 /**
134 * Verify the disposal of the loader.
135 *
136 * Verified Methods: loader.dispose()
137 * Expected result: All providers are removed from SDView.
138 */
139 @Test
140 public void verifyLoaderDispose() {
141 fFacility.getLoader().dispose();
142 assertTrue("loader.dispose", fFacility.getSdView().getSDPagingProvider() == null);
143 assertTrue("loader.dispose", fFacility.getSdView().getSDFindProvider() == null);
144 assertTrue("loader.dispose", fFacility.getSdView().getSDFilterProvider() == null);
145 assertTrue("loader.dispose", fFacility.getSdView().getExtendedFindProvider() == null);
146 assertTrue("loader.dispose", fFacility.getSdView().getExtendedFilterProvider() == null);
147
148 // Set again loader as signal handler, which was removed by the the dispose above
149 TmfSignalManager.register(fFacility.getLoader());
150 }
151
152 /**
153 * Verify setViewer.
154 *
155 * Verified Methods: loader.setViewer
156 * Expected result: Paging, find and filter provider are set
157 */
158 @Test
159 public void testSetViewer() {
160 fFacility.getLoader().setViewer(fFacility.getSdView());
161 ISDPagingProvider pagingProvider = fFacility.getSdView().getSDPagingProvider();
162 assertTrue("loader.setViewer", pagingProvider != null);
163 assertTrue("loader.setViewer", pagingProvider instanceof ISDAdvancedPagingProvider);
164 assertTrue("loader.setViewer", pagingProvider instanceof TmfUml2SDSyncLoader);
165
166 assertTrue("loader.setViewer", fFacility.getSdView().getSDFindProvider() != null);
167
168 assertTrue("loader.setViewer", fFacility.getSdView().getSDFilterProvider() != null);
169
170 // All other providers are not used.
171 assertTrue("loader.setViewer", fFacility.getSdView().getExtendedFindProvider() == null);
172 assertTrue("loader.setViewer", fFacility.getSdView().getExtendedFilterProvider() == null);
173 }
174
175 private static void verifyPage(int currentPage, int numMsg, boolean hasNext,
176 boolean hasPrev, int lifelineCount) {
177 assertEquals("currentPage", currentPage, fFacility.getLoader().currentPage());
178 assertEquals("syncMessageCount, ", numMsg, fFacility.getSdView().getFrame().syncMessageCount());
179 if (hasNext) {
180 assertTrue("hasNextpage", fFacility.getLoader().hasNextPage());
181 } else {
182 assertFalse("hasNextPage", fFacility.getLoader().hasNextPage());
183 }
184 if (hasPrev) {
185 assertTrue("hasPrevPage", fFacility.getLoader().hasPrevPage());
186 } else {
187 assertFalse("hasPrevPage", fFacility.getLoader().hasPrevPage());
188 }
189 assertEquals("lifeLinesCount", lifelineCount, fFacility.getSdView().getFrame().lifeLinesCount());
190 }
191 }
This page took 0.038046 seconds and 4 git commands to generate.