I try this but nothing is displayed on the console :

    @Test
    public void testUnMarshallMessage() throws Exception {

        for(Exchange exch : resultEndpoint.getExchanges()) {
                models = (List<HashMap<String, Object>>) exch.getIn().getBody();
                
                Iterator it = models.iterator();

                LOG.info("Before list iteration");
                
                while(it.hasNext()){
                        modelObjects = (HashMap<String, Object>) it.next();
                        LOG.info("while iteration");
                        for (String key : modelObjects.keySet()) {
                                LOG.info("get object");
                                Object obj = modelObjects.get(key);
                                LOG.info("Data : " + obj.toString());
                        }
                }
                
        }
        
        resultEndpoint.expectedBodiesReceived(models);
        resultEndpoint.assertIsSatisfied();



James.Strachan wrote:
> 
> 2009/1/16 cmoulliard <cmoulli...@gmail.com>:
>>
>> @James,
>>
>> I'm a little bit bored because I don't know if the following code works
>> or
>> not. The test is passed but I don't know if assertEquals is executed.
> 
> You could always add a counter inside the loop and assert its
> incremented once :)
> 
> 
>>    @Test
>>    public void testUnMarshallMessage() throws Exception {
>>
>>        resultEndpoint.expectedMessageCount(1);
>>
>>        for(Exchange exch : resultEndpoint.getExchanges()) {
>>                models = (List<HashMap<String, Object>>)
>> exch.getIn().getBody();
>>
>>                Iterator it = models.iterator();
>>                double count = 0;
>>                while(it.hasNext()){
>>                        modelObjects = (HashMap<String, Object>)
>> it.next();
>>                        count++;
>>                }
>>
>>                assertEquals(100, count);
>>
>>        }
>>
>>        resultEndpoint.assertIsSatisfied();
> 
> the above line needs to be moved above the for loop - more below...
> 
>>    }
>>
>> I have different questions :
>>
>> - Can we mix mockendpoint assertion with junit assertions ?
> 
> Sure.
> 
> The trick is - you execute the resultEndpoint.assertIsSatisfied();
> code first. This then pauses the test until asynchronously the
> messages arrive and expectations are met - or things timeout and the
> test fails. Then after this point - you can grab the received messages
> and perform any particular JUnit assertions you want on the received
> messages.
> 
> In psuedocode a mock endpoint test looks like
> 
> * get mock endpoints and add expectations
> * assert expectations are met
> * perform any extra JUnit assertions on received messages (or
> endpoints, beans whatever)
> 
> Another option is to add an assertion to be evaluated as the messages
> arrive - e.g.
> 
> mockEndpoint.allMessages().predicate().xpath('/foo/bar = 'abc'");
> mockEndpoint.message(3).predicate().xpath('/foo/bar = 'abc'");
> 
> but its often easier to just do the assertions after the expectations
> are met (though the downside is that more messages could arrive after
> this point if you have an async publisher sending continuously to the
> mock endpoint).
> 
> -- 
> 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/only-testMocksAreValid-is-executed-by-Camel-Spring-unit-test-%21%21-tp21436628s22882p21502317.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to