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/13 15:19:47 UTC

only testMocksAreValid is executed by Camel/Spring unit test !!

Hi ,

I'm faced to a strange problem. The following code does not execute my test
method (testMarshallMessage) but only (i presume because this is a value by
default) testMocksAreValid :

package org.apache.camel.bindy.csv;

import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
import org.springframework.config.java.test.JavaConfigContextLoader;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

@ContextConfiguration(locations =
"org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig",
loader = JavaConfigContextLoader.class)
public class BindyCSVUnmarshallTest extends AbstractJUnit4SpringContextTests
{

	private static final transient Log LOG = LogFactory
			.getLog(BindyCSVUnmarshallTest.class);
	
	String record = "01,A,Albert,Cartier,BE12345678,Belgacom Ventage
10/10,1500,EUR,08-01-2009";

	@EndpointInject(uri = "mock:result")
	protected MockEndpoint resultEndpoint;
	
    @Produce(uri = "direct:start")
    protected ProducerTemplate template;

    @DirtiesContext
    public void testMarshallMessage() throws Exception {
    	
    	template.sendBody(record);
    	resultEndpoint.expectedBodiesReceived(record);
    }


	@Configuration
	public static class ContextConfig extends SingleRouteCamelConfiguration {
		
		CamelDataFormat camelDataFormat = new
CamelDataFormat("org.apache.camel.bindy.model");

		@Bean
		public RouteBuilder route() {
			return new RouteBuilder() {
				public void configure() {
					from("direct:start")
					//from("file://src/test/data/")
				    .unmarshal(camelDataFormat)
					.to("mock:result");
				}
			};
		}
	}

}

question : Why testMarshallMessage is not executed ?




-----
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-tp21436628s22882p21436628.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@gmail.com>.
I launch the test using junit tool of Eclipse.

Does removing @DirtiesContext help? No

When I use maven command : mvn clean install test. I can see the following
error in the surefire reprot :

-------------------------------------------------------------------------------
Test set: org.apache.camel.bindy.csv.BindyCSVUnmarshallTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.125 sec
<<< FAILURE!
initializationError(org.apache.camel.bindy.csv.BindyCSVUnmarshallTest)  Time
elapsed: 0.031 sec  <<< ERROR!
java.lang.Exception: No runnable methods
	at
org.junit.internal.runners.MethodValidator.validateInstanceMethods(MethodValidator.java:39)
	at
org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:50)
	at
org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4ClassRunner.java:44)
	at
org.junit.internal.runners.JUnit4ClassRunner.<init>(JUnit4ClassRunner.java:35)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:76)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
	at
org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
	at
org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
	at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
	at
org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
	at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
	at
org.apache.maven.surefire.junit4.JUnit4TestSet.<init>(JUnit4TestSet.java:45)
	at
org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite.createTestSet(JUnit4DirectoryTestSuite.java:56)
	at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:96)
	at
org.apache.maven.surefire.Surefire.createSuiteFromDefinition(Surefire.java:209)
	at org.apache.maven.surefire.Surefire.run(Surefire.java:156)
	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:585)
	at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
	at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)


Do I have to add the tag '@Test' to the method that I want to test ?


