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