[
https://issues.apache.org/jira/browse/CAMEL-13766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16887826#comment-16887826
]
Hemang Ajmera commented on CAMEL-13766:
---------------------------------------
Here is complete test class where some of the client details are
removed/replaced
{code:java}
package xxx.routing;
import xxx.AccountApplication;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.test.spring.CamelSpringBootRunner;
import org.apache.camel.test.spring.UseAdviceWith;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(classes = AccountApplication.class)
@UseAdviceWith
public class AccountRouteTest {
@Autowired
private CamelContext context;
@Autowired
private ProducerTemplate template;
@EndpointInject(uri = "mock:ems:topic:{{tibcoems.topicname.account}}")
private MockEndpoint target2Mock;
@EndpointInject(uri = "mock:ems:queue:{{tibcoems.queuename.account}}")
private MockEndpoint target1Mock;
@EndpointInject(uri = "mock:salesforce:query")
private MockEndpoint sfMock;
@Test
public void testMessageWithOneId() throws Exception {
RouteDefinition deliveryAccountOwnerMain =
context.getRouteDefinition("delivery-accountowner-main");
deliveryAccountOwnerMain.adviceWith(context, new
AdviceWithRouteBuilder(){
@Override
public void configure() throws Exception {
replaceFromWith("direct:hitme");
mockEndpointsAndSkip("ems.*");
mockEndpointsAndSkip("salesforce.*");
}
});
String input = "input data";
String sfResponse = "sf response data";
String expectedtarget2 = "expected target 1";
context.start();
sfMock.whenAnyExchangeReceived(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(sfResponse);
}
});
//Set all expections
target2Mock.expectedBodiesReceived(expectedtarget2);
target1Mock.allMessages().xpath("//UserId/text()").isEqualTo("user");
target1Mock.allMessages().xpath("//Email/text()").isEqualTo("[email protected]");
//Trigger the message
template.sendBody("direct:hitme", input);
//Confirm all expections
target2Mock.assertIsSatisfied();
target1Mock.assertIsSatisfied();
}
}
{code}
> Salesforce component Mocking does not work correctly
> ----------------------------------------------------
>
> Key: CAMEL-13766
> URL: https://issues.apache.org/jira/browse/CAMEL-13766
> Project: Camel
> Issue Type: Bug
> Components: camel-salesforce, camel-test
> Affects Versions: 2.24.0
> Reporter: Hemang Ajmera
> Priority: Minor
>
> In my unit test, I am replacing salesfoce component with a mock. However,
> still the component is getting activated with being replace with mock.
> Because of this test case fails in our Jenkins environment as from Jenkins
> server, there is no connectivity to salesforce.
>
> Here is the part of unit test code
> {code:java}
> @EndpointInject(uri = "mock:salesforce:query")
> private MockEndpoint sfMock;
> String sfResponse = "{}"; // Expected response value from SF
> RouteDefinition mainRoute = context.getRouteDefinition("main-route");
> mainRoute.adviceWith(context, new AdviceWithRouteBuilder(){
>
> @Override
> public void configure() throws Exception {
> mockEndpointsAndSkip("salesforce.*");
> }
> });
> sfMock.whenAnyExchangeReceived(new Processor(){
> @Override
> public void process(Exchange exchange) throws Exception {
> exchange.getIn().setBody(sfResponse);
> }
> });{code}
> Here is the logs in my local machine
>
> {quote}
> 2019-07-18 13:43:42.719 INFO 4288 --- [ main]
> org.eclipse.jetty.util.log : Logging initialized @22433ms to
> org.eclipse.jetty.util.log.Slf4jLog}}
> {{2019-07-18 13:43:42.890 INFO 4288 --- [ main]
> o.a.c.util.jsse.SSLContextParameters : Available providers: SUN version
> 1.8.}}
> {{2019-07-18 13:43:43.608 INFO 4288 --- [ main]
> o.a.c.c.s.internal.SalesforceSession : Login at Salesforce loginUrl:
> https://test.salesforce.com/services/oauth2/token}}
> {{2019-07-18 13:43:46.514 INFO 4288 --- [ main]
> o.a.c.c.s.internal.SalesforceSession : Login successful}}
> {{2019-07-18 13:43:46.519 INFO 4288 --- [ main]
> o.a.c.c.salesforce.SalesforceComponent : Found 0 generated classes in
> packages: [org.apache.camel.salesforce.dto]}}
> {{2019-07-18 13:43:46.523 INFO 4288 --- [ main]
> .c.i.InterceptSendToMockEndpointStrategy : Adviced endpoint
> [salesforce://query?format=JSON&rawPayload=true&sObjectQuery=SELECT+Id%2C+OwnerId%2CLastModifiedById%2CLastModifiedDate+FROM+Account+WHERE+Id+IN%28%27abcd%27%29]
> with mock endpoint [mock:salesforce:query]
> {quote}
> We can clearly see the component is initiated first and then replaced with
> mock. The idea of replacing with mock is that we should be able to test even
> if component cannot be initiated.
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)