use of org.apache.camel.component.salesforce.SalesforceComponent in project camel by apache.
the class SubscriptionHelperTest method shouldSupportInitialConfigMapWithTwoKeySyntaxes.
@Test
public void shouldSupportInitialConfigMapWithTwoKeySyntaxes() throws Exception {
final Map<String, Long> initialReplayIdMap = new HashMap<>();
initialReplayIdMap.put("my-topic-1", 10L);
initialReplayIdMap.put("/topic/my-topic-1", 20L);
initialReplayIdMap.put("/topic/my-topic-2", 30L);
final SalesforceEndpointConfig config = new SalesforceEndpointConfig();
config.setDefaultReplayId(14L);
config.setInitialReplayIdMap(initialReplayIdMap);
final SalesforceComponent component = mock(SalesforceComponent.class);
final SalesforceEndpoint endpoint = mock(SalesforceEndpoint.class);
when(endpoint.getReplayId()).thenReturn(null);
when(endpoint.getComponent()).thenReturn(component);
when(endpoint.getConfiguration()).thenReturn(config);
when(component.getConfig()).thenReturn(new SalesforceEndpointConfig());
assertEquals("Expecting replayId for `my-topic-1` to be 10, as short topic names have priority", Optional.of(10L), determineReplayIdFor(endpoint, "my-topic-1"));
assertEquals("Expecting replayId for `my-topic-2` to be 30, the only one given", Optional.of(30L), determineReplayIdFor(endpoint, "my-topic-2"));
assertEquals("Expecting replayId for `my-topic-3` to be 14, the default", Optional.of(14L), determineReplayIdFor(endpoint, "my-topic-3"));
}
use of org.apache.camel.component.salesforce.SalesforceComponent in project camel by apache.
the class SalesforceComponentAutoConfiguration method configureSalesforceComponent.
@Lazy
@Bean(name = "salesforce-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SalesforceComponent.class)
public SalesforceComponent configureSalesforceComponent(CamelContext camelContext, SalesforceComponentConfiguration configuration) throws Exception {
SalesforceComponent component = new SalesforceComponent();
component.setCamelContext(camelContext);
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
Class<?> paramClass = value.getClass();
if (paramClass.getName().endsWith("NestedConfiguration")) {
Class nestedClass = null;
try {
nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
HashMap<String, Object> nestedParameters = new HashMap<>();
IntrospectionSupport.getProperties(value, nestedParameters, null, false);
Object nestedProperty = nestedClass.newInstance();
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
entry.setValue(nestedProperty);
} catch (NoSuchFieldException e) {
}
}
}
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
return component;
}
use of org.apache.camel.component.salesforce.SalesforceComponent in project wildfly-camel by wildfly-extras.
the class SalesforceIntegrationTest method testSalesforceCreateJob.
@Test
public void testSalesforceCreateJob() throws Exception {
Map<String, Object> salesforceOptions = createSalesforceOptions();
Assume.assumeTrue("[#1676] Enable Salesforce testing in Jenkins", salesforceOptions.size() == SalesforceOption.values().length);
SalesforceLoginConfig loginConfig = new SalesforceLoginConfig();
IntrospectionSupport.setProperties(loginConfig, salesforceOptions);
SalesforceComponent component = new SalesforceComponent();
component.setPackages("org.wildfly.camel.test.salesforce.dto");
component.setLoginConfig(loginConfig);
JobInfo jobInfo = new JobInfo();
jobInfo.setOperation(OperationEnum.QUERY);
jobInfo.setContentType(ContentType.CSV);
jobInfo.setObject(Opportunity.class.getSimpleName());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addComponent("salesforce", component);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("salesforce:createJob");
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
JobInfo result = template.requestBody("direct:start", jobInfo, JobInfo.class);
Assert.assertNotNull("Expected JobInfo result to not be null", result);
Assert.assertNotNull("Expected JobInfo result ID to not be null", result.getId());
} finally {
camelctx.stop();
}
}
use of org.apache.camel.component.salesforce.SalesforceComponent in project wildfly-camel by wildfly-extras.
the class SalesforceIntegrationTest method testSalesforceTopicConsumer.
@Test
public void testSalesforceTopicConsumer() throws Exception {
Map<String, Object> salesforceOptions = createSalesforceOptions();
Assume.assumeTrue("[#1676] Enable Salesforce testing in Jenkins", salesforceOptions.size() == SalesforceOption.values().length);
SalesforceLoginConfig loginConfig = new SalesforceLoginConfig();
IntrospectionSupport.setProperties(loginConfig, salesforceOptions);
SalesforceComponent component = new SalesforceComponent();
component.setPackages("org.wildfly.camel.test.salesforce.dto");
component.setLoginConfig(loginConfig);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addComponent("salesforce", component);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("salesforce:CamelTestTopic?notifyForFields=ALL&" + "notifyForOperationCreate=true¬ifyForOperationDelete=true¬ifyForOperationUpdate=true&" + "sObjectName=Opportunity&" + "updateTopic=true&sObjectQuery=SELECT Id, Name FROM Opportunity").to("mock:result");
}
});
Opportunity opportunity = new Opportunity();
opportunity.setName("test");
opportunity.setStageName(Opportunity_StageNameEnum.PROSPECTING);
opportunity.setCloseDate(ZonedDateTime.now());
MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
mockEndpoint.expectedMinimumMessageCount(1);
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
template.sendBody("salesforce:upsertSObject?SObjectIdName=Name", opportunity);
mockEndpoint.assertIsSatisfied(5000);
} finally {
camelctx.stop();
}
}
use of org.apache.camel.component.salesforce.SalesforceComponent in project camel by apache.
the class JsonRestProcessorTest method getRequestStream.
@Test
public void getRequestStream() throws Exception {
SalesforceComponent comp = new SalesforceComponent();
SalesforceEndpointConfig conf = new SalesforceEndpointConfig();
OperationName op = OperationName.CREATE_BATCH;
SalesforceEndpoint endpoint = new SalesforceEndpoint("", comp, conf, op, "");
JsonRestProcessor jsonRestProcessor = new JsonRestProcessor(endpoint);
DefaultCamelContext context = new DefaultCamelContext();
Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
TestObject doc = new TestObject();
doc.setCreationDate(ZonedDateTime.of(1717, 1, 2, 3, 4, 5, 6, ZoneId.systemDefault()));
exchange.getIn().setBody(doc);
ByteArrayInputStream is = (ByteArrayInputStream) jsonRestProcessor.getRequestStream(exchange);
String result = IOUtils.toString(is);
assertThat(result, result.length() <= 48, Is.is(true));
}
Aggregations