
hope.kola.contract.api.PathParameters Maven / Gradle / Ivy
package hope.kola.contract.api;
import static hope.kola.contract.api.KolaTestFunctions.$VString;
import com.squareup.javapoet.CodeBlock;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import java.util.LinkedHashSet;
import java.util.Set;
public class PathParameters {
protected Set entries = new LinkedHashSet<>();
public Set entries() {
return entries;
}
public boolean hasEntries() {
return !entries.isEmpty();
}
public void parameter(String name, @DelegatesTo(PathParameter.class) Closure consumer) {
final PathParameter qp = new PathParameter(name);
consumer.setDelegate(qp);
consumer.call();
entries.add(qp);
}
/**
* Populate dynamic value from the global context by the key
*
* @param name the Path parameter name
* @param key the key from the context
*/
public void fromGlobal(String name, final String key) {
final PathParameter qp = new PathParameter(name);
qp.code(CodeBlock.builder().add("$L($S)", $VString, key));
entries.add(qp);
}
public void parameter(String name, String value) {
final PathParameter qp = new PathParameter(name);
qp.withString(value);
entries.add(qp);
}
public void parameter(String name, Integer value) {
final PathParameter qp = new PathParameter(name);
qp.withInteger(value);
entries.add(qp);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy