@Override public void validate(Interaction interaction) throws UnexpectedException { 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); }
private File verifyDir(File dir, String label, boolean create) { if (create && !dir.exists()) { E.unexpectedIf(!dir.mkdirs(), "Cannot create %s dir %s for %s", dir, label, app); return dir; } E.unexpectedIf(!dir.isDirectory(), "%s %s is not a directory", label, dir); E.unexpectedIf(!dir.canRead(), "Cannot read %s dir %s", label, dir); E.unexpectedIf(!dir.canWrite(), "Cannot write %s dir %s", label, dir); return dir; }
private File verifyDir(File dir, String label, boolean create) { if (create && !dir.exists()) { E.unexpectedIf(!dir.mkdirs(), "Cannot create %s dir %s for %s", dir, label, app); return dir; } E.unexpectedIf(!dir.isDirectory(), "%s %s is not a directory", label, dir); E.unexpectedIf(!dir.canRead(), "Cannot read %s dir %s", label, dir); E.unexpectedIf(!dir.canWrite(), "Cannot write %s dir %s", label, dir); return dir; }
/** * Returns package name of a class * * @param clazz * the class * @return * the package name of the class */ public static String packageNameOf(Class<?> clazz) { String name = clazz.getName(); int pos = name.lastIndexOf('.'); E.unexpectedIf(pos < 0, "Class does not have package: " + name); return name.substring(0, pos); }
/** * Returns package name of a class * * @param clazz * the class * @return * the package name of the class */ public static String packageNameOf(Class<?> clazz) { String name = clazz.getName(); int pos = name.lastIndexOf('.'); E.unexpectedIf(pos < 0, "Class does not have package: " + name); return name.substring(0, pos); }
private static Class<?> getCallerClass() { StackTraceElement[] sa = new RuntimeException().getStackTrace(); E.unexpectedIf(sa.length < 3, "Whoops!"); StackTraceElement ste = sa[2]; String className = ste.getClassName(); if ("act.Act$start".equals(className)) { // groovy launched app ste = sa[6]; className = ste.getClassName(); } E.unexpectedIf(!className.contains("."), "The main class must have package name to use Act"); return $.classForName(className); }
private static Class<?> getCallerClass() { StackTraceElement[] sa = new RuntimeException().getStackTrace(); E.unexpectedIf(sa.length < 3, "Whoops!"); StackTraceElement ste = sa[2]; String className = ste.getClassName(); if ("act.Act$start".equals(className)) { // groovy launched app ste = sa[6]; className = ste.getClassName(); } E.unexpectedIf(!className.contains("."), "The main class must have package name to use Act"); return $.classForName(className); }
void register(Keyword keyword, NamedLogic logic, boolean force) { Class<? extends NamedLogic> type = logic.type(); Map<Keyword, NamedLogic> lookup = registry.get(type); if (null == lookup) { lookup = new HashMap<>(); registry.put(type, lookup); } NamedLogic existing = lookup.put(keyword, logic); E.unexpectedIf(!force && null != existing && logic != existing, "Keyword already used: " + keyword.hyphenated()); }
void register(Keyword keyword, NamedLogic logic, boolean force) { Class<? extends NamedLogic> type = logic.type(); Map<Keyword, NamedLogic> lookup = registry.get(type); if (null == lookup) { lookup = new HashMap<>(); registry.put(type, lookup); } NamedLogic existing = lookup.put(keyword, logic); E.unexpectedIf(!force && null != existing && logic != existing, "Keyword already used: " + keyword.hyphenated()); }
private void register(Keyword keyword) { Class<? extends NamedLogic> type = type(); Map<Keyword, NamedLogic> lookup = registry.get(type); if (null == lookup) { lookup = new HashMap<>(); registry.put(type, lookup); } NamedLogic existing = lookup.put(keyword, this); E.unexpectedIf(null != existing, "Keyword already used: " + keyword.hyphenated()); }
@Override public void init(Object param) { String s = S.string(param); if (s.startsWith("/")) { s = s.substring(1); } resourcePath = s; E.unexpectedIf(null == tryRead(), "ReadContent init param[%s] must be a valid resource path.", s); }
@Override public void init(Object param) { String s = S.string(param); if (s.startsWith("/")) { s = s.substring(1); } resourcePath = s; E.unexpectedIf(null == tryRead(), "ReadContent init param[%s] must be a valid resource path.", s); }
@Override public void run(Scenario scenario) { String fileName = (String) initVal; File file = new File(fileName); E.unexpectedIf(!file.exists() || !file.canRead(), "File not exists or not readable: " + fileName); String content = IO.read(file).toString(); scenario.cache(S.underscore(fileName), content); } }
@Override public void validate(Scenario scenario) throws UnexpectedException { E.unexpectedIf(S.blank(description), "no description in the interaction of [%s]", scenario); E.unexpectedIf(null == request, "request spec not specified in interaction[%s]", this); //E.unexpectedIf(null == response, "response spec not specified"); scenario.resolveRequest(request); request.validate(this); if (null != response) { response.validate(this); } reset(); }
@Override protected void initialized() { String path = (String) options.get("value"); E.unexpectedIf(S.blank(path), "resource path not specified"); boolean trimLeadingSlash = !$.bool(options.get("skipTrimLeadingSlash")); while (trimLeadingSlash && path.startsWith("/")) { path = path.substring(1); } E.unexpectedIf(S.blank(path), "resource path not specified"); HeaderMapping anno = spec.getAnnotation(HeaderMapping.class); if (null != anno) { this.hint = HeaderMapping.Parser.parse(anno.value()); } resource = load(path, spec, hint); }
private void register(Meta meta, App app) { Class<?> cls = app.classForName(meta.className); Method method = findMethod(cls, meta.methodName); E.unexpectedIf(null == method, "Unable to find method %s", meta); register(meta, cls, method, app); }
private void register(Meta meta, App app) { Class<?> cls = app.classForName(meta.className); Method method = findMethod(cls, meta.methodName); E.unexpectedIf(null == method, "Unable to find method %s", meta); register(meta, cls, method, app); }
@Override public void validate(Scenario scenario) throws UnexpectedException { E.unexpectedIf(null == request, "request spec not specified in interaction[%s]", this); //E.unexpectedIf(null == response, "response spec not specified"); scenario.resolveRequest(request); request.validate(this); if (null != response) { response.validate(this); } reset(); }
private long convert(String param) { App app = Act.app(); if (null != app) { AppConfig config = app.config(); Long l = tryWithAppConfig(param, config); if (null != l) { return l; } } Long l = tryWithDefaultDateTimeFormats(param); E.unexpectedIf(null == l, "Unknown date time string: " + param); return l; }
@Override public void validate(Scenario scenario) throws UnexpectedException { E.unexpectedIf(null == request, "request spec not specified in interaction[%s]", this); //E.unexpectedIf(null == response, "response spec not specified"); scenario.resolveRequest(request); request.validate(this); if (null != response) { response.validate(this); } reset(); }