James.Strachan wrote:
> 
> What happens when you try run it in maven or in your IDE?
> 
> Does removing @DirtiesContext help?
> 
> 2009/1/13 cmoulliard <cm...@gmail.com>:
>>
>> Hi ,
>>
>> I'm faced to a strange problem. The following code does not execute my
>> test
>> method (testMarshallMessage) but only (i presume because this is a value
>> by
>> default) testMocksAreValid :
>>
>> package org.apache.camel.bindy.csv;
>>
>> import org.apache.camel.EndpointInject;
>> import org.apache.camel.Produce;
>> import org.apache.camel.ProducerTemplate;
>> import org.apache.camel.builder.RouteBuilder;
>> import org.apache.camel.component.mock.MockEndpoint;
>> import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> import org.springframework.config.java.annotation.Bean;
>> import org.springframework.config.java.annotation.Configuration;
>> import org.springframework.config.java.test.JavaConfigContextLoader;
>> import org.springframework.test.annotation.DirtiesContext;
>> import org.springframework.test.context.ContextConfiguration;
>> import
>> org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
>>
>> @ContextConfiguration(locations =
>> "org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig",
>> loader = JavaConfigContextLoader.class)
>> public class BindyCSVUnmarshallTest extends
>> AbstractJUnit4SpringContextTests
>> {
>>
>>        private static final transient Log LOG = LogFactory
>>                        .getLog(BindyCSVUnmarshallTest.class);
>>
>>        String record = "01,A,Albert,Cartier,BE12345678,Belgacom Ventage
>> 10/10,1500,EUR,08-01-2009";
>>
>>        @EndpointInject(uri = "mock:result")
>>        protected MockEndpoint resultEndpoint;
>>
>>    @Produce(uri = "direct:start")
>>    protected ProducerTemplate template;
>>
>>    @DirtiesContext
>>    public void testMarshallMessage() throws Exception {
>>
>>        template.sendBody(record);
>>        resultEndpoint.expectedBodiesReceived(record);
>>    }
>>
>>
>>        @Configuration
>>        public static class ContextConfig extends
>> SingleRouteCamelConfiguration {
>>
>>                CamelDataFormat camelDataFormat = new
>> CamelDataFormat("org.apache.camel.bindy.model");
>>
>>                @Bean
>>                public RouteBuilder route() {
>>                        return new RouteBuilder() {
>>                                public void configure() {
>>                                        from("direct:start")
>>                                        //from("file://src/test/data/")
>>                                    .unmarshal(camelDataFormat)
>>                                        .to("mock:result");
>>                                }
>>                        };
>>                }
>>        }
>>
>> }
>>
>> question : Why testMarshallMessage is not executed ?
>>
>>
>>
>>
>> -----
>> 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-tp21436628s22882p21436628.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/only-testMocksAreValid-is-executed-by-Camel-Spring-unit-test-%21%21-tp21436628s22882p21437124.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
What happens when you try run it in maven or in your IDE?

Does removing @DirtiesContext help?

2009/1/13 cmoulliard <cm...@gmail.com>:
>
> Hi ,
>
> I'm faced to a strange problem. The following code does not execute my test
> method (testMarshallMessage) but only (i presume because this is a value by
> default) testMocksAreValid :
>
> package org.apache.camel.bindy.csv;
>
> import org.apache.camel.EndpointInject;
> import org.apache.camel.Produce;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.springframework.config.java.annotation.Bean;
> import org.springframework.config.java.annotation.Configuration;
> import org.springframework.config.java.test.JavaConfigContextLoader;
> import org.springframework.test.annotation.DirtiesContext;
> import org.springframework.test.context.ContextConfiguration;
> import
> org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
>
> @ContextConfiguration(locations =
> "org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig",
> loader = JavaConfigContextLoader.class)
> public class BindyCSVUnmarshallTest extends AbstractJUnit4SpringContextTests
> {
>
>        private static final transient Log LOG = LogFactory
>                        .getLog(BindyCSVUnmarshallTest.class);
>
>        String record = "01,A,Albert,Cartier,BE12345678,Belgacom Ventage
> 10/10,1500,EUR,08-01-2009";
>
>        @EndpointInject(uri = "mock:result")
>        protected MockEndpoint resultEndpoint;
>
>    @Produce(uri = "direct:start")
>    protected ProducerTemplate template;
>
>    @DirtiesContext
>    public void testMarshallMessage() throws Exception {
>
>        template.sendBody(record);
>        resultEndpoint.expectedBodiesReceived(record);
>    }
>
>
>        @Configuration
>        public static class ContextConfig extends SingleRouteCamelConfiguration {
>
>                CamelDataFormat camelDataFormat = new
> CamelDataFormat("org.apache.camel.bindy.model");
>
>                @Bean
>                public RouteBuilder route() {
>                        return new RouteBuilder() {
>                                public void configure() {
>                                        from("direct:start")
>                                        //from("file://src/test/data/")
>                                    .unmarshal(camelDataFormat)
>                                        .to("mock:result");
>                                }
>                        };
>                }
>        }
>
> }
>
> question : Why testMarshallMessage is not executed ?
>
>
>
>
> -----
> 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-tp21436628s22882p21436628.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



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

