Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mvn plugin updates #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -59,7 +59,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadoc</id>
Expand All @@ -72,7 +72,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M2</version>
<version>3.0.0-M4</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class LongRunnerClassInfo {

public LongRunnerClassInfo() {
testClass = null;
methods = new Vector<LongRunnerMethodInfo>();
methods = new Vector<>();
}

public LongRunnerClassInfo(Class<?> aTestClass) {
this(aTestClass, new Vector<LongRunnerMethodInfo>());
this(aTestClass, new Vector<>());
}

public LongRunnerClassInfo(Class<?> aTestClass, Collection<LongRunnerMethodInfo> methods) {
Expand Down Expand Up @@ -114,7 +114,7 @@ private String getDataFileName(boolean isCompleted) {
}

private Field[] getFields() {
List<Field> dataFields = new ArrayList<Field>();
List<Field> dataFields = new ArrayList<>();
Field[] fields = testClass.getFields();
for (Field field : fields) {
if (field.isAnnotationPresent(Data.class)) {
Expand Down Expand Up @@ -160,9 +160,7 @@ public void load() {
}

public void loadData() {
FileReader fileReader = null;
try {
fileReader = new FileReader(getDataFileName(false));
try (FileReader fileReader = new FileReader(getDataFileName(false))) {
Properties data = getData();
data.load(fileReader);
for (Object key : data.keySet()) {
Expand Down Expand Up @@ -194,36 +192,21 @@ public void loadData() {
}
}
catch (Exception e) {
assertTrue("Some error occurred when trying to set variable " + key + " to " + data.get(key), false);
fail("Some error occurred when trying to set variable " + key + " to " + data.get(key));
}
}
}
catch (IOException e) {
fail("store of test data has NOT been correctly done");
}
finally {
try {
fileReader.close();
}
catch (Exception e) {}
}
}

public void loadProcess() {
FileReader fileReader = null;
try {
fileReader = new FileReader(getProcessFileName(false));
try (FileReader fileReader = new FileReader(getProcessFileName(false))) {
methods = LongRunnerMethodInfo.loadWith(fileReader);
}
catch (IOException e) {
} catch (IOException e) {
fail("load of test state information has NOT been correctly done");
}
finally {
try {
fileReader.close();
}
catch (Exception e) {}
}
}

public boolean longRunnerMethodInfoExists(String methodName) {
Expand All @@ -237,38 +220,20 @@ public void store() {
}

public void storeData() {
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(getDataFileName(false));
try (FileWriter fileWriter = new FileWriter(getDataFileName(false))) {
Properties data = getData();
data.store(fileWriter, "Data for long running JUnit test");
}
catch (IOException e) {
} catch (IOException e) {
fail("store of test data has NOT been correctly done");
}
finally {
try {
fileWriter.close();
}
catch (Exception e) {}
}
}

public void storeProcess() {
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(getProcessFileName(false));
try (FileWriter fileWriter = new FileWriter(getProcessFileName(false))) {
LongRunnerMethodInfo.print(fileWriter, methods);
}
catch (IOException e) {
} catch (IOException e) {
fail("store of test state information has NOT been correctly done");
}
finally {
try {
fileWriter.close();
}
catch (Exception e) {}
}
}

}
Expand All @@ -288,7 +253,7 @@ public LongRunnerInfo(Class<?> aTestClass, long anId) {
public int compareTo(Object o) {
if (o instanceof LongRunnerInfo) {
LongRunnerInfo lri = (LongRunnerInfo)o;
return new Long(id).compareTo(new Long(lri.id));
return Long.compare(id, lri.id);
}
return 0;
}
Expand All @@ -306,7 +271,6 @@ private static String cellContents(CSVRecord header, CSVRecord line, String colu
if (colIndex >= 0) {
return line.get(colIndex);
}
;
return "";
}

Expand All @@ -324,7 +288,7 @@ private static Object[] getHeaders() {

public static Collection<LongRunnerMethodInfo> loadWith(FileReader fileReader) throws IOException {
CSVParser csvParser = new CSVParser(fileReader, getCSVFormat());
Vector<LongRunnerMethodInfo> result = new Vector<LongRunnerMethodInfo>();
Vector<LongRunnerMethodInfo> result = new Vector<>();
List<CSVRecord> records = csvParser.getRecords();
CSVRecord header = null;
for (int i = 0; i < records.size(); i++) {
Expand Down Expand Up @@ -369,11 +333,11 @@ public static void print(FileWriter fileWriter, Collection<LongRunnerMethodInfo>

private TestStatus lastStatus = TestStatus.unknown;

private Date modified = null;
private Date modified;

private Date nextTry = null;
private Date nextTry;

private Date lastTry = null;
private Date lastTry;

public LongRunnerMethodInfo(String aMethodName, TestStatus aLastStatus, Date aModified, Date aNextTry, Date aLastTry) {
methodName = aMethodName;
Expand Down Expand Up @@ -470,9 +434,9 @@ private String timeAsString(Date d) {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Suspend {
public double firstTryAfterHours() default 0.01;
double firstTryAfterHours() default 0.01;

public double maxHours() default 1.0;
double maxHours() default 1.0;
}

public enum TestStatus {
Expand All @@ -484,30 +448,26 @@ public enum TestStatus {
private static String path = "";

public static Collection<LongRunnerInfo> getFor(Class<?> testClass) {
Vector<LongRunnerInfo> result = new Vector<LongRunner.LongRunnerInfo>();
Vector<LongRunnerInfo> result = new Vector<>();
// TODO korrekte Prüfung
assertTrue("Test class must be annotated with a Runner that is a LongRunner or a subclass of it", true);

final String testClassName = testClass.getName();
FilenameFilter fnf = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith(testClassName) && name.endsWith(".csv");
}
};
FilenameFilter fnf = (dir, name) -> name.startsWith(testClassName) && name.endsWith(".csv");
File dir;
if (path == null | path.isEmpty()) {
if (path == null || path.isEmpty()) {
dir = new File(".");
}
else {
dir = new File(path);
}
final File[] files = dir.listFiles(fnf);

for (File file : files) {
final String id = file.getName().replace(testClassName, "").replace(".csv", "").replace(".", "");
Long l = Long.parseLong(id);
result.add(new LongRunnerInfo(testClass, l));
if (files != null) {
for (File file : files) {
final String id = file.getName().replace(testClassName, "").replace(".csv", "").replace(".", "");
result.add(new LongRunnerInfo(testClass, Long.parseLong(id)));
}
}
return result;
}
Expand Down Expand Up @@ -562,7 +522,7 @@ protected Statement methodBlock(FrameworkMethod method) {
if (lrmi.isPassed()) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
public void evaluate() {
m.getName();
info(m.getName() + " has passed in a previous test");
}
Expand All @@ -571,7 +531,7 @@ public void evaluate() throws Throwable {
if (lrmi.isFailed()) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
public void evaluate() {
Assert.fail(m.getName() + "has failed in a previous test run");
}
};
Expand All @@ -580,7 +540,7 @@ public void evaluate() throws Throwable {
if (lrmi.cantResumeAnymore()) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
public void evaluate() {
Assert.fail(m.getName() + " has timeout and cannot be resumed anymore");
}
};
Expand All @@ -593,7 +553,7 @@ public void evaluate() throws Throwable {
LongRunnerMethodInfo lrmi = aLrmi;

@Override
public void evaluate() throws Throwable {
public void evaluate() {
try {
superStatement.evaluate();
lrmi.setToPassed();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.baloise.testautomation.taf.base.testing.e2e;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -21,14 +17,16 @@

import com.baloise.testautomation.taf.base.testing.e2e.LongRunner.LongRunnerInfo;

import static org.junit.Assert.*;

public class LongRunnerSuite extends Suite {

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LongRunnerInit {
}

private static Vector<LongRunnerInfo> longRunnerInfo = new Vector<LongRunnerInfo>();
private static Vector<LongRunnerInfo> longRunnerInfo = new Vector<>();
private static int currentIndex = 0;

public static void addLongRunnerInfosFor(Class<?>... testClasses) {
Expand All @@ -48,10 +46,10 @@ private static Class<?>[] getLongRunnerClasses(Class<?> testClass) {
for (Method method : methods) {
if (method.isAnnotationPresent(LongRunnerInit.class)) {
try {
method.invoke(testClass, new Object[] {});
method.invoke(testClass);
}
catch (Exception e) {
assertNull("Mit 'LongRunnerInit' annotierte Methode konnte nicht ausgeführt werden. Muss 'static' sein.", e);
fail("Mit 'LongRunnerInit' annotierte Methode konnte nicht ausgeführt werden. Muss 'static' sein.");
}
}
}
Expand Down
Loading