1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.views
.uml2sd
.loader
;
14 import java
.util
.List
;
16 import junit
.framework
.Test
;
17 import junit
.framework
.TestCase
;
18 import junit
.framework
.TestSuite
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalManager
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDPagingProvider
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
.TmfUml2SDSyncLoader
;
28 * Test cases for Experiment handling.
30 * @author Bernd Hufmann
33 @SuppressWarnings("nls")
34 public class TmfUml2SDSyncLoaderExpTest
extends TestCase
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
39 private Uml2SDTestFacility fFacility
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * Returns test setup used when executing test case stand-alone.
47 * @return Test setup class
49 public static Test
suite() {
50 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderExpTest
.class));
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
60 public TmfUml2SDSyncLoaderExpTest() {
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 public void setUp() throws Exception
{
69 fFacility
= Uml2SDTestFacility
.getInstance();
70 // create filter criteria (incl. save)
71 fFacility
.createFilterCriteria();
72 fFacility
.selectExperiment();
77 public void tearDown() throws Exception
{
84 * Main method with test cases.
86 public void testExperimentHandling() {
90 * Description: Verify setup
91 * Verified Methods: loader.getTitleString()
94 * Expected result: Title, view name are set properly.
97 assertEquals("getTitleString", "Component Interactions", fFacility
.getLoader().getTitleString());
98 assertEquals("getPartName", "Sequence Diagram", fFacility
.getSdView().getPartName());
99 assertNotNull("getFrame", fFacility
.getSdView().getFrame());
101 fFacility
.disposeExperiment();
103 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
104 verifyPage(0, 0, false, false, 0);
108 * Description: Verifies cancellation of ongoing indexing.
109 * Verified Methods: loader.experimentSelected(), loader.experimentDisposed(), loader.nextPage()
110 * Expected result: No exceptions during cancellation and nextPage() operation..
112 * Note this test is not sufficient to verify the concurrent access of the loader attributes
113 * by multiple threads. Contention might happen but it's not guaranteed.
116 for(int i
= 0; i
< 5; i
++) {
117 fFacility
.selectExperiment(false);
118 fFacility
.delay(IUml2SDTestConstants
.INITIAL_INDEX_DELAY
);
121 fFacility
.disposeExperiment();
122 fFacility
.getLoader().nextPage(); // to test out of bounce
123 // Note: To actually create an out of bound exception remove
124 // safety-checks in nextPage/moveToPage of loader class
125 } catch (Exception e
){
126 // No Exception expected
127 fail("exp.select/exp.dispose");
133 * Description: Verifies disposed experiment.
134 * Verified Methods: loader.nextPage(),
135 * loader.pagesCount(), loader.hasNextPage(), loader.hasPrevPage(),
136 * frame.syncMessagesCount, frame.lifeLinesCount
137 * Expected result: Page values and filter are reset.
139 * Note this test is not sufficient to verify the concurrent access ofthe loader attributes
140 * by multiple threads. Contention might happen but it's not guaranteed.
143 verifyPage(0, 0, false, false, 0);
145 // verify that all enable filters are disabled after disposal
146 List
<FilterCriteria
> filter
= FilterListDialog
.getGlobalFilters();
148 for (FilterCriteria filterCriteria
: filter
) {
149 assertFalse("exp.dispose", filterCriteria
.isActive());
154 * Description: Verifies the disposal of the loader.
155 * Verified Methods: loader.dispose(),
156 * Expected result: All providers are removed from SDView.
158 fFacility
.getLoader().dispose();
159 assertTrue("loader.dispose", fFacility
.getSdView().getSDPagingProvider() == null);
160 assertTrue("loader.dispose", fFacility
.getSdView().getSDFindProvider() == null);
161 assertTrue("loader.dispose", fFacility
.getSdView().getSDFilterProvider() == null);
162 assertTrue("loader.dispose", fFacility
.getSdView().getExtendedFindProvider() == null);
163 assertTrue("loader.dispose", fFacility
.getSdView().getExtendedFilterProvider() == null);
165 // Set again loader as signal handler, which was removed by the the dispose above
166 TmfSignalManager
.register(fFacility
.getLoader());
170 * Description: Verifies setViewer.
171 * Verified Methods: loader.setViewer
172 * Expected result: Paging, find and filter provider are set
175 fFacility
.getLoader().setViewer(fFacility
.getSdView());
176 ISDPagingProvider pagingProvider
= fFacility
.getSdView().getSDPagingProvider();
177 assertTrue("loader.setViewer", pagingProvider
!= null);
178 assertTrue("loader.setViewer", pagingProvider
instanceof ISDAdvancedPagingProvider
);
179 assertTrue("loader.setViewer", pagingProvider
instanceof TmfUml2SDSyncLoader
);
181 assertTrue("loader.setViewer", fFacility
.getSdView().getSDFindProvider() != null);
183 assertTrue("loader.setViewer", fFacility
.getSdView().getSDFilterProvider() != null);
185 // All other providers are not used.
186 assertTrue("loader.setViewer", fFacility
.getSdView().getExtendedFindProvider() == null);
187 assertTrue("loader.setViewer", fFacility
.getSdView().getExtendedFilterProvider() == null);
190 private void verifyPage(int currentPage
, int numMsg
, boolean hasNext
, boolean hasPrev
, int lifelineCount
) {
191 assertEquals("currentPage", currentPage
, fFacility
.getLoader().currentPage());
192 assertEquals("syncMessageCount, ", numMsg
, fFacility
.getSdView().getFrame().syncMessageCount());
194 assertTrue("hasNextpage", fFacility
.getLoader().hasNextPage());
196 assertFalse("hasNextPage", fFacility
.getLoader().hasNextPage());
199 assertTrue("hasPrevPage", fFacility
.getLoader().hasPrevPage());
201 assertFalse("hasPrevPage", fFacility
.getLoader().hasPrevPage());
203 assertEquals("lifeLinesCount", lifelineCount
, fFacility
.getSdView().getFrame().lifeLinesCount());