/
AftersLogCollector.java
67 lines (58 loc) · 2.56 KB
/
AftersLogCollector.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.junit.extension.log.collector;
import org.eclipse.reddeer.common.properties.RedDeerProperties;
import org.eclipse.reddeer.direct.platform.Platform;
import org.eclipse.reddeer.junit.extension.ExtensionPriority;
import org.eclipse.reddeer.junit.extensionpoint.IAfterTest;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.TestClass;
/**
* Afters log collector provides collecting workbench log at two points. First one is
* after execution of AfterTest extensions. Second point is after execution of AfterClass
* extensions.
*
* @author mlabuda@redhat.com
* @since 1.2.0
*
*/
public class AftersLogCollector extends LogCollector implements IAfterTest {
public static String AFTER_TEST_METHOD_DESCRIPTION =
"Log entries collected between before extensions (included) and\n"
+ "after extensions (included) for test method:";
public static final String AFTER_TEST_CLASS_DESCRIPTION =
"Log entries collected between after extensions (excluded) \n"
+ "and after class extensions (included):";
@Override
public long getPriority() {
return ExtensionPriority.AFTERSLOG_COLLECTOR_PRIORITY;
}
@Override
public void runAfterTestClass(String config, TestClass testClass) {
processWorkbenchLog(config, testClass.getJavaClass().getSimpleName(), AFTER_TEST_CLASS_DESCRIPTION);
Platform.getWorkbenchLog().delete();
}
@Override
public void runAfterTest(String config, Object target, FrameworkMethod method) {
constructAfterTestMethodDescription(method.getMethod().getName());
processWorkbenchLog(config, method.getDeclaringClass().getSimpleName(), AFTER_TEST_METHOD_DESCRIPTION);
Platform.getWorkbenchLog().delete();
}
@Override
public boolean hasToRun() {
return RedDeerProperties.LOG_COLLECTOR_ENABLED.getBooleanValue() && eclipseLogFileExists();
}
private void constructAfterTestMethodDescription(String testMethodName) {
AFTER_TEST_METHOD_DESCRIPTION = "Log entries collected between before extensions (included) and\n"
+ "after extensions (included) for test method " + testMethodName + ":";
}
}