Skip to content

Commit

Permalink
defect #600012 : UFT SVN Integration - deleted test from existing svn…
Browse files Browse the repository at this point in the history
… repository are not detected by discovery job. (#74)
  • Loading branch information
radislavB authored and m-seldin committed Mar 27, 2018
1 parent f02b476 commit f6761dd
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class UFTTestDetectionResult {
@XmlElement(name = "dataTable")
private List<ScmResourceFile> updatedScmResourceFiles = new ArrayList<>();

@XmlElementWrapper(name = "deletedFolders")
@XmlElement(name = "folder")
private List<String> deletedFolders = new ArrayList<>();

@XmlAttribute
private String scmRepositoryId;
Expand Down Expand Up @@ -145,4 +148,12 @@ public boolean isHasQuotedPaths() {
public void setHasQuotedPaths(boolean hasQuotedPaths) {
this.hasQuotedPaths = hasQuotedPaths;
}

public List<String> getDeletedFolders() {
return deletedFolders;
}

public void setDeletedFolders(List<String> deletedFolders) {
this.deletedFolders = deletedFolders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.model.*;
import hudson.plugins.git.GitChangeSet;
import hudson.scm.ChangeLogSet;
import hudson.scm.EditType;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.reflect.FieldUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -107,6 +107,10 @@ public static UFTTestDetectionResult startScanning(AbstractBuild<?, ?> build, St
printToConsole(buildListener, String.format("Found %s deleted data tables", result.getDeletedScmResourceFiles().size()));
}

if (!result.getDeletedFolders().isEmpty()) {
printToConsole(buildListener, String.format("Found %s deleted folders", result.getDeletedFolders().size()));
}

if (result.isHasQuotedPaths()) {
printToConsole(buildListener, "This run may not have discovered all updated tests. \n" +
"It seems that the changes in this build included filenames with Unicode characters, which Git did not list correctly.\n" +
Expand Down Expand Up @@ -233,48 +237,59 @@ private static UFTTestDetectionResult doChangeSetDetection(Object[] changeSetIte
for (int i = 0; i < changeSetItems.length; i++) {
ChangeLogSet.Entry changeSet = (ChangeLogSet.Entry) changeSetItems[i];
for (ChangeLogSet.AffectedFile path : changeSet.getAffectedFiles()) {
if(path.getPath().startsWith("\"")){
if (path.getPath().startsWith("\"")) {
result.setHasQuotedPaths(true);
}
boolean isDir = isDir(path);
String fileFullPath = workspace + File.separator + path.getPath();
if (isTestMainFilePath(path.getPath())) {
FilePath filePath = new FilePath(new File(fileFullPath));
boolean fileExist = filePath.exists();

if (EditType.ADD.equals(path.getEditType())) {
if (fileExist) {
FilePath testFolder = getTestFolderForTestMainFile(fileFullPath);
scanFileSystemRecursively(workspace, testFolder, result.getNewTests(), result.getNewScmResourceFiles());
} else {
logger.error("doChangeSetDetection : file not exist " + fileFullPath);
}
} else if (EditType.DELETE.equals(path.getEditType())) {
if (!fileExist) {
FilePath testFolder = getTestFolderForTestMainFile(fileFullPath);
AutomatedTest test = createAutomatedTest(workspace, testFolder, null, false);
result.getDeletedTests().add(test);
}
} else if (EditType.EDIT.equals(path.getEditType())) {
if (fileExist) {
FilePath testFolder = getTestFolderForTestMainFile(fileFullPath);
scanFileSystemRecursively(workspace, testFolder, result.getUpdatedTests(), result.getUpdatedScmResourceFiles());
if (!isDir) {
if (isTestMainFilePath(path.getPath())) {
FilePath filePath = new FilePath(new File(fileFullPath));
boolean fileExist = filePath.exists();

if (EditType.ADD.equals(path.getEditType())) {
if (fileExist) {
FilePath testFolder = getTestFolderForTestMainFile(fileFullPath);
scanFileSystemRecursively(workspace, testFolder, result.getNewTests(), result.getNewScmResourceFiles());
} else {
logger.error("doChangeSetDetection : file not exist " + fileFullPath);
}
} else if (EditType.DELETE.equals(path.getEditType())) {
if (!fileExist) {
FilePath testFolder = getTestFolderForTestMainFile(fileFullPath);
AutomatedTest test = createAutomatedTest(workspace, testFolder, null, false);
result.getDeletedTests().add(test);
}
} else if (EditType.EDIT.equals(path.getEditType())) {
if (fileExist) {
FilePath testFolder = getTestFolderForTestMainFile(fileFullPath);
scanFileSystemRecursively(workspace, testFolder, result.getUpdatedTests(), result.getUpdatedScmResourceFiles());
}
}
}
} else if (isUftDataTableFile(path.getPath())) {
FilePath filePath = new FilePath(new File(fileFullPath));
if (EditType.ADD.equals(path.getEditType())) {
UftTestType testType = isUftTestFolder(filePath.getParent().list());
if (testType.isNone()) {
if (filePath.exists()) {
} else if (isUftDataTableFile(path.getPath())) {
FilePath filePath = new FilePath(new File(fileFullPath));
if (EditType.ADD.equals(path.getEditType())) {
UftTestType testType = isUftTestFolder(filePath.getParent().list());
if (testType.isNone()) {
if (filePath.exists()) {
ScmResourceFile resourceFile = createDataTable(workspace, filePath);
result.getNewScmResourceFiles().add(resourceFile);
}
}
} else if (EditType.DELETE.equals(path.getEditType())) {
if (!filePath.exists()) {
ScmResourceFile resourceFile = createDataTable(workspace, filePath);
result.getNewScmResourceFiles().add(resourceFile);
result.getDeletedScmResourceFiles().add(resourceFile);
}
}
} else if (EditType.DELETE.equals(path.getEditType())) {
if (!filePath.exists()) {
ScmResourceFile resourceFile = createDataTable(workspace, filePath);
result.getDeletedScmResourceFiles().add(resourceFile);
}
}
} else //isDir
{
if (EditType.DELETE.equals(path.getEditType())) {

FilePath filePath = new FilePath(new File(path.getPath()));
String deletedFolder = filePath.getRemote().replace(linuxPathSplitter, windowsPathSplitter);
result.getDeletedFolders().add(deletedFolder);
}
}
}
Expand All @@ -283,6 +298,19 @@ private static UFTTestDetectionResult doChangeSetDetection(Object[] changeSetIte
return result;
}

private static boolean isDir(ChangeLogSet.AffectedFile path) {

if (path.getClass().getName().equals("hudson.scm.SubversionChangeLogSet$Path")) {
try {
String value = (String) FieldUtils.readDeclaredField(path, "kind", true);
return "dir".equals(value);
} catch (Exception e) {
//treat it as false
}
}
return false;
}

private static AutomatedTest createAutomatedTest(FilePath root, FilePath dirPath, UftTestType testType, boolean executable) {
AutomatedTest test = new AutomatedTest();
test.setName(dirPath.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
<br/>
<br/>
</j:if>
Deleted folders : ${it.results.deletedFolders.size()}
<br/>
<br/>
</p>
<p>
<table class = "myTable" frame="vsides above bottom" >
Expand Down Expand Up @@ -177,6 +180,30 @@
</p>

<br/><br/>


<p>
<table class = "myTable" frame="vsides above bottom" >
<caption>Deleted Folders</caption>
<thead>
<tr>
<th>Path</th>
</tr>
</thead>

<tbody>
<j:forEach var="s" items="${it.results.deletedFolders}">
<tr>
<td >${s}</td>

</tr>
</j:forEach>

</tbody>
</table>
</p>

<br/><br/>
<j:if test="${it.hasQuotedPaths}">
<b>NOTE</b>: This run may not have discovered all updated tests.
<br/>It seems that the changes in this build included filenames with Unicode characters, which Git did not list correctly.
Expand Down

0 comments on commit f6761dd

Please sign in to comment.