How to update JSON node value in jmeter using beanshell preprocessor - json

Currently, I am trying to update the JSON response node value using BeanShell PreProcessor.
Need help in converting JSON response in Object and then updating the node value and then stringify.
I have the following JSON and I want to update the OrderTypeId and IsCredentialOff values using BeanShell PreProcessor in Jmeter. I have tried a solution in postman which worked well. whereas getting difficulty in BeanShell Scripting.
{"DeliveryCharge":0.0,"ApplyCouponToCart":true,"CartId":6970,"SessionId":"DB84A55E-82A9-4BC9-98E8-2A845FB6893A","StoreId":10061,"UserId":10011690,"AppId":10061,"ListCartItem":[{"CartItemId":55513,"UserId":0,"StoreId":0,"AppId":0,"CartId":6970,"PID":772544,"Pack":1,"ProductId":5712,"ProductImage":"https://s3.amazonaws.com/images.liquorapps.com/sm/000457-TWO-FINGERS-GOLD-TEQUILA.png","ProductName":"TWO FINGERS GOLD","UnitSize":"750 ML","Quantity":1,"UPC":"89540135328","SKU":"1014","CategoryId":2,"TypeId":15,"VarietalId":0,"UnitSizeId":12,"CountryId":7,"RegionId":32,"Price":14.99,"PriceDisplay":"$14.99","OfferPrice":14.99,"OfferPriceDisplay":"$14.99","FinalPrice":14.99,"FinalPriceDisplay":"$14.99","TaxRate":0.066250,"QuantityOrdered":1,"Remark":"","ItemTotal":14.99,"ItemTotalDisplay":"$14.99","FinalItemTotal":14.99,"FinalItemTotalDisplay":"$14.99","ItemTotalSaving":0.00,"ItemTotalSavingDisplay":"","ListDiscount":[],"ListCharge":[],"CartItemCount":0,"Deposit":0.00,"DealId":0,"DealInventory":0,"DealInventoryMessage":"","IsBottleLimitAtRetail":false,"TotalQuantity":1,"IsOfferItem":false,"SuccessMessage":"","ErrorDetail":"","ErrorMessage":"","MessageType":"","MessageTitle":"","TextType":""}],"ListDiscount":[],"ListCharge":[],"CouponCode":"","OrderTypeId":1,"AddressId":0,"PaymentTypeId":0,"TipForDriver":0.00,"ListTipForDriver":[],"SubTotal":14.99,"SubTotalDisplay":"$14.99","TotalSavings":0.0,"TotalSavingsDisplay":"-$0.00","TotalCharges":0.0,"TotalChargesDisplay":"$0.00","TotalValue":14.99,"TotalValueDisplay":"$14.99","SubTotalAfterDsicount":14.99,"SubTotalAfterDiscountDisplay":"$14.99","CartPaymentItemUser":{"UserId":10011690,"StoreId":10061,"AppId":0,"PaymentTypeId":0,"UserProfileId":"","IsDefault":false,"IsCardDefault":false,"Credential1":"","Credential2":"UdVYyaeBH+IBzsetzftdBw==","Credential3":"","IsLive":false},"DoPDate":"01/01/1900","DoPTimeSlot":"","DopUtcStartDate":"","DopUtcEndDate":"","Remark":"","DeliveryTax":0.0,"ShippingCost":0.0,"CartItemCount":1,"IsCredentialOff":false,"IsDeliverySolution":false,"DeliveryFeeMarkUp":0.0,"ShippingTax":0.0,"DeliveryTaxRate":0.0,"IsFromCheckOut":true,"IsUpgradeUser":true,"IsToCallDSP":false,"DeliveryInstruction":"","IsStoreCreditUtilize":false,"OrderRewardCredit":5.00,"OrderRewardCreditDisplay":"-$5.00","OrderTotalWithCredit":0.0,"IsStoreReward":false,"CouponRemark":"","IsShipping":false,"CartTotalQuan":1,"ShippingServiceCode":"","ActualDeliveryCharge":0.0,"EstimatedShippingCost":0.0,"ShippingDeliveryCharge":0.0,"DoordashValidateCustomer":false,"CustomerSessionId":13733,"ConvenienceFee":0.0,"IsDoCalculation":false,"SuccessMessage":"","ErrorDetail":"","ErrorMessage":"","MessageType":"","MessageTitle":"","TextType":""}
I have tried in BeanShell PreProcessor:
var CartGetDetailsObject = prev.getResponseDataAsString();
var jsonData = JSON.parse(CartGetDetailsObject);
jsonData.OrderTypeId=2;
jsonData.IsCredentialOff=true;
vars.put("vCartGetDetailsObject",JSON.stringify(jsonData));
log.info(vCartGetDetailsObject);
Error Log
2020-04-06 12:56:48,139 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2020-04-06 12:56:48,145 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2020-04-06 12:56:48,153 INFO o.a.j.r.ResultCollector: Folder at F:\Office\Performance Test Cases\BottlecappsJmeterPerformanceScripts\apache-jmeter-5.0\RunScript\Date 6-Apr-2020 125648 was created
2020-04-06 12:56:48,154 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2020-04-06 12:56:48,958 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2020-04-06 12:56:48,958 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2020-04-06 12:56:48,958 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2020-04-06 12:56:48,958 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=0 perThread=0.0 delayedStart=false
2020-04-06 12:56:48,984 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2020-04-06 12:56:48,984 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2020-04-06 12:56:48,986 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2020-04-06 12:56:48,987 INFO o.a.j.s.FileServer: Stored: F:\Office\Performance Test Cases\BottlecappsJmeterPerformanceScripts\apache-jmeter-5.0\testrundata.csv
2020-04-06 12:56:53,982 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``var CartGetDetailsObject = prev.getResponseDataAsString(); var jsonData = JSON. . . . '' : Typed variable declaration : Attempt to resolve method: parse() on undefined variable or class name: JSON
2020-04-06 12:56:53,982 WARN o.a.j.m.BeanShellPreProcessor: Problem in BeanShell script. org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``var CartGetDetailsObject = prev.getResponseDataAsString(); var jsonData = JSON. . . . '' : Typed variable declaration : Attempt to resolve method: parse() on undefined variable or class name: JSON
2020-04-06 12:56:54,645 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.io.IOException: Server returned HTTP response code: 400 for URL: https://staging.liquorapps.com/Bcapi/api/Cart/CartUpdate
2020-04-06 12:56:54,645 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.io.IOException: Server returned HTTP response code: 400 for URL: https://staging.liquorapps.com/Bcapi/api/Cart/CartUpdate
2020-04-06 12:56:54,645 INFO o.a.j.p.h.s.HTTPJavaImpl: Error Response Code: 400
2020-04-06 12:56:57,171 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``var CartGetDetailsObject = prev.getResponseDataAsString(); var jsonData = JSON. . . . '' : Typed variable declaration : Attempt to resolve method: parse() on undefined variable or class name: JSON
2020-04-06 12:56:57,171 WARN o.a.j.m.BeanShellPreProcessor: Problem in BeanShell script. org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``var CartGetDetailsObject = prev.getResponseDataAsString(); var jsonData = JSON. . . . '' : Typed variable declaration : Attempt to resolve method: parse() on undefined variable or class name: JSON
2020-04-06 12:56:57,389 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.io.IOException: Server returned HTTP response code: 400 for URL: https://staging.liquorapps.com/Bcapi/api/Cart/CartUpdate
2020-04-06 12:56:57,389 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.io.IOException: Server returned HTTP response code: 400 for URL: https://staging.liquorapps.com/Bcapi/api/Cart/CartUpdate
2020-04-06 12:56:57,389 INFO o.a.j.p.h.s.HTTPJavaImpl: Error Response Code: 400
2020-04-06 12:56:58,364 INFO o.a.j.g.a.Start: Stopping test
2020-04-06 12:56:58,377 INFO o.a.j.t.JMeterThread: Stopping: Thread Group 1-1
2020-04-06 12:56:58,377 WARN o.a.j.t.JMeterThread: Interrupting: Thread Group 1-1 sampler: LoginCustomer
2020-04-06 12:56:58,382 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2020-04-06 12:56:58,383 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2020-04-06 12:56:58,383 INFO o.a.j.s.FileServer: Close: F:\Office\Performance Test Cases\BottlecappsJmeterPerformanceScripts\apache-jmeter-5.0\testrundata.csv
2020-04-06 12:56:58,385 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

