Commit | Line | Data |
---|---|---|
73005152 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2011-2014 Ericsson |
64636df8 | 3 | * |
73005152 BH |
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 | |
64636df8 | 8 | * |
73005152 BH |
9 | * Contributors: |
10 | * Bernd Hufmann - Initial API and implementation | |
90ed5958 | 11 | * Alexandre Montplaisir - Port to JUnit4 |
73005152 | 12 | *******************************************************************************/ |
90ed5958 | 13 | |
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader; |
73005152 | 15 | |
90ed5958 AM |
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; | |
73005152 | 24 | |
64636df8 BH |
25 | /** |
26 | * Test cases for pages handling. | |
27 | * | |
28 | * @author Bernd Hufmann | |
64636df8 | 29 | */ |
90ed5958 | 30 | public class TmfUml2SDSyncLoaderPagesTest { |
73005152 BH |
31 | |
32 | // ------------------------------------------------------------------------ | |
33 | // Attributes | |
34 | // ------------------------------------------------------------------------ | |
73005152 | 35 | |
90ed5958 | 36 | private static Uml2SDTestFacility fFacility; |
4f5d9f9b | 37 | |
73005152 | 38 | // ------------------------------------------------------------------------ |
90ed5958 | 39 | // Operations |
73005152 | 40 | // ------------------------------------------------------------------------ |
90ed5958 | 41 | |
64636df8 | 42 | /** |
90ed5958 | 43 | * Initialization |
64636df8 | 44 | */ |
90ed5958 AM |
45 | @BeforeClass |
46 | public static void setUpClass() { | |
73005152 | 47 | fFacility = Uml2SDTestFacility.getInstance(); |
73005152 BH |
48 | fFacility.selectExperiment(); |
49 | } | |
50 | ||
90ed5958 AM |
51 | /** |
52 | * Cleanup | |
53 | */ | |
54 | @AfterClass | |
55 | public static void tearDownClass() { | |
73005152 | 56 | fFacility.disposeExperiment(); |
73005152 | 57 | fFacility = null; |
73005152 BH |
58 | } |
59 | ||
64636df8 | 60 | /** |
90ed5958 AM |
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 | |
64636df8 | 65 | */ |
90ed5958 AM |
66 | @Test |
67 | public void verifyPagesCount() { | |
73005152 BH |
68 | assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES, fFacility.getLoader().pagesCount()); |
69 | } | |
64636df8 | 70 | |
64636df8 | 71 | |
90ed5958 AM |
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 | |
73005152 BH |
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 | } | |
64636df8 | 93 | |
73005152 BH |
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 | } | |
64636df8 | 104 | |
73005152 BH |
105 | fFacility.firstPage(); |
106 | } | |
107 | ||
90ed5958 AM |
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() { | |
73005152 BH |
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(); | |
64636df8 | 128 | if (i == IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES) { |
73005152 | 129 | verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES); |
64636df8 | 130 | } else { |
73005152 | 131 | verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true); |
64636df8 | 132 | } |
73005152 BH |
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 | ||
90ed5958 AM |
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() { | |
73005152 | 156 | fFacility.lastPage(); |
64636df8 | 157 | |
73005152 BH |
158 | // First Page |
159 | fFacility.firstPage(); | |
160 | verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false); | |
161 | } | |
162 | ||
90ed5958 AM |
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() { | |
73005152 BH |
172 | fFacility.lastPage(); |
173 | verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true); | |
174 | fFacility.firstPage(); | |
175 | } | |
176 | ||
90ed5958 AM |
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() { | |
73005152 BH |
187 | // any page |
188 | fFacility.setPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES); | |
90ed5958 AM |
189 | verifyPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES, |
190 | IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, | |
191 | IUml2SDTestConstants.NUM_OF_ALL_LIFELINES); | |
73005152 BH |
192 | fFacility.firstPage(); |
193 | } | |
194 | ||
90ed5958 | 195 | private static void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev) { |
73005152 BH |
196 | verifyPage(currentPage, numMsg, hasNext, hasPrev, IUml2SDTestConstants.DEFAULT_NUM_LIFELINES); |
197 | } | |
198 | ||
90ed5958 AM |
199 | private static void verifyPage(int currentPage, int numMsg, boolean hasNext, |
200 | boolean hasPrev, int lifelineCount) { | |
73005152 BH |
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 | } |