Skip to content

Commit c90e0cc

Browse files
Add Test Execution system test jobs (#182)
* Add Test Execution system test jobs
1 parent 7eaca3a commit c90e0cc

File tree

12 files changed

+588
-75
lines changed

12 files changed

+588
-75
lines changed

src/systemtest/java/com/ericsson/ei/systemtest/artifactflow/ArtifactFlowSteps.java

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import java.util.List;
88

99
import org.junit.Ignore;
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
1210
import org.springframework.test.context.support.AbstractTestExecutionListener;
1311

1412
import com.ericsson.ei.systemtest.utils.Config;
@@ -20,10 +18,8 @@
2018
import cucumber.api.java.en.When;
2119

2220
@Ignore
23-
public class ArtifactFlowSteps extends AbstractTestExecutionListener{
24-
private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactFlowSteps.class);
21+
public class ArtifactFlowSteps extends AbstractTestExecutionListener {
2522
private static final String JENKINS_TOKEN = "123";
26-
private static final String JENKINS_JOB_XML = "jenkinsJobTemplate.xml";
2723

2824
private ArrayList<String> jenkinsJobNames = new ArrayList<String>();
2925
private Config config = new Config();
@@ -36,7 +32,28 @@ public void configurations_are_provided() {
3632
config.initRemRemConfig();
3733
}
3834

39-
@Given("^a jenkins job '\\\"([^\\\"]*)\\\"' from '\"([^\"]*)\"' is created with parameters: (.*)$")
35+
@Given("^subscription object \"([^\"]*)\" is created which will trigger \"([^\"]*)\"(.*)$")
36+
public void subscription_is_created(String subscriptionName, String nameOfTriggeredJob, String hasParameters) throws Throwable {
37+
StepsUtils.createSubscription(subscriptionName, nameOfTriggeredJob, config.getJenkinsUsername(), config.getJenkinsPassword(),
38+
config.getJenkinsBaseUrl(), !hasParameters.isEmpty());
39+
}
40+
41+
@Given("^the jenkins job \"([^\"]*)\" is triggered$")
42+
public void the_jenkins_job_is_triggered(String jenkinsJobToTrigger) throws Throwable {
43+
StepsUtils.triggerJenkinsJob(jenkinsJobToTrigger, JENKINS_TOKEN);
44+
}
45+
46+
@When("^notification with key \"([^\"]*)\" and value \"([^\"]*)\" is added to \"([^\"]*)\"$")
47+
public void notification_with_key_and_value_is_added_to(String key, String value, String subscriptionName) throws Throwable {
48+
StepsUtils.addNotificationToSubscription(key, value, subscriptionName);
49+
}
50+
51+
@When("^condition with jmespath \"([^\"]*)\" is added to \"([^\"]*)\"$")
52+
public void condition_with_jmespath_is_added_to(String jmesPath, String subscriptionName) throws Throwable {
53+
StepsUtils.addConditionToRequirement(jmesPath, subscriptionName);
54+
}
55+
56+
@Then("^a jenkins job \"([^\"]*)\" from \"([^\"]*)\" is created with parameters: (.*)$")
4057
public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFileName, List<String> parameters) throws Throwable {
4158
boolean success = StepsUtils.createJenkinsJob(
4259
jenkinsJobName,
@@ -56,41 +73,21 @@ public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFi
5673
assertTrue("Failed to create jenkins job.", success);
5774
}
5875

59-
@Then("^subscriptions and jenkins jobs should be removed$")
60-
public void subscriptions_and_jenkins_jobs_should_be_removed() throws Throwable {
61-
StepsUtils.deleteJenkinsJobs(jenkinsJobNames);
62-
StepsUtils.deleteSubscriptions(config.getEiFrontendBaseUrl(), config.getEiBackendBaseUrl());
63-
}
64-
65-
@Given("^subscription object \"([^\"]*)\" is created which will trigger \"([^\"]*)\"$")
66-
public void subscription_is_created(String subscriptionName, String nameOfTriggeredJob) throws Throwable {
67-
StepsUtils.createSubscription(subscriptionName, nameOfTriggeredJob, config.getJenkinsUsername(), config.getJenkinsPassword(), config.getJenkinsBaseUrl());
68-
}
69-
70-
@When("^notification with key \"([^\"]*)\" and value \"([^\"]*)\" is added to \"([^\"]*)\"$")
71-
public void notification_with_key_and_value_is_added_to(String key, String value, String subscriptionName) throws Throwable {
72-
StepsUtils.addNotificationToSubscription(key, value, subscriptionName);
73-
}
74-
75-
@When("^condition with jmespath \"([^\"]*)\" is added to \"([^\"]*)\"$")
76-
public void condition_with_jmespath_is_added_to(String jmesPath, String subscriptionName) throws Throwable {
77-
StepsUtils.addConditionToRequirement(jmesPath, subscriptionName);
78-
}
79-
8076
@Then("^we send the \"([^\"]*)\" to eiffel intelligence for creation\\.$")
8177
public void we_send_the_to_eiffel_intelligence_for_creation(String subscriptionName) throws Throwable {
8278
ResponseEntity response = StepsUtils.sendSubscriptionToEiffelIntelligence(subscriptionName, config.getEiFrontendBaseUrl(), config.getEiBackendBaseUrl());
8379

8480
assertEquals("Failed to create subscription. Response: " + response.getBody(), 200, response.getStatusCode());
8581
}
8682

87-
@Given("^the jenkins job \"([^\"]*)\" is triggered$")
88-
public void the_jenkins_job_is_triggered(String jenkinsJobToTrigger) throws Throwable {
89-
StepsUtils.triggerJenkinsJob(jenkinsJobToTrigger, JENKINS_TOKEN);
90-
}
91-
92-
@When("^all jenkins jobs has been triggered$")
83+
@Then("^all jenkins jobs has been triggered$")
9384
public void the_jenkins_job_has_been_triggered() throws Throwable {
9485
StepsUtils.hasJenkinsJobsBeenTriggered(jenkinsJobNames, config.getJobTimeoutMilliseconds());
9586
}
96-
}
87+
88+
@Then("^subscriptions and jenkins jobs should be removed$")
89+
public void subscriptions_and_jenkins_jobs_should_be_removed() throws Throwable {
90+
StepsUtils.deleteJenkinsJobs(jenkinsJobNames);
91+
StepsUtils.deleteSubscriptions(config.getEiFrontendBaseUrl(), config.getEiBackendBaseUrl());
92+
}
93+
}

