mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-21 01:00:54 +08:00
Merge pull request #150 from jtulach/putPeopleUsesRightMethod
Put people uses right method
This commit is contained in:
commit
8b1e913940
2
pom.xml
2
pom.xml
@ -66,7 +66,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<sonatypeOssDistMgmtSnapshotsUrl>https://oss.sonatype.org/content/repositories/snapshots/</sonatypeOssDistMgmtSnapshotsUrl>
|
||||
<html4j.version>1.1</html4j.version>
|
||||
<html4j.version>1.2</html4j.version>
|
||||
<jetty.version>9.2.1.v20140609</jetty.version>
|
||||
<slf4j.version>1.7.7</slf4j.version>
|
||||
<checker.version>1.9.3</checker.version>
|
||||
|
@ -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<String, String> urlMap = new HashMap<>();
|
||||
private final Map<String, Request> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user