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