Skip to content

Commit cc4790f

Browse files
committed
CAMEL-22782: camel-salesforce: Modernize integration test setup with SF CLI
Migrate from Ant-based deployment to Salesforce CLI with improved authentication, automatic environment setup, and better credential management. Key changes: Authentication: - Use refresh token flow with SF CLI's built-in PlatformCLI connected app - Automatically extract refresh token from SF CLI's stored authentication - No security token required for scratch orgs Credential Management: - Store credentials in git-ignored .local/ directory - Separate version-controlled config/ from user-specific .local/ files - Auto-generate connected app credentials on first deployment Automatic Setup: - Assign Hard_Delete_Permission_Set during deployment - Deactivate standard duplicate rules (Account, Contact, Lead) - Enable username/password OAuth flow in scratch org definition
1 parent 2ee7855 commit cc4790f

File tree

76 files changed

+1171
-1014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1171
-1014
lines changed

components/camel-salesforce/camel-salesforce-component/pom.xml

Lines changed: 32 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -335,28 +335,29 @@
335335
<requireFilesExist>
336336
<files>
337337
<file>
338-
${salesforce.component.root}/it/resources/migration-tool/ant-salesforce.jar
338+
${salesforce.component.root}/it/resources/setup-salesforce.sh
339339
</file>
340340
</files>
341-
<message><![CDATA[Salesforce Migration Tool required
341+
<message><![CDATA[Salesforce CLI Setup Script required
342342
343-
You need to download the Salesforce Migration Tool (ZIP file) and
344-
extract the `ant-salesforce.jar` out of it to:
343+
The integration tests require the Salesforce CLI (sf) to be installed.
345344
346-
${salesforce.component.root}/it/resources/migration-tool/ant-salesforce.jar
345+
For information about the Salesforce CLI:
346+
https://developer.salesforce.com/tools/salesforcecli
347347
348-
It's needed by the integration tests to setup the Salesforce instance
349-
with custom sObjects/fields that are required by the tests.
348+
EASIEST OPTION - Auto Scratch Org:
349+
1. Authenticate to Dev Hub (one-time):
350+
sf org login web --set-default-dev-hub
350351
351-
Have a look at:
352+
2. Run tests (scratch org auto-created):
353+
mvn clean verify -Pintegration
352354
353-
${salesforce.component.root}/it/resources/salesforce
355+
ALTERNATIVE - Traditional Org:
356+
- Set SALESFORCE_USERNAME, SALESFORCE_PASSWORD, and SALESFORCE_LOGIN_URL
357+
- Or configure in test-salesforce-login.properties
354358
355-
To see what will be done.
356-
357-
For information and download of the Salesforce Migration Tool consult:
358-
359-
https://developer.salesforce.com/page/Force.com_Migration_Tool]]></message>
359+
Source metadata location:
360+
${salesforce.component.root}/it/resources/salesforce-source]]></message>
360361
</requireFilesExist>
361362
</rules>
362363
<fail>true</fail>
@@ -385,79 +386,35 @@ https://developer.salesforce.com/page/Force.com_Migration_Tool]]></message>
385386
</resources>
386387
</configuration>
387388
</execution>
388-
<execution>
389-
<id>set-connected-app-client-id</id>
390-
<phase>generate-test-resources</phase>
391-
<goals>
392-
<goal>copy-resources</goal>
393-
</goals>
394-
<configuration>
395-
<outputDirectory>
396-
${salesforce.component.root}/it/resources/salesforce/connectedApps
397-
</outputDirectory>
398-
<overwrite>true</overwrite>
399-
<filters>
400-
<filter>${salesforce.component.root}/test-salesforce-login.properties</filter>
401-
</filters>
402-
<resources>
403-
<resource>
404-
<directory>${salesforce.component.root}/it/resources/</directory>
405-
<include>CamelSalesforceIntegrationTests.connectedApp</include>
406-
<filtering>true</filtering>
407-
</resource>
408-
</resources>
409-
</configuration>
410-
</execution>
411389
</executions>
412390
</plugin>
413391
<plugin>
414-
<groupId>org.apache.maven.plugins</groupId>
415-
<artifactId>maven-antrun-plugin</artifactId>
392+
<groupId>org.codehaus.mojo</groupId>
393+
<artifactId>exec-maven-plugin</artifactId>
416394
<executions>
417395
<execution>
418396
<id>setup-salesforce-instance</id>
397+
<phase>pre-integration-test</phase>
419398
<goals>
420-
<goal>run</goal>
399+
<goal>exec</goal>
421400
</goals>
422-
<phase>pre-integration-test</phase>
423401
<configuration>
424-
<target xmlns:if="ant:if" xmlns:unless="ant:unless">
425-
<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
426-
<classpath>
427-
<pathelement location="${salesforce.component.root}/it/resources/migration-tool/ant-salesforce.jar" />
428-
</classpath>
429-
</taskdef>
430-
431-
<property prefix="prop" file="${project.build.directory}/test-classes/test-salesforce-login.properties" />
432-
<property environment="env" />
433-
434-
<property name="username" value="${prop.salesforce.username}" if:set="prop.salesforce.username" />
435-
<property name="username" value="${env.SALESFORCE_USERNAME}" if:set="env.SALESFORCE_USERNAME" />
436-
437-
<property name="password" value="${prop.salesforce.password}" if:set="prop.salesforce.password" />
438-
<property name="password" value="${env.SALESFORCE_PASSWORD}" if:set="env.SALESFORCE_PASSWORD" />
439-
440-
<property name="serverurl" value="${prop.salesforce.login.url}" if:set="prop.salesforce.login.url" />
441-
<property name="serverurl" value="${env.SALESFORCE_LOGIN_URL}" if:set="env.SALESFORCE_LOGIN_URL" />
442-
443-
<fail unless:set="username" message="To run the migrations you need to specify either `salesforce.username` in: ${project.build.directory}/generated-resources/test-salesforce-login.properties or set SALESFORCE_USERNAME environment variable" />
444-
445-
<fail unless:set="password" message="To run the migrations you need to specify either `salesforce.password` in: ${project.build.directory}/generated-resources/test-salesforce-login.properties or set SALESFORCE_PASSWORD environment variable" />
446-
447-
<fail unless:set="serverurl" message="To run the migrations you need to specify either `salesforce.login.url` in: ${project.build.directory}/generated-resources/test-salesforce-login.properties or set SALESFORCE_LOGIN_URL environment variable" />
448-
449-
<sf:deploy xmlns:sf="antlib:com.salesforce" username="${username}" password="${password}" deployRoot="${salesforce.component.root}/it/resources/salesforce" rollbackOnError="true" serverurl="${serverurl}" />
450-
</target>
402+
<executable>bash</executable>
403+
<workingDirectory>${salesforce.component.root}/it/resources</workingDirectory>
404+
<arguments>
405+
<argument>setup-salesforce.sh</argument>
406+
</arguments>
407+
<environmentVariables>
408+
<SALESFORCE_USERNAME>${env.SALESFORCE_USERNAME}</SALESFORCE_USERNAME>
409+
<SALESFORCE_PASSWORD>${env.SALESFORCE_PASSWORD}</SALESFORCE_PASSWORD>
410+
<SALESFORCE_LOGIN_URL>${env.SALESFORCE_LOGIN_URL}</SALESFORCE_LOGIN_URL>
411+
<SALESFORCE_DEV_HUB>${env.SALESFORCE_DEV_HUB}</SALESFORCE_DEV_HUB>
412+
<SALESFORCE_DEPLOY_SOURCE>${env.SALESFORCE_DEPLOY_SOURCE}</SALESFORCE_DEPLOY_SOURCE>
413+
<SALESFORCE_SCRATCH_ORG_DURATION>${env.SALESFORCE_SCRATCH_ORG_DURATION}</SALESFORCE_SCRATCH_ORG_DURATION>
414+
</environmentVariables>
451415
</configuration>
452416
</execution>
453417
</executions>
454-
<dependencies>
455-
<dependency>
456-
<groupId>org.apache.ant</groupId>
457-
<artifactId>ant</artifactId>
458-
<version>1.10.15</version>
459-
</dependency>
460-
</dependencies>
461418
</plugin>
462419
<plugin>
463420
<artifactId>maven-failsafe-plugin</artifactId>

components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceLoginConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public AuthenticationType getType() {
193193
throw new IllegalArgumentException(
194194
"You must specify parameters aligned with one of the supported authentication methods:"
195195
+ " for username and password authentication: userName, password, clientSecret;"
196-
+ " for refresh token authentication: refreshToken, clientSecret;"
196+
+ " for refresh token authentication: refreshToken (clientSecret optional);"
197197
+ " for JWT: userName, keystore. And for every one of those loginUrl and clientId must be specified also.");
198198
}
199199

@@ -252,7 +252,7 @@ public void validate() {
252252
break;
253253
case REFRESH_TOKEN:
254254
ObjectHelper.notNull(refreshToken, "refreshToken (authentication with refresh token)");
255-
ObjectHelper.notNull(clientSecret, "clientSecret (authentication with refresh token)");
255+
// clientSecret can be optional for refresh token flow
256256
break;
257257
case JWT:
258258
ObjectHelper.notNull(userName, "userName (JWT authentication)");

components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/SalesforceSession.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ public Request getLoginRequest(HttpConversation conversation) {
220220
fields.put("password", config.getPassword());
221221
break;
222222
case REFRESH_TOKEN:
223-
fields.put("client_secret", config.getClientSecret());
223+
if (ObjectHelper.isNotEmpty(config.getClientSecret())) {
224+
fields.put("client_secret", config.getClientSecret());
225+
}
224226
fields.put("grant_type", "refresh_token");
225227
fields.put("refresh_token", config.getRefreshToken());
226228
break;

components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/BulkApiJobManualIT.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.camel.component.salesforce;
1818

19-
import java.io.IOException;
2019
import java.util.ArrayList;
2120
import java.util.List;
2221
import java.util.stream.Collectors;
@@ -26,23 +25,13 @@
2625
import org.apache.camel.component.salesforce.api.dto.bulk.JobStateEnum;
2726
import org.apache.camel.component.salesforce.api.dto.bulk.OperationEnum;
2827
import org.apache.camel.component.salesforce.dto.generated.Merchandise__c;
29-
import org.junit.jupiter.api.BeforeEach;
3028
import org.junit.jupiter.params.ParameterizedTest;
3129
import org.junit.jupiter.params.provider.MethodSource;
3230

3331
import static org.junit.jupiter.api.Assertions.assertSame;
3432

3533
public class BulkApiJobManualIT extends AbstractBulkApiTestBase {
3634

37-
@BeforeEach
38-
public void setupProfileWithHardDelete() throws IOException {
39-
final SalesforceLoginConfig loginConfig = LoginConfigHelper.getLoginConfig();
40-
41-
template().requestBodyAndHeader("salesforce:apexCall/UpdateProfile?apexMethod=PATCH&sObjectClass=java.lang.String",
42-
null,
43-
SalesforceEndpointConfig.APEX_QUERY_PARAM_PREFIX + "username", loginConfig.getUserName());
44-
}
45-
4635
@ParameterizedTest
4736
@MethodSource("getJobs")
4837
public void testJobLifecycle(JobInfo jobInfo, String operationName) throws Exception {

0 commit comments

Comments
 (0)