JSON is a standard built-in object for Web API, you can run it in Postman because Postman is an electron application (browser). JMeter isn't a browser therefore you cannot use JSON functions.
Add JSR223 PostProcessor as a child of the request which returns above JSON
Put the following code into "Script" area:
def jsonData = new groovy.json.JsonSlurper().parse(prev.getResponseData())
jsonData.OrderTypeId = 2
jsonData.IsCredentialOff = true
vars.put("vCartGetDetailsObject", new groovy.json.JsonBuilder(jsonData).toPrettyString())
log.info(vars.get('vCartGetDetailsObject'))
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Related

JsonLoader throws error in pig

I am unable to decode this simple json , i dont know what i am doing wrong.
please help me in this pig script.
I have to decode the below data in json format.
3.json
{
"id": 6668,
"source_name": "National Stock Exchange of India",
"source_code": "NSE"
}
and my pig script is
a = LOAD '3.json' USING org.apache.pig.builtin.JsonLoader ('id:int, source_name:chararray, source_code:chararray');
dump a;
the error i get is given below:
2015-07-23 13:40:08,715 [LocalJobRunner Map Task Executor #0] INFO org.apache.hadoop.mapred.LocalJobRunner - Starting task: attempt_local1664361500_0001_m_000000_0
2015-07-23 13:40:08,775 [LocalJobRunner Map Task Executor #0] INFO org.apache.hadoop.mapred.Task - Using ResourceCalculatorProcessTree : [ ]
2015-07-23 13:40:08,780 [LocalJobRunner Map Task Executor #0] INFO org.apache.hadoop.mapred.MapTask - Processing split: Number of splits :1
Total Length = 88
Input split[0]:
Length = 88
Locations:
-----------------------
2015-07-23 13:40:08,793 [LocalJobRunner Map Task Executor #0] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigRecordReader - Current split being processed file:/home/hariprasad.sudo/3.json:0+88
2015-07-23 13:40:08,844 [LocalJobRunner Map Task Executor #0] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigMapOnly$Map - Aliases being processed per job phase (AliasName[line,offset]): M: a[1,4] C: R:
2015-07-23 13:40:08,861 [Thread-5] INFO org.apache.hadoop.mapred.LocalJobRunner - map task executor complete.
2015-07-23 13:40:08,867 [Thread-5] WARN org.apache.hadoop.mapred.LocalJobRunner - job_local1664361500_0001
java.lang.Exception: org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for OBJECT (from [Source: java.io.ByteArrayInputStream#61a79110; line: 1, column: 0])
at [Source: java.io.ByteArrayInputStream#61a79110; line: 1, column: 3]
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
Caused by: org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for OBJECT (from [Source: java.io.ByteArrayInputStream#61a79110; line: 1, column: 0])
at [Source: java.io.ByteArrayInputStream#61a79110; line: 1, column: 3]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1291)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportInvalidEOF(JsonParserMinimalBase.java:318)
at org.codehaus.jackson.impl.JsonParserBase._handleEOF(JsonParserBase.java:354)
at org.codehaus.jackson.impl.Utf8StreamParser._skipWSOrEnd(Utf8StreamParser.java:1841)
at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:275)
at org.apache.pig.builtin.JsonLoader.readField(JsonLoader.java:180)
at org.apache.pig.builtin.JsonLoader.getNext(JsonLoader.java:164)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigRecordReader.nextKeyValue(PigRecordReader.java:211)
at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:533)
at org.apache.hadoop.mapreduce.task.MapContextImpl.nextKeyValue(MapContextImpl.java:80)
at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.nextKeyValue(WrappedMapper.java:91)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:340)
at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:243)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
2015-07-23 13:40:09,179 [main] WARN org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - Ooops! Some job has failed! Specify -stop_on_failure if you want Pig to stop immediately on failure.
2015-07-23 13:40:09,179 [main] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - job job_local1664361500_0001 has failed! Stop running all dependent jobs
2015-07-23 13:40:09,179 [main] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - 100% complete
2015-07-23 13:40:09,180 [main] ERROR org.apache.pig.tools.pigstats.PigStatsUtil - 1 map reduce job(s) failed!
2015-07-23 13:40:09,180 [main] INFO org.apache.pig.tools.pigstats.SimplePigStats - Detected Local mode. Stats reported below may be incomplete
2015-07-23 13:40:09,181 [main] INFO org.apache.pig.tools.pigstats.SimplePigStats - Script Statistics:
HadoopVersion PigVersion UserId StartedAt FinishedAt Features
2.3.0-cdh5.1.3 0.12.0-cdh5.1.3 hariprasad.sudo 2015-07-23 13:40:07 2015-07-23 13:40:09 UNKNOWN
Failed!
Failed Jobs:
JobId Alias Feature Message Outputs
job_local1664361500_0001 a MAP_ONLY Message: Job failed! file:/tmp/temp-65649055/tmp1240506051,
Input(s):
Failed to read data from "file:///home/hariprasad.sudo/3.json"
Output(s):
Failed to produce result in "file:/tmp/temp-65649055/tmp1240506051"
Job DAG:
job_local1664361500_0001
2015-07-23 13:40:09,181 [main] INFO org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher - Failed!
2015-07-23 13:40:09,186 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1066: Unable to open iterator for alias a
Details at logfile: /home/hariprasad.sudo/pig_1437673203961.log
grunt> 2015-07-23 13:40:14,754 [communication thread] INFO org.apache.hadoop.mapred.LocalJobRunner - map > map
Please help me in understanding what is wrong.
Thanks,
Hari
Have the compact version of json in 3.json. We can use http://www.jsoneditoronline.org for the same.
3.json
{"id":6668,"source_name":"National Stock Exchange of India","source_code":"NSE"}
with this we are able to dump the data :
(6668,National Stock Exchange of India,NSE)
Ref : Error from Json Loader in Pig where similar issue is discussed.
Extract from the above ref. link :
Pig doesn't usually like "human readable" json. Get rid of the spaces and/or indentations, and you're good.

Upload api fails and throws below exception when file is more than 3MB

I am having issue with box-sdk (https://github.com/box/box-windows-sdk-v2) upload API.
Issue :
When try to upload large file (more than 3MB) (file less than 3mb works great.)
Upload api fails and throws below exception.
Error :
ToString :
System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at XXXX.Program.d__34.MoveNext() in d:\Gaurav\TFS\XXXX\XXXX\Program.cs:line 319
---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
StackTrace :
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at XXXX.Program.d__34.MoveNext() in d:\Gaurav\TFS\XXXX\XXXX\Program.cs:line 319
InnerException :
System.Threading.Tasks.TaskCanceledException: A task was canceled. TIME : 2014-05-28 04:55:59 PM
Code that is generating error :
using (Task<BoxFile> uploadTask = boxClient.FilesManager.UploadAsync(boxFileRequest, spStream))
{
BoxFile newFile = uploadTask.Result;
}
Try to use timeout parameter in UploadAsync method:
boxFile = Client.FilesManager.UploadAsync(req, fs, null, new TimeSpan(1, 0, 0)).Result;

graphhopper GHRequest not fetching

I have a problem with this code:
GraphHopperAPI gh = new GraphHopperWeb();
gh.load("http://localhost:8989/api/route");
GHResponse ph = gh.route(new GHRequest(45.104546,7.69043,45.104546,7.69043));
It gives me this error:
2014-03-29 09:33:00,036 [main] INFO graphhopper.http.GraphHopperWeb - Full request took:0.037406, API took:0.0
Exception in thread "main" java.lang.RuntimeException: Problem while fetching path 45.104546, 7.69043->45.104546, 7.69043
at com.graphhopper.http.GraphHopperWeb.route(GraphHopperWeb.java:119)
at provaMain.main(provaMain.java:23)
Caused by: org.json.JSONException: A JSONObject text must begin with '{' at character 0
at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
at org.json.JSONObject.<init>(JSONObject.java:179)
at org.json.JSONObject.<init>(JSONObject.java:402)
at com.graphhopper.http.GraphHopperWeb.route(GraphHopperWeb.java:95)
... 1 more
The documentation currently undergoes a change (moving it from wiki to source). Where did you find that snippet? Please try gh.load("http://localhost:8989/"); for the latest branch and gh.load("http://localhost:8989/api"); before.

Exception while try to get jmeter directory

I would like to start jmeter load test via console but it's Data Driven Load Test, so I need to read some information from csv files. I found a solution to include into User Parameters row to get the path to the place where the script was launched:
${__BeanShell(newFile(org.apache.jmeter.gui.GuiPackage.getInstance().getTestPlanFile().toString()).getParent())}
but I got an error in logs:
2013/06/11 15:23:54 ERROR - jmeter.util.BeanShellInterpreter: Error
invoking bsh method: eval Sourced file: inline evaluation of:
``newFile(org.apache.jmeter.gui.GuiPackage.getInstance().getTestPlanFile().toStrin
. . . '' : Command not found: newFile( java.lang.String )
2013/06/11 15:23:54 WARN - jmeter.functions.BeanShell: Error running
BSH script org.apache.jorphan.util.JMeterException: Error invoking bsh
method: eval Sourced file: inline evaluation of:
``newFile(org.apache.jmeter.gui.GuiPackage.getInstance().getTestPlanFile().toStrin
. . . '' : Command not found: newFile( java.lang.String ) at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:192)
What's wrong with this method?
The issue is you have:
newFile
instead of:
new File

ESB Mule Client staring with xml-properties fails

I use Mule 3.x
I have a code that tests MuleClient connectivity.
This test is ok and works proper way:
public void testHello() throws Exception
{
MuleClient client = new MuleClient(muleContext);
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
But this tes is not ok - it fail with an connection exceptions:
public void testHello_with_Spring() throws Exception {
MuleClient client = new MuleClient("mule-config-test.xml");
client.getMuleContext().start();
//it fails here
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
The 'mule-config-test.xml' is used in both tests, the path for this file is ok, i checked.
This is error message I have in the end:
Exception stack is:
1. Address already in use (java.net.BindException) java.net.PlainSocketImpl:-2 (null)
2. Failed to bind to uri "http://127.0.0.1:8080/hello" (org.mule.transport.ConnectException)
org.mule.transport.tcp.TcpMessageReceiver:81
(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/ConnectException.html)
-------------------------------------------------------------------------------- Root Exception stack trace: java.net.BindException: Address already in
use at java.net.PlainSocketImpl.socketBind(Native Method) at
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383) at
java.net.ServerSocket.bind(ServerSocket.java:328)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
[10-05 16:33:37] ERROR HttpConnector [main]:
org.mule.transport.ConnectException: Failed to bind to uri
"http://127.0.0.1:8080/hello" [10-05 16:33:37] ERROR ConnectNotifier
[main]: Failed to connect/reconnect: HttpConnector {
name=connector.http.mule.default lifecycle=stop this=7578a7d9
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=false
supportedProtocols=[http] serviceOverrides= } . Root Exception
was: Address already in use. Type: class java.net.BindException [10-05
16:33:37] ERROR DefaultSystemExceptionStrategy [main]: Failed to bind
to uri "http://127.0.0.1:8080/hello"
org.mule.api.lifecycle.LifecycleException: Cannot process event as
"connector.http.mule.default" is stopped
I think the problem is in what you're not showing: testHello_with_Spring() is probably executing while Mule is already running. The second Mule you're starting in it then port-conflicts with the other one.
Are testHello() and testHello_with_Spring() in the same test suite? If yes, seeing that testHello() relies on an already running Mule, I'd say that would be the cause of port conflict for testHello_with_Spring().