This repository has been archived by the owner on Jun 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logs (and tests) to the force-user-permset-assign task
- Loading branch information
Showing
4 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/test/com/mcartoixa/ant/sfdx/force/user/permset/AssignTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright 2021 Mathieu Cartoixa. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mcartoixa.ant.sfdx.force.user.permset; | ||
|
||
import java.io.File; | ||
import org.apache.tools.ant.BuildFileRule; | ||
import org.apache.tools.ant.Project; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
/** | ||
* | ||
* @author Mathieu Cartoixa | ||
*/ | ||
public class AssignTaskTest { | ||
|
||
@Rule | ||
public final BuildFileRule buildRule = new BuildFileRule(); | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
public AssignTaskTest() { | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
buildRule.configureProject("src/test/com/mcartoixa/ant/sfdx/force/user/permset/assign.xml", Project.MSG_DEBUG); | ||
} | ||
|
||
@Test | ||
public void executeShouldSetStatusProperty() { | ||
buildRule.executeTarget("execute"); | ||
Assert.assertEquals("Status property should be set", "0", buildRule.getProject().getProperty("execute.status")); | ||
} | ||
|
||
@Test | ||
public void executeShouldAddJsonArgument() { | ||
buildRule.executeTarget("execute"); | ||
Assert.assertTrue("Full log should contain --json argument", buildRule.getFullLog().contains("'--json'")); | ||
} | ||
|
||
@Test | ||
public void executeShouldAddPermsetNameArgument() { | ||
buildRule.executeTarget("execute"); | ||
Assert.assertTrue("Full log should contain -n argument", buildRule.getFullLog().contains("'-n'" + System.lineSeparator() + "'testpermset'")); | ||
} | ||
|
||
@Test | ||
public void executeShouldAddOnBehalfOfArgument() { | ||
buildRule.executeTarget("execute"); | ||
Assert.assertTrue("Full log should contain -o argument", buildRule.getFullLog().contains("'-o'" + System.lineSeparator() + "'testtarget'")); | ||
} | ||
|
||
@Test | ||
public void executeShouldAddTargetUsernameArgument() { | ||
buildRule.executeTarget("execute"); | ||
Assert.assertTrue("Full log should contain -u argument", buildRule.getFullLog().contains("'-u'" + System.lineSeparator() + "'testuser'")); | ||
} | ||
|
||
@Test | ||
public void executeShouldLogAssignedPermissionSet() { | ||
buildRule.executeTarget("execute"); | ||
Assert.assertTrue("Assigned permission set should be logged " + buildRule.getLog(), buildRule.getLog().contains("Permission set testpermset assigned to testuser")); | ||
} | ||
|
||
@Test | ||
public void executeQuietShouldHaveNoOutput() { | ||
buildRule.executeTarget("execute-quiet"); | ||
Assert.assertTrue("Log should be empty", buildRule.getLog().isEmpty()); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/test/com/mcartoixa/ant/sfdx/force/user/permset/assign.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"result": { | ||
"failures": [ | ||
|
||
], | ||
"successes": [ | ||
{ | ||
"name": "testuser", | ||
"value": "testpermset" | ||
} | ||
] | ||
}, | ||
"status": 0 | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/com/mcartoixa/ant/sfdx/force/user/permset/assign.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project name="AssignTaskTest" basedir="." xmlns:sfdx="com.mcartoixa.ant.sfdx"> | ||
<condition property="sfdx-path" value="..\..\..\sfdx.cmd" else="../../../sfdx"> | ||
<os family="dos" /> | ||
</condition> | ||
|
||
<target name="init"> | ||
<taskdef uri="com.mcartoixa.ant.sfdx" resource="com/mcartoixa/ant/sfdx/antlib.xml" classpath="tmp/obj/classes" /> | ||
</target> | ||
|
||
<target name="execute" depends="init"> | ||
<sfdx:force-user-permset-assign permsetname="testpermset" onbehalfof="testtarget" targetusername="testuser" statusproperty="execute.status" resultproperty="execute.result" executable="${sfdx-path}" /> | ||
</target> | ||
|
||
<target name="execute-quiet" depends="init"> | ||
<sfdx:force-user-permset-assign quiet="true" executable="${sfdx-path}" /> | ||
</target> | ||
</project> |