Search in sources :

Example 1 with SalesforceEndpointConfig

use of org.apache.camel.component.salesforce.SalesforceEndpointConfig 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 SalesforceEndpointConfig

use of org.apache.camel.component.salesforce.SalesforceEndpointConfig 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)

Example 3 with SalesforceEndpointConfig

use of org.apache.camel.component.salesforce.SalesforceEndpointConfig in project camel by apache.

the class SubscriptionHelperTest method precedenceShouldBeFollowed.

@Test
public void precedenceShouldBeFollowed() {
    final SalesforceEndpointConfig componentConfig = new SalesforceEndpointConfig();
    componentConfig.setDefaultReplayId(1L);
    componentConfig.setInitialReplayIdMap(Collections.singletonMap("my-topic-1", 2L));
    componentConfig.setInitialReplayIdMap(Collections.singletonMap("my-topic-2", 3L));
    final SalesforceEndpointConfig endpointConfig = new SalesforceEndpointConfig();
    endpointConfig.setDefaultReplayId(4L);
    endpointConfig.setInitialReplayIdMap(Collections.singletonMap("my-topic-1", 5L));
    final SalesforceComponent component = mock(SalesforceComponent.class);
    when(component.getConfig()).thenReturn(componentConfig);
    final SalesforceEndpoint endpoint = mock(SalesforceEndpoint.class);
    when(endpoint.getReplayId()).thenReturn(null);
    when(endpoint.getComponent()).thenReturn(component);
    when(endpoint.getConfiguration()).thenReturn(endpointConfig);
    assertEquals("Expecting replayId for `my-topic-1` to be 5, as endpoint configuration has priority", Optional.of(5L), determineReplayIdFor(endpoint, "my-topic-1"));
    assertEquals("Expecting replayId for `my-topic-2` to be 3, as endpoint does not configure it", Optional.of(3L), determineReplayIdFor(endpoint, "my-topic-2"));
    assertEquals("Expecting replayId for `my-topic-3` to be 4, as it is endpoint's default", Optional.of(4L), determineReplayIdFor(endpoint, "my-topic-3"));
    endpointConfig.setDefaultReplayId(null);
    assertEquals("Expecting replayId for `my-topic-3` to be 1, as it is component's default when endpoint does not have a default", Optional.of(1L), determineReplayIdFor(endpoint, "my-topic-3"));
    when(endpoint.getReplayId()).thenReturn(6L);
    assertEquals("Expecting replayId for `my-topic-1` to be 6, as it is endpoint configured explicitly on the endpoint", Optional.of(6L), determineReplayIdFor(endpoint, "my-topic-1"));
    assertEquals("Expecting replayId for `my-topic-2` to be 6, as it is endpoint configured explicitly on the endpoint", Optional.of(6L), determineReplayIdFor(endpoint, "my-topic-2"));
    assertEquals("Expecting replayId for `my-topic-3` to be 6, as it is endpoint configured explicitly on the endpoint", Optional.of(6L), determineReplayIdFor(endpoint, "my-topic-3"));
}
Also used : SalesforceEndpoint(org.apache.camel.component.salesforce.SalesforceEndpoint) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent) Test(org.junit.Test)

Example 4 with SalesforceEndpointConfig

use of org.apache.camel.component.salesforce.SalesforceEndpointConfig in project camel by apache.

the class SubscriptionHelper method determineReplayIdFor.

static Optional<Long> determineReplayIdFor(final SalesforceEndpoint endpoint, final String topicName) {
    final String channelName = getChannelName(topicName);
    final Long replayId = endpoint.getReplayId();
    final SalesforceComponent component = endpoint.getComponent();
    final SalesforceEndpointConfig endpointConfiguration = endpoint.getConfiguration();
    final Map<String, Long> endpointInitialReplayIdMap = endpointConfiguration.getInitialReplayIdMap();
    final Long endpointReplayId = endpointInitialReplayIdMap.getOrDefault(topicName, endpointInitialReplayIdMap.get(channelName));
    final Long endpointDefaultReplayId = endpointConfiguration.getDefaultReplayId();
    final SalesforceEndpointConfig componentConfiguration = component.getConfig();
    final Map<String, Long> componentInitialReplayIdMap = componentConfiguration.getInitialReplayIdMap();
    final Long componentReplayId = componentInitialReplayIdMap.getOrDefault(topicName, componentInitialReplayIdMap.get(channelName));
    final Long componentDefaultReplayId = componentConfiguration.getDefaultReplayId();
    // over give topic values
    return Stream.of(replayId, endpointReplayId, componentReplayId, endpointDefaultReplayId, componentDefaultReplayId).filter(Objects::nonNull).findFirst();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) SalesforceComponent(org.apache.camel.component.salesforce.SalesforceComponent)

Aggregations

SalesforceComponent (org.apache.camel.component.salesforce.SalesforceComponent)4 SalesforceEndpointConfig (org.apache.camel.component.salesforce.SalesforceEndpointConfig)4 SalesforceEndpoint (org.apache.camel.component.salesforce.SalesforceEndpoint)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Exchange (org.apache.camel.Exchange)1 OperationName (org.apache.camel.component.salesforce.internal.OperationName)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1