Commit | Line | Data |
---|---|---|
73005152 | 1 | /******************************************************************************* |
90ed5958 | 2 | * Copyright (c) 2011-2013 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 | |
df0b8ff4 | 14 | package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader; |
73005152 | 15 | |
90ed5958 AM |
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; | |
73005152 | 21 | |
90ed5958 | 22 | import java.util.List; |
73005152 | 23 | |
6c13869b | 24 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; |
df0b8ff4 BH |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterCriteria; |
26 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterListDialog; | |
73005152 BH |
27 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider; |
28 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider; | |
df0b8ff4 | 29 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader; |
90ed5958 AM |
30 | import org.junit.AfterClass; |
31 | import org.junit.BeforeClass; | |
32 | import org.junit.Test; | |
73005152 | 33 | |
64636df8 BH |
34 | /** |
35 | * Test cases for Experiment handling. | |
36 | * | |
37 | * @author Bernd Hufmann | |
64636df8 | 38 | */ |
90ed5958 | 39 | public class TmfUml2SDSyncLoaderExpTest { |
73005152 | 40 | |
90ed5958 | 41 | private static Uml2SDTestFacility fFacility; |
4f5d9f9b BH |
42 | |
43 | /** | |
90ed5958 | 44 | * Initialization |
4f5d9f9b | 45 | */ |
90ed5958 AM |
46 | @BeforeClass |
47 | public static void setUpClass() { | |
73005152 | 48 | fFacility = Uml2SDTestFacility.getInstance(); |
73005152 BH |
49 | // create filter criteria (incl. save) |
50 | fFacility.createFilterCriteria(); | |
51 | fFacility.selectExperiment(); | |
52 | } | |
53 | ||
90ed5958 AM |
54 | /** |
55 | * Cleanup | |
56 | */ | |
57 | @AfterClass | |
58 | public static void tearDownClass() { | |
59 | fFacility.disposeExperiment(); | |
73005152 | 60 | fFacility = null; |
73005152 | 61 | } |
64636df8 | 62 | |
64636df8 | 63 | /** |
90ed5958 AM |
64 | * Verify setup |
65 | * | |
66 | * Verified Methods: loader.getTitleString() | |
67 | * view.getPartName() | |
68 | * view.getFrame() | |
69 | * Expected result: Title, view name are set properly. | |
64636df8 | 70 | */ |
90ed5958 AM |
71 | @Test |
72 | public void verifySetup() { | |
73005152 BH |
73 | assertEquals("getTitleString", "Component Interactions", fFacility.getLoader().getTitleString()); |
74 | assertEquals("getPartName", "Sequence Diagram", fFacility.getSdView().getPartName()); | |
75 | assertNotNull("getFrame", fFacility.getSdView().getFrame()); | |
64636df8 | 76 | |
73005152 | 77 | fFacility.disposeExperiment(); |
64636df8 | 78 | |
73005152 BH |
79 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); |
80 | verifyPage(0, 0, false, false, 0); | |
90ed5958 | 81 | } |
64636df8 | 82 | |
90ed5958 AM |
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() { | |
73005152 BH |
94 | for(int i = 0; i < 5; i++) { |
95 | fFacility.selectExperiment(false); | |
96 | fFacility.delay(IUml2SDTestConstants.INITIAL_INDEX_DELAY); | |
64636df8 | 97 | |
73005152 | 98 | try { |
faa38350 | 99 | fFacility.disposeExperiment(); |
73005152 | 100 | fFacility.getLoader().nextPage(); // to test out of bounce |
64636df8 BH |
101 | // Note: To actually create an out of bound exception remove |
102 | // safety-checks in nextPage/moveToPage of loader class | |
73005152 BH |
103 | } catch (Exception e){ |
104 | // No Exception expected | |
105 | fail("exp.select/exp.dispose"); | |
106 | } | |
107 | } | |
90ed5958 | 108 | } |
73005152 | 109 | |
90ed5958 AM |
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() { | |
73005152 BH |
123 | verifyPage(0, 0, false, false, 0); |
124 | ||
125 | // verify that all enable filters are disabled after disposal | |
126 | List<FilterCriteria> filter = FilterListDialog.getGlobalFilters(); | |
64636df8 | 127 | |
73005152 BH |
128 | for (FilterCriteria filterCriteria : filter) { |
129 | assertFalse("exp.dispose", filterCriteria.isActive()); | |
130 | } | |
90ed5958 | 131 | } |
64636df8 | 132 | |
90ed5958 AM |
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() { | |
73005152 BH |
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); | |
64636df8 BH |
147 | |
148 | // Set again loader as signal handler, which was removed by the the dispose above | |
149 | TmfSignalManager.register(fFacility.getLoader()); | |
90ed5958 | 150 | } |
64636df8 | 151 | |
90ed5958 AM |
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() { | |
73005152 BH |
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); | |
64636df8 | 165 | |
73005152 BH |
166 | assertTrue("loader.setViewer", fFacility.getSdView().getSDFindProvider() != null); |
167 | ||
168 | assertTrue("loader.setViewer", fFacility.getSdView().getSDFilterProvider() != null); | |
64636df8 | 169 | |
73005152 BH |
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 | ||
90ed5958 AM |
175 | private static void verifyPage(int currentPage, int numMsg, boolean hasNext, |
176 | boolean hasPrev, int lifelineCount) { | |
73005152 BH |
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 | } |