Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@
<version>${springBootVersion}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${springBootVersion}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down Expand Up @@ -125,6 +133,12 @@
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.4.1</version>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-netty -->
<dependency>
Expand Down Expand Up @@ -167,10 +181,17 @@
<dependency>
<groupId>com.github.eiffel-community</groupId>
<artifactId>eiffel-commons</artifactId>
<version>master-SNAPSHOT</version>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
</dependencies>

<dependencyManagement>
</dependencyManagement>
<repositories>
<repository>
<id>jitpack.io</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.junit.Ignore;
import org.slf4j.Logger;
Expand Down Expand Up @@ -35,17 +36,17 @@ public void configurations_are_provided() {
config.initRemRemConfig();
}

@Given("^a jenkins job '\\\"([^\\\"]*)\\\"' from '\"([^\"]*)\"' is created$")
public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFileName) throws Throwable {
@Given("^a jenkins job '\\\"([^\\\"]*)\\\"' from '\"([^\"]*)\"' is created with parameters: (.*)$")
public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFileName, List<String> parameters) throws Throwable {
boolean success = StepsUtils.createJenkinsJob(
jenkinsJobName,
scriptFileName,
config.getJenkinsBaseUrl(),
config.getJenkinsUsername(),
config.getJenkinsPassword(),
config.getRemremBaseUrl(),
JENKINS_TOKEN,
JENKINS_JOB_XML,
config.getRemremBaseUrl()
parameters
);

if (success) {
Expand All @@ -55,11 +56,6 @@ public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFi
assertTrue("Failed to create jenkins job.", success);
}

@Then("^we continue with the next step$")
public void we_continue_with_the_next_step() {
//Just for cucumber to make sense
}

@Then("^subscriptions and jenkins jobs should be removed$")
public void subscriptions_and_jenkins_jobs_should_be_removed() throws Throwable {
StepsUtils.deleteJenkinsJobs(jenkinsJobNames);
Expand Down Expand Up @@ -88,18 +84,13 @@ public void we_send_the_to_eiffel_intelligence_for_creation(String subscriptionN
assertEquals("Failed to create subscription. Response: " + response.getBody(), 200, response.getStatusCode());
}

@Given("^all previous tests passes\\.$")
public void all_previous_tests_passes() {
//Just for cucumber to make sense
}

@When("^future story is done\\.$")
public void future_story_is_done() {

@Given("^the jenkins job \"([^\"]*)\" is triggered$")
public void the_jenkins_job_is_triggered(String jenkinsJobToTrigger) throws Throwable {
StepsUtils.triggerJenkinsJob(jenkinsJobToTrigger, JENKINS_TOKEN);
}

@Then("^everything should be fine\\.$")
public void everything_should_be_fine() {

@When("^all jenkins jobs has been triggered$")
public void the_jenkins_job_has_been_triggered() throws Throwable {
StepsUtils.hasJenkinsJobsBeenTriggered(jenkinsJobNames, config.getJobTimeoutMilliseconds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.junit.Ignore;
import org.slf4j.Logger;
Expand Down Expand Up @@ -35,17 +36,17 @@ public void configurations_are_provided() {
config.initRemRemConfig();
}

@Given("^a jenkins job '\\\"([^\\\"]*)\\\"' from '\"([^\"]*)\"' is created$")
public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFileName) throws Throwable {
@Given("^a jenkins job '\\\"([^\\\"]*)\\\"' from '\"([^\"]*)\"' is created with parameters: (.*)$")
public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFileName, List<String> parameters) throws Throwable {
boolean success = StepsUtils.createJenkinsJob(
jenkinsJobName,
scriptFileName,
config.getJenkinsBaseUrl(),
config.getJenkinsUsername(),
config.getJenkinsPassword(),
config.getRemremBaseUrl(),
JENKINS_TOKEN,
JENKINS_JOB_XML,
config.getRemremBaseUrl()
parameters
);

if (success) {
Expand Down
15 changes: 15 additions & 0 deletions src/systemtest/java/com/ericsson/ei/systemtest/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ public class Config {

private String eiFrontendBaseUrl;
private String eiBackendBaseUrl;

private int jobTimeoutMilliseconds = 60000;

/**
* Initializes the configuration. Some configurations are set to default and some are mendatory.
* These are the current default configuration values:
* int jobTimeoutMilliseconds = 60000
*/
public Config() {
String jobTimeoutMilliseconds = System.getProperty("job.timeout.milliseconds");
if(jobTimeoutMilliseconds != null) {
this.jobTimeoutMilliseconds = Integer.parseInt(jobTimeoutMilliseconds);
}
}

/**
*
* This method retrieves the jenkins properties from the system properties.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package com.ericsson.ei.systemtest.utils;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ericsson.eiffelcommons.JenkinsManager;
import com.ericsson.eiffelcommons.helpers.JenkinsXmlData;
import com.ericsson.eiffelcommons.subscriptionobject.RestPostSubscriptionObject;
import com.ericsson.eiffelcommons.utils.HttpRequest;
import com.ericsson.eiffelcommons.utils.HttpRequest.HttpMethod;
import com.ericsson.eiffelcommons.utils.ResponseEntity;
import com.ericsson.eiffelcommons.utils.Utils;

public class StepsUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(StepsUtils.class);
Expand All @@ -39,19 +44,29 @@ public class StepsUtils {
* @return boolean - If the creation was a success or not
* @throws Exception
*/
public static boolean createJenkinsJob(String jenkinsJobName, String scriptFileName, String jenkinsBaseUrl, String jenkinsUsername, String jenkinsPassword, String jenkinsToken, String jenkinsJobXml, String remremBaseUrl) throws Exception {
public static boolean createJenkinsJob(String jenkinsJobName, String scriptFileName, String jenkinsBaseUrl, String jenkinsUsername, String jenkinsPassword, String remremBaseUrl, String jenkinsToken, List<String> parameters) throws Exception {
String script = new String(Files.readAllBytes(Paths.get(scriptFileName)));
script = script.replace("REMREM_BASE_URL_TO_BE_REPLACED", remremBaseUrl);

JenkinsXmlData jenkinsXmlData = new JenkinsXmlData()
.addJobToken(jenkinsToken)
.addSystemGrovyScript(script, false);


for (String parameter: parameters) {
jenkinsXmlData.addBuildParameter(parameter);
}

String jenkinsXmlAsString = jenkinsXmlData.getXmlAsString();

jenkinsManager = new JenkinsManager(jenkinsBaseUrl, jenkinsUsername, jenkinsPassword);

if(!jenkinsManager.pluginExists("Groovy")) {
jenkinsManager.installPlugin("Groovy", "2.1");
jenkinsManager.restartJenkins();
}
String script = new String(Files.readAllBytes(Paths.get(scriptFileName)));
script = script.replace("REMREM_BASE_URL_TO_BE_REPLACED", remremBaseUrl);

String xmlJobData = Utils.getResourceFileAsString(jenkinsJobXml);
xmlJobData = xmlJobData.replace("SCRIPT_TO_BE_REPLACED", script);
return jenkinsManager.forceCreateJob(jenkinsJobName, xmlJobData);
return jenkinsManager.forceCreateJob(jenkinsJobName, jenkinsXmlAsString);
}

/**
Expand Down Expand Up @@ -169,6 +184,69 @@ public static void deleteSubscriptions(String frontendBaseUrl, String backendBas
}
}

/**
* Triggers a jenkins job with parameters.
*
* @param jenkinsJobToTrigger
* @param jenkinsToken
* @throws Exception
*/
public static void triggerJenkinsJob(String jenkinsJobToTrigger, String jenkinsToken) throws Exception {
boolean success = jenkinsManager.buildJob(jenkinsJobToTrigger, jenkinsToken);
assertEquals("Was not able to trigger jenkins job", true, success);
}

/**
* Check if all jenkins jobs in a list of jenkins job names has been triggered
*
* @param jenkinsJobNames
* @throws Exception
*/
public static void hasJenkinsJobsBeenTriggered(ArrayList<String> jenkinsJobNames, int timeoutMilliseconds) throws Exception {
for(int i=0; i<jenkinsJobNames.size(); i++) {
hasJenkinsJobBeenTriggered(jenkinsJobNames.get(i), timeoutMilliseconds);
}
}

/**
* Check if a single jenkins job has been triggered
*
* @param jenkinsJob
* @throws Exception
*/
public static void hasJenkinsJobBeenTriggered(String jenkinsJob, int timeoutMilliseconds) throws Exception {
long maxTime = System.currentTimeMillis() + timeoutMilliseconds;

while(System.currentTimeMillis() < maxTime) {
try {
JSONObject status = jenkinsManager.getJenkinsBuildStatusData(jenkinsJob);
int duration = status.getInt("duration");
String result = status.getString("result");

if(result.equals("null")) {
LOGGER.info(jenkinsJob + " triggered but not finished yet. Rechecking...");
continue;
}

String infoMessage = jenkinsJob + " was triggered. Duration(ms): " + duration + ". Result: " + result;

boolean statusContainsParameters = status.has("actions") && status.getJSONArray("actions").length() != 0 && status.getJSONArray("actions").getJSONObject(0).has("parameters");
if (statusContainsParameters) {
JSONArray parameters = status.getJSONArray("actions").getJSONObject(0).getJSONArray("parameters");
infoMessage += " Parameters: " + parameters;
}

LOGGER.info(infoMessage);
return;
} catch (Exception e) {
TimeUnit.SECONDS.sleep(1);
continue;
}
}

throw new Exception("Jenkins job \"" + jenkinsJob + "\" was never triggered successfully.");
}

/**
* Deletes a subscription from eiffel intelligence
*
Expand Down
14 changes: 7 additions & 7 deletions src/systemtest/resources/JenkinsShellScripts/ArtC2Script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def baseUrl = "REMREM_BASE_URL_TO_BE_REPLACED";
///////////////////////////////////////SCC2/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathSCC2 = baseUrl + "/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelSourceChangeCreatedEvent";
def uriPathSCC2 = baseUrl + "/generateAndPublish?mp=eiffelsemantics&msgType=EiffelSourceChangeCreatedEvent";
def jsonSCC2 = """{
"msgParams": {
"meta": {
Expand Down Expand Up @@ -63,7 +63,7 @@ SCC2ID = generateEiffelEventAndPublish(uriPathSCC2, jsonSCC2);
///////////////////////////////////////SCC1/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathSCC1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelSourceChangeCreatedEvent';
def uriPathSCC1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelSourceChangeCreatedEvent';
def jsonSCC1 = """
{
"msgParams": {
Expand Down Expand Up @@ -122,7 +122,7 @@ SCC1ID = generateEiffelEventAndPublish(uriPathSCC1, jsonSCC1);
///////////////////////////////////////SCS1/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathSCS1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelSourceChangeSubmittedEvent';
def uriPathSCS1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelSourceChangeSubmittedEvent';
def jsonSCS1 = """
{
"msgParams": {
Expand Down Expand Up @@ -181,7 +181,7 @@ SCS1ID = generateEiffelEventAndPublish(uriPathSCS1, jsonSCS1);
///////////////////////////////////////CDef1/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathCDef1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelCompositionDefinedEvent';
def uriPathCDef1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelCompositionDefinedEvent';
def jsonCDef1 = """
{
"msgParams": {
Expand Down Expand Up @@ -218,7 +218,7 @@ CDef1ID = generateEiffelEventAndPublish(uriPathCDef1, jsonCDef1);
///////////////////////////////////////ArtC1/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathArtC1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelArtifactCreatedEvent';
def uriPathArtC1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelArtifactCreatedEvent';
def jsonArtC1 = """
{
"msgParams": {
Expand Down Expand Up @@ -260,7 +260,7 @@ ArtC1ID = generateEiffelEventAndPublish(uriPathArtC1, jsonArtC1);
///////////////////////////////////////CDef2/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathCDef2 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelCompositionDefinedEvent';
def uriPathCDef2 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelCompositionDefinedEvent';
def jsonCDef2 = """
{
"msgParams": {
Expand Down Expand Up @@ -297,7 +297,7 @@ CDef2ID = generateEiffelEventAndPublish(uriPathCDef2, jsonCDef2);
///////////////////////////////////////ArtC2/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathArtC2 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelArtifactCreatedEvent';
def uriPathArtC2 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelArtifactCreatedEvent';
def jsonArtC2 = """
{
"msgParams": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def baseUrl = "REMREM_BASE_URL_TO_BE_REPLACED";
///////////////////////////////////////CLM1/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathArtP1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelArtifactPublishedEvent';
def uriPathArtP1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelArtifactPublishedEvent';
def jsonArtP1 = """
{
"msgParams": {
Expand Down
2 changes: 1 addition & 1 deletion src/systemtest/resources/JenkinsShellScripts/CLMScript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def baseUrl = "REMREM_BASE_URL_TO_BE_REPLACED";
///////////////////////////////////////CLM1/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

def uriPathCLM1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&amp;msgType=EiffelConfidenceLevelModifiedEvent';
def uriPathCLM1 = baseUrl + '/generateAndPublish?mp=eiffelsemantics&msgType=EiffelConfidenceLevelModifiedEvent';
def jsonCLM1 = """
{
"msgParams": {
Expand Down
Loading