Skip to content

Commit

Permalink
Merge pull request #317 from BSchneppe/jmte-upgrade
Browse files Browse the repository at this point in the history
upgraded jmte version to 5.0.0
  • Loading branch information
vmi authored Mar 14, 2020
2 parents 2b0c660 + 66302d2 commit d85cbb1
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 90 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ It supports test-case and test-suite which are Selenium IDE's native format.</de
<dependency>
<groupId>com.floreysoft</groupId>
<artifactId>jmte</artifactId>
<version>3.2.0</version>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/jp/vmi/html/result/HtmlEscapeRenderer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package jp.vmi.html.result;

import java.util.Locale;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import jp.vmi.selenium.selenese.utils.EscapeUtils;

import java.util.Locale;
import java.util.Map;

/**
* HTML escape renderer for JMTE.
*/
Expand All @@ -28,7 +28,7 @@ public Class<?>[] getSupportedClasses() {
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
return EscapeUtils.escapeHtml(o.toString(), true);
}
}
29 changes: 14 additions & 15 deletions src/main/java/jp/vmi/html/result/HtmlResult.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
package jp.vmi.html.result;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.floreysoft.jmte.AnnotationProcessor;
import com.floreysoft.jmte.Engine;
import com.floreysoft.jmte.TemplateContext;
import com.floreysoft.jmte.token.AnnotationToken;

