1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertTrue
;
18 import java
.util
.Collection
;
19 import java
.util
.List
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.apache
.log4j
.varia
.NullAppender
;
23 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
24 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
25 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
26 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
27 import org
.eclipse
.ui
.IViewReference
;
28 import org
.hamcrest
.BaseMatcher
;
29 import org
.hamcrest
.Description
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.Test
;
32 import org
.junit
.runner
.RunWith
;
35 * Tests perspectives to make sure they have all the views
37 * @author Matthew Khouzam
39 @RunWith(SWTBotJunit4ClassRunner
.class)
40 public abstract class AbstractPerspectiveChecker
{
42 private static SWTWorkbenchBot fBot
;
43 /** The Log4j logger instance. */
44 private static final Logger fLogger
= Logger
.getRootLogger();
49 protected String fPerspectiveId
;
51 * the view id collection
53 protected Collection
<String
> fViewIds
;
55 /** Test Class setup */
57 public static void beforeInit() {
58 SWTBotUtil
.failIfUIThread();
60 /* set up for swtbot */
61 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
62 fLogger
.addAppender(new NullAppender());
63 fBot
= new SWTWorkbenchBot();
65 SWTBotUtil
.closeView("welcome", fBot
);
70 * Gets the perspective and checks if all the views specified in the list
71 * are present in the perspective
74 public void testPerspectiveForViews() {
75 SWTBotUtil
.switchToPerspective(fPerspectiveId
);
76 SWTBotUtil
.waitForJobs();
77 for (final String viewID
: fViewIds
) {
78 List
<SWTBotView
> view
= fBot
.views(new BaseMatcher
<String
>() {
81 public boolean matches(Object item
) {
82 if (!(item
instanceof IViewReference
)) {
85 IViewReference reference
= (IViewReference
) item
;
86 return reference
.getId().equals(viewID
);
90 public void describeTo(Description description
) {
94 assertEquals("view " + viewID
+ "is present", 1, view
.size());
99 * Gets the perspective and checks if all the views of that perspective are
103 public void testPerspectiveComplete() {
104 SWTBotUtil
.switchToPerspective(fPerspectiveId
);
105 SWTBotUtil
.waitForJobs();
106 for (SWTBotView view
: fBot
.views()) {
107 assertTrue("view " + view
.toString() + "is present", fViewIds
.contains(view
.getViewReference().getId()));