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