Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need solution for Java way of testing direct camel component #61

Open
suresh-devaki opened this issue Jul 13, 2021 · 0 comments
Open

Need solution for Java way of testing direct camel component #61

suresh-devaki opened this issue Jul 13, 2021 · 0 comments

Comments

@suresh-devaki
Copy link

Based on XML way of sample code given at below link for direct camel component, I tried changing it in Java way as below and ran the test case. But test case is not working. Please suggest how it can be written in Java.

Link for Sample code written in XML
https://labs.consol.de/citrus/development/2015/05/28/testing-apache-camel-part-2.html

Implemented code in Java as below.

EndPointConfig.java

import org.apache.camel.CamelContext;
import org.apache.camel.ExchangePattern;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.spring.SpringCamelContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.consol.citrus.channel.ChannelSyncEndpoint;
import com.consol.citrus.dsl.endpoint.CitrusEndpoints;

@configuration
@propertysource("citrus.properties")
public class EndPointConfig {

@Bean
public ChannelSyncEndpoint directHelloEndpoint() {
    return CitrusEndpoints
    		.channel()
    		.synchronous()
    		.name("direct:hello")
    	.build();
       
}
 
@Bean
public ChannelSyncEndpoint sedaHelloEndpoint() {
    return CitrusEndpoints
    		.channel()
    		.synchronous()
    		.name("seda:sayHello")
    	.build();
       
}

@Bean
public CamelContext camelContext() throws Exception {
    SpringCamelContext context = new SpringCamelContext();
    context.addRouteDefinition(new RouteDefinition()
        .from("direct:hello").routeId("helloRoute")
        .log("body after hello: ${body}")
        .to("seda:sayHello")
        .log("body after say hello: ${body}")
        .setExchangePattern(ExchangePattern.InOut)
        );
    return context;
}

}


Test case

import org.junit.Test;

import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;
import com.consol.citrus.message.MessageType;

public class SayHelloTest extends JUnit4CitrusTestRunner {

@Test
@CitrusTest
public void testMessage() {
    
    send(sendMessageBuilder -> sendMessageBuilder
            .endpoint("camel:sync:direct:input")
            .fork(true)
	        .messageType(MessageType.PLAINTEXT)
            .payload("Hello Camel!"));

	receive(receiveMessageBuilder -> receiveMessageBuilder
             .endpoint("camel:sync:seda:sayHello")
             .messageType(MessageType.PLAINTEXT)
             .payload("Hello Camel!"));
}

}


Console log trace with error details

