From deb628e3b35ff0dd026e8cd7fd9c1aa1d048795e Mon Sep 17 00:00:00 2001 From: Nicolas Deblock Date: Wed, 9 Aug 2017 11:01:20 +0200 Subject: [PATCH] #2 Severals robots is not possible #3 New settings value needed #4 Issue when building URL : AddToExecutionQueue ? Added more documentation, and use addToExecutionQueueV001 instead of addToExecutionQueue --- README.md | 262 +++--- .../ExecuteCerberusCampaign.java | 773 ++++++++++-------- .../cerberus/launchcampaign/Constantes.java | 2 +- .../checkcampaign/ResultCIDto.java | 629 +++++++------- .../executecampaign/ExecuteCampaignDto.java | 104 ++- .../ExecuteCerberusCampaign/config.jelly | 84 +- .../ExecuteCerberusCampaign/global.jelly | 34 +- .../ExecuteCerberusCampaign/help-browser.html | 6 + .../help-browserVersion.html | 6 + .../help-platform.html | 5 +- .../ExecuteCerberusCampaign/help-robot.html | 6 + .../ExecuteCerberusCampaign/help-ssIp.html | 6 + .../ExecuteCerberusCampaign/help-ss_p.html | 6 + .../executecampaign/ExecuteCampaignTest.java | 2 +- 14 files changed, 1043 insertions(+), 882 deletions(-) create mode 100644 src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browser.html create mode 100644 src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browserVersion.html create mode 100644 src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-robot.html create mode 100644 src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ssIp.html create mode 100644 src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ss_p.html diff --git a/README.md b/README.md index e1707a2..be522df 100644 --- a/README.md +++ b/README.md @@ -1,129 +1,135 @@ -# Cerberus Jenkins Plugin - -This plugin allows : -* To launch a test campaign on Cerberus -* To wait Cerberus executes it -* To display a report on console. Fail if a test is ko, else sucess. - -## What is cerberus ? -Cerberus is an open source, user friendly, **automated testing sofware**. See [website](https://www.cerberus-testing.org) for more information - - -## Get started -* Install plugin on Jenkins -* Set parameters on "Manage Jenkins" screen : -![global_parameter](docs/global_parameter.png "Global parameter") - -### On Jenkins -* To add a campaign Cerberus execution on a job, add a new build step "Execute Cerberus Campaign", and set parameters : -![build_parameter](docs/build_parameter.png "Build parameter") - - -### On Jenkinsfile -* Just call `executeCerberusCampaigne` function with parameters : - * `campaignName` : Campaign name to execute - * `platform` : Platform to execute (define into Cerberus) - * `environment` : Environment to execute (define into Cerberus) - * `browser` : Browser executed by Cerberus to test application. If `browser` is empty, use global settings of Cerberus plugin. - * `browserVersion` : Browser version executed by Cerberus to test application. If `browserVersion` is empty, use global settings of Cerberus plugin. - -``` -pipeline { - ... - stages { - ... - stage('cerberus Test') { - steps { - executeCerberusCampaign campaignName : "Test_campaign" , platform : "", environment : "QA", browser : "firefox", browserVersion : "47" - } - } - ... - } -} -``` - -## Run plugin on localhost -For more detail on how develop a plugin for Jenkins, see [here](https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial). - -NetBeans 6.7+ users can just hit Debug. For all others, run the following command to launch Jenkins with your plugin: -Convenient: -``` -mvnDebug hpi:run -``` - -Unix: -``` -$ export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n" -$ mvn package hpi:run -``` - -Windows: - -``` -> set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n -> mvn package hpi:run -``` - -If you open http://localhost:8080/jenkins in your browser, you should see the Jenkins page running in Jetty. The MAVEN_OPTS portion launches this whole thing with the debugger port 8000, so you should be able to start a debug session to this port from your IDE. - -Once this starts running, keep it running. Jetty will pick up all the changes automatically. - -When you make changes to view files in `src/main/resources` or resource files in `src/main/webapp`, just hit `F5` in your browser to see the changes. - -When you change Java source files, compile them in your IDE and Jetty should automatically redeploy Jenkins to pick up those changes. There is no need to run mvn at all. - -`MAVEN_OPTS` can be used to specify all sorts of other JVM parameters, like -Xmx - - -#### Import project into Eclispe - -``` -$ mvn -DdownloadSources=true -DdownloadJavadocs=true -DoutputDirectory=target/eclipse-classes -Declipse.workspace= eclipse:eclipse eclipse:configure-workspace -``` - - -## Technical Architecture -### Principle -![principle](docs/principle.png "Principle") - -### Code -`ExecuteCerberusCampaign` is the main class call by Jenkins. -It use : -* `ExecuteCampaign` who add Cerberus campaign to Ceberus Queue. -```java -executeCampaign.execute(); -``` - -* `CheckCampaignStatus` who check all 5 seconds status of campaign execution. When all test executed, job is finished -```java -checkCampaignStatus.execute(resultDto -> { - // display advancement - logger.println("Advancement : " + resultDto.getPercentOfTestExecuted() + "%"); -}, resultDto -> { - // display result and shutdown - logger.println("Result : " + resultDto.getResult() + "); -}); -``` - -`ExecuteCampaign` and `CheckCampaignStatus` are independent and could be used by other process than Jenkins. - - - -## License - -Cerberus Copyright (C) 2013 - 2017 cerberustesting - -This file is part of Cerberus. - -Cerberus is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Cerberus is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License +# Cerberus Jenkins Plugin + +This plugin allows : +* To launch a test campaign on Cerberus +* To wait Cerberus executes it +* To display a report on console. Fail if a test is ko, else sucess. + +## What is cerberus ? +Cerberus is an open source, user friendly, **automated testing sofware**. See [website](https://www.cerberus-testing.org) for more information + +## Compatibility table +| cerberus jenkins plugin | cerberus | +| ----------------------- | ----------------------- | +| 1.0.0 -> 1.0.1 | 1.11.0 -> 1.13.2 | +| 1.0.2 -> today version | 1.14.0 -> today version | + + +## Get started +* Install plugin on Jenkins +* Set parameters on "Manage Jenkins" screen : +![global_parameter](docs/global_parameter.png "Global parameter") + +### On Jenkins +* To add a campaign Cerberus execution on a job, add a new build step "Execute Cerberus Campaign", and set parameters : +![build_parameter](docs/build_parameter.png "Build parameter") + + +### On Jenkinsfile +* Just call `executeCerberusCampaigne` function with parameters : + * `campaignName` : Campaign name to execute + * `platform` : Platform to execute (define into Cerberus) + * `environment` : Environment to execute (define into Cerberus) + * `browser` : Browser executed by Cerberus to test application. If `browser` is empty, use global settings of Cerberus plugin. + * `browserVersion` : Browser version executed by Cerberus to test application. If `browserVersion` is empty, use global settings of Cerberus plugin. + +``` +pipeline { + ... + stages { + ... + stage('cerberus Test') { + steps { + executeCerberusCampaign campaignName : "Test_campaign" , platform : "", environment : "QA", browser : "firefox", browserVersion : "47" + } + } + ... + } +} +``` + +## Run plugin on localhost +For more detail on how develop a plugin for Jenkins, see [here](https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial). + +NetBeans 6.7+ users can just hit Debug. For all others, run the following command to launch Jenkins with your plugin: +Convenient: +``` +mvnDebug hpi:run +``` + +Unix: +``` +$ export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n" +$ mvn package hpi:run +``` + +Windows: + +``` +> set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n +> mvn package hpi:run +``` + +If you open http://localhost:8080/jenkins in your browser, you should see the Jenkins page running in Jetty. The MAVEN_OPTS portion launches this whole thing with the debugger port 8000, so you should be able to start a debug session to this port from your IDE. + +Once this starts running, keep it running. Jetty will pick up all the changes automatically. + +When you make changes to view files in `src/main/resources` or resource files in `src/main/webapp`, just hit `F5` in your browser to see the changes. + +When you change Java source files, compile them in your IDE and Jetty should automatically redeploy Jenkins to pick up those changes. There is no need to run mvn at all. + +`MAVEN_OPTS` can be used to specify all sorts of other JVM parameters, like -Xmx + + +#### Import project into Eclispe + +``` +$ mvn -DdownloadSources=true -DdownloadJavadocs=true -DoutputDirectory=target/eclipse-classes -Declipse.workspace= eclipse:eclipse eclipse:configure-workspace +``` + + +## Technical Architecture +### Principle +![principle](docs/principle.png "Principle") + +### Code +`ExecuteCerberusCampaign` is the main class call by Jenkins. +It use : +* `ExecuteCampaign` who add Cerberus campaign to Ceberus Queue. +```java +executeCampaign.execute(); +``` + +* `CheckCampaignStatus` who check all 5 seconds status of campaign execution. When all test executed, job is finished +```java +checkCampaignStatus.execute(resultDto -> { + // display advancement + logger.println("Advancement : " + resultDto.getPercentOfTestExecuted() + "%"); +}, resultDto -> { + // display result and shutdown + logger.println("Result : " + resultDto.getResult() + "); +}); +``` + +`ExecuteCampaign` and `CheckCampaignStatus` are independent and could be used by other process than Jenkins. + + + +## License + +Cerberus Copyright (C) 2013 - 2017 cerberustesting + +This file is part of Cerberus. + +Cerberus is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Cerberus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with Cerberus. If not, see . \ No newline at end of file diff --git a/src/main/java/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign.java b/src/main/java/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign.java index d38120f..3363640 100644 --- a/src/main/java/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign.java +++ b/src/main/java/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign.java @@ -1,361 +1,412 @@ -/** - * Cerberus Copyright (C) 2013 - 2017 cerberustesting - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This file is part of Cerberus. - * - * Cerberus is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Cerberus is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cerberus. If not, see . - */ -package org.cerberus.jenkinsci.plugins.executecerberustest; -import org.apache.commons.lang.StringUtils; -import org.cerberus.launchcampaign.checkcampaign.*; -import org.cerberus.launchcampaign.event.LogEvent; -import org.cerberus.launchcampaign.executecampaign.*; -import org.jenkinsci.Symbol; -import org.kohsuke.stapler.*; - -import hudson.*; -import hudson.model.*; -import hudson.tasks.*; -import jenkins.tasks.SimpleBuildStep; -import net.sf.json.JSONObject; - -/** - * ExecuteCerberusCampaign {@link Builder}. - * - *

