~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/views/uml2sd/loader/TmfUml2SDSyncLoaderPagesTest.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2011, 2012 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
 *******************************************************************************/
 
12
package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
 
13
 
 
14
import junit.framework.Test;
 
15
import junit.framework.TestCase;
 
16
import junit.framework.TestSuite;
 
17
 
 
18
public class TmfUml2SDSyncLoaderPagesTest extends TestCase {
 
19
 
 
20
    // ------------------------------------------------------------------------
 
21
    // Attributes
 
22
    // ------------------------------------------------------------------------
 
23
    private Uml2SDTestFacility fFacility;
 
24
 
 
25
    // ------------------------------------------------------------------------
 
26
    // Static methods
 
27
    // ------------------------------------------------------------------------ 
 
28
 
 
29
    /**
 
30
     * Returns test setup used when executing test case stand-alone.
 
31
     * @return Test setup class 
 
32
     */
 
33
    public static Test suite() {
 
34
        return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderPagesTest.class));
 
35
    }
 
36
 
 
37
    // ------------------------------------------------------------------------
 
38
    // Constructors
 
39
    // ------------------------------------------------------------------------
 
40
    public TmfUml2SDSyncLoaderPagesTest() {
 
41
    }
 
42
 
 
43
    // ------------------------------------------------------------------------
 
44
    // Operations
 
45
    // ------------------------------------------------------------------------
 
46
    @Override
 
47
    public void setUp() throws Exception {
 
48
        super.setUp();
 
49
        fFacility = Uml2SDTestFacility.getInstance();
 
50
        fFacility.selectExperiment();
 
51
    }
 
52
 
 
53
 
 
54
    @Override
 
55
    public void tearDown() throws Exception {
 
56
        fFacility.disposeExperiment();
 
57
        fFacility = null;
 
58
        super.tearDown();
 
59
    }
 
60
 
 
61
    public void testPageHandling() {
 
62
        
 
63
        verifyPagesCount();
 
64
        verifyNextPage();
 
65
        verifyPrevPage();
 
66
        verifyFirstPage();
 
67
        verifyLastPage();
 
68
        verifyPageNumberChanged();
 
69
 
 
70
    }
 
71
    
 
72
     private void verifyPagesCount() {
 
73
        
 
74
        /*
 
75
         * Test Case: 001
 
76
         * Description: Test number of pages.
 
77
         * Verified Methods: loader.pagesCount().
 
78
         * Expected result: ITestConstants.TOTAL_NUMBER_OF_PAGES of pages
 
79
         */
 
80
        assertEquals(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES, fFacility.getLoader().pagesCount());
 
81
    }
 
82
    
 
83
    private void verifyNextPage() {
 
84
        // assuming we are at the first page
 
85
 
 
86
        /*
 
87
         * Test Case: 002
 
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.
 
93
         */
 
94
        
 
95
        for(int i = 0; i < IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES-2; i++) {
 
96
            fFacility.nextPage();
 
97
 
 
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);
 
100
            }
 
101
            else {
 
102
                verifyPage(i+1, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
 
103
            }
 
104
        }
 
105
 
 
106
        // Last Page
 
107
        fFacility.nextPage();
 
108
        verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
 
109
 
 
110
        // Check for index out of bounce
 
111
        try {
 
112
            fFacility.getLoader().nextPage();
 
113
        } catch (Exception e) {
 
114
            fail();
 
115
        }
 
116
        
 
117
        fFacility.firstPage();
 
118
    }
 
119
 
 
120
 
 
121
    private void verifyPrevPage() {
 
122
        // assuming we are at the first page
 
123
 
 
124
        /*
 
125
         * Test Case: 003
 
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.
 
131
         */
 
132
 
 
133
        // Last Page
 
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());
 
140
 
 
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);
 
145
            else
 
146
                verifyPage(i, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, true);
 
147
        }
 
148
 
 
149
        fFacility.prevPage();
 
150
        verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
 
151
 
 
152
        // Check for index out of bounce
 
153
        try {
 
154
            fFacility.getLoader().prevPage();
 
155
        } catch (Exception e) {
 
156
            fail();
 
157
        }
 
158
    }
 
159
 
 
160
    private void verifyFirstPage() {
 
161
        fFacility.lastPage();
 
162
        /*
 
163
         * Test Case: 004
 
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.
 
169
         */
 
170
        
 
171
        // First Page
 
172
        fFacility.firstPage();
 
173
        verifyPage(0, IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE, true, false);
 
174
    }
 
175
 
 
176
 
 
177
    private void verifyLastPage() {
 
178
        /*
 
179
         * Test Case: 005
 
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.
 
184
         */
 
185
        fFacility.lastPage();
 
186
        verifyPage(IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1, IUml2SDTestConstants.NUM_MESSAGES_OF_LAST_PAGE, false, true);
 
187
        fFacility.firstPage();
 
188
    }
 
189
 
 
190
    private void verifyPageNumberChanged() {
 
191
        
 
192
        /*
 
193
         * Test Case: 006
 
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.
 
199
         */
 
200
 
 
201
        // any page
 
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();
 
205
    }
 
206
 
 
207
    private void verifyPage(int currentPage, int numMsg, boolean hasNext, boolean hasPrev) {
 
208
        verifyPage(currentPage, numMsg, hasNext, hasPrev, IUml2SDTestConstants.DEFAULT_NUM_LIFELINES);
 
209
    }
 
210
 
 
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());
 
215
        if (hasNext) {
 
216
            assertTrue("hasNextpage", fFacility.getLoader().hasNextPage());
 
217
        } else {
 
218
            assertFalse("hasNextPage", fFacility.getLoader().hasNextPage());
 
219
        }
 
220
        if (hasPrev) {
 
221
            assertTrue("hasPrevPage", fFacility.getLoader().hasPrevPage());
 
222
        } else {
 
223
            assertFalse("hasPrevPage", fFacility.getLoader().hasPrevPage());
 
224
        }
 
225
        assertEquals("lifeLinesCount", lifelineCount, fFacility.getSdView().getFrame().lifeLinesCount());
 
226
    }
 
227
}