Contributions
Re: Mock (REST) service, as a (mostly) passthrough
Here is the code I have for calling a SOAP service within the mock script. the host can be override in the header as in <header> <host>142.234.345.67</host> </header> ``` /**************************************/ /* get the override host value */ /**************************************/ def String host = holder.getNodeValue("//host"); //def host = context.expand('${#Project#host}'); //log.info("HOST => " + host); /**************************************/ /* if no host override, use localhost */ /**************************************/ if (host == null || host.length() == 0) host = "localhost"; /**************************************/ /* build the URL */ /**************************************/ service_url = "http://" + host + ":7001/my_downstream_service"; /**************************************/ /* setup the soap connection */ /**************************************/ def soapUrl = new URL(service_url); def connection = soapUrl.openConnection(); def soapRequest = mockRequest.requestContent; connection.setRequestMethod("POST"); connection.setRequestProperty("Accept-Encoding" ,"gzip,deflate"); connection.setRequestProperty("Content-Type" ,"text/xml;charset=UTF-8"); connection.setRequestProperty("SOAPAction", mockRequest.getSoapAction()); // mockRequest.getSoapAction()); connection.doOutput = true; /**************************************/ /* remove host override from reqeust */ /**************************************/ def String requestStr = mockRequest.requestContent def int pos1 = requestStr.indexOf("<host>"); if (pos1 > 0){ def String newReqeustStr def int pos2 = requestStr.indexOf("</host>"); newReqeustStr = requestStr.substring(0, pos1) + requestStr.substring(pos2 + 8, requestStr.length()); soapRequest = newReqeustStr; } /**************************************/ /* call service */ /**************************************/ Writer writer = new OutputStreamWriter(connection.outputStream); writer.write(soapRequest); writer.flush(); writer.close(); connection.connect(); def soapResponse = connection.content.text; requestContext.responseMessage = soapResponse; return "Response 1" ```2.6KViews1like0CommentsFrom the mock service calling downstream service
Adding a new operation to an existing REST service. Will becreating a mock response for the new operation but for existing operations, would like to call the real service and return the response. Has anyone got example ofa groovy script that will take the request and call the real service and return response. TIA Gary570Views0likes0CommentsHow to get the request and response from WsdlTestStepResult
Hi I have the following code fragment. I would like to get the request and response XML. I can see the request and response XML via the eclipse debugger. But how can I get at these values from java ? WsdlProject project = new WsdlProject("c:\\soapUiTest\\....); WsdlTestSuite wsdlTestSuite = project.getTestSuiteByName("CalculatePrice TestSuite") WsdlTestCase wsdlTestCase = wsdlTestSuite.getTestCaseByName("calculatePrice TestCase"); WsdlTestStep wsdlTestStep = wsdlTestCase.getTestStepByName("calculatePrice"); WsdlTestCaseRunner runner = new WsdlTestCaseRunner(wsdlTestCase, new PropertiesMap()); WsdlTestStepResult result = (WsdlTestStepResult) wsdlTestStep.run(runner, new WsdlTestRunContext(wsdlTestStep) ); WsdlTestStep resultStep = (WsdlTestStep) result.getTestStep(); In eclipse debug mode, I am able to navigate from resultStep->testStep->testRequest to get rquestContent and response.responseContent. What are the method I should call to get these ? Thanks11 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.4KViews0likes1CommentHow to find and report test result from Java/JUnit
Hi Starting to use soapUI with Junit. I can see when using SoapUITestCaseRunner.run, I get the steps, assertion and request/response if the step failed. When I switch to use Testcase.run(), how can I interpreted the result from TestRunner. The only public method I can find is the status which does not give much detail other than VALID of FAIL. Can someone please point me to the document or java sample I can use to report the test result. Thanks685Views0likes1Commentdifferent behavior when running with jUnit
Hi Have a line in the groovy script test step that runs fine while within the soapUI environment. But when I run the test case in jUnit. I am getting a null error. The line that is in question is def project= testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("EssTest"); It works fine until I try to run this in a junit testing. Got the following error 09:55:52,960 ERROR [SoapUI] An error occured [Cannot invoke method getProjectByName() on null object], see error log for details java.lang.NullPointerException: Cannot invoke method getProjectByName() on null object at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124) at Script1.run(Script1.groovy:5) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148) at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runTestStep(WsdlTestCaseRunner.java:207) at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.internalRun(WsdlTestCaseRunner.java:138) at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.internalRun(WsdlTestCaseRunner.java:39) at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:135) at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:77) at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:599) at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:66) at com.telus.ess.test.CalculatePrice.runner(CalculatePrice.java:90) at com.telus.ess.test.CalculatePrice.exchangeActivation(CalculatePrice.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)816Views0likes1CommentWhat are the parameters in TestCase run()
Hi Trying to execute com.eviware.soapui.model.testsuite.TestCase.run(StringToObjectMap map, boolean boolean) in a jUnit test case. Can someone let me know where I can find the document of this or help me understand what these two parameters are and how they are used. Thanks712Views0likes1Comment