public static ContentResource template(final String template, final String name1, final String value1, final String name2, final String value2) { return template(text(checkNotNullOrEmpty(template, "Template should not be null")), checkNotNullOrEmpty(name1, "Template variable name should not be null"), checkNotNullOrEmpty(value1, "Template variable value should not be null"), checkNotNullOrEmpty(name2, "Template variable name should not be null"), checkNotNullOrEmpty(value2, "Template variable value should not be null")); }
public static MountPredicate include(final String glob) { checkNotNullOrEmpty(glob, "Glob should not be null or empty"); final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); return new MountPredicate() { @Override public boolean apply(final String filename) { return matcher.matches(Paths.get(filename)); } }; }
public static URL toUrl(final String url) { try { return new URL(checkNotNullOrEmpty(url, "URL should not be null")); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } }
public static String checkValidVariableName(final String name) { if (!RESERVED_NAME.contains( checkNotNullOrEmpty(name, "Template variable name should not be null"))) { return name; } throw new IllegalArgumentException("Template variable name should not be same with reserved name"); }
public static HttpsCertificate certificate(final ContentResource resource, final String keyStorePassword, final String certPassword) { return new HttpsCertificate(checkNotNull(resource), checkNotNullOrEmpty(keyStorePassword, "Key store password should not be null"), checkNotNullOrEmpty(certPassword, "Cert password should not be null")); } }
private static File joinFiles(final String path1, final String path2) { checkNotNullOrEmpty(path2, "Empty path is not allowed"); if (path1 == null) { return new File(path2); } return new File(new File(path1), path2); }
public static <ExtractorType1, ExtractorType2> ContentResource template(final String template, final String name1, final RequestExtractor<ExtractorType1> extractor1, final String name2, final RequestExtractor<ExtractorType2> extractor2) { return template(text(checkNotNullOrEmpty(template, "Template should not be null")), checkNotNullOrEmpty(name1, "Template variable name should not be null"), checkNotNull(extractor1, "Template variable extractor should not be null"), checkNotNullOrEmpty(name2, "Template variable name should not be null"), checkNotNull(extractor2, "Template variable extractor should not be null")); }
public static ContentResource template(final ContentResource template, final String name1, final String value1, final String name2, final String value2) { return template(checkNotNull(template, "Template should not be null"), checkNotNullOrEmpty(name1, "Template variable name should not be null"), var(checkNotNullOrEmpty(value1, "Template variable value should not be null")), checkNotNullOrEmpty(name2, "Template variable name should not be null"), var(checkNotNullOrEmpty(value2, "Template variable value should not be null"))); }
private static String checkValidUrlItem(final String id, final String item) { checkNotNullOrEmpty(id, item + " should not be null or empty"); if (id.contains(URLs.SEPARATOR)) { throw new IllegalArgumentException(item + " should not contain '/'"); } if (!URLs.isValidUrl(id)) { throw new IllegalArgumentException(item + " should not contains invalid URI character"); } return id; }
public static ResponseHandler cookie(final String key, final String value, final CookieAttribute... attributes) { return cookie(checkNotNullOrEmpty(key, "Cookie key should not be null"), text(checkNotNullOrEmpty(value, "Cookie value should not be null")), checkNotNull(attributes, "Cookie options should not be null")); }
public static <T> ContentResource template(final String template, final String name, final RequestExtractor<T> extractor) { return template(text(checkNotNullOrEmpty(template, "Template should not be null")), checkNotNullOrEmpty(name, "Template variable name should not be null"), checkNotNull(extractor, "Template variable extractor should not be null")); }
public static ContentResource template(final ContentResource template, final String name, final String value) { return template(checkNotNull(template, "Template should not be null"), checkNotNullOrEmpty(name, "Template variable name should not be null"), var(checkNotNullOrEmpty(value, "Template variable value should not be null"))); }
public static MocoJunitRunner jsonHttpsRunner(final int port, final String filename, final HttpsCertificate certificate) { checkArgument(port > 0, "Port must be greater than zero"); checkNotNullOrEmpty(filename, "Filename should not be null"); checkNotNull(certificate, "Certificate should not be null"); return jsonHttpsRunner(port, file(filename), certificate); }
public static ResponseHandler cookie(final String key, final Resource resource, final CookieAttribute... attributes) { return header(SET_COOKIE, cookieResource( checkNotNullOrEmpty(key, "Cookie key should not be null"), checkNotNull(resource, "Cookie value should not be null"), checkNotNull(attributes, "Cookie options should not be null"))); }
public static MocoJunitRunner jsonHttpRunner(final int port, final String filename) { checkArgument(port > 0, "Port must be greater than zero"); checkNotNullOrEmpty(filename, "Filename should not be null"); return jsonHttpRunner(port, file(filename)); }
public static MocoJunitRunner jsonRestRunner(final int port, final String filename) { checkArgument(port > 0, "Port must be greater than zero"); checkNotNullOrEmpty(filename, "Filename should not be null"); return jsonRestRunner(port, file(filename)); }
public static MocoJunitRunner jsonSocketRunner(final int port, final String filename) { checkArgument(port > 0, "Port must be greater than zero"); checkNotNullOrEmpty(filename, "Filename should not be null"); return jsonSocketRunner(port, file(filename)); }
public static ResponseHandler attachment(final String filename, final Resource resource) { return AndResponseHandler.and( header(HttpHeaders.CONTENT_DISPOSITION, format("attachment; filename=%s", checkNotNullOrEmpty(filename, "Filename should not be null or empty"))), with(checkNotNull(resource, "Resource should not be null"))); }
@Override public final HttpResponseSetting mount(final String dir, final MountTo target, final MountPredicate... predicates) { File mountedDir = new File(checkNotNullOrEmpty(dir, "Directory should not be null")); checkNotNull(target, "Target should not be null"); return this.request(new MountMatcher(mountedDir, target, copyOf(predicates))) .response(new MountHandler(mountedDir, target)); }
public ProxyConfig to(final String remoteBase) { return new ProxyConfig(toBase(localBase), toBase(checkNotNullOrEmpty(remoteBase, "Remote base should not be null"))); } }