Open Source Integration
http://fusesource.com/

Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@gmail.com>.
models = list of HashMap objects returned by the body = which are not empty

Is it related to the fact that I use Junit 4 ?


James.Strachan wrote:
> 
> 2009/1/16 cmoulliard <cm...@gmail.com>:
>>
>> Sorry but even if i place the two assertions before, nothing appears on
>> the
>> log
>>
>>    @Test
>>    public void testUnMarshallMessage() throws Exception {
>>
>>        resultEndpoint.expectedBodiesReceived(models);
>>        resultEndpoint.assertIsSatisfied();
> 
> models is a non empty array of bodies right?
> 
> If so try debugging or printing the list of exchanges? We've zillions
> of tests which use this mechanism to extract the exchanges from the
> endpoint; so am pretty sure it works
> 
> 
>>
>>        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());
>>                        }
>>                }
>>
>>        }
>>
>>
>>
>> James.Strachan wrote:
>>>
>>> 2009/1/16 cmoulliard <cm...@gmail.com>:
>>>>
>>>> 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());
>>>>                        }
>>>>                }
>>>>
>>>>        }
>>>
>>> As I said in the previous mail - you must setup the expectations and
>>> assert they are satisfied *before* you look at the received exchanges.
>>> So move these next two lines *before* the for loop.
>>>
>>>>        resultEndpoint.expectedBodiesReceived(models);
>>>>        resultEndpoint.assertIsSatisfied();
>>>>
>>>>
>>>>
>>>> James.Strachan wrote:
>>>>>
>>>>> 2009/1/16 cmoulliard <cm...@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.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> 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-tp21436628s22882p21503138.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/only-testMocksAreValid-is-executed-by-Camel-Spring-unit-test-%21%21-tp21436628s22882p21503591.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
2009/1/16 cmoulliard <cm...@gmail.com>:
>
> Sorry but even if i place the two assertions before, nothing appears on the
> log
>
>    @Test
>    public void testUnMarshallMessage() throws Exception {
>
>        resultEndpoint.expectedBodiesReceived(models);
>        resultEndpoint.assertIsSatisfied();

models is a non empty array of bodies right?

If so try debugging or printing the list of exchanges? We've zillions
of tests which use this mechanism to extract the exchanges from the
endpoint; so am pretty sure it works


>
>        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());
>                        }
>                }
>
>        }
>
>
>
> James.Strachan wrote:
>>
>> 2009/1/16 cmoulliard <cm...@gmail.com>:
>>>
>>> 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());
>>>                        }
>>>                }
>>>
>>>        }
>>
>> As I said in the previous mail - you must setup the expectations and
>> assert they are satisfied *before* you look at the received exchanges.
>> So move these next two lines *before* the for loop.
>>
>>>        resultEndpoint.expectedBodiesReceived(models);
>>>        resultEndpoint.assertIsSatisfied();
>>>
>>>
>>>
>>> James.Strachan wrote:
>>>>
>>>> 2009/1/16 cmoulliard <cm...@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.
>>>
>>>
>>
>>
>>
>> --
>> 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-tp21436628s22882p21503138.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



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

Open Source Integration
http://fusesource.com/

Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@gmail.com>.
Sorry but even if i place the two assertions before, nothing appears on the
log 

    @Test
    public void testUnMarshallMessage() throws Exception {

    	resultEndpoint.expectedBodiesReceived(models);
    	resultEndpoint.assertIsSatisfied();

    	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());
    			}
    		}
   		
    	}



James.Strachan wrote:
> 
> 2009/1/16 cmoulliard <cm...@gmail.com>:
>>
>> 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());
>>                        }
>>                }
>>
>>        }
> 
> As I said in the previous mail - you must setup the expectations and
> assert they are satisfied *before* you look at the received exchanges.
> So move these next two lines *before* the for loop.
> 
>>        resultEndpoint.expectedBodiesReceived(models);
>>        resultEndpoint.assertIsSatisfied();
>>
>>
>>
>> James.Strachan wrote:
>>>
>>> 2009/1/16 cmoulliard <cm...@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.
>>
>>
> 
> 
> 
> -- 
> 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-tp21436628s22882p21503138.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
2009/1/16 cmoulliard <cm...@gmail.com>:
>
> 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());
>                        }
>                }
>
>        }

