allMetadata, String testClassRegex)
159 | {
160 | String match = "noneFound";
161 | Matcher matcher;
162 |
163 | for (String s : allMetadata)
164 | {
165 | matcher = Pattern.compile(testClassRegex).matcher(s);
166 | if (matcher.find())
167 | {
168 | match = s;
169 | break;
170 | }
171 | }
172 |
173 | return match;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/global.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-maxPoll.html:
--------------------------------------------------------------------------------
1 |
2 | The number of times to poll the server for the results of the deploy
3 | request. Note that deployment may succeed even if you stop waiting.
4 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-password.html:
--------------------------------------------------------------------------------
1 |
2 | The password for the user you provided above.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-pollWait.html:
--------------------------------------------------------------------------------
1 |
2 | The number of milliseconds to wait when polling for results of
3 | the deployment. Note that deployment may succeed even if you stop waiting.
4 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-prTargetBranch.html:
--------------------------------------------------------------------------------
1 |
2 | If this job is configured to deploy or validate pull requests, specify what the target branch will be (e.g. "develop").
3 |
4 | SMA will use this information to generate the appropriate delta as pull requests must be handled differently.
5 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-proxyPass.html:
--------------------------------------------------------------------------------
1 |
2 | The password for the proxy user entered above.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-proxyPort.html:
--------------------------------------------------------------------------------
1 |
2 | The port needed for proxy server defined above.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-proxyServer.html:
--------------------------------------------------------------------------------
1 |
2 | If you're behind a proxy, use this field to configure your proxy server.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-proxyUser.html:
--------------------------------------------------------------------------------
1 |
2 | If your proxy requires authentication, enter the username here.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-runTestRegex.html:
--------------------------------------------------------------------------------
1 |
2 | Enter a valid Java regular expression to enable SMA to find your unmanaged package unit tests.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-securityToken.html:
--------------------------------------------------------------------------------
1 |
2 | The security token for the user.
3 |
4 | You can leave this field blank if you do not use security tokens in your organization.
5 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-serverType.html:
--------------------------------------------------------------------------------
1 |
2 | The instance type of Salesforce that you are deploying against.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-testLevel.html:
--------------------------------------------------------------------------------
1 |
2 | The test level you wish to perform this deployment at.
3 |
4 | - None: No tests will be run during this deployment.
5 | - Relevant: the RunSpecifiedTests level. Jenkins will use the information provided in the Run Test Regex field under the System Configuration section to determine which set of tests need to be run for this particular deployment. A warning will be generated in Jenkins log if no relevant test is found for a particular ApexClass.
6 | - Local: All unit tests are run, excluding those found in managed packages.
7 | - All: All unit tests are run, including those found in managed packages.
8 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-username.html:
--------------------------------------------------------------------------------
1 |
2 | The Salesforce user that will perform the deployment.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/SMABuilder/help-validateEnabled.html:
--------------------------------------------------------------------------------
1 |
2 | Indicate whether you would like to perform a test deployment only.
3 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/index.jelly:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 | This Jenkins plugin generates automatically deploys metadata changes to a Salesforce organization based on differences between two commits in Git. Instead of deploying a repository's contents every time a change is made, the plugin can determine what metadata needs to be deployed and deleted and coordinate only those changes. This has the benefit of drastically reducing deployment times and uncoupling the reliance on the package manifest file (package.xml).
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/sma/salesforceMetadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CustomApplication
5 | applications
6 | true
7 | false
8 |
9 |
10 | AppMenu
11 | appMenus
12 | false
13 | false
14 |
15 |
16 | ApprovalProcess
17 | approvalProcesses
18 | true
19 | false
20 |
21 |
22 | AssignmentRule
23 | assignmentRules
24 | true
25 | false
26 |
27 |
28 | AuthProvider
29 | authproviders
30 | true
31 | false
32 |
33 |
34 | AutoResponseRule
35 | autoResponseRules
36 | true
37 | false
38 |
39 |
40 | CallCenter
41 | callCenters
42 | true
43 | false
44 |
45 |
46 | Community
47 | communities
48 | true
49 | false
50 |
51 |
52 | ApexClass
53 | classes
54 | true
55 | true
56 |
57 |
58 | CustomPermission
59 | customPermissions
60 | true
61 | false
62 |
63 |
64 | ApexComponent
65 | components
66 | true
67 | true
68 |
69 |
70 | ConnectedApp
71 | connectedapps
72 | true
73 | false
74 |
75 |
76 | CustomApplicationComponent
77 | customApplicationComponents
78 | true
79 | false
80 |
81 |
82 | Dashboard
83 | dashboards
84 | true
85 | false
86 |
87 |
88 | DataCategoryGroups
89 | datacategorygroups
90 | true
91 | false
92 |
93 |
94 | Document
95 | documents
96 | true
97 | false
98 |
99 |
100 | EmailTemplate
101 | emails
102 | true
103 | false
104 |
105 |
106 | EntitlementProcess
107 | entitlementProcesses
108 | true
109 | false
110 |
111 |
112 | EscalationRules
113 | escalationRules
114 | true
115 | false
116 |
117 |
118 | FlexiPage
119 | flexipages
120 | true
121 | false
122 |
123 |
124 | Flow
125 | flow
126 |
127 |
128 | ExternalDataSource
129 | dataSources
130 | true
131 | false
132 |
133 |
134 | Group
135 | groups
136 | true
137 | false
138 |
139 |
140 | HomePageComponent
141 | homepagecomponents
142 | true
143 | false
144 |
145 |
146 | HomePageLayout
147 | homepageLayouts
148 | true
149 | false
150 |
151 |
152 | CustomLabels
153 | labels
154 | true
155 | false
156 |
157 |
158 | Layout
159 | layouts
160 | true
161 | false
162 |
163 |
164 | Letterhead
165 | letterhead
166 | true
167 | false
168 |
169 |
170 | LiveChatAgentConfig
171 | liveChatAgentConfigs
172 | true
173 | false
174 |
175 |
176 | LiveChatButton
177 | liveChatButtons
178 | true
179 | false
180 |
181 |
182 | LiveChatDeployment
183 | liveChatDeployments
184 | true
185 | false
186 |
187 |
188 | Milestonetype
189 | milestonetypes
190 | true
191 | false
192 |
193 |
194 | Network
195 | networks
196 | true
197 | false
198 |
199 |
200 | CustomObject
201 | objects
202 | true
203 | false
204 |
205 |
206 | CustomObjectTranslation
207 | objectTranslations
208 | true
209 | false
210 |
211 |
212 | ApexPage
213 | pages
214 | true
215 | true
216 |
217 |
218 | PermissionSet
219 | permissionsets
220 | true
221 | false
222 |
223 |
224 | Portal
225 | portals
226 | true
227 | false
228 |
229 |
230 | PostTemplate
231 | postTemplates
232 | true
233 | false
234 |
235 |
236 | Profile
237 | profiles
238 | true
239 | false
240 |
241 |
242 | Queue
243 | queues
244 | true
245 | false
246 |
247 |
248 | QuickAction
249 | quickActions
250 | true
251 | false
252 |
253 |
254 | RemoteSite
255 | remoteSiteSettings
256 | true
257 | false
258 |
259 |
260 | Reports
261 | reports
262 | true
263 | false
264 |
265 |
266 | ReportType
267 | reporttype
268 | true
269 | false
270 |
271 |
272 | Role
273 | roles
274 | true
275 | false
276 |
277 |
278 | SamlSsoConfig
279 | samlssoconfigs
280 | false
281 | false
282 |
283 |
284 | Settings
285 | settings
286 | true
287 | false
288 |
289 |
290 | SharingSet
291 | sharingSets
292 | true
293 | false
294 |
295 |
296 | CustomSite
297 | sites
298 | true
299 | false
300 |
301 |
302 | Skill
303 | skills
304 | true
305 | false
306 |
307 |
308 | Territory
309 | territories
310 | true
311 | false
312 |
313 |
314 | Translation
315 | translations
316 | true
317 | false
318 |
319 |
320 | ApexTrigger
321 | triggers
322 | true
323 | true
324 |
325 |
326 | CustomTab
327 | tabs
328 | true
329 | false
330 |
331 |
332 | StaticResource
333 | staticresources
334 | true
335 | true
336 |
337 |
338 | CustomPageWeblink
339 | weblinks
340 | true
341 | false
342 |
343 |
344 | Workflow
345 | workflows
346 | false
347 | false
348 |
349 |
355 |
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/sma/SMAConnectionTest.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.sma;
2 |
3 | import com.google.common.io.Files;
4 | import com.sforce.soap.metadata.CodeCoverageResult;
5 | import com.sforce.soap.metadata.DeployDetails;
6 | import com.sforce.soap.metadata.RunTestsResult;
7 | import com.sforce.soap.metadata.TestLevel;
8 | import org.junit.After;
9 | import org.junit.Assert;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 |
13 | import java.io.ByteArrayOutputStream;
14 | import java.io.File;
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | public class SMAConnectionTest
21 | {
22 | //TODO: need to mock this configuration
23 | SMAConnection sfConnection;
24 | String username = "";
25 | String password = "";
26 | String securityToken = "";
27 | String server = "";
28 | String proxyServer = "";
29 | String proxyUser = "";
30 | String proxyPass = "";
31 | Integer proxyPort;
32 | File localPath;
33 | ByteArrayOutputStream boas;
34 |
35 | @Before
36 | public void setUp() throws Exception
37 | {
38 | localPath = Files.createTempDir();
39 |
40 | String apex = "public class TestApex {}";
41 | StringBuilder sb = new StringBuilder();
42 | sb.append("");
43 | sb.append("34.0");
44 | sb.append("Active");
45 | sb.append("");
46 |
47 | Map metadata = new HashMap();
48 | metadata.put("classes/TestApex.cls", apex.getBytes());
49 | metadata.put("classes/TestApex.cls-meta.xml", sb.toString().getBytes());
50 |
51 | List metadataList = new ArrayList();
52 |
53 | for (String s : metadata.keySet())
54 | {
55 | if (!s.contains("-meta.xml"))
56 | {
57 | metadataList.add(SMAMetadataTypes.createMetadataObject(s, metadata.get(s)));
58 | }
59 | }
60 |
61 | SMAPackage packageManifest = new SMAPackage(metadataList, false);
62 | SMAPackage destructiveChange = new SMAPackage(new ArrayList(), true);
63 |
64 | boas = SMAUtility.zipPackage(metadata, packageManifest, destructiveChange);
65 |
66 | SMAUtility.writeZip(boas, localPath.getPath() + "/testDeploy.zip");
67 |
68 |
69 | }
70 |
71 | @Test
72 | public void testDeployment() throws Exception
73 | {
74 | boolean success;
75 |
76 | if (username.isEmpty() || password.isEmpty() || securityToken.isEmpty())
77 | {
78 | success = true;
79 | }
80 | else
81 | {
82 | sfConnection = new SMAConnection(
83 | username,
84 | password,
85 | securityToken,
86 | server,
87 | "30000",
88 | "200",
89 | proxyServer,
90 | proxyUser,
91 | proxyPass,
92 | proxyPort
93 | );
94 |
95 | success = sfConnection.deployToServer(
96 | boas,
97 | TestLevel.NoTestRun,
98 | null,
99 | true,
100 | true
101 | );
102 | }
103 |
104 | Assert.assertTrue(success);
105 | }
106 |
107 | @Test
108 | public void testGetCodeCoverageResults() throws Exception
109 | {
110 | if (username.isEmpty() || password.isEmpty() || securityToken.isEmpty())
111 | {
112 | Assert.assertTrue(true);
113 | }
114 | else
115 | {
116 | sfConnection = new SMAConnection(
117 | username,
118 | password,
119 | securityToken,
120 | server,
121 | "30000",
122 | "200",
123 | proxyServer,
124 | proxyUser,
125 | proxyPass,
126 | proxyPort
127 | );
128 |
129 | StringBuilder sb = new StringBuilder();
130 | sb.append(
131 | "[SMA] Code Coverage Results\n" +
132 | "1st Test.cls -- 80%\n" +
133 | "2nd Test.cls -- 80%\n" +
134 | "\n" +
135 | "Total code coverage for this deployment -- 80%" +
136 | "\n"
137 | );
138 | String expectedCoverage = sb.toString();
139 | DeployDetails details = new DeployDetails();
140 | RunTestsResult testsResult = new RunTestsResult();
141 |
142 | CodeCoverageResult testCCR1 = new CodeCoverageResult();
143 | testCCR1.setName("1st Test");
144 | testCCR1.setNumLocations(10);
145 | testCCR1.setNumLocationsNotCovered(2);
146 | CodeCoverageResult testCCR2 = new CodeCoverageResult();
147 | testCCR2.setName("2nd Test");
148 | testCCR2.setNumLocations(20);
149 | testCCR2.setNumLocationsNotCovered(4);
150 |
151 | CodeCoverageResult[] expectedCCR = new CodeCoverageResult[]{testCCR1, testCCR2};
152 |
153 | testsResult.setCodeCoverage(expectedCCR);
154 | details.setRunTestResult(testsResult);
155 |
156 | sfConnection.setDeployDetails(details);
157 |
158 | String actualCoverage = sfConnection.getCodeCoverage();
159 | Assert.assertEquals(expectedCoverage, actualCoverage);
160 | }
161 | }
162 |
163 | @After
164 | public void tearDown() throws Exception
165 | {
166 | localPath.delete();
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/sma/SMAGitTest.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.sma;
2 |
3 | import org.apache.commons.io.FileUtils;
4 | import org.eclipse.jgit.api.CreateBranchCommand;
5 | import org.eclipse.jgit.api.Git;
6 | import org.eclipse.jgit.lib.Repository;
7 | import org.eclipse.jgit.revwalk.RevCommit;
8 | import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
9 | import org.junit.After;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 |
13 | import java.io.File;
14 | import java.io.PrintWriter;
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | import static org.junit.Assert.assertEquals;
21 | import static org.junit.Assert.assertTrue;
22 |
23 | public class SMAGitTest
24 | {
25 |
26 | private Repository repository;
27 | private SMAGit git;
28 | private File addition, addMeta;
29 | private File modification, modifyMeta;
30 | private File deletion, deleteMeta;
31 | private File localPath;
32 | private String oldSha, newSha, gitDir;
33 | private final String contents = "\n";
34 |
35 | /**
36 | * Before to setup the test.
37 | *
38 | * @throws Exception
39 | */
40 | @Before
41 | public void setUp() throws Exception
42 | {
43 | //Setup the fake repository
44 | localPath = File.createTempFile("TestGitRepository", "");
45 | localPath.delete();
46 | repository = FileRepositoryBuilder.create(new File(localPath, ".git"));
47 | repository.create();
48 |
49 | File classesPath = new File(repository.getDirectory().getParent() + "/src/classes");
50 | classesPath.mkdirs();
51 | File pagesPath = new File(repository.getDirectory().getParent() + "/src/pages");
52 | pagesPath.mkdirs();
53 | File triggersPath = new File(repository.getDirectory().getParent() + "/src/triggers");
54 | triggersPath.mkdirs();
55 |
56 |
57 | //Add the first collection of files
58 | deletion = createFile("deleteThis.cls", classesPath);
59 | deleteMeta = createFile("deleteThis.cls-meta.xml", classesPath);
60 | modification = createFile("modifyThis.page", pagesPath);
61 | modifyMeta = createFile("modifyThis.page-meta.xml", pagesPath);
62 | new Git(repository).add().addFilepattern("src/classes/deleteThis.cls").call();
63 | new Git(repository).add().addFilepattern("src/classes/deleteThis.cls-meta.xml").call();
64 | new Git(repository).add().addFilepattern("src/pages/modifyThis.page").call();
65 | new Git(repository).add().addFilepattern("src/pages/modifyThis.page-meta.xml").call();
66 |
67 | //Create the first commit
68 | RevCommit firstCommit = new Git(repository).commit().setMessage("Add deleteThis and modifyThis").call();
69 | oldSha = firstCommit.getName();
70 |
71 |
72 | //Delete the deletion file, modify the modification file, and add the addition file
73 | new Git(repository).rm().addFilepattern("src/classes/deleteThis.cls").call();
74 | new Git(repository).rm().addFilepattern("src/classes/deleteThis.cls-meta.xml").call();
75 | modification.setExecutable(true);
76 | addition = createFile("addThis.trigger", triggersPath);
77 | addMeta = createFile("addThis.trigger-meta.xml", triggersPath);
78 | new Git(repository).add().addFilepattern("src/pages/modifyThis.page").call();
79 | new Git(repository).add().addFilepattern("src/pages/modifyThis.page-meta.xml").call();
80 | new Git(repository).add().addFilepattern("src/triggers/addThis.trigger").call();
81 | new Git(repository).add().addFilepattern("src/triggers/addThis.trigger-meta.xml").call();
82 | new Git(repository).add().addFilepattern("src/classes/deleteThis.cls").call();
83 | new Git(repository).add().addFilepattern("src/classes/deleteThis.cls-meta.xml").call();
84 |
85 | //Create the second commit
86 | RevCommit secondCommit = new Git(repository).commit().setMessage("Remove deleteThis. Modify " +
87 | "modifyThis. Add addThis.").call();
88 | newSha = secondCommit.getName();
89 |
90 | gitDir = localPath.getPath();
91 | }
92 |
93 | /**
94 | * After to tear down the test.
95 | *
96 | * @throws Exception
97 | */
98 | @After
99 | public void tearDown() throws Exception
100 | {
101 | repository.close();
102 | FileUtils.deleteDirectory(localPath);
103 | }
104 |
105 | /**
106 | * Test the diff capability of the wrapper.
107 | *
108 | * @throws Exception
109 | */
110 | @Test
111 | public void testDiff() throws Exception
112 | {
113 | Map expectedDelete = new HashMap();
114 | expectedDelete.put("src/classes/deleteThis.cls", contents.getBytes());
115 |
116 | Map expectedMods = new HashMap();
117 | expectedMods.put("src/pages/modifyThis.page", contents.getBytes());
118 |
119 | Map expectedAdds = new HashMap();
120 | expectedAdds.put("src/triggers/addThis.trigger", contents.getBytes());
121 |
122 | git = new SMAGit(gitDir, newSha, oldSha, SMAGit.Mode.STD);
123 |
124 | Map deletedContents = git.getDeletedMetadata();
125 | Map modifiedContents = git.getUpdatedMetadata();
126 | Map addedContents = git.getNewMetadata();
127 |
128 | assertEquals(expectedAdds.size(), addedContents.size());
129 | assertEquals(expectedMods.size(), modifiedContents.size());
130 | assertEquals(expectedDelete.size(), deletedContents.size());
131 | }
132 |
133 | /**
134 | * Test the overloaded constructors.
135 | *
136 | * @throws Exception
137 | */
138 | @Test
139 | public void testInitialCommit() throws Exception
140 | {
141 | Map expectedContents = new HashMap();
142 | expectedContents.put("src/pages/modifyThis.page", contents.getBytes());
143 | expectedContents.put("src/pages/modifyThis.page-meta.xml", contents.getBytes());
144 | expectedContents.put("src/triggers/addThis.trigger", contents.getBytes());
145 | expectedContents.put("src/triggers/addThis.trigger-meta.xml", contents.getBytes());
146 |
147 | git = new SMAGit(gitDir, newSha, null, SMAGit.Mode.INI);
148 |
149 | Map allMetadata = git.getAllMetadata();
150 |
151 | assertEquals(expectedContents.size(), allMetadata.size());
152 | }
153 |
154 | /**
155 | * Test the ghprb constructor.
156 | *
157 | * @throws Exception
158 | */
159 | @Test
160 | public void testPullRequest() throws Exception
161 | {
162 | Map expectedContents = new HashMap();
163 | expectedContents.put("src/pages/modifyThis.page", contents.getBytes());
164 | expectedContents.put("src/pages/modifyThis.page-meta.xml", contents.getBytes());
165 | expectedContents.put("src/triggers/addThis.trigger", contents.getBytes());
166 | expectedContents.put("src/triggers/addThis.trigger-meta.xml", contents.getBytes());
167 |
168 | String oldBranch = "refs/remotes/origin/oldBranch";
169 | CreateBranchCommand cbc = new Git(repository).branchCreate();
170 | cbc.setName(oldBranch);
171 | cbc.setStartPoint(oldSha);
172 | cbc.call();
173 |
174 | git = new SMAGit(gitDir, newSha, "oldBranch", SMAGit.Mode.PRB);
175 |
176 | Map allMetadata = git.getAllMetadata();
177 |
178 | assertEquals(expectedContents.size(), allMetadata.size());
179 | }
180 |
181 | /**
182 | * Test the ability to update the package manifest.
183 | *
184 | * @throws Exception
185 | */
186 | @Test
187 | public void testCommitPackageXML() throws Exception
188 | {
189 | Map metadataContents = new HashMap();
190 | List metadata = new ArrayList();
191 |
192 | git = new SMAGit(gitDir, newSha, oldSha, SMAGit.Mode.STD);
193 | metadataContents = git.getUpdatedMetadata();
194 | metadataContents.putAll(git.getNewMetadata());
195 |
196 | for (String s : metadataContents.keySet())
197 | {
198 | metadata.add(SMAMetadataTypes.createMetadataObject(s, metadataContents.get(s)));
199 | }
200 |
201 | SMAPackage manifest = new SMAPackage(metadata, false);
202 |
203 | Boolean createdManifest = git.updatePackageXML(
204 | localPath.getPath(),
205 | "Test Guy",
206 | "testguy@example.net",
207 | manifest
208 | );
209 |
210 | assertTrue(createdManifest);
211 | }
212 |
213 | /**
214 | * Test the ability to update the package manifest.
215 | *
216 | * @throws Exception
217 | */
218 | @Test
219 | public void testCommitExistingPackage() throws Exception
220 | {
221 | File sourceDir = new File(localPath.getPath() + "/src");
222 | File existingPackage = createFile("package.xml", sourceDir);
223 |
224 | new Git(repository).add().addFilepattern("src/package.xml").call();
225 | new Git(repository).commit().setMessage("Add package.xml").call();
226 |
227 | Map metadataContents = new HashMap();
228 | List metadata = new ArrayList();
229 |
230 | git = new SMAGit(gitDir, newSha, oldSha, SMAGit.Mode.STD);
231 | metadataContents = git.getUpdatedMetadata();
232 | metadataContents.putAll(git.getNewMetadata());
233 |
234 | for (String s : metadataContents.keySet())
235 | {
236 | metadata.add(SMAMetadataTypes.createMetadataObject(s, metadataContents.get(s)));
237 | }
238 |
239 | SMAPackage manifest = new SMAPackage(metadata, false);
240 |
241 | Boolean createdManifest = git.updatePackageXML(
242 | localPath.getPath(),
243 | "Test Guy",
244 | "testguy@example.net",
245 | manifest
246 | );
247 |
248 | assertTrue(createdManifest);
249 |
250 | // Also check to make sure we didn't create the default package
251 | File unexpectedPackage = new File(localPath.getPath() + "/unpackaged/package.xml");
252 | assertTrue(!unexpectedPackage.exists());
253 | }
254 |
255 | private File createFile(String name, File path) throws Exception
256 | {
257 | File thisFile;
258 |
259 | thisFile = new File(path, name);
260 | thisFile.createNewFile();
261 |
262 | PrintWriter print = new PrintWriter(thisFile);
263 | print.println(contents);
264 | print.close();
265 |
266 | return thisFile;
267 | }
268 | }
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/sma/SMAMetadataTest.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.sma;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.assertEquals;
7 | import static org.junit.Assert.assertTrue;
8 |
9 | public class SMAMetadataTest {
10 |
11 | private SMAMetadata metadataObject;
12 | String extension = ".ext";
13 | String container = "container";
14 | String member = "Member";
15 | String metadataType = "MDType";
16 | String path = "src/container/";
17 | boolean destructible = true;
18 | boolean valid = true;
19 | boolean metaxml = true;
20 | String body = "";
21 |
22 | @Before
23 | public void setUp() throws Exception {
24 | metadataObject = new SMAMetadata(extension, container, member, metadataType,
25 | path, destructible, valid, metaxml, body.getBytes());
26 | }
27 |
28 | @Test
29 | public void testGetExtension() throws Exception {
30 | assertEquals(extension, metadataObject.getExtension());
31 | }
32 |
33 | @Test
34 | public void testGetContainer() throws Exception {
35 | assertEquals(container, metadataObject.getContainer());
36 | }
37 |
38 | @Test
39 | public void testGetPath() throws Exception {
40 | assertEquals(path, metadataObject.getPath());
41 | }
42 |
43 | @Test
44 | public void testGetMember() throws Exception {
45 | assertEquals(member, metadataObject.getMember());
46 | }
47 |
48 | @Test
49 | public void testGetMetadataType() throws Exception {
50 | assertEquals(metadataType, metadataObject.getMetadataType());
51 | }
52 |
53 | @Test
54 | public void testIsDestructible() throws Exception {
55 | if (destructible){
56 | assertTrue(metadataObject.isDestructible());
57 | }else{
58 | assertTrue(!metadataObject.isDestructible());
59 | }
60 | }
61 |
62 | @Test
63 | public void testHasMetaxml() throws Exception {
64 | if (metaxml){
65 | assertTrue(metadataObject.hasMetaxml());
66 | }else{
67 | assertTrue(!metadataObject.hasMetaxml());
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/sma/SMAPackageTest.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.sma;
2 |
3 | import org.apache.commons.io.FileUtils;
4 | import org.junit.After;
5 | import org.junit.Assert;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import java.io.File;
10 | import java.util.Arrays;
11 | import java.util.List;
12 |
13 | public class SMAPackageTest
14 | {
15 | private String jenkinsHome;
16 | private String runTestRegex;
17 | private String pollWait;
18 | private String maxPoll;
19 | private List contents;
20 | private File testWorkspace;
21 | private String testWorkspacePath;
22 |
23 | @Before
24 | public void setUp() throws Exception
25 | {
26 | //Setup the fake workspace and package manifest
27 | testWorkspace = File.createTempFile("TestWorkspace", "");
28 | testWorkspace.delete();
29 | testWorkspace.mkdirs();
30 | testWorkspacePath = testWorkspace.getPath();
31 |
32 | String emptyString = "";
33 |
34 | SMAMetadata apex = SMAMetadataTypes.createMetadataObject("/src/classes/TestApex.cls", emptyString.getBytes());
35 | SMAMetadata trigger = SMAMetadataTypes.createMetadataObject("/src/triggers/TestTrigger.trigger", emptyString.getBytes());
36 | SMAMetadata page = SMAMetadataTypes.createMetadataObject("/src/pages/TestPage.page", emptyString.getBytes());
37 | SMAMetadata workflow = SMAMetadataTypes.createMetadataObject("/src/workflows/TestWorkflow.workflow", emptyString.getBytes());
38 |
39 | contents = Arrays.asList(apex, trigger, page, workflow);
40 | }
41 |
42 | @Test
43 | public void testPackage() throws Exception
44 | {
45 | SMAPackage testPackage = new SMAPackage(contents, false);
46 |
47 | System.out.println(testPackage.getPackage());
48 |
49 | Assert.assertTrue(testPackage.getPackage().contains("Workflow"));
50 | }
51 |
52 | @Test
53 | public void testDestructiveChange() throws Exception
54 | {
55 | SMAPackage testPackage = new SMAPackage(contents, true);
56 |
57 | System.out.println(testPackage.getPackage());
58 |
59 | Assert.assertTrue(!testPackage.getPackage().contains("Workflow"));
60 | }
61 |
62 | @After
63 | public void tearDown() throws Exception
64 | {
65 | FileUtils.deleteDirectory(testWorkspace);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/sma/SMAUtilityTest.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.sma;
2 |
3 | import com.google.common.io.Files;
4 | import org.junit.After;
5 | import org.junit.Assert;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.File;
11 | import java.util.ArrayList;
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | public class SMAUtilityTest
17 | {
18 | File localPath;
19 | Map metadata;
20 | SMAPackage packageManifest;
21 | SMAPackage destructiveChange;
22 |
23 | @Before
24 | public void setUp() throws Exception
25 | {
26 | localPath = Files.createTempDir();
27 |
28 | String[] strings = {"TestContents", "TestXML"};
29 |
30 | metadata = new HashMap();
31 | metadata.put("classes/TestApex.cls", strings[0].getBytes());
32 | metadata.put("classes/TestApex.cls-meta.xml", strings[1].getBytes());
33 | metadata.put("pages/TestPages.page", strings[0].getBytes());
34 | metadata.put("pages/TestPages.page-meta.xml", strings[1].getBytes());
35 | metadata.put("triggers/TestTrigger.trigger", strings[0].getBytes());
36 | metadata.put("triggers/TestTrigger.trigger-meta.xml", strings[1].getBytes());
37 |
38 | List metadataList = new ArrayList();
39 |
40 | for (String s : metadata.keySet())
41 | {
42 | if (!s.contains("-meta.xml"))
43 | {
44 | metadataList.add(SMAMetadataTypes.createMetadataObject(s, metadata.get(s)));
45 | }
46 | }
47 |
48 | packageManifest = new SMAPackage(metadataList, false);
49 | destructiveChange = new SMAPackage(metadataList, true);
50 | }
51 |
52 | @After
53 | public void tearDown() throws Exception
54 | {
55 | localPath.delete();
56 | }
57 |
58 | @Test
59 | public void testZipPackage() throws Exception
60 | {
61 | ByteArrayOutputStream testStream = new ByteArrayOutputStream();
62 |
63 | testStream = SMAUtility.zipPackage(metadata, packageManifest, destructiveChange);
64 |
65 | System.out.println(testStream);
66 |
67 | Assert.assertNotNull(testStream);
68 | }
69 |
70 | @Test
71 | public void testWriteZip() throws Exception
72 | {
73 | ByteArrayOutputStream testStream = new ByteArrayOutputStream();
74 |
75 | testStream = SMAUtility.zipPackage(metadata, packageManifest, destructiveChange);
76 |
77 | SMAUtility.writeZip(testStream, localPath.getPath() + "/streamToZip.zip");
78 |
79 | File zipFile = new File(localPath.getPath() + "/streamToZip.zip");
80 |
81 | Assert.assertTrue(zipFile.exists());
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/test/resources/testAddsMods.txt:
--------------------------------------------------------------------------------
1 | src/classes/Test.cls
2 | src/classes/Test.cls-meta.xml
3 | src/components/Test.component
4 | src/components/Test.component-meta.xml
5 | src/pages/Test.page
6 | src/pages/Test.page-meta.xml
7 | src/triggers/Test.trigger
8 | src/triggers/Test.trigger-meta.xml
9 | src/staticresources/Test.resource
10 | src/staticresources/Test.resource-meta.xml
11 | src/classes/Test2.cls
12 | src/classes/Test2.cls-meta.xml
13 | src/components/Test2.component
14 | src/components/Test2.component-meta.xml
15 | src/pages/Test2.page
16 | src/pages/Test2.page-meta.xml
17 | src/triggers/Test2.trigger
18 | src/triggers/Test2.trigger-meta.xml
19 | src/staticresources/Test2.resource
20 | src/staticresources/Test2.resource-meta.xml
21 |
--------------------------------------------------------------------------------
/src/test/resources/testDeletes.txt:
--------------------------------------------------------------------------------
1 | src/classes/Test.cls
2 | src/classes/Test.cls-meta.xml
3 | src/components/Test.component
4 | src/components/Test.component-meta.xml
5 | src/pages/Test.page
6 | src/pages/Test.page-meta.xml
7 | src/triggers/Test.trigger
8 | src/triggers/Test.trigger-meta.xml
9 | src/staticresources/Test.resource
10 | src/staticresources/Test.resource-meta.xml
11 | src/classes/Test2.cls
12 | src/classes/Test2.cls-meta.xml
13 | src/components/Test2.component
14 | src/components/Test2.component-meta.xml
15 | src/pages/Test2.page
16 | src/pages/Test2.page-meta.xml
17 | src/triggers/Test2.trigger
18 | src/triggers/Test2.trigger-meta.xml
19 | src/staticresources/Test2.resource
20 | src/staticresources/Test2.resource-meta.xml
21 | src/appMenus/Test.appMenu
22 | src/samlssoconfigs/Test.samlssoconfig
23 | src/workflows/Test.workflow
--------------------------------------------------------------------------------
/src/test/resources/testPackage.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ApexClass
5 | Test
6 | Test2
7 |
8 |
9 | ApexComponent
10 | Test
11 | Test2
12 |
13 |
14 | ApexPage
15 | Test
16 | Test2
17 |
18 |
19 | ApexTrigger
20 | Test
21 | Test2
22 |
23 |
24 | StaticResource
25 | Test
26 | Test2
27 |
28 | 32.0
29 |
30 |
--------------------------------------------------------------------------------