mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
The $ substitution should happen when processing the URL. When text/plain MIME type is requested, return plain String, not a JSON object.
This commit is contained in:
parent
b4ba3719d0
commit
d06ca2d2a2
|
@ -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,30 @@ 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.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 +171,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