As I said in the previous mail - you must setup the expectations and
assert they are satisfied *before* you look at the received exchanges.
So move these next two lines *before* the for loop.

>        resultEndpoint.expectedBodiesReceived(models);
>        resultEndpoint.assertIsSatisfied();
>
>
>
> James.Strachan wrote:
>>
>> 2009/1/16 cmoulliard <cm...@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.
>
>



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

Open Source Integration
http://fusesource.com/

Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@gmail.com>.
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 <cm...@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.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
2009/1/16 cmoulliard <cm...@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/

Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@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.

    @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();

    }

I have different questions :

- Can we mix mockendpoint assertion with junit assertions ?
- if this is not the case, How can I achieve what I would like to do in my
test ?



James.Strachan wrote:
> 
> 2009/1/13 cmoulliard <cm...@gmail.com>:
>>
>> Ok. I continue to use Junit4.
>>
>> Can a mockendpoint iterates through the exchanges because the following
>> code
>> does not display anything ?
>>
>>    @Test
>>    public void testMarshallMessage() throws Exception {
>>
>>        resultEndpoint.expectedBodiesReceived(models);
> 
> You're missing the
> 
> resultEndpoint.assertIsSatisfied() call.
> 
> Adding an expectation doesn't cause an assertion failure
> 
> 
> 
>>
>>        List<Exchange> exchanges = resultEndpoint.getExchanges();
>>
>>        for(Exchange exchange : exchanges) {
>>                Object body = exchange.getIn().getBody();
>>                System.out.println("Result : " + body);
>>        }
>>
>>
>>
>> James.Strachan wrote:
>>>
>>> 2009/1/13 cmoulliard <cm...@gmail.com>:
>>>>
>>>> Indeed, I use junit4.
>>>>
>>>> Do you prefer that I switch to Junit3 for the test ?
>>>
>>> Ultimately I think we should switch Camel to JUnit 4 so feel free to
>>> go for it - I was really just mentioning that you can't copy/paste
>>> test cases to JUnit4 and expect them to run without adding @Test
>>>
>>> --
>>> 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-tp21436628s22882p21438228.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/only-testMocksAreValid-is-executed-by-Camel-Spring-unit-test-%21%21-tp21436628s22882p21498424.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
2009/1/13 cmoulliard <cm...@gmail.com>:
>
> Ok. I continue to use Junit4.
>
> Can a mockendpoint iterates through the exchanges because the following code
> does not display anything ?
>
>    @Test
>    public void testMarshallMessage() throws Exception {
>
>        resultEndpoint.expectedBodiesReceived(models);

You're missing the

resultEndpoint.assertIsSatisfied() call.

Adding an expectation doesn't cause an assertion failure



>
>        List<Exchange> exchanges = resultEndpoint.getExchanges();
>
>        for(Exchange exchange : exchanges) {
>                Object body = exchange.getIn().getBody();
>                System.out.println("Result : " + body);
>        }
>
>
>
> James.Strachan wrote:
>>
>> 2009/1/13 cmoulliard <cm...@gmail.com>:
>>>
>>> Indeed, I use junit4.
>>>
>>> Do you prefer that I switch to Junit3 for the test ?
>>
>> Ultimately I think we should switch Camel to JUnit 4 so feel free to
>> go for it - I was really just mentioning that you can't copy/paste
>> test cases to JUnit4 and expect them to run without adding @Test
>>
>> --
>> 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-tp21436628s22882p21438228.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



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

Open Source Integration
http://fusesource.com/

Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@gmail.com>.
Ok. I continue to use Junit4.

Can a mockendpoint iterates through the exchanges because the following code
does not display anything ?

    @Test
    public void testMarshallMessage() throws Exception {

    	resultEndpoint.expectedBodiesReceived(models);
    	
    	List<Exchange> exchanges = resultEndpoint.getExchanges();
    	
    	for(Exchange exchange : exchanges) {
    		Object body = exchange.getIn().getBody();
    		System.out.println("Result : " + body);
    	}



James.Strachan wrote:
> 
> 2009/1/13 cmoulliard <cm...@gmail.com>:
>>
>> Indeed, I use junit4.
>>
>> Do you prefer that I switch to Junit3 for the test ?
> 
> Ultimately I think we should switch Camel to JUnit 4 so feel free to
> go for it - I was really just mentioning that you can't copy/paste
> test cases to JUnit4 and expect them to run without adding @Test
> 
> -- 
> 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-tp21436628s22882p21438228.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
2009/1/13 cmoulliard <cm...@gmail.com>:
>
> Indeed, I use junit4.
>
> Do you prefer that I switch to Junit3 for the test ?

Ultimately I think we should switch Camel to JUnit 4 so feel free to
go for it - I was really just mentioning that you can't copy/paste
test cases to JUnit4 and expect them to run without adding @Test

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

Open Source Integration
http://fusesource.com/

Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@gmail.com>.
Indeed, I use junit4.

Do you prefer that I switch to Junit3 for the test ?


James.Strachan wrote:
> 
> I'd not noticed you'd used junit4; all the Camel examples still use
> JUnit3.
> 
> To run a test case in JUnit4 the name of the method is irrelevant -
> you have to use @Test to make it a test
> 
> 
> 2009/1/13 cmoulliard <cm...@gmail.com>:
>>
>> Using the following syntax, the test is executed :
>>
>> package org.apache.camel.bindy.csv;
>>
>> import org.apache.camel.EndpointInject;
>> import org.apache.camel.Produce;
>> import org.apache.camel.ProducerTemplate;
>> import org.apache.camel.builder.RouteBuilder;
>> import org.apache.camel.component.mock.MockEndpoint;
>> import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> import org.junit.Test;
>> import org.springframework.config.java.annotation.Bean;
>> import org.springframework.config.java.annotation.Configuration;
>> import org.springframework.config.java.test.JavaConfigContextLoader;
>> import org.springframework.test.annotation.DirtiesContext;
>> import org.springframework.test.context.ContextConfiguration;
>> import
>> org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
>>
>> @ContextConfiguration(locations =
>> "org.apache.camel.bindy.csv.BindyCSVUnmarshallTest$ContextConfig",
>>                              loader = JavaConfigContextLoader.class)
>> public class BindyCSVUnmarshallTest extends
>> AbstractJUnit4SpringContextTests
>> {
>>
>>        private static final transient Log LOG = LogFactory
>>                        .getLog(BindyCSVUnmarshallTest.class);
>>
>>        String record = "01,A,Albert,Cartier,BE12345678,Belgacom Ventage
>> 10/10,1500,EUR,08-01-2009";
>>
>>        @EndpointInject(uri = "mock:result")
>>        protected MockEndpoint resultEndpoint;
>>
>>    @Produce(uri = "direct:start")
>>    protected ProducerTemplate template;
>>
>>    @Test
>>    public void testMarshallMessage() throws Exception {
>>
>>        resultEndpoint.expectedBodiesReceived(record);
>>        template.sendBody(record);
>>
>>        resultEndpoint.assertIsSatisfied();
>>
>>    }
>>
>>
>>        @Configuration
>>        public static class ContextConfig extends
>> SingleRouteCamelConfiguration {
>>
>>                CamelDataFormat camelDataFormat = new
>> CamelDataFormat("org.apache.camel.bindy.model");
>>
>>                @Bean
>>                public RouteBuilder route() {
>>                        return new RouteBuilder() {
>>                                public void configure() {
>>                                        from("direct:start")
>>                                        //from("file://src/test/data/")
>>                                    .unmarshal(camelDataFormat)
>>                                        .to("mock:result");
>>                                }
>>                        };
>>                }
>>        }
>>
>> }
>>
>>
>> BUT junit reports the following error :
>>
>> main INFO
>> [org.springframework.beans.factory.support.DefaultListableBeanFactory] -
>> Destroying singletons in
>> org.springframework.beans.factory.support.DefaultListableBeanFactory@1e78c96:
>> defining beans
>> [org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,camelBeanPostProcessor];
>> parent:
>> org.springframework.beans.factory.support.DefaultListableBeanFactory@105d88a
>> org.apache.maven.surefire.booter.SurefireExecutionException:
>> org/junit/Assume$AssumptionViolatedException; nested exception is
>> java.lang.NoClassDefFoundError:
>> org/junit/Assume$AssumptionViolatedException
>> java.lang.NoClassDefFoundError:
>> org/junit/Assume$AssumptionViolatedException
>>        at
>> org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:240)
>>        at
>> org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
>>        at
>> org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
>>        at
>> org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
>>        at
>> org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
>>        at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
>>        at
>> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
>>        at
>> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
>>        at
>> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
>>        at
>> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
>>        at
>> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
>>        at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
>>        at
>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>>        at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>>        at
>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>>        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:585)
>>        at
>> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
>>        at
>> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
>> [ERROR]
>>
>> James.Strachan wrote:
>>>
>>> Ah...
>>>
>>>
>>> 2009/1/13 cmoulliard <cm...@gmail.com>:
>>> [snip]
>>>
>>>
>>>> @ContextConfiguration(locations =
>>>> "org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig",
>>>
>>> The above annotation is the name of the class to create for your
>>> ApplicationContext - not the one inside BindyCSVUnmarshallTest.
>>>
>>> Currently JavaConfig and Spring Test don't work that nicely together
>>> so you have to use a fully qualified class name unfortunatley
>>>
>>> --
>>> 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-tp21436628s22882p21437293.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/only-testMocksAreValid-is-executed-by-Camel-Spring-unit-test-%21%21-tp21436628s22882p21437517.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
I'd not noticed you'd used junit4; all the Camel examples still use JUnit3.

To run a test case in JUnit4 the name of the method is irrelevant -
you have to use @Test to make it a test


2009/1/13 cmoulliard <cm...@gmail.com>:
>
> Using the following syntax, the test is executed :
>
> package org.apache.camel.bindy.csv;
>
> import org.apache.camel.EndpointInject;
> import org.apache.camel.Produce;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.junit.Test;
> import org.springframework.config.java.annotation.Bean;
> import org.springframework.config.java.annotation.Configuration;
> import org.springframework.config.java.test.JavaConfigContextLoader;
> import org.springframework.test.annotation.DirtiesContext;
> import org.springframework.test.context.ContextConfiguration;
> import
> org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
>
> @ContextConfiguration(locations =
> "org.apache.camel.bindy.csv.BindyCSVUnmarshallTest$ContextConfig",
>                              loader = JavaConfigContextLoader.class)
> public class BindyCSVUnmarshallTest extends AbstractJUnit4SpringContextTests
> {
>
>        private static final transient Log LOG = LogFactory
>                        .getLog(BindyCSVUnmarshallTest.class);
>
>        String record = "01,A,Albert,Cartier,BE12345678,Belgacom Ventage
> 10/10,1500,EUR,08-01-2009";
>
>        @EndpointInject(uri = "mock:result")
>        protected MockEndpoint resultEndpoint;
>
>    @Produce(uri = "direct:start")
>    protected ProducerTemplate template;
>
>    @Test
>    public void testMarshallMessage() throws Exception {
>
>        resultEndpoint.expectedBodiesReceived(record);
>        template.sendBody(record);
>
>        resultEndpoint.assertIsSatisfied();
>
>    }
>
>
>        @Configuration
>        public static class ContextConfig extends SingleRouteCamelConfiguration {
>
>                CamelDataFormat camelDataFormat = new
> CamelDataFormat("org.apache.camel.bindy.model");
>
>                @Bean
>                public RouteBuilder route() {
>                        return new RouteBuilder() {
>                                public void configure() {
>                                        from("direct:start")
>                                        //from("file://src/test/data/")
>                                    .unmarshal(camelDataFormat)
>                                        .to("mock:result");
>                                }
>                        };
>                }
>        }
>
> }
>
>
> BUT junit reports the following error :
>
> main INFO
> [org.springframework.beans.factory.support.DefaultListableBeanFactory] -
> Destroying singletons in
> org.springframework.beans.factory.support.DefaultListableBeanFactory@1e78c96:
> defining beans
> [org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,camelBeanPostProcessor];
> parent:
> org.springframework.beans.factory.support.DefaultListableBeanFactory@105d88a
> org.apache.maven.surefire.booter.SurefireExecutionException:
> org/junit/Assume$AssumptionViolatedException; nested exception is
> java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
> java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
>        at
> org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:240)
>        at
> org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
>        at
> org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
>        at
> org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
>        at
> org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
>        at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
>        at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
>        at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
>        at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
>        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
>        at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
>        at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
>        at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>        at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>        at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        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:585)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
> [ERROR]
>
> James.Strachan wrote:
>>
>> Ah...
>>
>>
>> 2009/1/13 cmoulliard <cm...@gmail.com>:
>> [snip]
>>
>>
>>> @ContextConfiguration(locations =
>>> "org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig",
>>
>> The above annotation is the name of the class to create for your
>> ApplicationContext - not the one inside BindyCSVUnmarshallTest.
>>
>> Currently JavaConfig and Spring Test don't work that nicely together
>> so you have to use a fully qualified class name unfortunatley
>>
>> --
>> 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-tp21436628s22882p21437293.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



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

Open Source Integration
http://fusesource.com/

Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by cmoulliard <cm...@gmail.com>.
Using the following syntax, the test is executed :

package org.apache.camel.bindy.csv;

import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
import org.springframework.config.java.test.JavaConfigContextLoader;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

@ContextConfiguration(locations =
"org.apache.camel.bindy.csv.BindyCSVUnmarshallTest$ContextConfig",
		              loader = JavaConfigContextLoader.class)
public class BindyCSVUnmarshallTest extends AbstractJUnit4SpringContextTests
{

	private static final transient Log LOG = LogFactory
			.getLog(BindyCSVUnmarshallTest.class);
	
	String record = "01,A,Albert,Cartier,BE12345678,Belgacom Ventage
10/10,1500,EUR,08-01-2009";

	@EndpointInject(uri = "mock:result")
	protected MockEndpoint resultEndpoint;
	
    @Produce(uri = "direct:start")
    protected ProducerTemplate template;

    @Test
    public void testMarshallMessage() throws Exception {

    	resultEndpoint.expectedBodiesReceived(record);
    	template.sendBody(record);

    	resultEndpoint.assertIsSatisfied();

    }


	@Configuration
	public static class ContextConfig extends SingleRouteCamelConfiguration {
		
		CamelDataFormat camelDataFormat = new
CamelDataFormat("org.apache.camel.bindy.model");

		@Bean
		public RouteBuilder route() {
			return new RouteBuilder() {
				public void configure() {
					from("direct:start")
					//from("file://src/test/data/")
				    .unmarshal(camelDataFormat)
					.to("mock:result");
				}
			};
		}
	}

}


BUT junit reports the following error :

main INFO
[org.springframework.beans.factory.support.DefaultListableBeanFactory] -
Destroying singletons in
org.springframework.beans.factory.support.DefaultListableBeanFactory@1e78c96:
defining beans
[org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,camelBeanPostProcessor];
parent:
org.springframework.beans.factory.support.DefaultListableBeanFactory@105d88a
org.apache.maven.surefire.booter.SurefireExecutionException:
org/junit/Assume$AssumptionViolatedException; nested exception is
java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
	at
org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:240)
	at
org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
	at
org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
	at
org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
	at
org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
	at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
	at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
	at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
	at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
	at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
	at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
	at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
	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:585)
	at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
	at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
[ERROR] 

James.Strachan wrote:
> 
> Ah...
> 
> 
> 2009/1/13 cmoulliard <cm...@gmail.com>:
> [snip]
> 
> 
>> @ContextConfiguration(locations =
>> "org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig",
> 
> The above annotation is the name of the class to create for your
> ApplicationContext - not the one inside BindyCSVUnmarshallTest.
> 
> Currently JavaConfig and Spring Test don't work that nicely together
> so you have to use a fully qualified class name unfortunatley
> 
> -- 
> 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-tp21436628s22882p21437293.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: only testMocksAreValid is executed by Camel/Spring unit test !!

Posted by James Strachan <ja...@gmail.com>.
Ah...


2009/1/13 cmoulliard <cm...@gmail.com>:
[snip]


> @ContextConfiguration(locations =
> "org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig",

The above annotation is the name of the class to create for your
ApplicationContext - not the one inside BindyCSVUnmarshallTest.

Currently JavaConfig and Spring Test don't work that nicely together
so you have to use a fully qualified class name unfortunatley

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

Open Source Integration
http://fusesource.com/