Last active
November 18, 2021 12:10
-
-
Save axeda/37b63e99d16ae26e68f9 to your computer and use it in GitHub Desktop.
Scaffold for Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.util.GroovyTestCase | |
import groovyx.net.http.HTTPBuilder | |
import groovyx.net.http.RESTClient | |
import groovy.json.JsonOutput | |
import groovy.util.XmlSlurper | |
import groovy.xml.MarkupBuilder | |
import groovyx.net.http.Method | |
import org.apache.http.HttpEntity | |
import org.apache.http.HttpResponse | |
import org.apache.http.client.HttpClient | |
import org.apache.http.client.methods.HttpPost | |
import org.apache.http.client.methods.HttpPut | |
import org.apache.http.impl.client.DefaultHttpClient | |
import org.apache.http.util.EntityUtils | |
import static groovyx.net.http.ContentType.JSON | |
import org.junit.Test; | |
import org.junit.Before; | |
import org.junit.After; | |
import groovy.io.FileType; | |
import groovy.xml.XmlUtil | |
import java.nio.charset.Charset | |
public class TestScaffold { | |
protected static String address ; | |
protected static String restaddress ; | |
protected static HTTPBuilder http | |
protected HttpClient client = new DefaultHttpClient() | |
protected RESTClient rc | |
protected static String UN | |
protected static String PW | |
protected static HashMap<String, String> queryParams | |
private XmlParser parser = new XmlParser() | |
def ns = new groovy.xml.Namespace("http://www.axeda.com/services/v2", 'v2') | |
/* Host information. */ | |
protected static String hardcodedPath = System.getProperty("user.dir") + "\\" | |
protected static String hardcodedName = "artisan.properties" | |
protected static String propertiesFile = hardcodedPath + hardcodedName | |
/* Custom Object Name */ | |
protected static String customObjectName = "myCustomObject" | |
// Add this test class to your build path to run tests | |
@Before | |
void readProperties(){ | |
// read the artisan.properties file in the root project directory | |
def fileContents = new File(propertiesFile).readLines() | |
address = fileContents.find{ it ==~ /^host.*/ }?.split("=")[1]?.trim() | |
UN = fileContents.find{ it ==~ /^username.*/ }?.split("=")[1]?.trim() | |
PW = fileContents.find{ it ==~ /^password.*/ }?.split("=")[1]?.trim() | |
queryParams = [username: UN, password: PW] | |
println address | |
http = new HTTPBuilder("${address}/") | |
rc = new RESTClient("${address}/") | |
} | |
@Test | |
void executeCustomObject(){ | |
def result = "" | |
http.post( path: "services/v1/rest/Scripto/execute/${customObjectName}", query: queryParams,body: json, | |
requestContentType: JSON ) { resp, data -> | |
result += data.toString(2) + "\n" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment