Skip to content

Commit

Permalink
Merge pull request #8 from marcocdlv/bug_org_validator_shows_error
Browse files Browse the repository at this point in the history
bug: "Undeploy task isn't excluding files" was fixed
  • Loading branch information
marcocdlv committed Oct 9, 2015
2 parents fcdc0d6 + 2a12cdb commit 6a5d000
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EnforcePluginExtension {
*/
ArrayList<String> deleteSubComponents = ['*']

ArrayList<String> standardObjects = []
ArrayList<String> standardComponents = []

String tool = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ abstract class Deployment extends SalesforceTask {
fileManager.createNewDirectory(pathDirectory)
}

/**
* Combines package that was updated from build folder and package from source directory
* @param buildPackagePath is path of package that is into build directory
*/
public void combinePackage(String buildPackagePath) {
PackageCombiner.packageCombine(projectPackagePath, buildPackagePath)
if (excludes) {
removeFilesExcluded(buildPackagePath)
}
}

/**
* Combines package from build folder and package from source directory
* @param buildPackagePath is path of package that is into build directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Undeploy extends Deployment {
@Override
void runTask() {
truncate()
addNewStandardObjects()
addNewStandardComponents()
unDeploy()
}

Expand All @@ -67,7 +67,7 @@ class Undeploy extends Deployment {
copyFilesToTaskDirectory(filesToTruncate)
addInterceptor()
writePackage(taskPackagePath, filesToTruncate)
combinePackage(taskPackagePath)
combinePackageToUpdate(taskPackagePath)
executeDeploy(taskFolderPath, START_MESSAGE_TRUNCATE, SUCCESS_MESSAGE_TRUNCATE)
}

Expand All @@ -93,7 +93,7 @@ class Undeploy extends Deployment {
public void unDeploy() {
createDeploymentDirectory(taskFolderPath)
deployToDeleteComponents()
combinePackage(taskDestructivePath)
combinePackageToUpdate(taskDestructivePath)
executeDeploy(taskFolderPath, START_MESSAGE_UNDEPLOY, SUCCESS_MESSAGE_DELETE)
}

Expand Down Expand Up @@ -159,10 +159,10 @@ class Undeploy extends Deployment {
/**
* Adds new standard objects from user property
*/
public void addNewStandardObjects() {
public void addNewStandardComponents() {
if (Util.isValidProperty(project, Constants.FORCE_EXTENSION) &&
project[Constants.FORCE_EXTENSION].standardObjects) {
standardComponents += project[Constants.FORCE_EXTENSION].standardObjects
project[Constants.FORCE_EXTENSION].standardComponents) {
standardComponents += project[Constants.FORCE_EXTENSION].standardComponents
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.fundacionjala.gradle.plugins.enforce.utils.salesforce

import org.fundacionjala.gradle.plugins.enforce.utils.Constants
import org.fundacionjala.gradle.plugins.enforce.utils.Util
import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files.BasicOrgComponentsValidator
import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files.DefaultOrgComponentsValidator
import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.BasicOrgComponentsValidator
import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.DefaultOrgComponentsValidator
import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files.SalesforceValidator
import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.BasicOrgSubcomponentsValidator
import org.fundacionjala.gradle.plugins.enforce.wsc.Credential
Expand Down Expand Up @@ -38,7 +38,7 @@ class OrgValidator {
* @param filesToValidate ia a list of files that need to validate
* @param projectPath our repository
*/
public static Map<String,ArrayList<File>> validateFiles(Credential credential,ArrayList<File> filesToValidate, String projectPath) {
public static Map<String,ArrayList<File>> validateFiles(Credential credential, ArrayList<File> filesToValidate, String projectPath) {
Map<String, ArrayList<File>> mapFiles = filesToValidate.groupBy {
Util.getFirstPath(Util.getRelativePath(it,projectPath))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files
package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org

import groovy.json.JsonSlurper
import org.fundacionjala.gradle.plugins.enforce.utils.Constants
Expand All @@ -24,12 +24,10 @@ public class BasicOrgComponentsValidator implements OrgInterfaceValidator{
*/
@Override
public Map<String,ArrayList<File>> validateFiles(Credential credential, ArrayList<File> filesToVerify, String folderComponent, String projectPath) {

Map<String,ArrayList<File>> mapFiles = [:]
mapFiles.put(Constants.VALID_FILE, new ArrayList<File>())
mapFiles.put(Constants.FILES_NOT_FOUND, new ArrayList<File>())
mapFiles.put(Constants.FILE_WITHOUT_VALIDATOR, new ArrayList<File>())

ArrayList<File> orgFiles = getFilesIntoOrg(credential, folderComponent, projectPath)

filesToVerify.findAll{ File file ->
Expand All @@ -52,22 +50,25 @@ public class BasicOrgComponentsValidator implements OrgInterfaceValidator{
* @param path orn repository
*/
public ArrayList<File> getFilesIntoOrg(Credential credential, String folderComponent, String projectPath) {

ToolingAPI toolingAPI = new ToolingAPI(credential)
QueryBuilder queryBuilder = new QueryBuilder()
JsonSlurper jsonSlurper = new JsonSlurper()

MetadataComponents component = MetadataComponents.getComponent(folderComponent)
ArrayList<File> orgFiles = []
def typeComponent = MetadataComponents.getComponent(folderComponent).getTypeName()
def extensionComponent = MetadataComponents.getComponent(folderComponent).getExtension()
def sqlString = queryBuilder.createQueryFromBasicComponent(typeComponent)
def resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString)
def jsonResulSet = jsonSlurper.parseText(resultSet as String)
if(component != null) {
String typeComponent = component.getTypeName()
String extensionComponent = component.getExtension()
String sqlString = queryBuilder.createQueryFromBasicComponent(typeComponent)
String resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString)
def jsonResulSet = jsonSlurper.parseText(resultSet as String)

for(def i = 0; i < jsonResulSet.records.size(); i++) {
def nameFile = "${jsonResulSet.records[i]['Name']}.${extensionComponent}"
orgFiles.add(new File(Paths.get(projectPath,folderComponent, nameFile ).toString()))
for(def i = 0; i < jsonResulSet.records.size(); i++) {
def nameFile = "${jsonResulSet.records[i]['Name']}.${extensionComponent}"
orgFiles.add(new File(Paths.get(projectPath,folderComponent, nameFile ).toString()))
}
}

return orgFiles
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,29 @@ public class BasicOrgSubcomponentsValidator implements OrgInterfaceValidator{
/**
* Validates the subcomponents defined in Salesforce organization
* @param credential contains the data needed to connect with the API sales force
* @param filesToValidate is a list of files that need to validate
* @param typeSubcomponent is a subcomponent type that we need validate
* @param fileToValidate is a list of files that need to validate
* @param subcomponentType is a subcomponent type that we need validate
* @return a boolean value that indicate if a subComponent exist in Salesforce organization
*/
public boolean existFileInOrg(Credential credential, File filesToValidate, String typeSubcomponent) {
public boolean existFileInOrg(Credential credential, File fileToValidate, String subcomponentType) {
ToolingAPI toolingAPI = new ToolingAPI(credential)
def typeComponent = MetadataComponents.getComponent(typeSubcomponent).getTypeName()
def extensionComponent = MetadataComponents.getComponent(typeSubcomponent).getExtension()
def existSubcomponent = false
def component = MetadataComponents.getComponent(subcomponentType)

if(component != null) {
def typeComponent = component.getTypeName()
def extensionComponent = component.getExtension()

def sqlString = queryBuilder.createQueryGetSubomponent(typeComponent, filesToValidate)
def resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString)
def jsonResulSet = jsonSlurper.parseText(resultSet as String)
for(def i = 0; i < jsonResulSet.records.size(); i++) {
String fullName = "${jsonResulSet.records[i]['FullName']}.${extensionComponent}"
if(fullName.equals(filesToValidate.getName())) {
return true
def sqlString = queryBuilder.createQueryGetSubomponent(typeComponent, fileToValidate)
def resultSet = toolingAPI.httpAPIClient.executeQuery(sqlString)
def jsonResulSet = jsonSlurper.parseText(resultSet as String)
for(def i = 0; i < jsonResulSet.records.size(); i++) {
String fullName = "${jsonResulSet.records[i]['FullName']}.${extensionComponent}"
if(fullName.equals(fileToValidate.getName())) {
existSubcomponent = true
}
}
}
return false
return existSubcomponent
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.files
package org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org

import org.fundacionjala.gradle.plugins.enforce.utils.Constants
import org.fundacionjala.gradle.plugins.enforce.utils.salesforce.component.validators.org.OrgInterfaceValidator
import org.fundacionjala.gradle.plugins.enforce.wsc.Credential

/**
* This class defines a default validate for some salesforce component
*/
public class DefaultOrgComponentsValidator implements OrgInterfaceValidator{
public class DefaultOrgComponentsValidator implements OrgInterfaceValidator {

@Override
public Map<String,ArrayList<File>> validateFiles(Credential credential, ArrayList<File> filesToVerify, String folderComponent, String projectPath) {
public Map<String, ArrayList<File>> validateFiles(Credential credential, ArrayList<File> filesToVerify, String folderComponent, String projectPath) {

Map<String,ArrayList<File>> mapFiles = [:]
Map<String, ArrayList<File>> mapFiles = [:]
mapFiles.put(Constants.VALID_FILE, new ArrayList<File>())
mapFiles.put(Constants.FILES_NOT_FOUND, new ArrayList<File>())
mapFiles.put(Constants.FILE_WITHOUT_VALIDATOR, new ArrayList<File>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class UndeployTest extends Specification {
project.apply(plugin: EnforcePlugin)
project.enforce {
srcPath = "${File.separator}home${File.separator}user${File.separator}project${File.separator}one"
standardObjects = ["Q2w_Test__c.object"]
standardComponents = ["Q2w_Test__c.object"]
tool = "metadata"
poll = 200
waitTime = 10
Expand Down Expand Up @@ -113,7 +113,7 @@ class UndeployTest extends Specification {

def "Test should get the standard objects assigned"() {
expect:
project.extensions.findByName('enforce').standardObjects == ["Q2w_Test__c.object"]
project.extensions.findByName('enforce').standardComponents == ["Q2w_Test__c.object"]
}

def "Test should get the tool assigned"() {
Expand Down Expand Up @@ -160,8 +160,8 @@ class UndeployTest extends Specification {
undeployInstance.copyFilesToTaskDirectory(undeployInstance.filesToTruncate)
undeployInstance.addInterceptor()
undeployInstance.writePackage(undeployInstance.taskPackagePath, undeployInstance.filesToTruncate)
undeployInstance.combinePackage(undeployInstance.taskPackagePath)
undeployInstance.addNewStandardObjects()
undeployInstance.combinePackageToUpdate(undeployInstance.taskPackagePath)
undeployInstance.addNewStandardComponents()
undeployInstance.createDeploymentDirectory(undeployInstance.taskFolderPath)
undeployInstance.deployToDeleteComponents()
def destructiveXmlContent = new File(Paths.get(SRC_PATH, 'build', 'undeploy', 'destructiveChanges.xml').toString()).text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RunTestTaskTest extends Specification {
project.apply(plugin: EnforcePlugin)
project.enforce {
srcPath = "${File.separator}home${File.separator}user${File.separator}project${File.separator}one"
standardObjects = ["Q2w_Test__c.object"]
standardComponents = ["Q2w_Test__c.object"]
tool = "metadata"
poll = 200
waitTime = 10
Expand All @@ -50,7 +50,7 @@ class RunTestTaskTest extends Specification {

def "Should get the standard objects assigned"() {
expect:
project.extensions.findByName('enforce').standardObjects == ["Q2w_Test__c.object"]
project.extensions.findByName('enforce').standardComponents == ["Q2w_Test__c.object"]
}

def "Should get the tool assigned"() {
Expand All @@ -62,7 +62,7 @@ class RunTestTaskTest extends Specification {
given:
project.enforce {
srcPath = SRC_PATH
standardObjects = ["Q2w_Test__c.object"]
standardComponents = ["Q2w_Test__c.object"]
tool = "metadata"
poll = 200
waitTime = 10
Expand All @@ -82,7 +82,7 @@ class RunTestTaskTest extends Specification {
given:
project.enforce {
srcPath = SRC_PATH
standardObjects = ["Q2w_Test__c.object"]
standardComponents = ["Q2w_Test__c.object"]
tool = "metadata"
poll = 200
waitTime = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class OrgValidatorTest extends Specification {
ArrayList<File> validTriggerFiles
ArrayList<File> invalidTriggerFiles
ArrayList<File> unvalidatedDocumentFiles
ArrayList<File> invalidNonexistentFiles
ArrayList<File> validPagesFiles
ArrayList<File> invalidPagesFiles

@Shared
Map<String, ArrayList<File>> mapExpected
Expand All @@ -46,7 +49,10 @@ class OrgValidatorTest extends Specification {
invalidClassFiles = []
validTriggerFiles = []
invalidTriggerFiles = []
validPagesFiles = []
invalidPagesFiles = []
unvalidatedDocumentFiles = []
invalidNonexistentFiles = []

mapExpected = [:]

Expand All @@ -72,9 +78,21 @@ class OrgValidatorTest extends Specification {
invalidTriggerFiles.add(new File(Paths.get(SRC_PATH,'triggers','triggerFall2.trigger').toString()))
invalidTriggerFiles.add(new File(Paths.get(SRC_PATH,'triggers','triggerFall3.trigger').toString()))

validPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','Page1.page').toString()))
validPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','Page2.page').toString()))
validPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','Page3.page').toString()))

invalidPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','PageFall1.page').toString()))
invalidPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','PageFall2.page').toString()))
invalidPagesFiles.add(new File(Paths.get(SRC_PATH,'pages','PageFall3.page').toString()))

unvalidatedDocumentFiles.add(new File(Paths.get(SRC_PATH,'documents','myDocuments','doc.txt').toString()))
unvalidatedDocumentFiles.add(new File(Paths.get(SRC_PATH,'documents','myDocuments','doc2.txt').toString()))

invalidNonexistentFiles.add(new File(Paths.get(SRC_PATH,'othercomponent','doc1.txt').toString()))
invalidNonexistentFiles.add(new File(Paths.get(SRC_PATH,'othercomponent','doc2.txt').toString()))
invalidNonexistentFiles.add(new File(Paths.get(SRC_PATH,'othercomponent','doc3.txt').toString()))

mapExpected.put(Constants.VALID_FILE, new ArrayList<File>())
mapExpected.put(Constants.FILES_NOT_FOUND, new ArrayList<File>())
mapExpected.put(Constants.FILE_WITHOUT_VALIDATOR, new ArrayList<File>())
Expand Down Expand Up @@ -166,4 +184,51 @@ class OrgValidatorTest extends Specification {
mapResponse[Constants.FILES_NOT_FOUND].sort() == mapExpected[Constants.FILES_NOT_FOUND].sort()
mapResponse[Constants.FILE_WITHOUT_VALIDATOR].sort() == mapExpected[Constants.FILE_WITHOUT_VALIDATOR].sort()
}

def "Test should returns a map that contains all valid, invalid and noneexistent files" () {
given:
mapExpected[Constants.VALID_FILE].addAll(validClassFiles)
mapExpected[Constants.VALID_FILE].addAll(validTriggerFiles)
mapExpected[Constants.FILE_WITHOUT_VALIDATOR].addAll(invalidNonexistentFiles)


allFiles.addAll(validClassFiles)
allFiles.addAll(validTriggerFiles)
allFiles.addAll(invalidNonexistentFiles)

when:
Map<String,ArrayList<File>> mapResponse = OrgValidator.validateFiles(credential, allFiles, SRC_PATH)
showMaps(true,mapExpected,mapResponse)

then:
mapResponse[Constants.VALID_FILE].sort() == mapExpected[Constants.VALID_FILE].sort()
mapResponse[Constants.FILES_NOT_FOUND].sort() == mapExpected[Constants.FILES_NOT_FOUND].sort()
mapResponse[Constants.FILE_WITHOUT_VALIDATOR].sort() == mapExpected[Constants.FILE_WITHOUT_VALIDATOR].sort()
}

def "Test should returns a map that contains all valid xistent files" () {
given:
mapExpected[Constants.VALID_FILE].addAll(validClassFiles)
mapExpected[Constants.VALID_FILE].addAll(validTriggerFiles)
mapExpected[Constants.VALID_FILE].addAll(validPagesFiles)
mapExpected[Constants.FILES_NOT_FOUND].addAll(invalidClassFiles)
mapExpected[Constants.FILES_NOT_FOUND].addAll(invalidTriggerFiles)
mapExpected[Constants.FILES_NOT_FOUND].addAll(invalidPagesFiles)

allFiles.addAll(validClassFiles)
allFiles.addAll(validTriggerFiles)
allFiles.addAll(validPagesFiles)
allFiles.addAll(invalidClassFiles)
allFiles.addAll(invalidTriggerFiles)
allFiles.addAll(invalidPagesFiles)

when:
Map<String,ArrayList<File>> mapResponse = OrgValidator.validateFiles(credential, allFiles, SRC_PATH)
showMaps(true,mapExpected,mapResponse)

then:
mapResponse[Constants.VALID_FILE].sort() == mapExpected[Constants.VALID_FILE].sort()
mapResponse[Constants.FILES_NOT_FOUND].sort() == mapExpected[Constants.FILES_NOT_FOUND].sort()
mapResponse[Constants.FILE_WITHOUT_VALIDATOR].sort() == mapExpected[Constants.FILE_WITHOUT_VALIDATOR].sort()
}
}

0 comments on commit 6a5d000

Please sign in to comment.