You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cmoulliard <cm...@gmail.com> on 2009/01/14 11:04:04 UTC

Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Hi,

Can someone tell me why MockEndpoint generates the following error when
executing the method 'assertIsSatisfied()' ?

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.RangeCheck(ArrayList.java:546)
	at java.util.ArrayList.get(ArrayList.java:321)
	at
org.apache.camel.component.mock.MockEndpoint$3.run(MockEndpoint.java:344)
	at
org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:251)
	at
org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:218)
	at
org.apache.camel.bindy.csv.BindyCSVMarshallTest.testMarshallMessage(BindyCSVMarshallTest.java:53)



-----
Charles Moulliard
SOA Architect

My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/  
-- 
View this message in context: http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21453025.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by cmoulliard <cm...@gmail.com>.
Yes. I will add these remarks.


Claus Ibsen-2 wrote:
> 
> On Thu, Jan 15, 2009 at 9:38 AM, cmoulliard <cm...@gmail.com> wrote:
>>
>> Hi,
>>
>> This should be interesting to add these(ose) remark(s) in the srping
>> testing
>> wiki page.
> Dont you have wiki rights to edit :)
> 
> 
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> Hi
>>>
>>> Yeah as James writes the expects *must* be set before you do start
>>> send exchanges into Camel.
>>>
>>> The send method is probably in a sync route so the exchange has
>>> finished routing when you in the next codeline set the expected body.
>>>
>>>
>>> On Wed, Jan 14, 2009 at 4:48 PM, James Strachan
>>> <ja...@gmail.com> wrote:
>>>> 2009/1/14 cmoulliard <cm...@gmail.com>:
>>>>>
>>>>> The error is solved.
>>>>>
>>>>> Question :
>>>>>
>>>>> Why the template.sendBody(Object) must be placed in the code after the
>>>>> MockEndpoint.expectedBodiesReceived() and not the inverse ?
>>>>>
>>>>> this code works :
>>>>>
>>>>>        resultEndpoint.expectedBodiesReceived(result);
>>>>>        template.sendBody(generateModel());
>>>>>
>>>>> Not this one
>>>>>
>>>>>        template.sendBody(generateModel()
>>>>>        resultEndpoint.expectedBodiesReceived(result);
>>>>
>>>> Up to now we've been assuming you setup the expectations before
>>>> running your route. It could be MockEndpoint needs further patches to
>>>> ensure it can cope with expectations being added after messages arrive
>>>> on it
>>>>
>>>> --
>>>> James
>>>> -------
>>>> http://macstrac.blogspot.com/
>>>>
>>>> Open Source Integration
>>>> http://fusesource.com/
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> /Claus Ibsen
>>> Apache Camel Committer
>>> Blog: http://davsclaus.blogspot.com/
>>>
>>>
>>
>>
>> -----
>> Charles Moulliard
>> SOA Architect
>>
>> My Blog :  http://cmoulliard.blogspot.com/
>> http://cmoulliard.blogspot.com/
>> --
>> View this message in context:
>> http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21473409.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 


-----
Charles Moulliard
SOA Architect

My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/  
-- 
View this message in context: http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21497119.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jan 15, 2009 at 9:38 AM, cmoulliard <cm...@gmail.com> wrote:
>
> Hi,
>
> This should be interesting to add these(ose) remark(s) in the srping testing
> wiki page.
Dont you have wiki rights to edit :)


