ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderPagesTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
15
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;
20
21 import org.junit.AfterClass;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24
25 /**
26 * Test cases for pages handling.
27 *
28 * @author Bernd Hufmann
29 */
30 public class TmfUml2SDSyncLoaderPagesTest {
31
32 // ------------------------------------------------------------------------
33 // Attributes
34 // ------------------------------------------------------------------------
35
36 private static Uml2SDTestFacility fFacility;
37
38 // ------------------------------------------------------------------------
39 // Operations
40 // ------------------------------------------------------------------------
41
42 /**
43 * Initialization
44 */
45 @BeforeClass
46 public static void setUpClass() {
47 fFacility = Uml2SDTestFacility.getInstance();
48 fFacility.selectExperiment();
49 }
50
51 /**
52 * Cleanup
53 */
54 @AfterClass
55 public static void tearDownClass() {
56 fFacility.disposeExperiment();
57 fFacility = null;
58 }
59
60 /**
61 * Test Case: 001
62 * Description: Test number of pages.
63 * Verified Methods: loader.pagesCount().
64 * Expected result: ITestConstants.TOTAL_NUMBER_OF_PAGES of pages
65 */
66 @Test
67 public void verifyPagesCount() {
68 assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES, fFacility.getLoader().pagesCount());
69 }
70
71
72 /**
73 * Test Case: 002
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.
79 */
80 @Test
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++) {
84 fFacility.nextPage();
85
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);
88 }
89 else {
90 verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
91 }
92 }
93
94 // Last Page
95 fFacility.nextPage();
96 verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
97
98 // Check for index out of bounce
99 try {
100 fFacility.getLoader().nextPage();
101 } catch (Exception e) {
102 fail();
103 }
104
105 fFacility.firstPage();
106 }
107
108 /**
109 * Test Case: 003
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.
115 */
116 @Test
117 public void verifyPrevPage() {
118 // Last Page
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());
125
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);
130 } else {
131 verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
132 }
133 }
134
135 fFacility.prevPage();
136 verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
137
138 // Check for index out of bounce
139 try {
140 fFacility.getLoader().prevPage();
141 } catch (Exception e) {
142 fail();
143 }
144 }
145
146 /**
147 * Test Case: 004
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.
153 */
154 @Test
155 public void verifyFirstPage() {
156 fFacility.lastPage();
157
158 // First Page
159 fFacility.firstPage();
160 verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
161 }
162
163 /**
164 * Test Case: 005
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.
169 */
170 @Test
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();
175 }
176
177 /**
178 * Test Case: 006
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.
184 */
185 @Test
186 public void verifyPageNumberChanged() {
187 // any page
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();
193 }
194
195 private static void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev) {
196 verifyPage(currentPage, numMsg, hasNext, hasPrev, IUml2SDTestConstants.DEFAULT_NUM_LIFELINES);
197 }
198
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());
203 if (hasNext) {
204 assertTrue("hasNextpage", fFacility.getLoader().hasNextPage());
205 } else {
206 assertFalse("hasNextPage", fFacility.getLoader().hasNextPage());
207 }
208 if (hasPrev) {
209 assertTrue("hasPrevPage", fFacility.getLoader().hasPrevPage());
210 } else {
211 assertFalse("hasPrevPage", fFacility.getLoader().hasPrevPage());
212 }
213 assertEquals("lifeLinesCount", lifelineCount, fFacility.getSdView().getFrame().lifeLinesCount());
214 }
215 }
This page took 0.037061 seconds and 6 git commands to generate.