videni / rest-client

Automatically exported from code.google.com/p/rest-client
Apache License 2.0
0 stars 0 forks source link

Groovy test scripts must support external Jars #181

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Mail from Tanusree M:

Hi,
First I want to thank you for the wonderful tool for helping testing the rest 
web services.
I just started using the RESTClient GUI tool. I found it very interesting. What 
I'm trying is, 
I'm trying to save my response to a jason file in my local machine, then trying 
to use JUnit to match the values for each keys from the json file.
Now when I'm trying to import some external libs I'm getting error.
Here 
I'm getting the following error:
When I imported the import org.json.simple.parser.JSONParser;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject; in eclipse, I added external jars but I 
don't know if I can do that for the RESTClient GUI tool.
Pls advice me.
================================================================================
==========================================================================
ERROR
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------

org.wiztools.restclient.bean.TestException: 
    at org.wiztools.restclient.TestUtil.getTestSuite(TestUtil.java:73)
    at org.wiztools.restclient.HTTPClientRequestExecuter.execute(HTTPClientRequestExecuter.java:461)
    at org.wiztools.restclient.ui.RESTViewImpl$2.run(RESTViewImpl.java:322)
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: 
startup failed, __GenRESTTestCase__: 4: unable to resolve class 
org.json.simple.parser.JSONParser
 @ line 4, column 1.__GenRESTTestCase__: 5: unable to resolve class org.json.simple.JSONObject
 @ line 5, column 1.__GenRESTTestCase__: 26: unable to resolve class org.json.simple.parser.JSONParser 
 @ line 26, column 18.__GenRESTTestCase__: 31: unable to resolve class org.json.simple.JSONObject 
 @ line 31, column 32.__GenRESTTestCase__: 34: unable to resolve class org.json.simple.JSONObject 
 @ line 34, column 30.__GenRESTTestCase__: 37: unable to resolve class org.json.simple.JSONObject 
 @ line 37, column 31.__GenRESTTestCase__: 40: unable to resolve class org.json.simple.JSONObject 
 @ line 40, column 34.__GenRESTTestCase__: 43: unable to resolve class org.json.simple.JSONObject 
 @ line 43, column 38.
8 errors

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:787)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:438)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:281)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:252)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:247)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:209)
    at org.wiztools.restclient.TestUtil.getTestSuite(TestUtil.java:40)
    ... 2 more
================================================================================
================================================================================
========================
My Test code for the response which I wrote in the Test area of the GUI
--------------------------------------------------------------------------------
-----------------------------------------------

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import org.json.simple.parser.JSONParser;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.junit.Assert;

import org.wiztools.restclient.RESTTestCase;
import org.wiztools.commons.MultiValueMap;

public class TemplateClassgetminspecTest extends
        org.wiztools.restclient.RESTTestCase {
    public void testStatus() {
        byte[] responseBody = response.getResponseBody();

        if ((response.getStatusCode() != 200) || (responseBody == null)) {
            fail("Test is failed!");

        } else {
            try {
                String str = new String(responseBody);
                File newTextFile = new File("C://RESTResponse/response.txt");
                FileWriter fw = new FileWriter(newTextFile);
                fw.write(str);
                fw.close();

                JSONParser parser = new JSONParser();

                Object obj = parser.parse(new FileReader(
                        "C://RESTResponse/response.txt"));

                JSONObject jsonObject = (JSONObject) obj;

                String Name = (String) jsonObject.get("Name");
                assertEquals(Name,"aaab","Name value is wrong");
                fail("Test is failed!");
                String SSN = (String) jsonObject.get("SSN");
                assertEquals(SSN,"432-97-7654","SSNvalue is wrong");
                fail("Test is failed!");

            }

            catch (IOException iox) {
                iox.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
}

Any help will be highly appreciated.
Best Regards.

Original issue reported on code.google.com by subwiz on 9 Jul 2013 at 5:49

GoogleCodeExporter commented 8 years ago
One quick fix:

https://code.google.com/p/rest-client/source/detail?r=13b2a87f31aa561501ceff80a1
dc59f334d25dad

Should be able to load Jars from ~/.rest-client/lib directory.

Original comment by subwiz on 9 Jul 2013 at 7:06