How to Use Groovy with a Custom Java HTTP Testing Framework
This tutorial shows how to package a Java‑based HTTP testing framework into a JAR, import it into Groovy, and write a concise Groovy script that sends an HTTP GET request, processes the JSON response, and prints the result.
While developing a Java framework for HTTP interface testing, the author found that using a scripting language simplifies test case execution and management, and chose Groovy based on a recommendation.
The approach is to build the Java framework into a JAR file, then import that JAR in a Groovy script and directly call the framework’s methods to send HTTP requests and handle responses.
Below is the complete Groovy script used for the demonstration:
import net.sf.json.JSONObject
import org.apache.http.client.methods.HttpGet
import source.FanLibrary
class one extends FanLibrary {
static void main(String[] args) {
def httpGet = new HttpGet("http://cost-api.fissionpie.com/cost?_t=200&_app=1&_v=1.0.0&token=601_200_1524035146010_d78096e246592dfa&userId=56&type=1&maxId=0&length=10")
def response = getHttpResponseEntityByJson(httpGet)
println response
}
}The script creates an HttpGet object with the target URL, invokes the framework’s getHttpResponseEntityByJson method to obtain the JSON response, and prints the result to the console.
Running the script produces the following response (illustrated in the image):
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