src/systemtest/java/com/ericsson/ei/systemtest/testexecutionflow/TestExecutionFlowSteps.java

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import java.util.List;
88

99
import org.junit.Ignore;
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
1210
import org.springframework.test.context.support.AbstractTestExecutionListener;
1311

1412
import com.ericsson.ei.systemtest.utils.Config;
@@ -20,10 +18,8 @@
2018
import cucumber.api.java.en.When;
2119

2220
@Ignore
23-
public class TestExecutionFlowSteps extends AbstractTestExecutionListener{
24-
private static final Logger LOGGER = LoggerFactory.getLogger(TestExecutionFlowSteps.class);
21+
public class TestExecutionFlowSteps extends AbstractTestExecutionListener {
2522
private static final String JENKINS_TOKEN = "123";
26-
private static final String JENKINS_JOB_XML = "jenkinsJobTemplate.xml";
2723

2824
private ArrayList<String> jenkinsJobNames = new ArrayList<String>();
2925
private Config config = new Config();
@@ -36,7 +32,28 @@ public void configurations_are_provided() {
3632
config.initRemRemConfig();
3733
}
3834

39-
@Given("^a jenkins job '\\\"([^\\\"]*)\\\"' from '\"([^\"]*)\"' is created with parameters: (.*)$")
35+
@Given("^subscription object \"([^\"]*)\" is created which will trigger \"([^\"]*)\"(.*)$")
36+
public void subscription_is_created(String subscriptionName, String nameOfTriggeredJob, String hasParameters) throws Throwable {
37+
StepsUtils.createSubscription(subscriptionName, nameOfTriggeredJob, config.getJenkinsUsername(), config.getJenkinsPassword(),
38+
config.getJenkinsBaseUrl(), !hasParameters.isEmpty());
39+
}
40+
41+
@Given("^the jenkins job \"([^\"]*)\" is triggered$")
42+
public void the_jenkins_job_is_triggered(String jenkinsJobToTrigger) throws Throwable {
43+
StepsUtils.triggerJenkinsJob(jenkinsJobToTrigger, JENKINS_TOKEN);
44+
}
45+
46+
@When("^notification with key \"([^\"]*)\" and value \"([^\"]*)\" is added to \"([^\"]*)\"$")
47+
public void notification_with_key_and_value_is_added_to(String key, String value, String subscriptionName) throws Throwable {
48+
StepsUtils.addNotificationToSubscription(key, value, subscriptionName);
49+
}
50+
51+
@When("^condition with jmespath \"([^\"]*)\" is added to \"([^\"]*)\"$")
52+
public void condition_with_jmespath_is_added_to(String jmesPath, String subscriptionName) throws Throwable {
53+
StepsUtils.addConditionToRequirement(jmesPath, subscriptionName);
54+
}
55+
56+
@Then("^a jenkins job \"([^\"]*)\" from \"([^\"]*)\" is created with parameters: (.*)$")
4057
public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFileName, List<String> parameters) throws Throwable {
4158
boolean success = StepsUtils.createJenkinsJob(
4259
jenkinsJobName,
@@ -56,31 +73,21 @@ public void a_jenkins_job_from_is_created(String jenkinsJobName, String scriptFi
5673
assertTrue("Failed to create jenkins job.", success);
5774
}
5875

59-
@Then("^subscriptions and jenkins jobs should be removed$")
60-
public void subscriptions_and_jenkins_jobs_should_be_removed() throws Throwable {
61-
StepsUtils.deleteJenkinsJobs(jenkinsJobNames);
62-
StepsUtils.deleteSubscriptions(config.getEiFrontendBaseUrl(), config.getEiBackendBaseUrl());
63-
}
64-
65-
@Given("^subscription object \"([^\"]*)\" is created which will trigger \"([^\"]*)\"$")
66-
public void subscription_is_created(String subscriptionName, String jenkinsJobName) throws Throwable {
67-
StepsUtils.createSubscription(subscriptionName, jenkinsJobName, config.getJenkinsUsername(), config.getJenkinsPassword(), config.getJenkinsBaseUrl());
68-
}
69-
70-
@When("^notification with key \"([^\"]*)\" and value \"([^\"]*)\" is added to \"([^\"]*)\"$")
71-
public void notification_with_key_and_value_is_added_to(String key, String value, String subscriptionName) throws Throwable {
72-
StepsUtils.addNotificationToSubscription(key, value, subscriptionName);
73-
}
74-
75-
@When("^condition with jmespath \"([^\"]*)\" is added to \"([^\"]*)\"$")
76-
public void condition_with_jmespath_is_added_to(String jmesPath, String subscriptionName) throws Throwable {
77-
StepsUtils.addConditionToRequirement(jmesPath, subscriptionName);
78-
}
79-
8076
@Then("^we send the \"([^\"]*)\" to eiffel intelligence for creation\\.$")
8177
public void we_send_the_to_eiffel_intelligence_for_creation(String subscriptionName) throws Throwable {
8278
ResponseEntity response = StepsUtils.sendSubscriptionToEiffelIntelligence(subscriptionName, config.getEiFrontendBaseUrl(), config.getEiBackendBaseUrl());
8379

8480
assertEquals("Failed to create subscription. Response: " + response.getBody(), 200, response.getStatusCode());
8581
}
86-
}
82+
83+
@Then("^all jenkins jobs has been triggered$")
84+
public void the_jenkins_job_has_been_triggered() throws Throwable {
85+
StepsUtils.hasJenkinsJobsBeenTriggered(jenkinsJobNames, config.getJobTimeoutMilliseconds());
86+
}
87+
88+
@Then("^subscriptions and jenkins jobs should be removed$")
89+
public void subscriptions_and_jenkins_jobs_should_be_removed() throws Throwable {
90+
StepsUtils.deleteJenkinsJobs(jenkinsJobNames);
91+
StepsUtils.deleteSubscriptions(config.getEiFrontendBaseUrl(), config.getEiBackendBaseUrl());
92+
}
93+
}

src/systemtest/java/com/ericsson/ei/systemtest/utils/StepsUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ public static void deleteJenkinsJobs(ArrayList<String> jenkinsJobNames) throws E
9999
* @throws IOException
100100
* @throws JSONException
101101
*/
102-
public static void createSubscription(String subscriptionName, String nameOfJobToBeTriggered, String jenkinsUserame, String jenkinsPassword, String jenkinsBaseUrl) throws IOException, JSONException {
102+
public static void createSubscription(String subscriptionName, String nameOfJobToBeTriggered, String jenkinsUserame, String jenkinsPassword, String jenkinsBaseUrl, boolean hasParameters) throws IOException, JSONException {
103103
RestPostSubscriptionObject subscription = new RestPostSubscriptionObject(subscriptionName);
104104
subscription.setRestPostBodyMediaType("application/x-www-form-urlencoded");
105105
subscription.setBasicAuth(jenkinsUserame, jenkinsPassword);
106-
subscription.setNotificationMeta(jenkinsBaseUrl + "/job/" + nameOfJobToBeTriggered + "/buildWithParameters");
106+
String notificationMeta = jenkinsBaseUrl + "/job/" + nameOfJobToBeTriggered;
107+
if(hasParameters) {
108+
notificationMeta += "/buildWithParameters";
109+
} else {
110+
notificationMeta += "/build";
111+
}
112+
subscription.setNotificationMeta(notificationMeta);
107113
subscriptions.put(subscriptionName, subscription);
108114
}
109115

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import groovy.json.JsonSlurper
2+
def baseUrl = "REMREM_BASE_URL_TO_BE_REPLACED";
3+
4+
////////////////////////////////////////////////////////////////////////////////////////
5+
///////////////////////////////////////ActT/////////////////////////////////////////////
6+
////////////////////////////////////////////////////////////////////////////////////////
7+
8+
def uriPathActT = baseUrl + "/generateAndPublish?mp=eiffelsemantics&msgType=EiffelActivityTriggeredEvent";
9+
def jsonActT = """
10+
{
11+
"msgParams": {
12+
"meta": {
13+
"type": "EiffelActivityTriggeredEvent",
14+
"version": "1.1.0",
15+
"tags": []
16+
}
17+
},
18+
"eventParams": {
19+
"data": {
20+
"name": "Test_01_Start",
21+
"categories": [],
22+
"triggers": [
23+
{
24+
"type": "MANUAL",
25+
"description": "Started by user admin"
26+
}
27+
],
28+
"customData": []
29+
},
30+
"links": []
31+
}
32+
}
33+
""";
34+
35+
generateEiffelEventAndPublish(uriPathActT, jsonActT);
36+
37+
def generateEiffelEventAndPublish(uriPath, json){
38+
def post = new URL(uriPath).openConnection();
39+
def message = json
40+
post.setRequestMethod("POST")
41+
post.setDoOutput(true)
42+
post.setRequestProperty("Content-Type", "application/json")
43+
post.getOutputStream().write(message.getBytes("UTF-8"));
44+
45+
responseText = post.getInputStream().getText();
46+
47+
def jsonSlurper = new JsonSlurper()
48+
responseJson = jsonSlurper.parseText(responseText);
49+
return responseJson["events"][0]["id"].toString();
50+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import groovy.json.JsonSlurper
2+
def baseUrl = "REMREM_BASE_URL_TO_BE_REPLACED";
3+
4+
////////////////////////////////////////////////////////////////////////////////////////
5+
///////////////////////////////////////ActS/////////////////////////////////////////////
6+
////////////////////////////////////////////////////////////////////////////////////////
7+
8+
def uriPathActS = baseUrl + "/generateAndPublish?mp=eiffelsemantics&msgType=EiffelActivityStartedEvent";
9+
def jsonActS = """
10+
{
11+
"msgParams": {
12+
"meta": {
13+
"type": "EiffelActivityStartedEvent",
14+
"version": "1.1.0",
15+
"tags": []
16+
}
17+
},
18+
"eventParams": {
19+
"data": {
20+
"liveLogs": [],
21+
"customData": []
22+
},
23+
"links": [
24+
{
25+
"type": "ACTIVITY_EXECUTION",
26+
"target": \"""" + build.environment.EVENT_ID + """\"
27+
}
28+
]
29+
}
30+
}
31+
""";
32+
33+
generateEiffelEventAndPublish(uriPathActS, jsonActS);
34+
35+
////////////////////////////////////////////////////////////////////////////////////////
36+
///////////////////////////////////////ActF/////////////////////////////////////////////
37+
////////////////////////////////////////////////////////////////////////////////////////
38+
39+
def uriPathActF = baseUrl + "/generateAndPublish?mp=eiffelsemantics&msgType=EiffelActivityFinishedEvent";
40+
def jsonActF = """
41+
{
42+
"msgParams": {
43+
"meta": {
44+
"type": "EiffelActivityFinishedEvent",
45+
"version": "1.1.0",
46+
"tags": []
47+
}
48+
},
49+
"eventParams": {
50+
"data": {
51+
"outcome": {
52+
"conclusion": "SUCCESSFUL",
53+
"description": ""
54+
},
55+
"persistentLogs": [],
56+
"customData": []
57+
},
58+
"links": [
59+
{
60+
"type": "ACTIVITY_EXECUTION",
61+
"target": \"""" + build.environment.EVENT_ID + """\"
62+
}
63+
]
64+
}
65+
}
66+
""";
67+
68+
generateEiffelEventAndPublish(uriPathActF, jsonActF);
69+
70+
def generateEiffelEventAndPublish(uriPath, json){
71+
def post = new URL(uriPath).openConnection();
72+
def message = json
73+
post.setRequestMethod("POST")
74+
post.setDoOutput(true)
75+
post.setRequestProperty("Content-Type", "application/json")
76+
post.getOutputStream().write(message.getBytes("UTF-8"));
77+
78+
responseText = post.getInputStream().getText();
79+
80+
def jsonSlurper = new JsonSlurper()
81+
responseJson = jsonSlurper.parseText(responseText);
82+
return responseJson["events"][0]["id"].toString();
83+
}

0 commit comments

Comments
 (0)