1 /*******************************************************************************
2 * Copyright (c) 2011-2013 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 * Alexandre Montplaisir - Port to JUnit4
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.tests
.views
.uml2sd
.loader
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertFalse
;
18 import static org
.junit
.Assert
.assertTrue
;
19 import static org
.junit
.Assert
.fail
;
21 import org
.junit
.AfterClass
;
22 import org
.junit
.BeforeClass
;
23 import org
.junit
.Test
;
26 * Test cases for pages handling.
28 * @author Bernd Hufmann
30 public class TmfUml2SDSyncLoaderPagesTest
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private static Uml2SDTestFacility fFacility
;
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
46 public static void setUpClass() {
47 fFacility
= Uml2SDTestFacility
.getInstance();
48 fFacility
.selectExperiment();
55 public static void tearDownClass() {
56 fFacility
.disposeExperiment();
62 * Description: Test number of pages.
63 * Verified Methods: loader.pagesCount().
64 * Expected result: ITestConstants.TOTAL_NUMBER_OF_PAGES of pages
67 public void verifyPagesCount() {
68 assertEquals(IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
, fFacility
.getLoader().pagesCount());
74 * Description: Tests next page feature.
75 * Verified Methods: loader.nextPage(), loader.fillCurrentPage(), loader.pagesCount(),
76 * loader.hasNextPage(), loader.hasPrevPage(),
77 * frame.syncMessagesCount, frame.lifeLinesCount
78 * Expected result: Expected values are return.
81 public void verifyNextPage() {
82 // assuming we are at the first page
83 for(int i
= 0; i
< IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
-2; i
++) {
86 if (i
+1 == IUml2SDTestConstants
.PAGE_OF_ALL_LIFELINES
) {
87 verifyPage(i
+1, IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
, true, true, IUml2SDTestConstants
.NUM_OF_ALL_LIFELINES
);
90 verifyPage(i
+1, IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
, true, true);
96 verifyPage(IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
- 1, IUml2SDTestConstants
.NUM_MESSAGES_OF_LAST_PAGE
, false, true);
98 // Check for index out of bounce
100 fFacility
.getLoader().nextPage();
101 } catch (Exception e
) {
105 fFacility
.firstPage();
110 * Description: Test previous page feature.
111 * Verified Methods: loader.prevPage(), loader.fillCurrentPage(), loader.pagesCount(),
112 * loader.hasNextPage(), loader.hasPrevPage(),
113 * frame.syncMessagesCount, frame.lifeLinesCount
114 * Expected result: Expected values are return.
117 public void verifyPrevPage() {
119 fFacility
.lastPage();
120 assertEquals(IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
- 1, fFacility
.getLoader().currentPage());
121 assertEquals(IUml2SDTestConstants
.NUM_MESSAGES_OF_LAST_PAGE
, fFacility
.getSdView().getFrame().syncMessageCount());
122 assertFalse(fFacility
.getLoader().hasNextPage());
123 assertTrue(fFacility
.getLoader().hasPrevPage());
124 assertEquals(2, fFacility
.getSdView().getFrame().lifeLinesCount());
126 for(int i
= IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
-2; i
> 0; i
--) {
127 fFacility
.prevPage();
128 if (i
== IUml2SDTestConstants
.PAGE_OF_ALL_LIFELINES
) {
129 verifyPage(i
, IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
, true, true, IUml2SDTestConstants
.NUM_OF_ALL_LIFELINES
);
131 verifyPage(i
, IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
, true, true);
135 fFacility
.prevPage();
136 verifyPage(0, IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
, true, false);
138 // Check for index out of bounce
140 fFacility
.getLoader().prevPage();
141 } catch (Exception e
) {
148 * Description: Test first page feature.
149 * Verified Methods: loader.firstPage(), loader.fillCurrentPage(), loader.pagesCount(),
150 * loader.hasNextPage(), loader.hasPrevPage(),
151 * frame.syncMessagesCount, frame.lifeLinesCount
152 * Expected result: Expected values are return.
155 public void verifyFirstPage() {
156 fFacility
.lastPage();
159 fFacility
.firstPage();
160 verifyPage(0, IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
, true, false);
165 * Description: Test last page feature.
166 * Verified Methods: loader.lastPage(), loader.pagesCount(), loader.hasNextPage(), loader.hasPrevPage()
167 * frame.syncMessagesCount, frame.lifeLinesCount
168 * Expected result: Expected values are return.
171 public void verifyLastPage() {
172 fFacility
.lastPage();
173 verifyPage(IUml2SDTestConstants
.TOTAL_NUMBER_OF_PAGES
- 1, IUml2SDTestConstants
.NUM_MESSAGES_OF_LAST_PAGE
, false, true);
174 fFacility
.firstPage();
179 * Description: Test move to any page feature.
180 * Verified Methods: loader.pageNumberChanged(), loader.fillCurrentPage(), loader.pagesCount(),
181 * loader.hasNextPage(), loader.hasPrevPage(),
182 * frame.syncMessagesCount, frame.lifeLinesCount
183 * Expected result: Expected values are return.
186 public void verifyPageNumberChanged() {
188 fFacility
.setPage(IUml2SDTestConstants
.PAGE_OF_ALL_LIFELINES
);
189 verifyPage(IUml2SDTestConstants
.PAGE_OF_ALL_LIFELINES
,
190 IUml2SDTestConstants
.MAX_MESSEAGES_PER_PAGE
, true, true,
191 IUml2SDTestConstants
.NUM_OF_ALL_LIFELINES
);
192 fFacility
.firstPage();
195 private static void verifyPage(int currentPage
, int numMsg
, boolean hasNext
, boolean hasPrev
) {
196 verifyPage(currentPage
, numMsg
, hasNext
, hasPrev
, IUml2SDTestConstants
.DEFAULT_NUM_LIFELINES
);
199 private static void verifyPage(int currentPage
, int numMsg
, boolean hasNext
,
200 boolean hasPrev
, int lifelineCount
) {
201 assertEquals("currentPage", currentPage
, fFacility
.getLoader().currentPage());
202 assertEquals("syncMessageCount, ", numMsg
, fFacility
.getSdView().getFrame().syncMessageCount());
204 assertTrue("hasNextpage", fFacility
.getLoader().hasNextPage());
206 assertFalse("hasNextPage", fFacility
.getLoader().hasNextPage());
209 assertTrue("hasPrevPage", fFacility
.getLoader().hasPrevPage());
211 assertFalse("hasPrevPage", fFacility
.getLoader().hasPrevPage());
213 assertEquals("lifeLinesCount", lifelineCount
, fFacility
.getSdView().getFrame().lifeLinesCount());