Forum Discussion

JMcKinley's avatar
JMcKinley
Contributor
18 years ago

Problem with global groovy script

I created a global groovy class and then tried to instantiate that class in a "local groovy" script. The system gives me an error that it can't find the class ("unable to resolve class soapui.Test.TestRequest").

Here is what I did:

1. I changed the path in the SOAP UI Pro settings to be the same path that the SOAP UI project is found (and this is where the class isdefined0.
2. Here is the code in my class:

package soapui.Test

class TestRequest
{
 
  TestRequest {
  }

  def getTest() { 
  return 123657;
  }

}

Here is the instantiation in my groovy script in my SOAP UI Pro project:

import soapui.Test.TestRequest;
def Test = new TestRequest();

I also tried this without the import statement...

Help!!

Thanks!
Jim

4 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Jim,

    hm.. can you see soapUI Pro picking up your class when it starts up (in the soapui log)?

    regards,

    /Ole
    eviware.com
  • It appears that it is erring off...

    It says something about unexpected token: TestRequest {

    With a caret under the T of TestRequest { 

    Not sure why... it also indicates to look at the error log for more details. I went to the error log (in my SOAP UI session) and it was empty.
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    try the following instead:

    package soapui.Test

    public class TestRequest
    {
     
      public TestRequest
      {
      }

      def getTest() {
          return 123657;
      }

    }


    any better?

    /Ole
    eviware.com
  • the public key words did not help... but with seeing the compile error, I did find the problem (I did not realize you could see it in the "soapui log" window until you suggested to look there)...

    Here is the corrected version:

    package soapui.Test

    class TestRequest
    {
       
    TestRequest() {
       }

       def getTest() { 
       return 123657;
       }

    }

    I did not have a () after my constructor. I could have sworn I saw some documentation somewhere (either on this site or somewhere) that showed the constructor (for Groovy code) without parentheses.

    Now, I can access the method and print out the return value in my project.

    Seeing the compile error helped point the direction to the problem.

    Thanks for the help!
    Jim