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
.TestCase
;
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
;
25 public class TmfUml2SDSyncLoaderExpTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
30 private Uml2SDTestFacility fFacility
;
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 public TmfUml2SDSyncLoaderExpTest() {
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 public void setUp() throws Exception
{
45 fFacility
= Uml2SDTestFacility
.getInstance();
46 fFacility
.init(false);
47 // create filter criteria (incl. save)
48 fFacility
.createFilterCriteria();
49 fFacility
.selectExperiment();
54 public void tearDown() throws Exception
{
60 @SuppressWarnings("nls")
61 public void testExperimentHandling() {
65 * Description: Verify setup
66 * Verified Methods: loader.getTitleString()
69 * Expected result: Title, view name are set properly.
72 assertEquals("getTitleString", "Component Interactions", fFacility
.getLoader().getTitleString());
73 assertEquals("getPartName", "Sequence Diagram", fFacility
.getSdView().getPartName());
74 assertNotNull("getFrame", fFacility
.getSdView().getFrame());
76 fFacility
.disposeExperiment();
78 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
79 verifyPage(0, 0, false, false, 0);
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..
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.
91 for(int i
= 0; i
< 5; i
++) {
92 fFacility
.selectExperiment(false);
93 fFacility
.delay(IUml2SDTestConstants
.INITIAL_INDEX_DELAY
);
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");
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.
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.
118 verifyPage(0, 0, false, false, 0);
120 // verify that all enable filters are disabled after disposal
121 List
<FilterCriteria
> filter
= FilterListDialog
.getGlobalFilters();
123 for (FilterCriteria filterCriteria
: filter
) {
124 assertFalse("exp.dispose", filterCriteria
.isActive());
129 * Description: Verifies the disposal of the loader.
130 * Verified Methods: loader.dispose(),
131 * Expected result: All providers are removed from SDView.
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);
140 // Set again loader as signal handler, which was removed by the the dispose above
141 TmfSignalManager
.register(fFacility
.getLoader());
145 * Description: Verifies setViewer.
146 * Verified Methods: loader.setViewer
147 * Expected result: Paging, find and filter provider are set
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
);
156 assertTrue("loader.setViewer", fFacility
.getSdView().getSDFindProvider() != null);
158 assertTrue("loader.setViewer", fFacility
.getSdView().getSDFilterProvider() != null);
160 // All other providers are not used.
161 assertTrue("loader.setViewer", fFacility
.getSdView().getExtendedFindProvider() == null);
162 assertTrue("loader.setViewer", fFacility
.getSdView().getExtendedFilterProvider() == null);
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());
170 assertTrue("hasNextpage", fFacility
.getLoader().hasNextPage());
172 assertFalse("hasNextPage", fFacility
.getLoader().hasNextPage());
175 assertTrue("hasPrevPage", fFacility
.getLoader().hasPrevPage());
177 assertFalse("hasPrevPage", fFacility
.getLoader().hasPrevPage());
179 assertEquals("lifeLinesCount", lifelineCount
, fFacility
.getSdView().getFrame().lifeLinesCount());