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 junit.framework.Test;
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
18
public class TmfUml2SDSyncLoaderPagesTest extends TestCase {
20
// ------------------------------------------------------------------------
22
// ------------------------------------------------------------------------
23
private Uml2SDTestFacility fFacility;
25
// ------------------------------------------------------------------------
27
// ------------------------------------------------------------------------
30
* Returns test setup used when executing test case stand-alone.
31
* @return Test setup class
33
public static Test suite() {
34
return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderPagesTest.class));
37
// ------------------------------------------------------------------------
39
// ------------------------------------------------------------------------
40
public TmfUml2SDSyncLoaderPagesTest() {
43
// ------------------------------------------------------------------------
45
// ------------------------------------------------------------------------
47
public void setUp() throws Exception {
49
fFacility = Uml2SDTestFacility.getInstance();
50
fFacility.selectExperiment();
55
public void tearDown() throws Exception {
56
fFacility.disposeExperiment();
61
public void testPageHandling() {
68
verifyPageNumberChanged();
72
private void verifyPagesCount() {
76
* Description: Test number of pages.
77
* Verified Methods: loader.pagesCount().
78
* Expected result: ITestConstants.TOTAL_NUMBER_OF_PAGES of pages
80
assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES, fFacility.getLoader().pagesCount());
83
private void verifyNextPage() {
84
// assuming we are at the first page
88
* Description: Tests next page feature.
89
* Verified Methods: loader.nextPage(), loader.fillCurrentPage(), loader.pagesCount(),
90
* loader.hasNextPage(), loader.hasPrevPage(),
91
* frame.syncMessagesCount, frame.lifeLinesCount
92
* Expected result: Expected values are return.
95
for(int i = 0; i < IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES-2; i++) {
98
if (i+1 == IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES) {
99
verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
102
verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
107
fFacility.nextPage();
108
verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
110
// Check for index out of bounce
112
fFacility.getLoader().nextPage();
113
} catch (Exception e) {
117
fFacility.firstPage();
121
private void verifyPrevPage() {
122
// assuming we are at the first page
126
* Description: Test previous page feature.
127
* Verified Methods: loader.prevPage(), loader.fillCurrentPage(), loader.pagesCount(),
128
* loader.hasNextPage(), loader.hasPrevPage(),
129
* frame.syncMessagesCount, frame.lifeLinesCount
130
* Expected result: Expected values are return.
134
fFacility.lastPage();
135
assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, fFacility.getLoader().currentPage());
136
assertEquals(IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, fFacility.getSdView().getFrame().syncMessageCount());
137
assertFalse(fFacility.getLoader().hasNextPage());
138
assertTrue(fFacility.getLoader().hasPrevPage());
139
assertEquals(2, fFacility.getSdView().getFrame().lifeLinesCount());
141
for(int i = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES-2; i > 0; i--) {
142
fFacility.prevPage();
143
if (i == IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES)
144
verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
146
verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
149
fFacility.prevPage();
150
verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
152
// Check for index out of bounce
154
fFacility.getLoader().prevPage();
155
} catch (Exception e) {
160
private void verifyFirstPage() {
161
fFacility.lastPage();
164
* Description: Test first page feature.
165
* Verified Methods: loader.firstPage(), loader.fillCurrentPage(), loader.pagesCount(),
166
* loader.hasNextPage(), loader.hasPrevPage(),
167
* frame.syncMessagesCount, frame.lifeLinesCount
168
* Expected result: Expected values are return.
172
fFacility.firstPage();
173
verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
177
private void verifyLastPage() {
180
* Description: Test last page feature.
181
* Verified Methods: loader.lastPage(), loader.pagesCount(), loader.hasNextPage(), loader.hasPrevPage()
182
* frame.syncMessagesCount, frame.lifeLinesCount
183
* Expected result: Expected values are return.
185
fFacility.lastPage();
186
verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
187
fFacility.firstPage();
190
private void verifyPageNumberChanged() {
194
* Description: Test move to any page feature.
195
* Verified Methods: loader.pageNumberChanged(), loader.fillCurrentPage(), loader.pagesCount(),
196
* loader.hasNextPage(), loader.hasPrevPage(),
197
* frame.syncMessagesCount, frame.lifeLinesCount
198
* Expected result: Expected values are return.
202
fFacility.setPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES);
203
verifyPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
204
fFacility.firstPage();
207
private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev) {
208
verifyPage(currentPage, numMsg, hasNext, hasPrev, IUml2SDTestConstants.DEFAULT_NUM_LIFELINES);
211
@SuppressWarnings("nls")
212
private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev, int lifelineCount) {
213
assertEquals("currentPage", currentPage, fFacility.getLoader().currentPage());
214
assertEquals("syncMessageCount, ", numMsg, fFacility.getSdView().getFrame().syncMessageCount());
216
assertTrue("hasNextpage", fFacility.getLoader().hasNextPage());
218
assertFalse("hasNextPage", fFacility.getLoader().hasNextPage());
221
assertTrue("hasPrevPage", fFacility.getLoader().hasPrevPage());
223
assertFalse("hasPrevPage", fFacility.getLoader().hasPrevPage());
225
assertEquals("lifeLinesCount", lifelineCount, fFacility.getSdView().getFrame().lifeLinesCount());