1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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 * Patrick Tasse - Fix assertion messages
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.util
.Collection
;
20 import java
.util
.List
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.apache
.log4j
.varia
.NullAppender
;
24 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
25 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
26 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
27 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
28 import org
.eclipse
.ui
.IViewReference
;
29 import org
.hamcrest
.BaseMatcher
;
30 import org
.hamcrest
.Description
;
31 import org
.junit
.AfterClass
;
32 import org
.junit
.BeforeClass
;
33 import org
.junit
.Test
;
34 import org
.junit
.runner
.RunWith
;
37 * Tests perspectives to make sure they have all the views
39 * @author Matthew Khouzam
41 @RunWith(SWTBotJunit4ClassRunner
.class)
42 public abstract class AbstractPerspectiveChecker
{
44 private static SWTWorkbenchBot fBot
;
45 /** The Log4j logger instance. */
46 private static final Logger fLogger
= Logger
.getRootLogger();
51 protected String fPerspectiveId
;
53 * the view id collection
55 protected Collection
<String
> fViewIds
;
57 /** Test Class setup */
59 public static void beforeInit() {
60 SWTBotUtils
.failIfUIThread();
62 /* set up for swtbot */
63 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
64 fLogger
.removeAllAppenders();
65 fLogger
.addAppender(new NullAppender());
66 fBot
= new SWTWorkbenchBot();
68 SWTBotUtils
.closeView("welcome", fBot
);
76 public static void terminate() {
77 fLogger
.removeAllAppenders();
81 * Gets the perspective and checks if all the views specified in the list
82 * are present in the perspective
85 public void testPerspectiveForViews() {
86 SWTBotUtils
.switchToPerspective(fPerspectiveId
);
87 SWTBotUtils
.waitForJobs();
88 for (final String viewID
: fViewIds
) {
89 List
<SWTBotView
> view
= fBot
.views(new BaseMatcher
<String
>() {
92 public boolean matches(Object item
) {
93 if (!(item
instanceof IViewReference
)) {
96 IViewReference reference
= (IViewReference
) item
;
97 return reference
.getId().equals(viewID
);
101 public void describeTo(Description description
) {
105 assertEquals("view " + viewID
+ " is present", 1, view
.size());
110 * Gets the perspective and checks if all the views of that perspective are
114 public void testPerspectiveComplete() {
115 SWTBotUtils
.switchToPerspective(fPerspectiveId
);
116 SWTBotUtils
.waitForJobs();
117 for (SWTBotView view
: fBot
.views()) {
118 assertTrue("view " + view
.getViewReference().getId() + " is present", fViewIds
.contains(view
.getViewReference().getId()));