Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c9ef78bb4925b303c9c799ca332c86302f74e32d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*******************************************************************************
 * Copyright (c) 2011, 2012 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Bernd Hufmann - Initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Test cases for pages handling.
 *
 * @author Bernd Hufmann
 *
 */
public class TmfUml2SDSyncLoaderPagesTest extends TestCase {

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------
    private Uml2SDTestFacility fFacility;

    // ------------------------------------------------------------------------
    // Static methods
    // ------------------------------------------------------------------------

    /**
     * Returns test setup used when executing test case stand-alone.
     * @return Test setup class
     */
    public static Test suite() {
        return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderPagesTest.class));
    }

    // ------------------------------------------------------------------------
    // Constructors
    // ------------------------------------------------------------------------
    /**
     * Constructor
     */
    public TmfUml2SDSyncLoaderPagesTest() {
    }

    // ------------------------------------------------------------------------
    // Operations
    // ------------------------------------------------------------------------
    @Override
    public void setUp() throws Exception {
        super.setUp();
        fFacility = Uml2SDTestFacility.getInstance();
        fFacility.selectExperiment();
    }


    @Override
    public void tearDown() throws Exception {
        fFacility.disposeExperiment();
        fFacility = null;
        super.tearDown();
    }

    /**
     * Main method with test cases.
     */
    public void testPageHandling() {

        verifyPagesCount();
        verifyNextPage();
        verifyPrevPage();
        verifyFirstPage();
        verifyLastPage();
        verifyPageNumberChanged();

    }

     private void verifyPagesCount() {

        /*
         * Test Case: 001
         * Description: Test number of pages.
         * Verified Methods: loader.pagesCount().
         * Expected result: ITestConstants.TOTAL_NUMBER_OF_PAGES of pages
         */
        assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES, fFacility.getLoader().pagesCount());
    }

    private void verifyNextPage() {
        // assuming we are at the first page

        /*
         * Test Case: 002
         * Description: Tests next page feature.
         * Verified Methods: loader.nextPage(), loader.fillCurrentPage(), loader.pagesCount(),
         *                   loader.hasNextPage(), loader.hasPrevPage(),
         *                   frame.syncMessagesCount, frame.lifeLinesCount
         * Expected result: Expected values are return.
         */

        for(int i = 0; i < IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES-2; i++) {
            fFacility.nextPage();

            if (i+1 == IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES) {
                verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
            }
            else {
                verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
            }
        }

        // Last Page
        fFacility.nextPage();
        verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);

        // Check for index out of bounce
        try {
            fFacility.getLoader().nextPage();
        } catch (Exception e) {
            fail();
        }

        fFacility.firstPage();
    }


    private void verifyPrevPage() {
        // assuming we are at the first page

        /*
         * Test Case: 003
         * Description: Test previous page feature.
         * Verified Methods: loader.prevPage(), loader.fillCurrentPage(), loader.pagesCount(),
         *                   loader.hasNextPage(), loader.hasPrevPage(),
         *                   frame.syncMessagesCount, frame.lifeLinesCount
         * Expected result: Expected values are return.
         */

        // Last Page
        fFacility.lastPage();
        assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, fFacility.getLoader().currentPage());
        assertEquals(IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, fFacility.getSdView().getFrame().syncMessageCount());
        assertFalse(fFacility.getLoader().hasNextPage());
        assertTrue(fFacility.getLoader().hasPrevPage());
        assertEquals(2, fFacility.getSdView().getFrame().lifeLinesCount());

        for(int i = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES-2; i > 0; i--) {
            fFacility.prevPage();
            if (i == IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES) {
                verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
            } else {
                verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
            }
        }

        fFacility.prevPage();
        verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);

        // Check for index out of bounce
        try {
            fFacility.getLoader().prevPage();
        } catch (Exception e) {
            fail();
        }
    }

    private void verifyFirstPage() {
        fFacility.lastPage();
        /*
         * Test Case: 004
         * Description: Test first page feature.
         * Verified Methods: loader.firstPage(), loader.fillCurrentPage(), loader.pagesCount(),
         *                   loader.hasNextPage(), loader.hasPrevPage(),
         *                   frame.syncMessagesCount, frame.lifeLinesCount
         * Expected result: Expected values are return.
         */

        // First Page
        fFacility.firstPage();
        verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
    }


    private void verifyLastPage() {
        /*
         * Test Case: 005
         * Description: Test last page feature.
         * Verified Methods: loader.lastPage(), loader.pagesCount(), loader.hasNextPage(), loader.hasPrevPage()
         *                   frame.syncMessagesCount, frame.lifeLinesCount
         * Expected result: Expected values are return.
         */
        fFacility.lastPage();
        verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
        fFacility.firstPage();
    }

    private void verifyPageNumberChanged() {

        /*
         * Test Case: 006
         * Description: Test move to any page feature.
         * Verified Methods: loader.pageNumberChanged(), loader.fillCurrentPage(), loader.pagesCount(),
         *                   loader.hasNextPage(), loader.hasPrevPage(),
         *                   frame.syncMessagesCount, frame.lifeLinesCount
         * Expected result: Expected values are return.
         */

        // any page
        fFacility.setPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES);
        verifyPage(IUml2SDTestConstants.PAGE_OF_ALL_LIFELINES, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true, IUml2SDTestConstants.NUM_OF_ALL_LIFELINES);
        fFacility.firstPage();
    }

    private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev) {
        verifyPage(currentPage, numMsg, hasNext, hasPrev, IUml2SDTestConstants.DEFAULT_NUM_LIFELINES);
    }

    @SuppressWarnings("nls")
    private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev, int lifelineCount) {
        assertEquals("currentPage", currentPage, fFacility.getLoader().currentPage());
        assertEquals("syncMessageCount, ", numMsg, fFacility.getSdView().getFrame().syncMessageCount());
        if (hasNext) {
            assertTrue("hasNextpage", fFacility.getLoader().hasNextPage());
        } else {
            assertFalse("hasNextPage", fFacility.getLoader().hasNextPage());
        }
        if (hasPrev) {
            assertTrue("hasPrevPage", fFacility.getLoader().hasPrevPage());
        } else {
            assertFalse("hasPrevPage", fFacility.getLoader().hasPrevPage());
        }
        assertEquals("lifeLinesCount", lifelineCount, fFacility.getSdView().getFrame().lifeLinesCount());
    }
}

Back to the top