title: How can I use relative paths to external response files for soapUI MockService
body: <h1>What I've Done</h1>
  
  <p>I am using soapUI (3.6.1 Free version) mock services to serve up specific data to 2 client applications I am testing. With some simple Groovy script I've set up some mock operations to fetch responses from specific files based on the requests made by the client applications.</p>
  
  <p>The static contents of the mock response is:</p>
  
  <pre><code>${responsefile}
  </code></pre>
  
  <p>The groovy in the operation dispatch scripting pane is:</p>
  
  <pre><code>def req = new XmlSlurper().parseText(mockRequest.requestContent)
  if (req =~ "CategoryA")
  {
      context.responsefile = new File("C:/soapProject/Test_Files/ID_List_CategoryA.xml").text
  }
  else
  {
      context.responsefile = new File("C:/soapProject/Test_Files/ID_List_CategoryB.xml").text
  }
  </code></pre>
  
  <p>In this example, when the client application issues a request to the mock service that contains the string CategoryA, the response returned by soapUI is the contents of file ID_List_CategoryA.xml</p>
  
  <h1>What I'm Trying To Achieve</h1>
  
  <p>This all works fine with the absolute paths in the groovy. Now I want to pull the whole collection of soapUI project file and external files into a package for easy re-deployment. From my reading about soapUI I hoped this would be as easy as setting the project Resource Root value to ${projectDir} and changing my paths to:</p>
  
  <pre><code>def req = new XmlSlurper().parseText(mockRequest.requestContent)
  if (req =~ "CategoryA")
  {
      context.responsefile = new File("Test_Files/ID_List_CategoryA.xml").text
  }
  else
  {
      context.responsefile = new File("Test_Files/ID_List_CategoryB.xml").text
  }
  </code></pre>
  
  <p>... keeping in mind that the soapUI project xml file resides in C:/soapProject/</p>
  
  <h1>What I've Tried So Far</h1>
  
  <p>So, that doesn't work. I've tried variations of relative paths:</p>
  
  <ul>
  <li>./Test_Files/ID_List_CategoryA.xml</li>
  <li>/Test_Files/ID_List_CategoryA.xml</li>
  <li>Test_Files/ID_List_CategoryA.xml</li>
  </ul>
  
  <p>One post indicated that soapUI might consider the project files parent directory as the root for the purposes of the relative path, so tried the following variations too:</p>
  
  <ul>
  <li>./soapProject/Test_Files/ID_List_CategoryA.xml</li>
  <li>/soapProject/Test_Files/ID_List_CategoryA.xml</li>
  <li>soapProject/Test_Files/ID_List_CategoryA.xml</li>
  </ul>
  
  <p>When none of that worked I tried making use of the ${projectDir} property in the groovy script, but all such attempts failed with a "No such property: mockService for class: Script[n]" error. Admittefly, I was really fumbling around when trying to do that.</p>
  
  <p>I tried using information from this post and others: <a href="https://stackoverflow.com/q/8490982/1375763">How do I make soapUI attachment paths relative?</a></p>
  
  <p>... without any luck. Replacing "test" with "mock," (among other changes), in the solution code from that post resulted in more property errors, e.g.</p>
  
  <pre><code>testFile = new File(mockRunner.project.getPath())
  </code></pre>
  
  <p>.. led to...</p>
  
  <pre><code>No such property: mockRunner for class: Script3
  </code></pre>
  
  <h1>What I Think I Need</h1>
  
  <p>The posts I've found related to this issue all focus on soapUI TestSuites. I really need a solution that is MockService centric or at least sheds some light on how it can be handled differently for MockServices as opposed to TestSuites.</p>
  
  <p>Any help is greatly appreciated. Thanks. Mark.</p>
  
  <h1>The Solution - Provided by <a href="https://stackoverflow.com/users/171012/gargantuchet">GargantuChet</a></h1>
  
  <p>The following includes the changes suggested by <a href="https://stackoverflow.com/users/171012/gargantuchet">GargantuChet</a> to solve the problem of trying to access the ${projectDir} property and enable the use of relative paths by defining a new projectDir object within the scope of the groovy script:</p>
  
  <pre><code>def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
  def projectDir = groovyUtils.projectPath
  
  def req = new XmlSlurper().parseText(mockRequest.requestContent)
  if (req =~ "CategoryA")
  {
      context.responsefile = new File(projectDir, "Test_Files/ID_List_CategoryA.xml").text
  }
  else
  {
      context.responsefile = new File(projectDir, "Test_Files/ID_List_CategoryB.xml").text
  }
  </code></pre>