diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c6d40..64ab42b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # act-e2e CHANGE LOG 1.1.0 +* `ClassCastException` on verifying list elements #53 +* Simplify RequestSpec declaration in scenario yaml file #51 * Extends constants pool from depending scenario #50 * Func enhancements #49 * Simplify function declaration #47 diff --git a/src/main/java/act/e2e/RequestSpec.java b/src/main/java/act/e2e/RequestSpec.java index e633a7e..ce9790a 100644 --- a/src/main/java/act/e2e/RequestSpec.java +++ b/src/main/java/act/e2e/RequestSpec.java @@ -27,8 +27,7 @@ import com.alibaba.fastjson.JSON; import org.osgl.exception.UnexpectedException; import org.osgl.http.H; -import org.osgl.util.C; -import org.osgl.util.E; +import org.osgl.util.*; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -42,6 +41,14 @@ public class RequestSpec implements InteractionPart { public String parent; public H.Method method; public String url; + // shortcut for (GET, url) pair + public String get; + // shortcut for (POST, url) pair + public String post; + // shortcut for (PUT, url) pair + public String put; + // shortcut for (DELETE, url) pair + public String delete; public String accept; public Boolean ajax; public List modifiers = new ArrayList<>(); @@ -78,6 +85,19 @@ public void resolveParent(RequestTemplateManager manager) { @Override public void validate(Interaction interaction) throws UnexpectedException { + if (S.notBlank(get)) { + method = H.Method.GET; + url = get; + } else if (S.notBlank(post)) { + method = H.Method.POST; + url = post; + } else if (S.notBlank(put)) { + method = H.Method.PUT; + url = put; + } else if (S.notBlank(delete)) { + method = H.Method.DELETE; + url = delete; + } E.unexpectedIf(null == method, "method not specified in request spec of interaction[%s]", interaction); E.unexpectedIf(null == url, "url not specified in the request spec of interaction[%s]", interaction); } diff --git a/src/main/java/act/e2e/Scenario.java b/src/main/java/act/e2e/Scenario.java index c7546ad..ff9ffd6 100644 --- a/src/main/java/act/e2e/Scenario.java +++ b/src/main/java/act/e2e/Scenario.java @@ -542,16 +542,18 @@ void verifyBody(String bodyString, ResponseSpec spec) { } } - void verifyList(String name, List array, Map spec) { - for (Map.Entry entry : spec.entrySet()) { - String key = entry.getKey(); + void verifyList(String name, List array, Map spec) { + for (Object obj : spec.entrySet()) { + Map.Entry entry = $.cast(obj); + Object key = entry.getKey(); + String sKey = S.string(key); Object test = entry.getValue(); Object value = null; if ("size".equals(key) || "len".equals(key) || "length".equals(key)) { value = array.size(); } else if ("toString".equals(key) || "string".equals(key) || "str".equals(key)) { value = JSON.toJSONString(array); - } else if ("?".equals(key) || "".equalsIgnoreCase(key)) { + } else if ("?".equals(key) || "".equalsIgnoreCase(sKey)) { for (Object arrayElement : array) { try { verifyValue(name, arrayElement, test); @@ -560,11 +562,11 @@ void verifyList(String name, List array, Map spec) { // try next one } } - } else if (S.isInt(key)) { - int id = Integer.parseInt(key); + } else if (S.isInt(sKey)) { + int id = Integer.parseInt(sKey); value = array.get(id); } else { - if (key.contains(".")) { + if (sKey.contains(".")) { String id = S.cut(key).beforeFirst("."); String prop = S.cut(key).afterFirst("."); if ("?".equals(id) || "".equalsIgnoreCase(id)) {