Skip to content

Commit

Permalink
add SSO option, updated file system and alm runners
Browse files Browse the repository at this point in the history
  • Loading branch information
Anda Laakso committed Jul 9, 2019
1 parent 4e28145 commit 58086ca
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 27 deletions.
2 changes: 1 addition & 1 deletion HpToolsLauncher/HpToolsLauncherTests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void TestQcTestRun()
100000,
QcRunMode.RUN_LOCAL,
null,
new List<string> { "Aaron\\Amit" }, false, "", new List<string> { "Failed", "Blocked" }, false, TestStorageType.Alm);
new List<string> { "Aaron\\Amit" }, false, "", new List<string> { "Failed", "Blocked" }, false, TestStorageType.Alm, false);

if (runner.Connected)
runner.Run();
Expand Down
25 changes: 18 additions & 7 deletions HpToolsLauncher/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciPara
switch (runType)
{
case TestStorageType.AlmLabManagement:
List<string> testSetsList = GetParamsWithPrefix("almEntityId");
List<string> testSetsList = GetParamsWithPrefix("TestSet");

string filterByName = (_ciParams.ContainsKey("FilterByName") ? _ciParams["FilterByName"] : "");

Expand All @@ -347,6 +347,9 @@ private IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciPara
filterByStatuses.Add(statuses);
}
}

bool isSSOEnabled = _ciParams.ContainsKey("SSOEnabled") && Convert.ToBoolean(_ciParams["SSOEnabled"]);

//create an Alm runner
runner = new AlmTestSetsRunner(_ciParams["almServerUrl"],
_ciParams["almUserName"],
Expand All @@ -361,11 +364,11 @@ private IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciPara
filterByName,
filterByStatuses,
initialTestRun,
TestStorageType.AlmLabManagement);
TestStorageType.AlmLabManagement,
isSSOEnabled);
break;

case TestStorageType.Alm:
Console.WriteLine("runType is alm");
//check that all required parameters exist
foreach (string param1 in requiredParamsForQcRun)
{
Expand Down Expand Up @@ -404,14 +407,15 @@ private IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciPara
}

//check if filterTests flag is selected; if yes apply filters on the list

bool isFilterSelected;
string filter = (_ciParams.ContainsKey("FilterTests") ? _ciParams["FilterTests"] : "");
string filter = _ciParams.ContainsKey("FilterTests") ? _ciParams["FilterTests"] : "";

isFilterSelected = !string.IsNullOrEmpty(filter) && Convert.ToBoolean(filter.ToLower());

filterByName = (_ciParams.ContainsKey("FilterByName") ? _ciParams["FilterByName"] : "");
filterByName = _ciParams.ContainsKey("FilterByName") ? _ciParams["FilterByName"] : "";

statuses = (_ciParams.ContainsKey("FilterByStatus") ? _ciParams["FilterByStatus"] : "");
statuses = _ciParams.ContainsKey("FilterByStatus") ? _ciParams["FilterByStatus"] : "";

filterByStatuses = new List<string>();

Expand All @@ -425,6 +429,8 @@ private IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciPara
filterByStatuses.Add(statuses);
}
}

isSSOEnabled = _ciParams.ContainsKey("SSOEnabled") && Convert.ToBoolean(_ciParams["SSOEnabled"]);

