Hi Its not really clear from your description what is your problem.
I think you talk about that there is 9 messages, but after 5 messages it completes, but you want it to fail. Or something like that. The assertion will complete when the expectations is satisfied. In your case thats when 5 messages reached. Then its regarded as completed. And then maybe a little sec later a new message arrives, so there is 6 messages. But the mock is still satisfied. There is a setAssertPeriod method you can use to let Camel "wait" after the mock is satisfied, to ensure no other messages arrives afterwards. On Mon, Mar 26, 2012 at 10:59 AM, Borut Bolčina <[email protected]> wrote: > Hello, > > I am trying to test the number of messages and there is something I do not > understand. The test ends successfully before the messages arrive at the > mock endpoint. here is the test class: > > public class WeatherCurrentTest extends CamelTestSupport { > @Override > protected RouteBuilder createRouteBuilder() throws Exception { > return new RouteBuilder() { > @Override > public void configure() throws Exception { > DataFormat jaxbDataFormat = new > JaxbDataFormat("com.mycompany.model.entities.weather"); > from("file:src/test/resources") > .split() > .tokenizeXML("metData") > .unmarshal(jaxbDataFormat) > .to("log:com.mycompany.datarobot?level=INFO") > .to("mock:meteo1"); > } > }; > } > @Test > public void testNumberOfWeatherStations() throws Exception { > MockEndpoint mock = getMockEndpoint("mock:meteo1"); > mock.expectedMessageCount(5); > > String fileName = "src/test/resources/observation_si_latest.xml"; > Endpoint endpoint = new FileEndpoint("file:" + fileName, new > FileComponent()); > File meteo = new File(fileName); > String content = context.getTypeConverter().convertTo(String.class, meteo); > //send data to route > template.sendBodyAndHeader(endpoint, content, Exchange.FILE_NAME, fileName); > > Thread.sleep(1000); > mock.assertIsSatisfied(); > } > } > > The input XML file has 9 <metData> elements by which the file is splitted > and converted to pojos. I would expect the above test to fail, as I am > expecting only 5 messages, but the test output > (.to("log:com.mycompany.datarobot?level=INFO")) prints out 5 messages and > then "quits": > > [2012/03/26 10:42:22.901] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText>jasno</nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Bilje pri Novi Gorici</domain_longTitle> > <t_degreesC>15</t_degreesC> > <dd_shortText>V</dd_shortText> > <ff_val_kmh>22</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.907] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText>pretežno jasno</nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Kredarica</domain_longTitle> > <t_degreesC>-10</t_degreesC> > <dd_shortText>S</dd_shortText> > <ff_val_kmh>11</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.912] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText>pretežno jasno</nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Letališče Cerklje ob Krki</domain_longTitle> > <t_degreesC>11</t_degreesC> > <dd_shortText>V</dd_shortText> > <ff_val_kmh>14</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.917] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText>zmerno oblačno</nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Letališče Edvarda Rusjana Maribor</domain_longTitle> > <t_degreesC>10</t_degreesC> > <dd_shortText>SV</dd_shortText> > <ff_val_kmh>11</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.927] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText>delno oblačno</nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Letališče Jožeta Pučnika Ljubljana</domain_longTitle> > <t_degreesC>12</t_degreesC> > <dd_shortText>JV</dd_shortText> > <ff_val_kmh>25</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.929] INFO [s.n.d.WeatherCurrentTest:tearDown]: > ******************************************************************************** > [2012/03/26 10:42:22.930] INFO [s.n.d.WeatherCurrentTest:tearDown]: > Testing done: (com.mycompany.datarobot.WeatherCurrentTest) > [2012/03/26 10:42:22.930] INFO [s.n.d.WeatherCurrentTest:tearDown]: Took: > 1.126 seconds (1126 millis) > [2012/03/26 10:42:22.930] INFO [s.n.d.WeatherCurrentTest:tearDown]: > ******************************************************************************** > [2012/03/26 10:42:22.931] INFO [o.a.c.i.DefaultCamelContext:doStop]: > Apache Camel 2.9.1 (CamelContext: camel-1) is shutting down > [2012/03/26 10:42:22.931] INFO > [o.a.c.i.DefaultShutdownStrategy:doShutdown]: Starting to graceful > shutdown 1 routes (timeout 10 seconds) > [2012/03/26 10:42:22.932] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText>jasno</nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Letališče Portorož</domain_longTitle> > <t_degreesC>15</t_degreesC> > <dd_shortText>SV</dd_shortText> > <ff_val_kmh>22</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.934] INFO [o.a.c.i.DefaultShutdownStrategy:run]: > Waiting as there are still 3 inflight and pending exchanges to complete, > timeout in 10 seconds. > [2012/03/26 10:42:22.937] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText></nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Lisca</domain_longTitle> > <t_degreesC>0</t_degreesC> > <dd_shortText></dd_shortText> > <ff_val_kmh>0</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.941] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText>pretežno jasno</nn_shortText> > <rh>0</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Ljubljana</domain_longTitle> > <t_degreesC>12</t_degreesC> > <dd_shortText>V</dd_shortText> > <ff_val_kmh>14</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:22.945] INFO [s.n.datarobot:log]: > Exchange[ExchangePattern:InOnly, > BodyType:com.mycompany.model.entities.weather.WeatherCurrent, Body:<?xml > version="1.0" encoding="UTF-8" standalone="yes"?> > <metData> > <id>0</id> > <nn_shortText></nn_shortText> > <rh>31</rh> > <msl>0</msl> > <pa_shortText></pa_shortText> > <domain_longTitle>Novo mesto</domain_longTitle> > <t_degreesC>10</t_degreesC> > <dd_shortText>V</dd_shortText> > <ff_val_kmh>18</ff_val_kmh> > </metData> > ] > [2012/03/26 10:42:23.935] INFO [o.a.c.i.DefaultShutdownStrategy:run]: > Route: route1 shutdown complete, was consuming from: > Endpoint[file://src/test/resources] > [2012/03/26 10:42:23.936] INFO > [o.a.c.i.DefaultShutdownStrategy:doShutdown]: Graceful shutdown of 1 > routes completed in 1 seconds > [2012/03/26 10:42:23.937] INFO [o.a.c.i.DefaultInflightRepository:doStop]: > Shutting down with no inflight exchanges. > [2012/03/26 10:42:23.938] INFO [o.a.c.i.DefaultCamelContext:doStop]: > Uptime: 2.525 seconds > [2012/03/26 10:42:23.938] INFO [o.a.c.i.DefaultCamelContext:doStop]: > Apache Camel 2.9.1 (CamelContext: camel-1) is shutdown in 1.007 seconds > PASSED: testNumberOfWeatherStations > > =============================================== > Default test > Tests run: 1, Failures: 0, Skips: 0 > =============================================== > > > =============================================== > Default suite > Total tests run: 1, Failures: 0, Skips: 0 > =============================================== > > [TestNG] Time taken by org.testng.reporters.EmailableReporter@a20892: 4 ms > [TestNG] Time taken by org.testng.reporters.jq.Main@e102dc: 31 ms > [TestNG] Time taken by org.testng.reporters.XMLReporter@1fdc96c: 9 ms > [TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: > 0 ms > [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@127734f: 4 > ms > [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@a1807c: 41 ms > > > I do not understand why the test ends at the expected messages count. > Clearly I am doing something wrong. Can anyone bring me out of the dark > please? > > -borut -- Claus Ibsen ----------------- CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com FuseSource Email: [email protected] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
