diff --git a/pom.xml b/pom.xml index a0f575d81..e815ebe04 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ UTF-8 https://oss.sonatype.org/content/repositories/snapshots/ - 1.1 + 1.2 9.2.1.v20140609 1.7.7 1.9.3 diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java index 50fc1bb75..a03433314 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java @@ -41,7 +41,7 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { private static Class browserClass; private static Fn.Presenter browserContext; private KO4J ko4j = new KO4J(); - private Map urlMap = new HashMap<>(); + private final Map urlMap = new HashMap<>(); public KnockoutFXTest() { } @@ -112,7 +112,7 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { public URI prepareURL(String content, String mimeType, String[] parameters) { try { String url = "http://localhost/dynamic/" + urlMap.size(); - urlMap.put(url, content); + urlMap.put(url, new Request(content, mimeType, parameters)); return new URI(url); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); @@ -140,10 +140,38 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { throw new IllegalArgumentException("This mock does not support JSONP calls"); } String url = call.composeURL(null); - String data = urlMap.get(url); + Request data = urlMap.get(url); if (data != null) { + String content = data.content; + for (int i = 0;; i++) { + String find = "$" + i; + int at = content.indexOf(find); + if (at == -1) { + break; + } + String value = data.parameters[i]; + if (value.startsWith("http.header.")) { + String header = value.substring(12); + int line = call.getHeaders().indexOf(header); + int end = call.getHeaders().indexOf("\n", line); + if (line >= 0 && end > line) { + value = call.getHeaders().substring(line + header.length() + 1, end).trim(); + } + } + if (value.equals("http.method")) { + value = call.getMethod(); + } + if (value.equals("http.requestBody")) { + value = call.getMessage(); + } + content = content.substring(0, at) + value + content.substring(at + find.length()); + } try { - call.notifySuccess(toJSON(new ByteArrayInputStream(data.getBytes()))); + if (data.mimeType.equals("text/plain")) { + call.notifySuccess(content); + } else { + call.notifySuccess(toJSON(new ByteArrayInputStream(content.getBytes()))); + } } catch (IOException e) { call.notifyError(e); } @@ -151,4 +179,16 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { call.notifyError(new IllegalStateException()); } } + + private static final class Request { + final String content; + final String mimeType; + final String[] parameters; + + public Request(String content, String mimeType, String[] parameters) { + this.content = content; + this.mimeType = mimeType; + this.parameters = parameters; + } + } }