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

Extension/annotation export #117

Merged
merged 12 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 11 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
/*
* Testerra
*
* (C) 2020, Mike Reiche, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG
* (C) 2021, Mike Reiche, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG
*
* Deutsche Telekom AG and all other contributors /
* copyright owners license this file to you under the Apache
Expand All @@ -19,6 +19,14 @@
* under the License.
*/

.rank-column {
text-align: center;
package eu.tsystems.mms.tic.testframework.report;

import java.lang.annotation.Annotation;
import java.util.Map;

public interface AnnotationConverter<T extends Annotation> {
/**
* Exports the annotation parameters
*/
Map<String, Object> toMap(T annotation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@
import eu.tsystems.mms.tic.testframework.utils.FileUtils;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class DefaultReport implements Report, Loggable {

private File currentReportDirectory;
private final String baseDir = PropertyManager.getProperty(TesterraProperties.REPORTDIR, "test-report");
private final File finalReportDirectory = new File(baseDir);
private final File tempReportDirectory;
private final ConcurrentHashMap<Class<? extends Annotation>, AnnotationConverter> annotationConverters = new ConcurrentHashMap<>();

public DefaultReport() {
FileUtils fileUtils = new FileUtils();
Expand Down Expand Up @@ -144,4 +148,16 @@ public String getRelativePath(File file) {
}
return absFilePath;
}

public void registerAnnotationConverter(Class<? extends Annotation> annotationClass, AnnotationConverter annotationExporter) {
annotationConverters.put(annotationClass, annotationExporter);
}

public void unregisterAnnotationConverter(Class<? extends Annotation> annotationClass) {
annotationConverters.remove(annotationClass);
}

public Optional<AnnotationConverter> getAnnotationConverter(Annotation annotation) {
return Optional.ofNullable(annotationConverters.get(annotation.annotationType()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Testerra
*
* (C) 2021, Mike Reiche, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG
*
* Deutsche Telekom AG and all other contributors /
* copyright owners license this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package eu.tsystems.mms.tic.testframework.report;

import eu.tsystems.mms.tic.testframework.annotations.Fails;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;

public class FailsAnnotationConverter implements AnnotationConverter<Fails> {

@Override
public Map<String, Object> toMap(Fails annotation) {
Map<String, Object> map = new HashMap<>();
if (!StringUtils.isBlank(annotation.description())) {
map.put("description", annotation.description());
}
if (!StringUtils.isBlank(annotation.ticketString())) {
map.put("ticketString", annotation.ticketString());
} else if (annotation.ticketId() > 0) {
map.put("ticketString", Integer.toString(annotation.ticketId()));
}
return map;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Testerra
*
* (C) 2021, Mike Reiche, T-Systems Multimedia Solutions GmbH, Deutsche Telekom AG
*
* Deutsche Telekom AG and all other contributors /
* copyright owners license this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package eu.tsystems.mms.tic.testframework.report;

import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.testng.annotations.Test;

public class TestAnnotationConverter implements AnnotationConverter<Test> {

@Override
public Map<String, Object> toMap(Test annotation) {
Map<String, Object> map = new HashMap<>();
if (!StringUtils.isBlank(annotation.description())) {
map.put("description", annotation.description());
}
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package eu.tsystems.mms.tic.testframework.report;

import com.google.common.eventbus.EventBus;
import eu.tsystems.mms.tic.testframework.annotations.Fails;
import eu.tsystems.mms.tic.testframework.boot.Booter;
import eu.tsystems.mms.tic.testframework.common.PropertyManager;
import eu.tsystems.mms.tic.testframework.constants.TesterraProperties;
Expand Down Expand Up @@ -71,6 +72,7 @@
import org.testng.ITestListener;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;

import java.util.List;
Expand Down Expand Up @@ -108,7 +110,7 @@ public class TesterraListener implements
private static final Object LOCK = new Object();
private static final LoggerContext loggerContext;
private static final BuildInformation buildInformation;
private static final Report report;
private static final DefaultReport report;
private static DefaultTestNGContextGenerator contextGenerator;

static {
Expand All @@ -122,6 +124,8 @@ public class TesterraListener implements
buildInformation = new BuildInformation();
eventBus = new EventBus();
report = new DefaultReport();
report.registerAnnotationConverter(Fails.class, new FailsAnnotationConverter());
report.registerAnnotationConverter(Test.class, new TestAnnotationConverter());
contextGenerator = new DefaultTestNGContextGenerator();

/*
Expand Down
5 changes: 1 addition & 4 deletions docs/src/docs/modules/localization.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ import eu.tsystems.mms.tic.testframework.l10n.LocalizedBundle;

LocalizedBundle bundle = new LocalizedBundle("testdata");
bundle.getString("TEST_KEY");

LocalizedBundle germanBundle = new LocalizedBundle("testdata", Locale.GERMAN);
germanBundle.getString("TEST_KEY");
----

Or bundles with a fixed locale.
Expand All @@ -79,7 +76,7 @@ Or bundles with a fixed locale.
----
LocalizedBundle germanBundle = new LocalizedBundle("testdata", Locale.GERMAN);
germanBundle.getString("TEST_KEY");
----
----R


== Change runtime locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.google.common.net.MediaType;
import com.google.gson.Gson;
import eu.tsystems.mms.tic.testframework.logging.Loggable;
import eu.tsystems.mms.tic.testframework.report.Report;
import eu.tsystems.mms.tic.testframework.report.DefaultReport;
import eu.tsystems.mms.tic.testframework.report.TesterraListener;
import eu.tsystems.mms.tic.testframework.report.model.ClickPathEvent;
import eu.tsystems.mms.tic.testframework.internal.IDUtils;
Expand Down Expand Up @@ -57,11 +57,8 @@
import eu.tsystems.mms.tic.testframework.report.model.context.Screenshot;
import eu.tsystems.mms.tic.testframework.report.model.context.Video;
import eu.tsystems.mms.tic.testframework.report.utils.ExecutionContextController;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -74,34 +71,34 @@

public class ContextExporter implements Loggable {
private static final Map<TestStatusController.Status, ResultStatusType> STATUS_MAPPING = new LinkedHashMap<>();
private final Report report = TesterraListener.getReport();
private final DefaultReport report = (DefaultReport)TesterraListener.getReport();
private final Gson jsonEncoder = new Gson();

private Map<String,Object> getAnnotationParameters(Annotation annotation) {
Method[] methods = annotation.annotationType().getMethods();
Map<String,Object> params = new HashMap<>();
for (Method method : methods) {
if (method.getDeclaringClass() == annotation.annotationType()) { //this filters out built-in methods, like hashCode etc
try {
Object value = method.invoke(annotation);
if (value == null) continue;

if (value.getClass().isArray()) {
Object[] values = (Object[])value;
if (values.length == 0) continue;
value = Arrays.asList(values);
} else {
value = value.toString();
if (((String) value).isEmpty()) continue;
}
params.put(method.getName(), value);
} catch (Exception e) {
log().error("Unable to retrieve annotation parameter", e);
}
}
}
return params;
}
// private Map<String,Object> getAnnotationParameters(Annotation annotation) {
// Method[] methods = annotation.annotationType().getMethods();
// Map<String,Object> params = new HashMap<>();
// for (Method method : methods) {
// if (method.getDeclaringClass() == annotation.annotationType()) { //this filters out built-in methods, like hashCode etc
// try {
// Object value = method.invoke(annotation);
// if (value == null) continue;
//
// if (value.getClass().isArray()) {
// Object[] values = (Object[])value;
// if (values.length == 0) continue;
// value = Arrays.asList(values);
// } else {
// value = value.toString();
// if (((String) value).isEmpty()) continue;
// }
// params.put(method.getName(), value);
// } catch (Exception e) {
// log().error("Unable to retrieve annotation parameter", e);
// }
// }
// }
// return params;
// }

public MethodContext.Builder buildMethodContext(eu.tsystems.mms.tic.testframework.report.model.context.MethodContext methodContext) {
MethodContext.Builder builder = MethodContext.newBuilder();
Expand Down Expand Up @@ -131,10 +128,10 @@ public MethodContext.Builder buildMethodContext(eu.tsystems.mms.tic.testframewor
}

methodContext.readAnnotations()
// Skip TestNG annotations
.filter(annotation -> !annotation.annotationType().getName().startsWith("org.testng"))
.forEach(annotation -> {
builder.putAnnotations(annotation.annotationType().getName(), this.jsonEncoder.toJson(getAnnotationParameters(annotation)));
report.getAnnotationConverter(annotation).ifPresent(annotationExporter -> {
builder.putAnnotations(annotation.annotationType().getName(), this.jsonEncoder.toJson(annotationExporter.toMap(annotation)));
});
});

apply(methodContext.getRetryCounter(), builder::setRetryNumber);
Expand Down
8 changes: 8 additions & 0 deletions report-ng/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Generates visualization of package sizes
npm run analyze
```

## Update aurelia-mdc

```shell
npm install -g npm-check-updates
ncu -u "/aurelia-mdc-web/"
npm install
```

## References

- Material Framework: https://github.com/aurelia-ui-toolkits/aurelia-mdc-web
Expand Down
Loading