import jp.vmi.html.result.TestSuiteTree.Node;
import jp.vmi.selenium.selenese.Selenese;
import jp.vmi.selenium.selenese.TestCase;
Expand All @@ -27,6 +13,18 @@
import jp.vmi.selenium.selenese.result.CommandResultList;
import jp.vmi.selenium.selenese.result.Result;
import jp.vmi.selenium.selenese.utils.SystemInformation;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* HTML result generator.
Expand Down Expand Up @@ -98,7 +96,7 @@ private String getTemplate(String filename) {

private Engine getEngine() {
if (engine == null) {
engine = Engine.createCompilingEngine();
engine = Engine.createEngine();
engine.registerNamedRenderer(new HtmlEscapeRenderer());
engine.registerNamedRenderer(new LogRenderer(this));
engine.registerNamedRenderer(new IndexRenderer());
Expand Down Expand Up @@ -193,6 +191,7 @@ public TestSuiteSummary generate(TestSuite testSuite) {
model.put("sysInfo", SystemInformation.getInstance());
model.put("testSuite", testSuite);
model.put("seleneseList", seleneseList);
model.put("testCaseList", testSuite.getTestCaseList());
model.put("numTestTotal", summary.numTestTotal);
model.put("numTestPasses", summary.numTestPasses);
model.put("numTestFailures", summary.numTestFailures);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/jp/vmi/html/result/IndexRenderer.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jp.vmi.html.result;

import java.util.Locale;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import java.util.Locale;
import java.util.Map;

/**
* Index renderer for JMTE.
*/
Expand All @@ -26,7 +27,7 @@ public Class<?>[] getSupportedClasses() {
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
if (((Number) o).intValue() >= 0)
return o.toString();
else
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/jp/vmi/html/result/LogRenderer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package jp.vmi.html.result;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.text.StringEscapeUtils;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import jp.vmi.selenium.selenese.utils.EscapeUtils;
import jp.vmi.selenium.selenese.utils.PathUtils;
import org.apache.commons.text.StringEscapeUtils;

import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* HTML escape renderer for JMTE.
Expand Down Expand Up @@ -51,7 +50,7 @@ public Class<?>[] getSupportedClasses() {
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
StringBuilder result = new StringBuilder();
String s = o.toString();
Matcher matcher = RE.matcher(s);
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/jp/vmi/html/result/NodeRenderer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package jp.vmi.html.result;

import java.util.HashMap;
import java.util.Locale;

import com.floreysoft.jmte.Engine;
import com.floreysoft.jmte.Renderer;

import jp.vmi.html.result.TestSuiteTree.Node;

import java.util.Locale;
import java.util.Map;

/**
* Test-suite tree node renderer for JMTE.
*/
Expand All @@ -28,8 +27,7 @@ public NodeRenderer(Engine engine, String template) {
}

@Override
public String render(Node node, Locale locale) {
HashMap<String, Object> model = new HashMap<>();
public String render(Node node, Locale locale, Map<String, Object> model) {
model.put("node", node);
return engine.transform(template, model);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/jp/vmi/html/result/NumberRenderer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package jp.vmi.html.result;

import java.text.NumberFormat;
import java.util.Locale;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import java.text.NumberFormat;
import java.util.Locale;
import java.util.Map;

/**
* Number with separator renderer for JMTE.
*/
Expand All @@ -27,7 +28,7 @@ public Class<?>[] getSupportedClasses() {
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
long value = ((Number) o).longValue();
return NumberFormat.getInstance(locale).format(value);
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/jp/vmi/html/result/RelativePathRenderer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package jp.vmi.html.result;

import java.util.Locale;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import jp.vmi.selenium.selenese.utils.PathUtils;

import java.util.Locale;
import java.util.Map;

/**
* Index renderer for JMTE.
*/
Expand Down Expand Up @@ -37,9 +37,8 @@ public String getName() {
public Class<?>[] getSupportedClasses() {
return new Class[] { Object.class };
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
// NB: Relativize has URI escaped the path
return PathUtils.relativize(htmlResult.getDir(), o.toString());
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/jp/vmi/html/result/ResultRenderer.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package jp.vmi.html.result;

import java.util.Locale;

import com.floreysoft.jmte.Renderer;

import jp.vmi.selenium.selenese.result.Result;

import java.util.Locale;
import java.util.Map;

/**
* Command result renderer for JMTE.
*/
public class ResultRenderer implements Renderer<Result> {

@Override
public String render(Result result, Locale locale) {
public String render(Result result, Locale locale, Map<String, Object> model) {
return result.getClass().getSimpleName().toLowerCase();
}
}
7 changes: 4 additions & 3 deletions src/main/java/jp/vmi/html/result/StringRenderer.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jp.vmi.html.result;

import java.util.Locale;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import java.util.Locale;
import java.util.Map;

/**
* String renderer for JMTE.
*/
Expand All @@ -26,7 +27,7 @@ public Class<?>[] getSupportedClasses() {
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
return o.toString();
}
}
10 changes: 5 additions & 5 deletions src/main/java/jp/vmi/html/result/TimeRenderer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package jp.vmi.html.result;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;
import java.util.Map;

/**
* Time with millisecond renderer for JMTE.
Expand All @@ -28,9 +29,8 @@ public String getName() {
public Class<?>[] getSupportedClasses() {
return new Class[] { long.class, Long.class };
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
long value = ((Number) o).longValue();
ZonedDateTime dateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), ZoneId.systemDefault());
return DateTimeFormatter.ofPattern(format).format(dateTime);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/jp/vmi/html/result/UrlEncodeRenderer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package jp.vmi.html.result;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.floreysoft.jmte.NamedRenderer;
import com.floreysoft.jmte.RenderFormatInfo;

/**
* URL encode renderer for JMTE.
*/
Expand Down Expand Up @@ -39,7 +40,7 @@ private StringBuilder encode(StringBuilder sb, String s) {
}

@Override
public String render(Object o, String format, Locale locale) {
public String render(Object o, String format, Locale locale, Map<String, Object> model) {
StringBuilder result = new StringBuilder();
String s = o.toString();
Matcher matcher = RE.matcher(s);
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/jp/vmi/selenium/selenese/TestSuite.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package jp.vmi.selenium.selenese;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jp.vmi.html.result.IHtmlResultTestSuite;
import jp.vmi.junit.result.ITestSuite;
import jp.vmi.selenium.selenese.command.ICommandFactory;
Expand All @@ -16,8 +9,15 @@
import jp.vmi.selenium.selenese.result.Result;
import jp.vmi.selenium.selenese.utils.PathUtils;
import jp.vmi.selenium.selenese.utils.StopWatch;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static jp.vmi.selenium.selenese.result.Unexecuted.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static jp.vmi.selenium.selenese.result.Unexecuted.UNEXECUTED;

/**
* test-suite object for execution.
Expand Down Expand Up @@ -173,6 +173,18 @@ public List<Selenese> getSeleneseList() {
return seleneseList;
}

/**
* Get Testcases included in TestSuite.
*
* @return Testcases list.
*/
public List<TestCase> getTestCaseList() {
return seleneseList.stream()
.filter(selenese -> selenese instanceof TestCase)
.map(selenese -> (TestCase) selenese)
.collect(Collectors.toList());
}

/**
* Get stop watch.
*
Expand Down
Loading

0 comments on commit d85cbb1

Please sign in to comment.