//create an Alm runner
runner = new AlmTestSetsRunner(_ciParams["almServerUrl"],
Expand All @@ -440,7 +446,8 @@ private IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciPara
filterByName,
filterByStatuses,
initialTestRun,
TestStorageType.Alm);
TestStorageType.Alm,
isSSOEnabled);
break;
case TestStorageType.FileSystem:
bool displayController = false;
Expand Down Expand Up @@ -833,6 +840,10 @@ private void RunTests(IAssetRunner runner, string resultsFile, TestSuiteRunResul

_xmlBuilder.CreateXmlFromRunResults(results);

if (results.TestRuns.Count == 0)
{
Launcher.ExitCode = Launcher.ExitCodeEnum.Failed;
}

//if there is an error
if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error))
Expand Down
44 changes: 36 additions & 8 deletions HpToolsLauncher/Runners/AlmTestSetsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace HpToolsLauncher
{
public class AlmTestSetsRunner : RunnerBase, IDisposable
{

private ITDConnection2 _tdConnection;

public ITDConnection2 TdConnection
Expand Down Expand Up @@ -79,6 +80,8 @@ public ITDConnection2 TdConnection

public double Timeout { get; set; }

public bool SSOEnabled { get; set; }


/// <summary>
/// constructor
Expand All @@ -97,6 +100,7 @@ public ITDConnection2 TdConnection
/// <param name="filterByStatuses"></param>
/// <param name="initialTestRun"></param>
/// <param name="testStorageType"></param>
/// <param name="isSSOEnabled"></param>
public AlmTestSetsRunner(string qcServer,
string qcUser,
string qcPassword,
Expand All @@ -110,8 +114,10 @@ public ITDConnection2 TdConnection
string filterByName,
List<string> filterByStatuses,
bool initialTestRun,
TestStorageType testStorageType)
TestStorageType testStorageType,
bool isSSOEnabled)
{

Timeout = intQcTimeout;
RunMode = enmQcRunMode;
RunHost = runHost;
Expand All @@ -125,8 +131,9 @@ public ITDConnection2 TdConnection
FilterByName = filterByName;
FilterByStatuses = filterByStatuses;
InitialTestRun = initialTestRun;
SSOEnabled = isSSOEnabled;

Connected = ConnectToProject(MQcServer, MQcUser, qcPassword, MQcDomain, MQcProject);
Connected = ConnectToProject(MQcServer, MQcUser, qcPassword, MQcDomain, MQcProject, SSOEnabled);
TestSets = qcTestSets;
Storage = testStorageType;
if (!Connected)
Expand Down Expand Up @@ -216,11 +223,12 @@ private bool CheckIsOldQc()
/// <param name="qcPass"></param>
/// <param name="qcDomain"></param>
/// <param name="qcProject"></param>
/// <param name="SSOEnabled"></param>
/// <returns></returns>
public bool ConnectToProject(string qcServerUrl, string qcLogin, string qcPass, string qcDomain, string qcProject)
public bool ConnectToProject(string qcServerUrl, string qcLogin, string qcPass, string qcDomain, string qcProject, bool SSOEnabled)
{
if (string.IsNullOrWhiteSpace(qcServerUrl)
|| string.IsNullOrWhiteSpace(qcLogin)
|| (string.IsNullOrWhiteSpace(qcLogin) && !SSOEnabled)
|| string.IsNullOrWhiteSpace(qcDomain)
|| string.IsNullOrWhiteSpace(qcProject))
{
Expand All @@ -244,7 +252,14 @@ public bool ConnectToProject(string qcServerUrl, string qcLogin, string qcPass,
}
try
{
TdConnection.Login(qcLogin, qcPass);
if (!SSOEnabled)
{
TdConnection.Login(qcLogin, qcPass);
}
else
{
//TODO - connect through SSO
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -512,12 +527,12 @@ public ITestSet GetTargetTestSet(List testSetList, string testSuiteName)

if (tsFolder != null)
{

if ((testStorageType.Equals(TestStorageType.AlmLabManagement) && !testSet.Equals(""))
|| testStorageType.Equals(TestStorageType.Alm))
{
List testList = tsFolder.FindTestSets(testSuiteName);

return testList;
}

Expand Down Expand Up @@ -1019,7 +1034,20 @@ public override TestSuiteRunResults Run()
}

//get target test set
ITestSet targetTestSet = GetTargetTestSet(testSetList, testSuiteName);
if (testSetList == null)
{
Console.WriteLine("Null test set list");
}

ITestSet targetTestSet = null;
try
{
targetTestSet = GetTargetTestSet(testSetList, testSuiteName);
}
catch (Exception ex)
{
Console.WriteLine("Null test set list");
}

ConsoleWriter.WriteLine(Resources.GeneralDoubleSeperator);
ConsoleWriter.WriteLine(Resources.AlmRunnerStartingExecution);
Expand Down
1 change: 1 addition & 0 deletions HpToolsLauncher/Runners/FileSystemTestsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ private bool CheckTimeout()
private TestRunResults RunHpToolsTest(TestInfo testInfo, ref string errorReason)
{
var testPath = testInfo.TestPath;

var type = Helper.GetTestType(testPath);

// if we have at least one environment for parallel runner,
Expand Down
6 changes: 5 additions & 1 deletion HpToolsLauncher/TestRunners/GuiTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,11 @@ private GuiTestRunResult ExecuteQTPRun(TestRunResults testResults)
Type runResultsOptionstype = Type.GetTypeFromProgID("QuickTest.RunResultsOptions");
var options = (RunResultsOptions)Activator.CreateInstance(runResultsOptionstype);
options.ResultsLocation = testResults.ReportLocation;
_qtpApplication.Options.Run.RunMode = _uftRunMode;
// _qtpApplication.Options.Run.RunMode = _uftRunMode;
if (_uftRunMode != null)
{
_qtpApplication.Options.Run.RunMode = _uftRunMode;
}

//Check for cancel before executing
if (_runCancelled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import java.util.Properties;

import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

Expand Down Expand Up @@ -64,12 +63,13 @@ public class RunFromAlmModel extends AbstractDescribableImpl<RunFromAlmModel> {
private String almTimeout;
private String almRunMode;
private String almRunHost;
private Boolean isSSOEnabled;

@DataBoundConstructor
public RunFromAlmModel(String almServerName, String almUserName,
String almPassword, String almDomain, String almProject,
String almTestSets, String almRunResultsMode, String almTimeout,
String almRunMode, String almRunHost){
String almRunMode, String almRunHost, Boolean isSSOEnabled){

this.almServerName = almServerName;
this.almUserName = almUserName;
Expand All @@ -86,6 +86,8 @@ public RunFromAlmModel(String almServerName, String almUserName,
this.almTimeout = almTimeout;
this.almRunMode = almRunMode;
this.almRunHost = almRunHost;

this.isSSOEnabled = isSSOEnabled;
}

public String getAlmUserName() {
Expand Down Expand Up @@ -128,6 +130,10 @@ public String getAlmServerName() {
return almServerName;
}

public Boolean isSSOEnabled() {
return isSSOEnabled;
}

public Properties getProperties(EnvVars envVars,
VariableResolver<String> varResolver) {
return CreateProperties(envVars, varResolver);
Expand All @@ -140,6 +146,7 @@ public Properties getProperties() {
private Properties CreateProperties(EnvVars envVars,
VariableResolver<String> varResolver) {
Properties props = new Properties();
props.put("SSOEnabled", Boolean.toString(isSSOEnabled));

if (envVars == null) {
props.put("almUserName", almUserName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private Properties createProperties() {
props.put("almProject", getAlmProject());
props.put("clientType", getClientType());
props.put("almRunType", getRunType());
props.put("almEntityId1", getAlmEntityId());
props.put("TestSet1", getAlmEntityId());
props.put("almTimeout", getTimeslotDuration());
props.put("description", getDescription());
props.put("environmentConfigurationId", getEnvironmentConfigurationId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public RunFromAlmBuilder(
String almTimeout,
String almRunMode,
String almRunHost,
boolean isSSOEnabled,
boolean isFilterTestsEnabled,
FilterTestsModel filterTestsModel){

Expand All @@ -101,13 +102,16 @@ public RunFromAlmBuilder(
almRunResultsMode,
almTimeout,
almRunMode,
almRunHost);
almRunHost,
isSSOEnabled);
}

public String getAlmServerName(){
return runFromAlmModel.getAlmServerName();
}

public boolean getIsSSOEnabled() { return runFromAlmModel.isSSOEnabled(); }

public String getAlmUserName(){
return runFromAlmModel.getAlmUserName();
}
Expand Down Expand Up @@ -148,7 +152,7 @@ public boolean getIsFilterTestsEnabled() {
return isFilterTestsEnabled;
}

@DataBoundSetter
@DataBoundSetter
public void setIsFilterTestsEnabled(boolean isFilterTestsEnabled) {
this.isFilterTestsEnabled = isFilterTestsEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<script type="text/javascript" src="${rootURL}/plugin/hp-application-automation-tools-plugin/js/almUtils.js"/>

<style>
#testName {
width: 300px;
Expand Down Expand Up @@ -95,20 +97,26 @@
</f:entry>
</f:entry>

<f:entry field="isSSOEnabled">
<f:checkbox id="ssoCheckbox" title="SSO enabled" name="runfromalm.isSSOEnabled" checked="${instance.runFromAlmModel.isSSOEnabled}"
value="${instance.runFromAlmModel.isSSOEnabled}" onclick="enableSSO(this)"/>
</f:entry>

<f:entry>
<label>User name</label>
<label id="userName">User name</label>
<f:entry field="almUserName">
<f:textbox name="runfromalm.almUserName" value="${instance.runFromAlmModel.almUserName}"/>
</f:entry>
</f:entry>

<f:entry>
<label>Password</label>
<label id="password">Password</label>
<f:entry field="almPassword">
<f:password name="runfromalm.almPassword" value="${instance.runFromAlmModel.almPassword}"/>
</f:entry>
</f:entry>


<f:entry>
<label>Domain</label>
<f:entry field="almDomain">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<script type="text/javascript" src="${rootURL}/plugin/hp-application-automation-tools-plugin/configure.js"/>
<script type="text/javascript" src="${rootURL}/plugin/hp-application-automation-tools-plugin/parallelRunnerEnvironment.js"/>
<script type="text/javascript" src="${rootURL}/plugin/hp-application-automation-tools-plugin/js/utils.js"/>
<script type="text/javascript" src="${rootURL}/plugin/hp-application-automation-tools-plugin/js/fileSystemUtils.js"/>

<style>
#testsTable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:cv="/lib/custom">

<script type="text/javascript" src="${rootURL}/plugin/hp-application-automation-tools-plugin/js/utils.js"/>
<script type="text/javascript" src="${rootURL}/plugin/hp-application-automation-tools-plugin/js/fileSystemUtils.js"/>

<f:entry>
<f:entry>
Expand Down
17 changes: 17 additions & 0 deletions src/main/webapp/js/almUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
document.addEventListener('DOMContentLoaded', function() {
var ssoCheckbox = document.getElementById('ssoCheckbox');
enableSSO(ssoCheckbox);
})

function enableSSO(element){
var username = document.getElementsByName('runfromalm.almUserName')[0];
var password = document.getElementsByName('runfromalm.almPassword')[0];
if(element.checked){
//disable username and password for ALM
username.disabled = true;
password.disabled = true;
} else {
username.disabled = false;
password.disabled = false;
}
}

0 comments on commit 58086ca

Please sign in to comment.