>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> Yeah as James writes the expects *must* be set before you do start
>> send exchanges into Camel.
>>
>> The send method is probably in a sync route so the exchange has
>> finished routing when you in the next codeline set the expected body.
>>
>>
>> On Wed, Jan 14, 2009 at 4:48 PM, James Strachan
>> <ja...@gmail.com> wrote:
>>> 2009/1/14 cmoulliard <cm...@gmail.com>:
>>>>
>>>> The error is solved.
>>>>
>>>> Question :
>>>>
>>>> Why the template.sendBody(Object) must be placed in the code after the
>>>> MockEndpoint.expectedBodiesReceived() and not the inverse ?
>>>>
>>>> this code works :
>>>>
>>>>        resultEndpoint.expectedBodiesReceived(result);
>>>>        template.sendBody(generateModel());
>>>>
>>>> Not this one
>>>>
>>>>        template.sendBody(generateModel()
>>>>        resultEndpoint.expectedBodiesReceived(result);
>>>
>>> Up to now we've been assuming you setup the expectations before
>>> running your route. It could be MockEndpoint needs further patches to
>>> ensure it can cope with expectations being added after messages arrive
>>> on it
>>>
>>> --
>>> James
>>> -------
>>> http://macstrac.blogspot.com/
>>>
>>> Open Source Integration
>>> http://fusesource.com/
>>>
>>
>>
>>
>> --
>>
>> /Claus Ibsen
>> Apache Camel Committer
>> Blog: http://davsclaus.blogspot.com/
>>
>>
>
>
> -----
> Charles Moulliard
> SOA Architect
>
> My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/
> --
> View this message in context: http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21473409.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by cmoulliard <cm...@gmail.com>.
Hi,

This should be interesting to add these(ose) remark(s) in the srping testing
wiki page.


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Yeah as James writes the expects *must* be set before you do start
> send exchanges into Camel.
> 
> The send method is probably in a sync route so the exchange has
> finished routing when you in the next codeline set the expected body.
> 
> 
> On Wed, Jan 14, 2009 at 4:48 PM, James Strachan
> <ja...@gmail.com> wrote:
>> 2009/1/14 cmoulliard <cm...@gmail.com>:
>>>
>>> The error is solved.
>>>
>>> Question :
>>>
>>> Why the template.sendBody(Object) must be placed in the code after the
>>> MockEndpoint.expectedBodiesReceived() and not the inverse ?
>>>
>>> this code works :
>>>
>>>        resultEndpoint.expectedBodiesReceived(result);
>>>        template.sendBody(generateModel());
>>>
>>> Not this one
>>>
>>>        template.sendBody(generateModel()
>>>        resultEndpoint.expectedBodiesReceived(result);
>>
>> Up to now we've been assuming you setup the expectations before
>> running your route. It could be MockEndpoint needs further patches to
>> ensure it can cope with expectations being added after messages arrive
>> on it
>>
>> --
>> James
>> -------
>> http://macstrac.blogspot.com/
>>
>> Open Source Integration
>> http://fusesource.com/
>>
> 
> 
> 
> -- 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 


-----
Charles Moulliard
SOA Architect

My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/  
-- 
View this message in context: http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21473409.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah as James writes the expects *must* be set before you do start
send exchanges into Camel.

The send method is probably in a sync route so the exchange has
finished routing when you in the next codeline set the expected body.


On Wed, Jan 14, 2009 at 4:48 PM, James Strachan
<ja...@gmail.com> wrote:
> 2009/1/14 cmoulliard <cm...@gmail.com>:
>>
>> The error is solved.
>>
>> Question :
>>
>> Why the template.sendBody(Object) must be placed in the code after the
>> MockEndpoint.expectedBodiesReceived() and not the inverse ?
>>
>> this code works :
>>
>>        resultEndpoint.expectedBodiesReceived(result);
>>        template.sendBody(generateModel());
>>
>> Not this one
>>
>>        template.sendBody(generateModel()
>>        resultEndpoint.expectedBodiesReceived(result);
>
> Up to now we've been assuming you setup the expectations before
> running your route. It could be MockEndpoint needs further patches to
> ensure it can cope with expectations being added after messages arrive
> on it
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://fusesource.com/
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by James Strachan <ja...@gmail.com>.
2009/1/14 cmoulliard <cm...@gmail.com>:
>
> The error is solved.
>
> Question :
>
> Why the template.sendBody(Object) must be placed in the code after the
> MockEndpoint.expectedBodiesReceived() and not the inverse ?
>
> this code works :
>
>        resultEndpoint.expectedBodiesReceived(result);
>        template.sendBody(generateModel());
>
> Not this one
>
>        template.sendBody(generateModel()
>        resultEndpoint.expectedBodiesReceived(result);

Up to now we've been assuming you setup the expectations before
running your route. It could be MockEndpoint needs further patches to
ensure it can cope with expectations being added after messages arrive
on it

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by cmoulliard <cm...@gmail.com>.
The error is solved.

Question : 

Why the template.sendBody(Object) must be placed in the code after the
MockEndpoint.expectedBodiesReceived() and not the inverse ?

this code works :

     	resultEndpoint.expectedBodiesReceived(result);
    	template.sendBody(generateModel());

Not this one 

    	template.sendBody(generateModel()
     	resultEndpoint.expectedBodiesReceived(result);




cmoulliard wrote:
> 
> So this code is not correct to send to the body through the marshalling
> method string corresponding to CSV record :
> 
> 	public void marshal(Exchange arg0, Object object, OutputStream
> outputStream) throws Exception {
> 		
> 		List<HashMap<String, Object>> models = (ArrayList<HashMap<String,
> Object>>) object;
> 		HashMap<String, Object> modelObjects = new HashMap<String, Object>();
> 		
> 		OutputStreamWriter out = new OutputStreamWriter(outputStream);
>         
> 		try {
>         	Iterator it = models.iterator();
>         	
>         	while (it.hasNext()) {
>         		String result = getFactory().unbind((HashMap<String, Object>)
> it.next());
>         		System.out.println("Result string : " + result);
>         		out.write(result);
>         	}
>         } finally {
>             out.close();
>         }
> 
> 
> James.Strachan wrote:
>> 
>> Looks like a bug :) I've just added a fix. Basically its thrown if you
>> don't receive the right actual number of values you are asserting.
>> 
>> 2009/1/14 cmoulliard <cm...@gmail.com>:
>>>
>>> Hi,
>>>
>>> Can someone tell me why MockEndpoint generates the following error when
>>> executing the method 'assertIsSatisfied()' ?
>>>
>>> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>>>        at java.util.ArrayList.RangeCheck(ArrayList.java:546)
>>>        at java.util.ArrayList.get(ArrayList.java:321)
>>>        at
>>> org.apache.camel.component.mock.MockEndpoint$3.run(MockEndpoint.java:344)
>>>        at
>>> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:251)
>>>        at
>>> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:218)
>>>        at
>>> org.apache.camel.bindy.csv.BindyCSVMarshallTest.testMarshallMessage(BindyCSVMarshallTest.java:53)
>>>
>>>
>>>
>>> -----
>>> Charles Moulliard
>>> SOA Architect
>>>
>>> My Blog :  http://cmoulliard.blogspot.com/
>>> http://cmoulliard.blogspot.com/
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21453025.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> 
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>> 
>> Open Source Integration
>> http://fusesource.com/
>> 
>> 
> 
> 


-----
Charles Moulliard
SOA Architect

My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/  
-- 
View this message in context: http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21458286.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by cmoulliard <cm...@gmail.com>.
So this code is not correct to send to the body through the marshalling
method string corresponding to CSV record :

	public void marshal(Exchange arg0, Object object, OutputStream
outputStream) throws Exception {
		
		List<HashMap<String, Object>> models = (ArrayList<HashMap<String,
Object>>) object;
		HashMap<String, Object> modelObjects = new HashMap<String, Object>();
		
		OutputStreamWriter out = new OutputStreamWriter(outputStream);
        
		try {
        	Iterator it = models.iterator();
        	
        	while (it.hasNext()) {
        		String result = getFactory().unbind((HashMap<String, Object>)
it.next());
        		System.out.println("Result string : " + result);
        		out.write(result);
        	}
        } finally {
            out.close();
        }


James.Strachan wrote:
> 
> Looks like a bug :) I've just added a fix. Basically its thrown if you
> don't receive the right actual number of values you are asserting.
> 
> 2009/1/14 cmoulliard <cm...@gmail.com>:
>>
>> Hi,
>>
>> Can someone tell me why MockEndpoint generates the following error when
>> executing the method 'assertIsSatisfied()' ?
>>
>> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>>        at java.util.ArrayList.RangeCheck(ArrayList.java:546)
>>        at java.util.ArrayList.get(ArrayList.java:321)
>>        at
>> org.apache.camel.component.mock.MockEndpoint$3.run(MockEndpoint.java:344)
>>        at
>> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:251)
>>        at
>> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:218)
>>        at
>> org.apache.camel.bindy.csv.BindyCSVMarshallTest.testMarshallMessage(BindyCSVMarshallTest.java:53)
>>
>>
>>
>> -----
>> Charles Moulliard
>> SOA Architect
>>
>> My Blog :  http://cmoulliard.blogspot.com/
>> http://cmoulliard.blogspot.com/
>> --
>> View this message in context:
>> http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21453025.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://fusesource.com/
> 
> 


-----
Charles Moulliard
SOA Architect

My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/  
-- 
View this message in context: http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21457114.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Reason why Mockendpoint generates an IndexOutOfBoundsException error ?

Posted by James Strachan <ja...@gmail.com>.
Looks like a bug :) I've just added a fix. Basically its thrown if you
don't receive the right actual number of values you are asserting.

2009/1/14 cmoulliard <cm...@gmail.com>:
>
> Hi,
>
> Can someone tell me why MockEndpoint generates the following error when
> executing the method 'assertIsSatisfied()' ?
>
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>        at java.util.ArrayList.RangeCheck(ArrayList.java:546)
>        at java.util.ArrayList.get(ArrayList.java:321)
>        at
> org.apache.camel.component.mock.MockEndpoint$3.run(MockEndpoint.java:344)
>        at
> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:251)
>        at
> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:218)
>        at
> org.apache.camel.bindy.csv.BindyCSVMarshallTest.testMarshallMessage(BindyCSVMarshallTest.java:53)
>
>
>
> -----
> Charles Moulliard
> SOA Architect
>
> My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/
> --
> View this message in context: http://www.nabble.com/Reason-why-Mockendpoint-generates-an-IndexOutOfBoundsException-error---tp21453025s22882p21453025.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/