Skip to content

Commit

Permalink
Merge pull request #251 from MicroFocus/octane-dev-latest
Browse files Browse the repository at this point in the history
Octane fixes 5.8.7
  • Loading branch information
NarcisaMGalan committed Sep 11, 2019
2 parents 77cf7a2 + c18a158 commit 856e482
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 127 deletions.
Expand Up @@ -61,6 +61,8 @@
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* This service is responsible to create jobs (discovery and execution) for execution process.
Expand Down Expand Up @@ -478,7 +480,9 @@ private static void addExecutionAssignedNode(FreeStyleProject proj) {
String label = "" + computer.getNode().getSelfLabel();
if (label.toLowerCase().contains("uft")) {
label = label.trim();
if (label.contains(" ")) {
Pattern p = Pattern.compile("[^\\w]");
Matcher m = p.matcher(label);
if (m.find()){
label = "\"" + label + "\"";
}
labels.add(label);
Expand Down
Expand Up @@ -28,5 +28,6 @@ public enum HPRunnerType {
StormRunnerFunctional,
UFT,
PerformanceCenter,
LoadRunner,
NONE
}
Expand Up @@ -36,9 +36,9 @@ public abstract class OctaneTestsExtension implements ExtensionPoint {
public abstract boolean supports(Run<?, ?> build) throws IOException, InterruptedException;


public abstract TestResultContainer getTestResults(Run<?, ?> build, HPRunnerType hpRunnerType, String jenkinsRootUrl) throws IOException, InterruptedException, TestProcessingException;
public abstract TestResultContainer getTestResults(Run<?, ?> build, String jenkinsRootUrl) throws IOException, InterruptedException, TestProcessingException;

public static ExtensionList<OctaneTestsExtension> all() {
return Jenkins.getInstance().getExtensionList(OctaneTestsExtension.class);
return Jenkins.get().getExtensionList(OctaneTestsExtension.class);
}
}
Expand Up @@ -22,19 +22,15 @@

import com.hp.octane.integrations.OctaneSDK;
import com.microfocus.application.automation.tools.octane.configuration.SDKBasedLoggerProvider;
import com.microfocus.application.automation.tools.octane.model.processors.projects.JobProcessorFactory;
import com.microfocus.application.automation.tools.octane.tests.build.BuildHandlerUtils;
import com.microfocus.application.automation.tools.octane.tests.detection.UFTExtension;
import com.microfocus.application.automation.tools.octane.tests.xml.TestResultXmlWriter;
import hudson.Extension;
import hudson.FilePath;
import hudson.model.Run;
import hudson.tasks.Builder;
import jenkins.model.Jenkins;
import org.apache.logging.log4j.Logger;

import javax.xml.stream.XMLStreamException;
import java.util.List;

/**
* Jenkins events life cycle listener for processing test results on build completed
Expand All @@ -44,44 +40,20 @@
public class TestListener {
private static Logger logger = SDKBasedLoggerProvider.getLogger(TestListener.class);

private static final String STORMRUNNER_LOAD_TEST_RUNNER_CLASS = "StormTestRunner";
private static final String STORMRUNNER_FUNCTIONAL_TEST_RUNNER_CLASS = "RunFromSrfBuilder";
private static final String PERFORMANCE_CENTER_TEST_RUNNER_CLASS = "PcBuilder";
public static final String TEST_RESULT_FILE = "mqmTests.xml";


public boolean processBuild(Run run) {
FilePath resultPath = new FilePath(new FilePath(run.getRootDir()), TEST_RESULT_FILE);
TestResultXmlWriter resultWriter = new TestResultXmlWriter(resultPath, run);
boolean success = true;
boolean hasTests = false;
String jenkinsRootUrl = Jenkins.get().getRootUrl();
HPRunnerType hpRunnerType = HPRunnerType.NONE;
List<Builder> builders = JobProcessorFactory.getFlowProcessor(run.getParent()).tryGetBuilders();
if (builders != null) {
for (Builder builder : builders) {
if (STORMRUNNER_LOAD_TEST_RUNNER_CLASS.equals(builder.getClass().getSimpleName())) {
hpRunnerType = HPRunnerType.StormRunnerLoad;
break;
}
if (STORMRUNNER_FUNCTIONAL_TEST_RUNNER_CLASS.equals(builder.getClass().getSimpleName())) {
hpRunnerType = HPRunnerType.StormRunnerFunctional;
break;
}
if (UFTExtension.RUN_FROM_FILE_BUILDER.equals(builder.getClass().getSimpleName()) || UFTExtension.RUN_FROM_ALM_BUILDER.equals(builder.getClass().getSimpleName())) {
hpRunnerType = HPRunnerType.UFT;
break;
}
if (PERFORMANCE_CENTER_TEST_RUNNER_CLASS.equals(builder.getClass().getSimpleName())) {
hpRunnerType = HPRunnerType.PerformanceCenter;
break;
}
}
}

try {
for (OctaneTestsExtension ext : OctaneTestsExtension.all()) {
if (ext.supports(run)) {
TestResultContainer testResultContainer = ext.getTestResults(run, hpRunnerType, jenkinsRootUrl);
TestResultContainer testResultContainer = ext.getTestResults(run, jenkinsRootUrl);
if (testResultContainer != null && testResultContainer.getIterator().hasNext()) {
resultWriter.writeResults(testResultContainer);
hasTests = true;
Expand Down
@@ -0,0 +1,123 @@
package com.microfocus.application.automation.tools.octane.tests.detection;

import com.microfocus.application.automation.tools.octane.configuration.SDKBasedLoggerProvider;
import com.microfocus.application.automation.tools.octane.model.processors.projects.JobProcessorFactory;
import com.microfocus.application.automation.tools.octane.tests.HPRunnerType;
import hudson.Extension;
import hudson.FilePath;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Run;
import hudson.tasks.Builder;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Recognize execution of Microfocus Tools
*/
@Extension
public class MFToolsDetectionExtension extends ResultFieldsDetectionExtension {

private static Logger logger = SDKBasedLoggerProvider.getLogger(MFToolsDetectionExtension.class);
private static final String STORMRUNNER_LOAD_TEST_RUNNER_CLASS = "StormTestRunner";
private static final String STORMRUNNER_FUNCTIONAL_TEST_RUNNER_CLASS = "RunFromSrfBuilder";
private static final String PERFORMANCE_CENTER_TEST_RUNNER_CLASS = "PcBuilder";
private static final String RUN_FROM_FILE_BUILDER = "RunFromFileBuilder";
private static final String RUN_FROM_ALM_BUILDER = "RunFromAlmBuilder";

private static final String UFT = "UFT";
private static final String STORMRUNNER_LOAD = "StormRunner Load";
private static final String STORMRUNNER_FUNCTIONAL = "StormRunner Functional";
private static final String LOAD_RUNNER = "LoadRunner";
private static final String PERFORMANCE_CENTER_RUNNER = "Performance Center";
private static final String PERFORMANCE_TEST_TYPE = "Performance";


private static final String PERFORMANCE_REPORT = "PerformanceReport";
private static final String TRANSACTION_SUMMARY = "TransactionSummary";

private static Map<String, HPRunnerType> builder2RunnerType = new HashMap<>();
private static Map<HPRunnerType, ResultFields> runnerType2ResultFields = new HashMap<>();

static {
builder2RunnerType.put(STORMRUNNER_LOAD_TEST_RUNNER_CLASS, HPRunnerType.StormRunnerLoad);
builder2RunnerType.put(STORMRUNNER_FUNCTIONAL_TEST_RUNNER_CLASS, HPRunnerType.StormRunnerFunctional);
builder2RunnerType.put(RUN_FROM_FILE_BUILDER, HPRunnerType.UFT);
builder2RunnerType.put(RUN_FROM_ALM_BUILDER, HPRunnerType.UFT);
builder2RunnerType.put(PERFORMANCE_CENTER_TEST_RUNNER_CLASS, HPRunnerType.PerformanceCenter);

runnerType2ResultFields.put(HPRunnerType.PerformanceCenter, new ResultFields(null, PERFORMANCE_CENTER_RUNNER, null, PERFORMANCE_TEST_TYPE));
runnerType2ResultFields.put(HPRunnerType.UFT, new ResultFields(UFT, UFT, null));
runnerType2ResultFields.put(HPRunnerType.StormRunnerLoad, new ResultFields(null, STORMRUNNER_LOAD, null));
runnerType2ResultFields.put(HPRunnerType.StormRunnerFunctional, new ResultFields(null, STORMRUNNER_FUNCTIONAL, null));
runnerType2ResultFields.put(HPRunnerType.LoadRunner, new ResultFields(null, LOAD_RUNNER, null));
}

/**
* Detect result fields for ALM Octane tests
*
* @param build
* @return
* @throws IOException
* @throws InterruptedException
*/
@Override
public ResultFields detect(Run<?, ?> build) throws IOException, InterruptedException {
HPRunnerType runnerType = getRunnerType(build);
return runnerType2ResultFields.get(runnerType);
}

/**
* Get MF runner type from run
*
* @param run
* @return
*/
public static HPRunnerType getRunnerType(Run run) {
HPRunnerType hpRunnerType = HPRunnerType.NONE;
if (JobProcessorFactory.WORKFLOW_RUN_NAME.equals(run.getClass().getName())) {
ParametersAction parameterAction = run.getAction(ParametersAction.class);
ParameterValue runnerTypePv = parameterAction != null ? parameterAction.getParameter(HPRunnerType.class.getSimpleName()) : null;
if (runnerTypePv != null) {
hpRunnerType = HPRunnerType.valueOf((String) runnerTypePv.getValue());
}
} else {
List<Builder> builders = JobProcessorFactory.getFlowProcessor(run.getParent()).tryGetBuilders();
if (builders != null) {
for (Builder builder : builders) {
String builderName = builder.getClass().getSimpleName();
if (builder2RunnerType.containsKey(builderName)) {
hpRunnerType = builder2RunnerType.get(builderName);
break;
}
}
}
}

if (hpRunnerType == HPRunnerType.UFT && isLoadRunnerProject(run)) {
hpRunnerType = HPRunnerType.LoadRunner;
}
return hpRunnerType;
}

private static boolean isLoadRunnerProject(Run run) {
if (run.getRootDir() != null) {
try {
FilePath performanceReportFolder = new FilePath(run.getRootDir()).child(PERFORMANCE_REPORT);
FilePath transactionSummaryFolder = new FilePath(run.getRootDir()).child(TRANSACTION_SUMMARY);
return performanceReportFolder.exists() &&
performanceReportFolder.isDirectory() &&
transactionSummaryFolder.exists() &&
transactionSummaryFolder.isDirectory();
} catch (IOException | InterruptedException e) {
logger.error("Failed to check isLoadRunnerProject :" + e.getMessage());
}
}
return false;
}

}
Expand Up @@ -57,7 +57,7 @@ public class TestNGExtension extends ResultFieldsDetectionExtension {
@Override
public ResultFields detect(final Run build) throws IOException, InterruptedException {
if (!(build instanceof AbstractBuild)) {
return new ResultFields(null, null, null);
return null;
}

final List<Object> publishers = ((AbstractBuild) build).getProject().getPublishersList().toList();
Expand Down

This file was deleted.

Expand Up @@ -50,7 +50,7 @@ public boolean supports(Run<?, ?> build) {
}

@Override
public TestResultContainer getTestResults(Run<?, ?> build, HPRunnerType hpRunnerType, String jenkinsRootUrl) throws
public TestResultContainer getTestResults(Run<?, ?> build, String jenkinsRootUrl) throws
TestProcessingException, IOException, InterruptedException {
try {
List<TestResult> testResults = GherkinTestResultsCollector.collectGherkinTestsResults(build.getRootDir());
Expand Down

0 comments on commit 856e482

Please sign in to comment.