Commit | Line | Data |
---|---|---|
664fa59c | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2014, 2015 Ericsson |
664fa59c MK |
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 | * Matthew Khouzam - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
fa24d78b | 13 | package org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared; |
664fa59c MK |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertTrue; | |
17 | ||
18 | import java.util.Collection; | |
19 | import java.util.List; | |
20 | ||
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; | |
cbbd323f | 25 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
664fa59c MK |
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; | |
cbbd323f | 32 | import org.junit.runner.RunWith; |
664fa59c MK |
33 | |
34 | /** | |
35 | * Tests perspectives to make sure they have all the views | |
36 | * | |
37 | * @author Matthew Khouzam | |
38 | */ | |
cbbd323f | 39 | @RunWith(SWTBotJunit4ClassRunner.class) |
664fa59c MK |
40 | public abstract class AbstractPerspectiveChecker { |
41 | ||
42 | private static SWTWorkbenchBot fBot; | |
43 | /** The Log4j logger instance. */ | |
44 | private static final Logger fLogger = Logger.getRootLogger(); | |
45 | ||
46 | /** | |
47 | * The perspective id | |
48 | */ | |
49 | protected String fPerspectiveId; | |
50 | /** | |
51 | * the view id collection | |
52 | */ | |
53 | protected Collection<String> fViewIds; | |
54 | ||
55 | /** Test Class setup */ | |
56 | @BeforeClass | |
57 | public static void beforeInit() { | |
fa24d78b | 58 | SWTBotUtils.failIfUIThread(); |
664fa59c MK |
59 | |
60 | /* set up for swtbot */ | |
61 | SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */ | |
62 | fLogger.addAppender(new NullAppender()); | |
63 | fBot = new SWTWorkbenchBot(); | |
64 | ||
fa24d78b | 65 | SWTBotUtils.closeView("welcome", fBot); |
664fa59c MK |
66 | |
67 | } | |
68 | ||
69 | /** | |
70 | * Gets the perspective and checks if all the views specified in the list | |
71 | * are present in the perspective | |
72 | */ | |
73 | @Test | |
74 | public void testPerspectiveForViews() { | |
fa24d78b AM |
75 | SWTBotUtils.switchToPerspective(fPerspectiveId); |
76 | SWTBotUtils.waitForJobs(); | |
664fa59c MK |
77 | for (final String viewID : fViewIds) { |
78 | List<SWTBotView> view = fBot.views(new BaseMatcher<String>() { | |
79 | ||
80 | @Override | |
81 | public boolean matches(Object item) { | |
82 | if (!(item instanceof IViewReference)) { | |
83 | return false; | |
84 | } | |
85 | IViewReference reference = (IViewReference) item; | |
86 | return reference.getId().equals(viewID); | |
87 | } | |
88 | ||
89 | @Override | |
90 | public void describeTo(Description description) { | |
91 | } | |
92 | ||
93 | }); | |
94 | assertEquals("view " + viewID + "is present", 1, view.size()); | |
95 | } | |
96 | } | |
97 | ||
98 | /** | |
99 | * Gets the perspective and checks if all the views of that perspective are | |
100 | * in the list | |
101 | */ | |
102 | @Test | |
103 | public void testPerspectiveComplete() { | |
fa24d78b AM |
104 | SWTBotUtils.switchToPerspective(fPerspectiveId); |
105 | SWTBotUtils.waitForJobs(); | |
664fa59c MK |
106 | for (SWTBotView view : fBot.views()) { |
107 | assertTrue("view " + view.toString() + "is present", fViewIds.contains(view.getViewReference().getId())); | |
108 | } | |
109 | } | |
110 | ||
111 | } |