1 /*******************************************************************************
2 * Copyright (c) 2011 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
.impl
;
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
.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
;
27 public class TmfUml2SDSyncLoaderExpTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
32 private Uml2SDTestFacility fFacility
;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
39 * Returns test setup used when executing test case stand-alone.
40 * @return Test setup class
42 public static Test
suite() {
43 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderExpTest
.class));
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 public TmfUml2SDSyncLoaderExpTest() {
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 public void setUp() throws Exception
{
59 fFacility
= Uml2SDTestFacility
.getInstance();
60 // create filter criteria (incl. save)
61 fFacility
.createFilterCriteria();
62 fFacility
.selectExperiment();
67 public void tearDown() throws Exception
{
72 @SuppressWarnings("nls")
73 public void testExperimentHandling() {
77 * Description: Verify setup
78 * Verified Methods: loader.getTitleString()
81 * Expected result: Title, view name are set properly.
84 assertEquals("getTitleString", "Component Interactions", fFacility
.getLoader().getTitleString());
85 assertEquals("getPartName", "Sequence Diagram", fFacility
.getSdView().getPartName());
86 assertNotNull("getFrame", fFacility
.getSdView().getFrame());
88 fFacility
.disposeExperiment();
90 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
91 verifyPage(0, 0, false, false, 0);
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..
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.
103 for(int i
= 0; i
< 5; i
++) {
104 fFacility
.selectExperiment(false);
105 fFacility
.delay(IUml2SDTestConstants
.INITIAL_INDEX_DELAY
);
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");
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.
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.
130 verifyPage(0, 0, false, false, 0);
132 // verify that all enable filters are disabled after disposal
133 List
<FilterCriteria
> filter
= FilterListDialog
.getGlobalFilters();
135 for (FilterCriteria filterCriteria
: filter
) {
136 assertFalse("exp.dispose", filterCriteria
.isActive());
141 * Description: Verifies the disposal of the loader.
142 * Verified Methods: loader.dispose(),
143 * Expected result: All providers are removed from SDView.
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);
152 // Set again loader as signal handler, which was removed by the the dispose above
153 TmfSignalManager
.register(fFacility
.getLoader());
157 * Description: Verifies setViewer.
158 * Verified Methods: loader.setViewer
159 * Expected result: Paging, find and filter provider are set
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
);
168 assertTrue("loader.setViewer", fFacility
.getSdView().getSDFindProvider() != null);
170 assertTrue("loader.setViewer", fFacility
.getSdView().getSDFilterProvider() != null);
172 // All other providers are not used.
173 assertTrue("loader.setViewer", fFacility
.getSdView().getExtendedFindProvider() == null);
174 assertTrue("loader.setViewer", fFacility
.getSdView().getExtendedFilterProvider() == null);
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());
182 assertTrue("hasNextpage", fFacility
.getLoader().hasNextPage());
184 assertFalse("hasNextPage", fFacility
.getLoader().hasNextPage());
187 assertTrue("hasPrevPage", fFacility
.getLoader().hasPrevPage());
189 assertFalse("hasPrevPage", fFacility
.getLoader().hasPrevPage());
191 assertEquals("lifeLinesCount", lifelineCount
, fFacility
.getSdView().getFrame().lifeLinesCount());