- * When the user configures the project and enables this builder, - * {@link DescriptorImpl#newInstance(StaplerRequest)} is invoked - * and a new {@link ExecuteCerberusCampaign} is created. The created - * instance is persisted to the project configuration XML by using - * XStream, so this allows you to use instance fields (like {@link #campaignName}) - * to remember the configuration. - * - *

- * When a build is performed, the {@link #perform} method will be invoked. - * - * @author Nicolas Deblock - */ -public class ExecuteCerberusCampaign extends Builder implements SimpleBuildStep { - - private final String campaignName; - private final String platform; - private final String environment; - private final String browser; - private final String browserVersion; - - private final int screenshot; // default is 1 - private final int verbose; // default is 1 - private final int pageSource; // default is Y - private final int seleniumLog; // default is Y - private final int timeOut; // default is 5000 - private final int retries; // default is 0 - private final String tag; // default is 'Jenkins--' + current timestamp - - // Fields in config.jelly must match the parameter names in the "DataBoundConstructor" - @DataBoundConstructor - public ExecuteCerberusCampaign(final String campaignName, final String platform, final String environment, final String browser, - final String browserVersion, final int screenshot, final int verbose, final int pageSource, final int seleniumLog, - final int timeOut, final int retries, String tag) { - this.campaignName = campaignName; - this.platform=platform; - this.environment=environment; - this.browser = browser; - this.browserVersion = browserVersion; - - this.screenshot = screenshot; // default is 1 - this.verbose = verbose; // default is 1 - this.pageSource = pageSource; // default is Y - this.seleniumLog = seleniumLog; // default is Y - this.timeOut = timeOut; // default is 5000 - this.retries = retries; // default is 0 - this.tag = tag; - } - - @Override - public void perform(final Run build, final FilePath workspace, final Launcher launcher, final TaskListener listener) { - final JenkinsLogger logger = new JenkinsLogger(listener.getLogger()); - - // overide attribute if local settings is empty - final String browser = StringUtils.isEmpty(this.browser) ? getDescriptor().getBrowser() : this.browser; - final String browserVersion = StringUtils.isEmpty(this.browserVersion) ? getDescriptor().getBrowserVersion() : this.browserVersion; - - - - try { - // calucation of tag - EnvVars env = build.getEnvironment(listener); - final String expandedTag = env.expand(this.tag); - - // 1 - Launch cerberus campaign - final ExecuteCampaignDto executeCampaignDto = new ExecuteCampaignDto(getDescriptor().getRobot(), getDescriptor().getSsIp(), - environment, browser, browserVersion, platform, campaignName, screenshot, verbose, pageSource, - seleniumLog, timeOut, retries, expandedTag); - - logger.info("Launch campaign " + executeCampaignDto.getSelectedCampaign() + " on " + getDescriptor().getUrlCerberus() + " with tag " + executeCampaignDto.getTagCerberus()); - - String urlCerberusReport = getDescriptor().getUrlCerberus() + "/ReportingExecutionByTag.jsp?Tag=" + executeCampaignDto.getTagCerberus(); - - LogEvent logEvent= new LogEvent() { - @Override - public void log(String error, String warning) { - if(!StringUtils.isEmpty(warning)) { - logger.warning(warning); - } - if(!StringUtils.isEmpty(error)) { - logger.error(error); - } - - } - }; - - final ExecuteCampaign executeCampaign = new ExecuteCampaign(getDescriptor().getUrlCerberus(), executeCampaignDto); - if(executeCampaign.execute(logEvent)) { - // 2 - check if cerberus campaign is finish - logger.info("Campaign is launched successfully. You can follow the report here : " + urlCerberusReport); - - CheckCampaignStatus checkCampaignStatus = new CheckCampaignStatus(executeCampaignDto.getTagCerberus(), getDescriptor().getUrlCerberus(), getDescriptor().timeToRefreshCheckCampaignStatus, getDescriptor().timeOutForCampaignExecution); - checkCampaignStatus.execute(new CheckCampaignStatus.CheckCampaignEvent() { - - @Override - public boolean checkCampaign(final ResultCIDto resultDto) { - logger.info(resultDto.getTotalTestExecuted() + " test executed ... ("+ resultDto.logDetailExecution() + ")"); - logger.info(resultDto.getStatusPE() + resultDto.getStatusNE() + " test pending ..."); - logger.info("cerberus message : " + resultDto.getMessage()); - logger.info("Advancement : " + resultDto.getPercentOfTestExecuted() + "%"); - return true; - } - }, new CheckCampaignStatus.ResultEvent() { - - @Override - public void result(final ResultCIDto resultDto) { - // display result and shutdown - long timeToExecuteTest = resultDto.getExecutionEnd().getTime() - resultDto.getExecutionStart().getTime(); - logger.info("---------------------------------------------------------------------------------------------"); - logger.info("Result : " + resultDto.getResult() + ", test executed in " + ((int)(timeToExecuteTest/1000)) + "s " + ((int)(timeToExecuteTest%1000)) + "ms"); - logger.info(resultDto.logDetailExecution()); - logger.info("---------------------------------------------------------------------------------------------"); - - // fail if test is not OK - if(!"OK".equals(resultDto.getResult())) { - logger.error("FAIL"); - build.setResult(Result.FAILURE); - } - } - },logEvent); - - logger.info("Campaign execution is finished. You can view the report here : " + urlCerberusReport); - } else { - logger.error("Fail to add campaign " + campaignName + " in cerberus queue"); - logger.error("UNSTABLE"); - build.setResult(Result.UNSTABLE); - } - } catch (Exception e) { - logger.error("error for campaign " + campaignName + " : " , e); - logger.error("UNSTABLE"); - build.setResult(Result.UNSTABLE); - } - } - - - public String getCampaignName() { - return campaignName; - } - - - public String getPlatform() { - return platform; - } - - public String getEnvironment() { - return environment; - } - - public String getBrowser() { - return browser; - } - - public String getBrowserVersion() { - return browserVersion; - } - - public int getScreenshot() { - return screenshot; - } - - public int getVerbose() { - return verbose; - } - - public int getPageSource() { - return pageSource; - } - - public int getSeleniumLog() { - return seleniumLog; - } - - public int getTimeOut() { - return timeOut; - } - - public int getRetries() { - return retries; - } - - public String getTag() { - return tag; - } - - // Overridden for better type safety. - // If your plugin doesn't really define any property on Descriptor, - // you don't have to do this. - @Override - public DescriptorImpl getDescriptor() { - return (DescriptorImpl) super.getDescriptor(); - } - - /** - * Descriptor for {@link ExecuteCerberusCampaign}. Used as a singleton. - * The class is marked as public so that it can be accessed from views. - * - *

- * See {@code src/main/resources/hudson/plugins/hello_world/HelloWorldBuilder/*.jelly} - * for the actual HTML fragment for the configuration screen. - */ - @Symbol("executeCerberusCampaign") - @Extension // This indicates to Jenkins that this is an implementation of an extension point. - public static final class DescriptorImpl extends BuildStepDescriptor { - /** - * To persist global configuration information, - * simply store it in a field and call save(). - * - *

- * If you don't want fields to be persisted, use {@code transient}. - */ - private String urlCerberus; - private String robot; - private String ssIp; - private String browser; - private String browserVersion; - private long timeToRefreshCheckCampaignStatus; - private int timeOutForCampaignExecution; - - - /** - * In order to load the persisted global configuration, you have to - * call load() in the constructor. - */ - public DescriptorImpl() { - load(); - } - - /** - * In order to load the persisted global configuration, you have to - * call load() in the constructor. - */ - public DescriptorImpl(boolean fortest) { - - } - - @Override - public boolean isApplicable(Class aClass) { - // Indicates that this builder can be used with all kinds of project types - return true; - } - - /** - * This human readable name is used in the configuration screen. - */ - @Override - public String getDisplayName() { - return "Execute Cerberus Campaign"; - } - - @Override - public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { - // To persist global configuration information, - // set that to properties and call save(). - urlCerberus = formData.getString("urlCerberus"); - robot = formData.getString("robot"); - ssIp = formData.getString("ssIp"); - browser = formData.getString("browser"); - browserVersion = formData.getString("browserVersion"); - timeToRefreshCheckCampaignStatus = formData.getLong("timeToRefreshCheckCampaignStatus"); - timeOutForCampaignExecution = formData.getInt("timeOutForCampaignExecution"); - // Can also use req.bindJSON(this, formData); - // (easier when there are many fields; need set* methods for this) - save(); - return super.configure(req,formData); - } - - public String getUrlCerberus() { - return urlCerberus; - } - public void setUrlCerberus(String url) { - this.urlCerberus=url; - } - - public String getRobot() { - return robot; - } - - public void setRobot(String robot) { - this.robot = robot; - } - - public String getSsIp() { - return ssIp; - } - - public void setSsIp(String ssIp) { - this.ssIp = ssIp; - } - - public String getBrowser() { - return browser; - } - - public void setBrowser(String browser) { - this.browser = browser; - } - - public String getBrowserVersion() { - return browserVersion; - } - - public void setBrowserVersion(String browserVersion) { - this.browserVersion = browserVersion; - } - - public long getTimeToRefreshCheckCampaignStatus() { - return timeToRefreshCheckCampaignStatus; - } - - public void setTimeToRefreshCheckCampaignStatus(long timeToRefreshCheckCampaignStatus) { - this.timeToRefreshCheckCampaignStatus = timeToRefreshCheckCampaignStatus; - } - - public int getTimeOutForCampaignExecution() { - return timeOutForCampaignExecution; - } - - public void setTimeOutForCampaignExecution(int timeOutForCampaignExecution) { - this.timeOutForCampaignExecution = timeOutForCampaignExecution; - } - - } - -} - +/** + * Cerberus Copyright (C) 2013 - 2017 cerberustesting + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This file is part of Cerberus. + * + * Cerberus is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cerberus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cerberus. If not, see . + */ +package org.cerberus.jenkinsci.plugins.executecerberustest; +import org.apache.commons.lang.StringUtils; +import org.cerberus.launchcampaign.checkcampaign.*; +import org.cerberus.launchcampaign.event.LogEvent; +import org.cerberus.launchcampaign.executecampaign.*; +import org.jenkinsci.Symbol; +import org.kohsuke.stapler.*; + +import hudson.*; +import hudson.model.*; +import hudson.tasks.*; +import jenkins.tasks.SimpleBuildStep; +import net.sf.json.JSONObject; + +/** + * ExecuteCerberusCampaign {@link Builder}. + * + *

+ * When the user configures the project and enables this builder, + * {@link DescriptorImpl#newInstance(StaplerRequest)} is invoked + * and a new {@link ExecuteCerberusCampaign} is created. The created + * instance is persisted to the project configuration XML by using + * XStream, so this allows you to use instance fields (like {@link #campaignName}) + * to remember the configuration. + * + *

+ * When a build is performed, the {@link #perform} method will be invoked. + * + * @author Nicolas Deblock + */ +public class ExecuteCerberusCampaign extends Builder implements SimpleBuildStep { + + private final String campaignName; + private final String platform; + private final String environment; + private final String browser; + private final String browserVersion; + private final String ssIp; + private final String ss_p; + private final String screensize; + private final String robot; + + private final int screenshot; // default is 1 + private final int verbose; // default is 1 + private final int pageSource; // default is Y + private final int seleniumLog; // default is Y + private final int timeOut; // default is 5000 + private final int retries; // default is 0 + private final String tag; // default is 'Jenkins--' + current timestamp + + // Fields in config.jelly must match the parameter names in the "DataBoundConstructor" + @DataBoundConstructor + public ExecuteCerberusCampaign(final String campaignName, final String platform, final String environment, final String browser, + final String browserVersion, final int screenshot, final int verbose, final int pageSource, final int seleniumLog, + final int timeOut, final int retries, String tag, final String ss_p, final String screensize, final String ssIp, final String robot) { + this.campaignName = campaignName; + this.platform=platform; + this.environment=environment; + this.browser = browser; + this.browserVersion = browserVersion; + + this.screenshot = screenshot; // default is 1 + this.verbose = verbose; // default is 1 + this.pageSource = pageSource; // default is Y + this.seleniumLog = seleniumLog; // default is Y + this.timeOut = timeOut; // default is 5000 + this.retries = retries; // default is 0 + this.tag = tag; + + this.ss_p =ss_p; + this.ssIp =ssIp; + this.robot =robot; + this.screensize =screensize; + } + + @Override + public void perform(final Run build, final FilePath workspace, final Launcher launcher, final TaskListener listener) { + final JenkinsLogger logger = new JenkinsLogger(listener.getLogger()); + + // overide attribute if local settings is empty + final String robot = StringUtils.isEmpty(this.robot) ? getDescriptor().getRobot() : this.robot; + + final String ssIp = StringUtils.isEmpty(this.ssIp) ? getDescriptor().getSsIp() : this.ssIp; + final String ss_p = StringUtils.isEmpty(this.ss_p) ? getDescriptor().getSs_p() : this.ss_p; + final String platform = StringUtils.isEmpty(this.platform) ? getDescriptor().getPlatform() : this.platform; + final String browser = StringUtils.isEmpty(this.browser) ? getDescriptor().getBrowser() : this.browser; + final String browserVersion = StringUtils.isEmpty(this.browserVersion) ? getDescriptor().getBrowserVersion() : this.browserVersion; + + + try { + // calucation of tag + EnvVars env = build.getEnvironment(listener); + final String expandedTag = env.expand(this.tag); + + // 1 - Launch cerberus campaign + final ExecuteCampaignDto executeCampaignDto = new ExecuteCampaignDto(robot, ssIp, + environment, browser, browserVersion, platform, campaignName, screenshot, verbose, pageSource, + seleniumLog, timeOut, retries, expandedTag, ss_p, screensize); + + logger.info("Launch campaign " + executeCampaignDto.getSelectedCampaign() + " on " + getDescriptor().getUrlCerberus() + " with tag " + executeCampaignDto.getTagCerberus()); + + String urlCerberusReport = getDescriptor().getUrlCerberus() + "/ReportingExecutionByTag.jsp?Tag=" + executeCampaignDto.getTagCerberus(); + + LogEvent logEvent= new LogEvent() { + @Override + public void log(String error, String warning) { + if(!StringUtils.isEmpty(warning)) { + logger.warning(warning); + } + if(!StringUtils.isEmpty(error)) { + logger.error(error); + } + + } + }; + + final ExecuteCampaign executeCampaign = new ExecuteCampaign(getDescriptor().getUrlCerberus(), executeCampaignDto); + if(executeCampaign.execute(logEvent)) { + // 2 - check if cerberus campaign is finish + logger.info("Campaign is launched successfully. You can follow the report here : " + urlCerberusReport); + + CheckCampaignStatus checkCampaignStatus = new CheckCampaignStatus(executeCampaignDto.getTagCerberus(), getDescriptor().getUrlCerberus(), getDescriptor().timeToRefreshCheckCampaignStatus, getDescriptor().timeOutForCampaignExecution); + checkCampaignStatus.execute(new CheckCampaignStatus.CheckCampaignEvent() { + + @Override + public boolean checkCampaign(final ResultCIDto resultDto) { + logger.info(resultDto.getTotalTestExecuted() + " test executed ... ("+ resultDto.logDetailExecution() + ")"); + logger.info(resultDto.getStatusPE() + resultDto.getStatusNE() + " test pending ..."); + logger.info("cerberus message : " + resultDto.getMessage()); + logger.info("Advancement : " + resultDto.getPercentOfTestExecuted() + "%"); + return true; + } + }, new CheckCampaignStatus.ResultEvent() { + + @Override + public void result(final ResultCIDto resultDto) { + // display result and shutdown + long timeToExecuteTest = resultDto.getExecutionEnd().getTime() - resultDto.getExecutionStart().getTime(); + logger.info("---------------------------------------------------------------------------------------------"); + logger.info("Result : " + resultDto.getResult() + ", test executed in " + ((int)(timeToExecuteTest/1000)) + "s " + ((int)(timeToExecuteTest%1000)) + "ms"); + logger.info(resultDto.logDetailExecution()); + logger.info("---------------------------------------------------------------------------------------------"); + + // fail if test is not OK + if(!"OK".equals(resultDto.getResult())) { + logger.error("FAIL"); + build.setResult(Result.UNSTABLE); + } + } + },logEvent); + + logger.info("Campaign execution is finished. You can view the report here : " + urlCerberusReport); + } else { + logger.error("Fail to add campaign " + campaignName + " in cerberus queue"); + logger.error("Think to check cerberus log or cerberus queue to resolve problem"); + logger.error("UNSTABLE"); + build.setResult(Result.FAILURE); + } + } catch (Exception e) { + logger.error("error for campaign " + campaignName + " : " , e); + logger.error("Think to check cerberus log or cerberus queue to resolve problem"); + logger.error("UNSTABLE"); + build.setResult(Result.FAILURE); + } + } + + + public String getCampaignName() { + return campaignName; + } + + + public String getPlatform() { + return platform; + } + + public String getEnvironment() { + return environment; + } + + public String getBrowser() { + return browser; + } + + public String getBrowserVersion() { + return browserVersion; + } + + public int getScreenshot() { + return screenshot; + } + + public int getVerbose() { + return verbose; + } + + public int getPageSource() { + return pageSource; + } + + public int getSeleniumLog() { + return seleniumLog; + } + + public int getTimeOut() { + return timeOut; + } + + public int getRetries() { + return retries; + } + + public String getTag() { + return tag; + } + + public String getSs_p() { + return ss_p; + } + + public String getScreensize() { + return screensize; + } + + public String getSsIp() { + return ssIp; + } + + public String getRobot() { + return robot; + } + + // Overridden for better type safety. + // If your plugin doesn't really define any property on Descriptor, + // you don't have to do this. + @Override + public DescriptorImpl getDescriptor() { + return (DescriptorImpl) super.getDescriptor(); + } + + /** + * Descriptor for {@link ExecuteCerberusCampaign}. Used as a singleton. + * The class is marked as public so that it can be accessed from views. + * + *

+ * See {@code src/main/resources/hudson/plugins/hello_world/HelloWorldBuilder/*.jelly} + * for the actual HTML fragment for the configuration screen. + */ + @Symbol("executeCerberusCampaign") + @Extension // This indicates to Jenkins that this is an implementation of an extension point. + public static final class DescriptorImpl extends BuildStepDescriptor { + /** + * To persist global configuration information, + * simply store it in a field and call save(). + * + *

+ * If you don't want fields to be persisted, use {@code transient}. + */ + private String urlCerberus; + private String robot; + private String ssIp; + private String ss_p; + private String platform; + private String browser; + private String browserVersion; + private long timeToRefreshCheckCampaignStatus; + private int timeOutForCampaignExecution; + + + /** + * In order to load the persisted global configuration, you have to + * call load() in the constructor. + */ + public DescriptorImpl() { + load(); + } + + /** + * In order to load the persisted global configuration, you have to + * call load() in the constructor. + */ + public DescriptorImpl(boolean fortest) { + + } + + @Override + public boolean isApplicable(Class aClass) { + // Indicates that this builder can be used with all kinds of project types + return true; + } + + /** + * This human readable name is used in the configuration screen. + */ + @Override + public String getDisplayName() { + return "Execute Cerberus Campaign"; + } + + @Override + public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { + // To persist global configuration information, + // set that to properties and call save(). + urlCerberus = formData.getString("urlCerberus"); + robot = formData.getString("robot"); + ssIp = formData.getString("ssIp"); + ss_p = formData.getString("ss_p"); + browser = formData.getString("browser"); + browserVersion = formData.getString("browserVersion"); + timeToRefreshCheckCampaignStatus = formData.getLong("timeToRefreshCheckCampaignStatus"); + timeOutForCampaignExecution = formData.getInt("timeOutForCampaignExecution"); + platform = formData.getString("platform"); + // Can also use req.bindJSON(this, formData); + // (easier when there are many fields; need set* methods for this) + save(); + return super.configure(req,formData); + } + + public String getUrlCerberus() { + return urlCerberus; + } + public void setUrlCerberus(String url) { + this.urlCerberus=url; + } + + public String getRobot() { + return robot; + } + + public void setRobot(String robot) { + this.robot = robot; + } + + public String getSsIp() { + return ssIp; + } + + public void setSsIp(String ssIp) { + this.ssIp = ssIp; + } + + public String getBrowser() { + return browser; + } + + public void setBrowser(String browser) { + this.browser = browser; + } + + public String getBrowserVersion() { + return browserVersion; + } + + public void setBrowserVersion(String browserVersion) { + this.browserVersion = browserVersion; + } + + public long getTimeToRefreshCheckCampaignStatus() { + return timeToRefreshCheckCampaignStatus; + } + + public void setTimeToRefreshCheckCampaignStatus(long timeToRefreshCheckCampaignStatus) { + this.timeToRefreshCheckCampaignStatus = timeToRefreshCheckCampaignStatus; + } + + public int getTimeOutForCampaignExecution() { + return timeOutForCampaignExecution; + } + + public void setTimeOutForCampaignExecution(int timeOutForCampaignExecution) { + this.timeOutForCampaignExecution = timeOutForCampaignExecution; + } + + public String getSs_p() { + return ss_p; + } + + public void setSs_p(String ss_p) { + this.ss_p = ss_p; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + } + +} + diff --git a/src/main/java/org/cerberus/launchcampaign/Constantes.java b/src/main/java/org/cerberus/launchcampaign/Constantes.java index a74bd88..0482c9d 100644 --- a/src/main/java/org/cerberus/launchcampaign/Constantes.java +++ b/src/main/java/org/cerberus/launchcampaign/Constantes.java @@ -21,7 +21,7 @@ public final class Constantes { - public final static String URL_ADD_CAMPAIGN_TO_EXECUTION_QUEUE = "AddToExecutionQueue"; + public final static String URL_ADD_CAMPAIGN_TO_EXECUTION_QUEUE = "AddToExecutionQueueV001"; public final static String URL_RESULT_CI = "ResultCIV002"; public final static String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss.ms"; diff --git a/src/main/java/org/cerberus/launchcampaign/checkcampaign/ResultCIDto.java b/src/main/java/org/cerberus/launchcampaign/checkcampaign/ResultCIDto.java index 62f3963..5ee1fe0 100644 --- a/src/main/java/org/cerberus/launchcampaign/checkcampaign/ResultCIDto.java +++ b/src/main/java/org/cerberus/launchcampaign/checkcampaign/ResultCIDto.java @@ -1,308 +1,321 @@ -/** - * Cerberus Copyright (C) 2013 - 2017 cerberustesting - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This file is part of Cerberus. - * - * Cerberus is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Cerberus is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cerberus. If not, see . - */ -package org.cerberus.launchcampaign.checkcampaign; - -import java.util.Date; - -import com.fasterxml.jackson.annotation.*; - -/** - * Represent object was return by cerberus to send status of campaign's execution - * @author ndeblock - * - */ -public class ResultCIDto { - - @JsonProperty("message") - private String message; - - @JsonProperty("result") - private String result; // OK / KO - - @JsonProperty("ExecutionStart") - // ex date format 1970-01-01 01:00:00.0 - @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss.SSS", timezone="GMT") - private Date executionStart; - - @JsonProperty("ExecutionEnd") - @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss.SSS", timezone="GMT") - private Date executionEnd; - - @JsonProperty("messageType") - private String messageType; // OK / KO - - @JsonProperty("tag") - private String tag; - - @JsonProperty("NonOK_prio1_nbOfExecution") - private long nonOkPrio1; - @JsonProperty("NonOK_prio2_nbOfExecution") - private long nonOkPrio2; - @JsonProperty("NonOK_prio3_nbOfExecution") - private long nonOkPrio3; - @JsonProperty("NonOK_prio4_nbOfExecution") - private long nonOkPrio4; - - @JsonProperty("CI_OK_prio1") - private double ciOkPrio1; - @JsonProperty("CI_OK_prio2") - private double ciOkPrio2; - @JsonProperty("CI_OK_prio3") - private double ciOkPrio3; - @JsonProperty("CI_OK_prio4") - private double ciOkPrio4; - @JsonProperty("CI_finalResult") - private double ciFinalResult; - - @JsonProperty("status_CA_nbOfExecution") - private long statusCA; - @JsonProperty("status_FA_nbOfExecution") - private long statusFA; - @JsonProperty("status_PE_nbOfExecution") - private long statusPE; - @JsonProperty("status_NA_nbOfExecution") - private long statusNA; - @JsonProperty("status_OK_nbOfExecution") - private long statusOK; - @JsonProperty("status_KO_nbOfExecution") - private long statusKO; - @JsonProperty("status_NE_nbOfExecution") - private long statusNE; - - @JsonProperty("TOTAL_nbOfExecution") - private long total; - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getResult() { - return result; - } - - public void setResult(String result) { - this.result = result; - } - - public Date getExecutionStart() { - return (Date) executionStart.clone(); - } - - public Date getExecutionEnd() { - return (Date) executionEnd.clone(); - } - - public String getMessageType() { - return messageType; - } - - public void setMessageType(String messageType) { - this.messageType = messageType; - } - - public String getTag() { - return tag; - } - - public void setTag(String tag) { - this.tag = tag; - } - - public long getNonOkPrio1() { - return nonOkPrio1; - } - - public void setNonOkPrio1(long nonOkPrio1) { - this.nonOkPrio1 = nonOkPrio1; - } - - public long getNonOkPrio2() { - return nonOkPrio2; - } - - public void setNonOkPrio2(long nonOkPrio2) { - this.nonOkPrio2 = nonOkPrio2; - } - - public long getNonOkPrio3() { - return nonOkPrio3; - } - - public void setNonOkPrio3(long nonOkPrio3) { - this.nonOkPrio3 = nonOkPrio3; - } - - public long getNonOkPrio4() { - return nonOkPrio4; - } - - public void setNonOkPrio4(long nonOkPrio4) { - this.nonOkPrio4 = nonOkPrio4; - } - - public double getCiOkPrio1() { - return ciOkPrio1; - } - - public void setCiOkPrio1(double ciOkPrio1) { - this.ciOkPrio1 = ciOkPrio1; - } - - public double getCiOkPrio2() { - return ciOkPrio2; - } - - public void setCiOkPrio2(double ciOkPrio2) { - this.ciOkPrio2 = ciOkPrio2; - } - - public double getCiOkPrio3() { - return ciOkPrio3; - } - - public void setCiOkPrio3(double ciOkPrio3) { - this.ciOkPrio3 = ciOkPrio3; - } - - public double getCiOkPrio4() { - return ciOkPrio4; - } - - public void setCiOkPrio4(double ciOkPrio4) { - this.ciOkPrio4 = ciOkPrio4; - } - - public double getCiFinalResult() { - return ciFinalResult; - } - - public void setCiFinalResult(double ciFinalResult) { - this.ciFinalResult = ciFinalResult; - } - - public long getStatusCA() { - return statusCA; - } - - public void setStatusCA(long statusCA) { - this.statusCA = statusCA; - } - - public long getStatusFA() { - return statusFA; - } - - public void setStatusFA(long statusFA) { - this.statusFA = statusFA; - } - - public long getStatusPE() { - return statusPE; - } - - public void setStatusPE(long statusPE) { - this.statusPE = statusPE; - } - - public long getStatusNA() { - return statusNA; - } - - public void setStatusNA(long statusNA) { - this.statusNA = statusNA; - } - - public long getStatusOK() { - return statusOK; - } - - public void setStatusOK(long statusOK) { - this.statusOK = statusOK; - } - - public long getStatusKO() { - return statusKO; - } - - public void setStatusKO(long statusKO) { - this.statusKO = statusKO; - } - - public long getStatusNE() { - return statusNE; - } - - public void setStatusNE(long statusNE) { - this.statusNE = statusNE; - } - - public long getTotal() { - return total; - } - - public void setTotal(long total) { - this.total = total; - } - - - // ******************* some calculated field ***************************** - - /** - * @return The total of executed test (OK + CA + FA + NA + KO) - */ - public long getTotalTestExecuted() { - return this.getStatusOK() + this.getStatusCA() + this.getStatusFA() + this.getStatusNA() + this.getStatusKO(); - } - - /** - * @return Total test waiting to execute (PE + NE) - */ - public long getTestToExecute() { - return this.getTotalTestExecuted() + this.getStatusPE() + this.getStatusNE(); - } - - /** - * @return Percent of test already executed by cerberus - */ - public int getPercentOfTestExecuted() { - if(this.getTestToExecute() == 0) return 0; - - return (int) ((this.getTotalTestExecuted() / (double) this.getTestToExecute()) * 100d); - } - - - public String logDetailExecution() { - return "Details : " + - "OK " + this.getStatusOK() + - " | CA " + this.getStatusCA() + - " | FA " + this.getStatusFA() + - " | NA " + this.getStatusNA() + - " | KO " + this.getStatusKO() + - " | PE " + this.getStatusPE() + - " | NE " + this.getStatusNE(); - } - - - -} +/** + * Cerberus Copyright (C) 2013 - 2017 cerberustesting + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This file is part of Cerberus. + * + * Cerberus is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cerberus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cerberus. If not, see . + */ +package org.cerberus.launchcampaign.checkcampaign; + +import java.util.Date; + +import com.fasterxml.jackson.annotation.*; + +/** + * Represent object was return by cerberus to send status of campaign's execution + * @author ndeblock + * + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class ResultCIDto { + + @JsonProperty("message") + private String message; + + @JsonProperty("result") + private String result; // OK / KO + + @JsonProperty("ExecutionStart") + // ex date format 1970-01-01 01:00:00.0 + @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss.SSS", timezone="GMT") + private Date executionStart; + + @JsonProperty("ExecutionEnd") + @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss.SSS", timezone="GMT") + private Date executionEnd; + + @JsonProperty("messageType") + private String messageType; // OK / KO + + @JsonProperty("tag") + private String tag; + + @JsonProperty("NonOK_prio1_nbOfExecution") + private long nonOkPrio1; + @JsonProperty("NonOK_prio2_nbOfExecution") + private long nonOkPrio2; + @JsonProperty("NonOK_prio3_nbOfExecution") + private long nonOkPrio3; + @JsonProperty("NonOK_prio4_nbOfExecution") + private long nonOkPrio4; + + @JsonProperty("CI_OK_prio1") + private double ciOkPrio1; + @JsonProperty("CI_OK_prio2") + private double ciOkPrio2; + @JsonProperty("CI_OK_prio3") + private double ciOkPrio3; + @JsonProperty("CI_OK_prio4") + private double ciOkPrio4; + @JsonProperty("CI_finalResult") + private double ciFinalResult; + + @JsonProperty("status_CA_nbOfExecution") + private long statusCA; + @JsonProperty("status_FA_nbOfExecution") + private long statusFA; + @JsonProperty("status_PE_nbOfExecution") + private long statusPE; + @JsonProperty("status_NA_nbOfExecution") + private long statusNA; + @JsonProperty("status_OK_nbOfExecution") + private long statusOK; + @JsonProperty("status_KO_nbOfExecution") + private long statusKO; + @JsonProperty("status_NE_nbOfExecution") + private long statusNE; + @JsonProperty("status_QU_nbOfExecution") + private long statusQU; + + @JsonProperty("TOTAL_nbOfExecution") + private long total; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + + public Date getExecutionStart() { + return (Date) executionStart.clone(); + } + + public Date getExecutionEnd() { + return (Date) executionEnd.clone(); + } + + public String getMessageType() { + return messageType; + } + + public void setMessageType(String messageType) { + this.messageType = messageType; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public long getNonOkPrio1() { + return nonOkPrio1; + } + + public void setNonOkPrio1(long nonOkPrio1) { + this.nonOkPrio1 = nonOkPrio1; + } + + public long getNonOkPrio2() { + return nonOkPrio2; + } + + public void setNonOkPrio2(long nonOkPrio2) { + this.nonOkPrio2 = nonOkPrio2; + } + + public long getNonOkPrio3() { + return nonOkPrio3; + } + + public void setNonOkPrio3(long nonOkPrio3) { + this.nonOkPrio3 = nonOkPrio3; + } + + public long getNonOkPrio4() { + return nonOkPrio4; + } + + public void setNonOkPrio4(long nonOkPrio4) { + this.nonOkPrio4 = nonOkPrio4; + } + + public double getCiOkPrio1() { + return ciOkPrio1; + } + + public void setCiOkPrio1(double ciOkPrio1) { + this.ciOkPrio1 = ciOkPrio1; + } + + public double getCiOkPrio2() { + return ciOkPrio2; + } + + public void setCiOkPrio2(double ciOkPrio2) { + this.ciOkPrio2 = ciOkPrio2; + } + + public double getCiOkPrio3() { + return ciOkPrio3; + } + + public void setCiOkPrio3(double ciOkPrio3) { + this.ciOkPrio3 = ciOkPrio3; + } + + public double getCiOkPrio4() { + return ciOkPrio4; + } + + public void setCiOkPrio4(double ciOkPrio4) { + this.ciOkPrio4 = ciOkPrio4; + } + + public double getCiFinalResult() { + return ciFinalResult; + } + + public void setCiFinalResult(double ciFinalResult) { + this.ciFinalResult = ciFinalResult; + } + + public long getStatusCA() { + return statusCA; + } + + public void setStatusCA(long statusCA) { + this.statusCA = statusCA; + } + + public long getStatusFA() { + return statusFA; + } + + public void setStatusFA(long statusFA) { + this.statusFA = statusFA; + } + + public long getStatusPE() { + return statusPE; + } + + public void setStatusPE(long statusPE) { + this.statusPE = statusPE; + } + + public long getStatusNA() { + return statusNA; + } + + public void setStatusNA(long statusNA) { + this.statusNA = statusNA; + } + + public long getStatusOK() { + return statusOK; + } + + public void setStatusOK(long statusOK) { + this.statusOK = statusOK; + } + + public long getStatusKO() { + return statusKO; + } + + public void setStatusKO(long statusKO) { + this.statusKO = statusKO; + } + + public long getStatusNE() { + return statusNE; + } + + public void setStatusNE(long statusNE) { + this.statusNE = statusNE; + } + + public long getTotal() { + return total; + } + + public void setTotal(long total) { + this.total = total; + } + + public long getStatusQU() { + return statusQU; + } + + public void setStatusQU(long statusQU) { + this.statusQU = statusQU; + } + + // ******************* some calculated field ***************************** + + + + /** + * @return The total of executed test (OK + CA + FA + NA + KO) + */ + public long getTotalTestExecuted() { + return this.getStatusOK() + this.getStatusCA() + this.getStatusFA() + this.getStatusNA() + this.getStatusKO(); + } + + /** + * @return Total test waiting to execute (PE + NE) + */ + public long getTestToExecute() { + return this.getTotalTestExecuted() + this.getStatusPE() + this.getStatusNE(); + } + + /** + * @return Percent of test already executed by cerberus + */ + public int getPercentOfTestExecuted() { + if(this.getTestToExecute() == 0) return 0; + + return (int) ((this.getTotalTestExecuted() / (double) this.getTestToExecute()) * 100d); + } + + + public String logDetailExecution() { + return "Details : " + + "OK " + this.getStatusOK() + + " | CA " + this.getStatusCA() + + " | FA " + this.getStatusFA() + + " | NA " + this.getStatusNA() + + " | KO " + this.getStatusKO() + + " | PE " + this.getStatusPE() + + " | QU " + this.getStatusQU() + + " | NE " + this.getStatusNE(); + } + + + +} diff --git a/src/main/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignDto.java b/src/main/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignDto.java index b7883ec..8b2ca84 100644 --- a/src/main/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignDto.java +++ b/src/main/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignDto.java @@ -37,7 +37,9 @@ public class ExecuteCampaignDto { private String platform; private String selectedCampaign; private String tagCerberusCampaign; - + private String ss_p; + private String screensize; + private final int screenshot; private final int verbose; private final int pageSource; @@ -45,9 +47,10 @@ public class ExecuteCampaignDto { private final int timeOut; private final int retries; + public ExecuteCampaignDto(final String robot, final String ss_ip, final String environment, final String browser, final String browserVersion, final String platform, final String selectedCampaign, final int screenshot, final int verbose, - final int pageSource, final int seleniumLog, final int timeOut, final int retries, String tag) { + final int pageSource, final int seleniumLog, final int timeOut, final int retries, String tag, String ss_p, String screensize) { super(); this.robot = robot; this.ss_ip = ss_ip; @@ -74,13 +77,27 @@ public ExecuteCampaignDto(final String robot, final String ss_ip, final String e public String verifyParameterWarning() { String warning = ""; - warning += checkIsEmpty(this.robot, "robot"); - warning += checkIsEmpty(this.ss_ip, "ss_ip"); - warning += checkIsEmpty(this.browser, "browser"); - warning += checkIsEmpty(this.browserVersion, "browserVersion"); - warning += checkIsEmpty(this.platform, "platform"); - warning += checkIsEmpty(this.selectedCampaign, "selectedCampaign"); + // rules : + // - either robot + // - or ss_ip+ ss_p + browser + browserVersion + platform + + if(StringUtils.isEmpty(this.robot) && + (StringUtils.isEmpty(this.ss_ip) || + StringUtils.isEmpty(this.ss_p) || + StringUtils.isEmpty(this.browser) || + StringUtils.isEmpty(this.browserVersion) || + StringUtils.isEmpty(this.platform)) ) { + warning += "either robot or selenium server ip + selenium server port + browser + browser Version + platform is required, "; + warning += checkIsEmpty(this.robot, "robot"); + warning += checkIsEmpty(this.ss_ip, "selenium server ip"); + warning += checkIsEmpty(this.ss_p, "selenium server port"); + warning += checkIsEmpty(this.browser, "browser"); + warning += checkIsEmpty(this.browserVersion, "browser Version"); + warning += checkIsEmpty(this.platform, "platform"); + } + warning += checkIsEmpty(this.selectedCampaign, "selectedCampaign"); + return warning; @@ -89,11 +106,11 @@ public String verifyParameterWarning() { public String verifyParameterError() { String error = ""; - error += check0or1(this.screenshot, "screenshot"); - error += check0or1(this.verbose, "verbose"); - error += check0or1(this.pageSource, "pageSource"); - error += check0or1(this.seleniumLog, "seleniumLog"); - error += check0or1(this.retries, "retries"); + error += check0or1or2(this.screenshot, "screenshot"); + error += check0or1or2(this.verbose, "verbose"); + error += check0or1or2(this.pageSource, "pageSource"); + error += check0or1or2(this.seleniumLog, "seleniumLog"); + error += checkRetries(this.retries); return error; } @@ -104,38 +121,45 @@ private String checkIsEmpty(String parameter, String parameterName) { } return ""; } - private String check0or1(int parameter, String parameterName) { - if(parameter != 0 && parameter != 1) { - return parameterName + " must be 0 or 1 but is " + parameter + ", "; + private String checkRetries(int parameter) { + if(parameter < 0 || parameter > 3) { + return "retries must be 0, 1, 2 or 3 but is " + parameter + ", "; } return ""; } - + private String check0or1or2(int parameter, String parameterName) { + if(parameter != 0 && parameter != 1) { + return parameterName + " must be 0, 1 or 2 but is " + parameter + ", "; + } + return ""; + } + public URL buildUrl(String urlCerberus) throws MalformedURLException, URISyntaxException { - URIBuilder b = new URIBuilder(urlCerberus + "/" + Constantes.URL_ADD_CAMPAIGN_TO_EXECUTION_QUEUE); - - b.addParameter("OutputFormat", "json"); - b.addParameter("Screenshot",this.screenshot +""); - b.addParameter("Verbose", this.verbose+""); - b.addParameter("timeout", this.timeOut+""); - b.addParameter("Synchroneous", "Y"); - b.addParameter("PageSource",this.pageSource + ""); - b.addParameter("SeleniumLog", this.seleniumLog +""); - b.addParameter("retries", this.retries+""); - b.addParameter("manualExecution", "N"); + URIBuilder b = new URIBuilder(urlCerberus + "/" + Constantes.URL_ADD_CAMPAIGN_TO_EXECUTION_QUEUE); - b.addParameter("ss_ip", ss_ip); - b.addParameter("Robot", robot); - b.addParameter("Environment", environment); - b.addParameter("Browser", browser); - b.addParameter("BrowserVersion", browserVersion); - b.addParameter("Platform", platform); - b.addParameter("SelectedCampaign", selectedCampaign); - - // genere a ramdom tag - b.addParameter("Tag", tagCerberusCampaign); - - return new URL(b.build().toString()); + b.addParameter("screenshot",this.screenshot +""); + b.addParameter("verbose", this.verbose+""); + b.addParameter("timeout", this.timeOut+""); + b.addParameter("pagesource",this.pageSource + ""); + b.addParameter("seleniumlog", this.seleniumLog +""); + b.addParameter("retries", this.retries+""); + b.addParameter("manualexecution", "N"); + + b.addParameter("ss_ip", ss_ip); + b.addParameter("ss_p", ss_p); + b.addParameter("robot", robot); + b.addParameter("environment", environment); + b.addParameter("browser", browser); + b.addParameter("version", browserVersion); + b.addParameter("platform", platform); + b.addParameter("campaign", selectedCampaign); + b.addParameter("screensize", screensize); + + // genere a random tag + b.addParameter("tag", tagCerberusCampaign); + + + return new URL(b.build().toString()); } public String getTagCerberus() { diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/config.jelly b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/config.jelly index 9ac8e7e..d91fbdd 100644 --- a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/config.jelly +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/config.jelly @@ -9,45 +9,69 @@ - - + + + + - - - - + + - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/global.jelly b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/global.jelly index 63f344a..c229e25 100644 --- a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/global.jelly +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/global.jelly @@ -13,20 +13,10 @@ description="Url of cerberus"> - - - - - - - - - - + + @@ -35,6 +25,26 @@ description="Timeout for campaign execution. After this time if campaign is not finished, job failed."> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browser.html b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browser.html new file mode 100644 index 0000000..46b775c --- /dev/null +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browser.html @@ -0,0 +1,6 @@ +

+- either robot
+- or Robot server ip + Robot server port + browser + browser version + platform
+ +If you enter a robot, no need to enter Robot server ip + Robot server port + browser + browser version + platform +
diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browserVersion.html b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browserVersion.html new file mode 100644 index 0000000..46b775c --- /dev/null +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-browserVersion.html @@ -0,0 +1,6 @@ +
+- either robot
+- or Robot server ip + Robot server port + browser + browser version + platform
+ +If you enter a robot, no need to enter Robot server ip + Robot server port + browser + browser version + platform +
diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-platform.html b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-platform.html index bdab798..46b775c 100644 --- a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-platform.html +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-platform.html @@ -1,3 +1,6 @@
- Platform Cerberus must use. +- either robot
+- or Robot server ip + Robot server port + browser + browser version + platform
+ +If you enter a robot, no need to enter Robot server ip + Robot server port + browser + browser version + platform
diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-robot.html b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-robot.html new file mode 100644 index 0000000..46b775c --- /dev/null +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-robot.html @@ -0,0 +1,6 @@ +
+- either robot
+- or Robot server ip + Robot server port + browser + browser version + platform
+ +If you enter a robot, no need to enter Robot server ip + Robot server port + browser + browser version + platform +
diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ssIp.html b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ssIp.html new file mode 100644 index 0000000..46b775c --- /dev/null +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ssIp.html @@ -0,0 +1,6 @@ +
+- either robot
+- or Robot server ip + Robot server port + browser + browser version + platform
+ +If you enter a robot, no need to enter Robot server ip + Robot server port + browser + browser version + platform +
diff --git a/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ss_p.html b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ss_p.html new file mode 100644 index 0000000..46b775c --- /dev/null +++ b/src/main/resources/org/cerberus/jenkinsci/plugins/executecerberustest/ExecuteCerberusCampaign/help-ss_p.html @@ -0,0 +1,6 @@ +
+- either robot
+- or Robot server ip + Robot server port + browser + browser version + platform
+ +If you enter a robot, no need to enter Robot server ip + Robot server port + browser + browser version + platform +
diff --git a/src/test/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignTest.java b/src/test/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignTest.java index 97afb6c..d96c962 100644 --- a/src/test/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignTest.java +++ b/src/test/java/org/cerberus/launchcampaign/executecampaign/ExecuteCampaignTest.java @@ -46,7 +46,7 @@ public class ExecuteCampaignTest { @Before public void before() { - ExecuteCampaignDto executeCampaignDto = new ExecuteCampaignDto("", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, ""); + ExecuteCampaignDto executeCampaignDto = new ExecuteCampaignDto("", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, "","",""); urlAddCampaign = "http://localhost:" + mockServerRule.getPort() + "/Cerberus/"+Constantes.URL_ADD_CAMPAIGN_TO_EXECUTION_QUEUE; executeCampaign = new ExecuteCampaign(urlAddCampaign, executeCampaignDto);