Navigation: JunoRestClient > Advanced >

Programming Support

 

Send comments on this topic.

 

 

Groovy Programming Support

App Class

 

JunoRestClient support Groovy language.  com.juno.api.rest.App class is available in all the Groovy scripts and Test Cases.

 

public interface JunoApp {


    public String getProjectName() ;
   
    public List<String> getDocumentNames() ;
   
    public String getURL( String documentName );
   
    public String getMethodName( String documentName );

    public String getRequestContentType(String documentName);

    public String getRequestHeader( String documentName );

    public String getRequestPayload( String documentName );

    public String getResponseHeader( String documentName );

    public String getResponsePayload( String documentName );

    public int getResponseStatusCode( String documentName );

    public String getResponseErrorMessage( String documentName );

    public long getLoadingTime(String documentName);

    public String getResponseContentType(String documentName);

    public int run( String documentName );

    public void sleep( long millis );

 

          // Loads properties and option to set variables at run time.
          public Properties importProperties( String filename,  boolean isSetProperties ); 

 

          // Loads properties file and set variables at run time.

          public Properties importProperties( String filename ); 
 

          // Loads groovy script from JunoRestClient groovy script item in Explorer.
          public Script loadGroovyScript( String scriptName ); 
 

          // Loads groovy script from an external file.
          public Script loadGroovyScriptFile( String fileName ); 

}

 

Examples

JunoRestClient com.juno.api.rest.App class support the following methods.

 

You can use the App class method in Groovy and Test Case Script.

 

Example:

//

// Groovy script usage

//

 

//

// Project name

//

println( "Project Name: " + app.getProjectName() ) ;

 

//

// List all the document names in this project.

//

def documentNames = app.getDocumentNames() ;

for (String item : documentNames) {

     println( "Document Name: " + item) ;

}

 

//

// REST Service methods

//

def restServiceName = "yourserviceName" ;

println( "URL: " + app.getURL(restServiceName ) ) ;

println( "Method: " + app.getMethodName(restServiceName ) ) ;

 

println( "Request Content-Type: " + app.getRequestContentType(restServiceName ) ) ;

println( "Request Header: " + app.getRequestHeader(restServiceName ) ) ;

println( "Request Payload: " + app.getRequestPayload(restServiceName ) ) ;

 

println( "Response Status Code: " + app.getResponseStatusCode(restServiceName ) ) ;

println( "Response Error Message: " + app.getResponseErrorMessage(restServiceName ) ) ;

println( "Response Loading Time: " + app.getLoadingTime(restServiceName ) ) ;

println( "Response Headers: " + app.getResponseHeader(restServiceName ) ) ;

println( "Response Payload: " + app.getResponsePayload(restServiceName ) ) ;

println( "Response Content-Type: " + app.getResponseContentType(restServiceName ) ) ;

 

//

// To run a service

//

app.run( "yourservicename" ) ;

 

//

// Sleep current thread for 1 second

//

app.sleep( 1000 ) ;

 

 

 

 

Execution Results

When you execute the above groovy script in a project, you will see the output in Log Results Window as shown below.

 

 

Script Execution Result

The Log Results shows the execution results.

Groovy script using App

Define groovy script in the Groovy script and test case editor.

 

Tutorial

Click on [Add Groovy Script] button in Ribbon bar

Add the following script in the groovy script editor.

 

println( "Project Name: " + app.getProjectName() ) ;

 

 

 

Click on the [Run Services and Scripts] button in Ribbon bar. The execution results will be shown in [Log Results] Windows.

 

11/14/2016 15:23:49 : Running Script-2

11/14/2016 15:23:49 : Project Name: UNTITLED-1

 

11/14/2016 15:23:49 : Success

 

 

 

 

 

 

Copyright © 2016 junorestclient.com

www.JunoRestClient.com