Skip to content

Instantly share code, notes, and snippets.

@hasithaa
Last active December 19, 2019 07:56
Show Gist options
  • Save hasithaa/e606661be03d7045be973868b9e9ed67 to your computer and use it in GitHub Desktop.
Save hasithaa/e606661be03d7045be973868b9e9ed67 to your computer and use it in GitHub Desktop.
A script to test Ballerina installers on windows.

How to run

  1. Install Ballerina using windows installer.
  2. Open cmd or powershell.
  3. Clone this scripts. git clone https://gist.github.com/e606661be03d7045be973868b9e9ed67.git wintests.
  4. cd to wintests.
  5. run test command.
import ballerina/http;
import ballerina/io;
http:Client clientEndpoint = new ("http://postman-echo.com");
public function main() {
io:println("GET request:");
var response = clientEndpoint->get("/get?test=123");
handleResponse(response);
io:println("\nPOST request:");
response = clientEndpoint->post("/post", "POST: Hello World");
handleResponse(response);
io:println("\nUse custom HTTP verbs:");
response = clientEndpoint->execute("COPY", "/get", "CUSTOM: Hello World");
http:Request req = new;
req.addHeader("Sample-Name", "http-client-connector");
response = clientEndpoint->get("/get", req);
if (response is http:Response) {
string contentType = response.getHeader("Content-Type");
io:println("Content-Type: " + contentType);
int statusCode = response.statusCode;
io:println("Status code: " + statusCode.toString());
} else {
io:println("Error when calling the backend: ", response.reason());
}
}
function handleResponse(http:Response | error response) {
if (response is http:Response) {
var msg = response.getJsonPayload();
if (msg is json) {
io:println(msg.toJsonString());
} else {
io:println("Invalid payload received:", msg.reason());
}
} else {
io:println("Error when calling the backend: ", response.reason());
}
}
@echo off
@echo "====================================="
@echo "======Testing Project Bal file======="
@echo "====================================="
rmdir hello-proj /S /Q
call ballerina new hello-proj
@echo on
cd hello-proj
call ballerina add hello_service -t service
@echo on
call ballerina add hello_main -t main
@echo on
call ballerina run hello_main
@echo on
call ballerina clean
@echo on
rmdir target /S /Q
call ballerina build -a
@echo on
call ballerina run target\bin\hello_main.jar
@echo on
rmdir target /S /Q
call ballerina build -a --skip-tests
@echo on
call ballerina run target\bin\hello_main.jar
@echo on
@cd ..
rmdir hello-proj /S /Q
@echo off
@echo "====================================="
@echo "======Testing Single Bal file========"
@echo "====================================="
CALL ballerina version
@echo on
@del hello.jar /f /Q > nul 2> nul
CALL ballerina run hello.bal
@echo on
@del hello.jar /f /Q > nul 2> nul
call ballerina build hello.bal
@echo on
call ballerina run hello.jar
@echo on
del hello.jar /f /Q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment