Search in sources :

Example 1 with SalesforceComponent

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"));
}
Also used : SalesforceEndpoint(org.apache.camel.component.salesforce.SalesforceEndpoint) HashMap(java.util.HashMap) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent) Test(org.junit.Test)

Example 2 with SalesforceComponent

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;
}
Also used : HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with SalesforceComponent

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) SalesforceLoginConfig(org.apache.camel.component.salesforce.SalesforceLoginConfig) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) JobInfo(org.apache.camel.component.salesforce.api.dto.bulk.JobInfo) QueryRecordsOpportunity(org.wildfly.camel.test.salesforce.dto.QueryRecordsOpportunity) Opportunity(org.wildfly.camel.test.salesforce.dto.Opportunity) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent) Test(org.junit.Test)

Example 4 with SalesforceComponent

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&notifyForOperationDelete=true&notifyForOperationUpdate=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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SalesforceLoginConfig(org.apache.camel.component.salesforce.SalesforceLoginConfig) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) QueryRecordsOpportunity(org.wildfly.camel.test.salesforce.dto.QueryRecordsOpportunity) Opportunity(org.wildfly.camel.test.salesforce.dto.Opportunity) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent) Test(org.junit.Test)

Example 5 with SalesforceComponent

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));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SalesforceEndpoint(org.apache.camel.component.salesforce.SalesforceEndpoint) OperationName(org.apache.camel.component.salesforce.internal.OperationName) ByteArrayInputStream(java.io.ByteArrayInputStream) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent) Test(org.junit.Test)

Aggregations

SalesforceComponent (org.apache.camel.component.salesforce.SalesforceComponent)8 Test (org.junit.Test)6 SalesforceEndpointConfig (org.apache.camel.component.salesforce.SalesforceEndpointConfig)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4 CamelContext (org.apache.camel.CamelContext)3 ProducerTemplate (org.apache.camel.ProducerTemplate)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 SalesforceEndpoint (org.apache.camel.component.salesforce.SalesforceEndpoint)3 SalesforceLoginConfig (org.apache.camel.component.salesforce.SalesforceLoginConfig)3 QueryRecordsOpportunity (org.wildfly.camel.test.salesforce.dto.QueryRecordsOpportunity)3 HashMap (java.util.HashMap)2 Opportunity (org.wildfly.camel.test.salesforce.dto.Opportunity)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Exchange (org.apache.camel.Exchange)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 JobInfo (org.apache.camel.component.salesforce.api.dto.bulk.JobInfo)1 OperationName (org.apache.camel.component.salesforce.internal.OperationName)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1