00:16:07,396 INFO port.LoggingReporter|
00:16:07,396 DEBUG port.LoggingReporter| TEST STEP 1: send
00:16:07,401 DEBUG faultEndpointFactory| Found cached endpoint for uri 'camel:sync:direct:input'
00:16:07,401 DEBUG ns.SendMessageAction| Forking message sending action ...
00:16:07,407 INFO port.LoggingReporter|
00:16:07,408 DEBUG port.LoggingReporter| TEST STEP 1 SUCCESS
00:16:07,411 INFO port.LoggingReporter|
00:16:07,411 DEBUG port.LoggingReporter| TEST STEP 2: receive
00:16:07,414 DEBUG faultEndpointFactory| Found cached endpoint for uri 'camel:sync:seda:sayHello'
00:16:07,421 DEBUG nt.CamelSyncProducer| Sending message to camel endpoint: 'direct:input'
00:16:07,422 DEBUG ltCorrelationManager| Saving correlation key for 'citrus_message_correlator_CamelSyncEndpoint:producer'
00:16:07,422 DEBUG context.TestContext| Setting variable: citrus_message_correlator_CamelSyncEndpoint:producer with value: 'citrus_message_id = '162463a3-ae22-453b-b1d2-27c954804628''
00:16:07,423 DEBUG Logger.Message_OUT| DEFAULTMESSAGE [id: 162463a3-ae22-453b-b1d2-27c954804628, payload: Hello Camel!][headers: {citrus_message_type=PLAINTEXT, citrus_message_id=162463a3-ae22-453b-b1d2-27c954804628, citrus_message_timestamp=1626201967398}]
00:16:07,425 DEBUG nt.CamelSyncConsumer| Receiving message from camel endpoint: 'seda:sayHello'
00:16:07,431 DEBUG impl.ConsumerCache| <<<< seda://sayHello
00:16:07,431 DEBUG mpl.DefaultComponent| Creating endpoint uri=[direct://input], path=[input]
00:16:07,433 DEBUG impl.ConsumerCache| Adding to consumer cache with key: seda://sayHello for consumer: PollingConsumer on seda://sayHello
00:16:07,433 DEBUG g.SpringCamelContext| direct://input converted to endpoint: direct://input by component: org.apache.camel.component.direct.DirectComponent@5626d18c
00:16:07,436 DEBUG rectBlockingProducer| Starting producer: Producer[direct://input]
00:16:07,437 DEBUG impl.ProducerCache| Adding to producer cache with key: direct://input for producer: Producer[direct://input]
00:16:07,445 INFO nt.CamelSyncProducer| Message was sent to camel endpoint: 'direct:input'
00:16:07,445 DEBUG impl.ProducerCache| >>>> direct://input Exchange[]
00:16:07,950 DEBUG rectBlockingProducer| Waited 500 for consumer to be ready
00:16:08,451 DEBUG rectBlockingProducer| Waited 1001 for consumer to be ready
00:16:08,951 DEBUG rectBlockingProducer| Waited 1501 for consumer to be ready
00:16:09,451 DEBUG rectBlockingProducer| Waited 2001 for consumer to be ready
00:16:09,951 DEBUG rectBlockingProducer| Waited 2501 for consumer to be ready
00:16:10,452 DEBUG rectBlockingProducer| Waited 3002 for consumer to be ready
00:16:10,952 DEBUG rectBlockingProducer| Waited 3502 for consumer to be ready
00:16:11,453 DEBUG rectBlockingProducer| Waited 4003 for consumer to be ready
00:16:11,953 DEBUG rectBlockingProducer| Waited 4503 for consumer to be ready
00:16:12,436 INFO port.LoggingReporter|
00:16:12,437 ERROR port.LoggingReporter| TEST FAILED SayHelloTest.testMessage <com.telia.citrus.camel.direct> Nested exception is:
com.consol.citrus.exceptions.TestCaseFailedException: Action timed out while receiving message from camel endpoint 'seda:sayHello'
at com.consol.citrus.TestCase.executeAction(TestCase.java:227)
at com.consol.citrus.dsl.runner.DefaultTestRunner.run(DefaultTestRunner.java:188)
at com.consol.citrus.dsl.runner.DefaultTestRunner.receive(DefaultTestRunner.java:309)
at com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner.receive(JUnit4CitrusTestRunner.java:210)
at com.telia.citrus.camel.direct.SayHelloTest.testMessage(SayHelloTest.java:21)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:223)
at com.consol.citrus.dsl.junit.JUnit4CitrusTest.invokeTestMethod(JUnit4CitrusTest.java:99)
at com.consol.citrus.dsl.junit.JUnit4CitrusTest.run(JUnit4CitrusTest.java:70)
at com.consol.citrus.junit.CitrusJUnit4Runner$InvokeRunMethod.evaluate(CitrusJUnit4Runner.java:217)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:768)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: com.consol.citrus.exceptions.ActionTimeoutException: Action timed out while receiving message from camel endpoint 'seda:sayHello'
at com.consol.citrus.camel.endpoint.CamelSyncConsumer.receive(CamelSyncConsumer.java:70)
at com.consol.citrus.actions.ReceiveMessageAction.receive(ReceiveMessageAction.java:141)
at com.consol.citrus.actions.ReceiveMessageAction.doExecute(ReceiveMessageAction.java:120)
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
at com.consol.citrus.TestCase.executeAction(TestCase.java:220)
... 36 more
00:16:12,441 INFO port.LoggingReporter| ------------------------------------------------------------------------
00:16:12,441 INFO port.LoggingReporter|
00:16:12,453 DEBUG rectBlockingProducer| Waited 5003 for consumer to be ready
00:16:12,455 INFO port.LoggingReporter|
00:16:12,455 INFO port.LoggingReporter| ------------------------------------------------------------------------
00:16:12,455 DEBUG port.LoggingReporter| AFTER TEST SUITE
00:16:12,455 INFO port.LoggingReporter|
00:16:12,455 INFO port.LoggingReporter|
00:16:12,456 INFO port.LoggingReporter| AFTER TEST SUITE: SUCCESS
00:16:12,456 INFO port.LoggingReporter| ------------------------------------------------------------------------
00:16:12,456 INFO port.LoggingReporter|
00:16:12,456 INFO port.LoggingReporter| ------------------------------------------------------------------------
00:16:12,456 INFO port.LoggingReporter|
00:16:12,456 INFO port.LoggingReporter| CITRUS TEST RESULTS
00:16:12,456 INFO port.LoggingReporter|
00:16:12,456 DEBUG g.SpringCamelContext| onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.support.GenericApplicationContext@6cc4cdb9: startup date [Wed Jul 14 00:16:03 IST 2021]; root of context hierarchy]
00:16:12,472 INFO port.LoggingReporter| SayHelloTest.testMessage ....................................... FAILED
00:16:12,473 INFO port.LoggingReporter| FAILURE: Caused by: TestCaseFailedException: Action timed out while receiving message from camel endpoint 'seda:sayHello'
00:16:12,474 INFO port.LoggingReporter|
00:16:12,474 INFO port.LoggingReporter| TOTAL: 1
00:16:12,474 DEBUG port.LoggingReporter| SKIPPED: 0 (0.0%)
00:16:12,474 INFO port.LoggingReporter| FAILED: 1 (100.0%)
00:16:12,474 INFO port.LoggingReporter| SUCCESS: 0 (0.0%)
00:16:12,475 INFO port.LoggingReporter|
00:16:12,475 INFO port.LoggingReporter| ------------------------------------------------------------------------
00:16:12,475 DEBUG report.HtmlReporter| Generating HTML test report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant