Skip to content

Commit be92e37

Browse files
committed
When callService that is attached to an application, host and contextroot of the corresponding application is used (if country env of the application does not exist on the test case application, search is also made on linked environments).
1 parent 037fe63 commit be92e37

21 files changed

+310
-99
lines changed

source/src/main/java/org/cerberus/core/apiprivate/ExecutionPrivateController.java

+4-46
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
*/
2020
package org.cerberus.core.apiprivate;
2121

22-
import java.sql.Timestamp;
2322
import java.util.List;
2423
import javax.servlet.http.HttpServletRequest;
2524
import org.apache.logging.log4j.LogManager;
2625
import org.apache.logging.log4j.Logger;
27-
import org.cerberus.core.crud.entity.TestCaseExecution;
28-
import org.cerberus.core.crud.service.impl.TestCaseExecutionService;
26+
import org.cerberus.core.crud.service.ITestCaseExecutionService;
2927
import org.cerberus.core.engine.entity.ExecutionUUID;
28+
import org.cerberus.core.engine.execution.IExecutionStartService;
3029
import org.cerberus.core.exception.CerberusException;
3130
import org.cerberus.core.util.servlet.ServletUtil;
3231
import org.json.JSONArray;
@@ -39,7 +38,6 @@
3938
import org.springframework.web.bind.annotation.RequestMapping;
4039
import org.springframework.web.bind.annotation.RequestParam;
4140
import org.springframework.web.bind.annotation.RestController;
42-
import org.springframework.web.context.support.WebApplicationContextUtils;
4341

4442
/**
4543
* @author bcivel
@@ -52,8 +50,7 @@ public class ExecutionPrivateController {
5250
private final PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
5351

5452
@Autowired
55-
TestCaseExecutionService executionService;
56-
53+
private ITestCaseExecutionService executionService;
5754
@Autowired
5855
private ExecutionUUID executionUUIDObject;
5956

@@ -105,47 +102,8 @@ public String getRunning(
105102
// Calling Servlet Transversal Util.
106103
ServletUtil.servletStart(request);
107104

108-
JSONObject jsonResponse = new JSONObject();
109-
110-
try {
111-
112-
// FIXME The executionUUIDObject unfortunatly does not return the Component Class content.
113-
// ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
114-
LOG.debug(executionUUIDObject.getExecutionUUIDList());
115-
JSONArray executionArray = new JSONArray();
116-
// for (Object ex : executionUUIDObject.getExecutionUUIDList().values()) {
117-
// TestCaseExecution execution = (TestCaseExecution) ex;
118-
// JSONObject object = new JSONObject();
119-
// object.put("id", execution.getId());
120-
// object.put("test", execution.getTest());
121-
// object.put("testcase", execution.getTestCase());
122-
// object.put("system", execution.getApplicationObj().getSystem());
123-
// object.put("application", execution.getApplication());
124-
// object.put("environment", execution.getEnvironmentData());
125-
// object.put("country", execution.getCountry());
126-
// object.put("robotIP", execution.getSeleniumIP());
127-
// object.put("tag", execution.getTag());
128-
// object.put("start", new Timestamp(execution.getStart()));
129-
// executionArray.put(object);
130-
// }
131-
jsonResponse.put("runningExecutionsList", executionArray);
132-
133-
JSONObject queueStatus = new JSONObject();
134-
// queueStatus.put("queueSize", executionUUIDObject.getQueueSize());
135-
// queueStatus.put("globalLimit", executionUUIDObject.getGlobalLimit());
136-
// queueStatus.put("running", executionUUIDObject.getRunning());
137-
// FIXME Force the servlet result to 0.
138-
queueStatus.put("queueSize", 0);
139-
queueStatus.put("globalLimit", 0);
140-
queueStatus.put("running", 0);
141-
jsonResponse.put("queueStats", queueStatus);
142-
143-
return jsonResponse.toString();
105+
return executionUUIDObject.getRunningStatus().toString();
144106

145-
} catch (Exception ex) {
146-
LOG.warn(ex, ex);
147-
return "error " + ex.getMessage();
148-
}
149107
}
150108

151109
}

source/src/main/java/org/cerberus/core/crud/dao/ICountryEnvironmentParametersDAO.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ public interface ICountryEnvironmentParametersDAO {
8585
*/
8686
AnswerList<CountryEnvironmentParameters> readByVariousByCriteria(String system, String country, String environment, String application, int start, int amount, String column, String dir, String searchTerm, String individualSearch);
8787

88+
/**
89+
*
90+
* @param system
91+
* @param country
92+
* @param environment
93+
* @return
94+
*/
95+
AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment);
96+
8897
/**
8998
*
9099
* @param object
@@ -106,5 +115,4 @@ public interface ICountryEnvironmentParametersDAO {
106115
*/
107116
Answer update(CountryEnvironmentParameters object);
108117

109-
110118
}

source/src/main/java/org/cerberus/core/crud/dao/impl/CountryEnvironmentParametersDAO.java

+108
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,114 @@ public AnswerList<CountryEnvironmentParameters> readByVariousByCriteria(String s
476476
return response;
477477
}
478478

479+
@Override
480+
public AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment) {
481+
AnswerList<CountryEnvironmentParameters> response = new AnswerList<>();
482+
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
483+
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
484+
List<CountryEnvironmentParameters> objectList = new ArrayList<>();
485+
486+
StringBuilder query = new StringBuilder();
487+
//SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
488+
//were applied -- used for pagination p
489+
query.append("SELECT SQL_CALC_FOUND_ROWS cea.* FROM countryenvironmentparameters cea");
490+
query.append(" JOIN application app on app.Application = cea.Application and app.`System` = cea.`System` ");
491+
query.append(" JOIN (SELECT systemLink , CountryLink , EnvironmentLink from countryenvlink where `system` = ? and Country = ? and Environment = ? ) as lnk ");
492+
query.append(" where cea.`system` = lnk.systemLink and cea.`Country` = lnk.CountryLink and cea.`Environment` = lnk.EnvironmentLink ; ");
493+
494+
// Debug message on SQL.
495+
if (LOG.isDebugEnabled()) {
496+
LOG.debug("SQL : " + query.toString());
497+
LOG.debug("SQL.param.system : " + system);
498+
LOG.debug("SQL.param.country : " + country);
499+
LOG.debug("SQL.param.environment : " + environment);
500+
}
501+
502+
Connection connection = this.databaseSpring.connect();
503+
try {
504+
PreparedStatement preStat = connection.prepareStatement(query.toString());
505+
try {
506+
int i = 1;
507+
if (!StringUtil.isEmpty(system)) {
508+
preStat.setString(i++, system);
509+
}
510+
if (!StringUtil.isEmpty(country)) {
511+
preStat.setString(i++, country);
512+
}
513+
if (!StringUtil.isEmpty(environment)) {
514+
preStat.setString(i++, environment);
515+
}
516+
ResultSet resultSet = preStat.executeQuery();
517+
try {
518+
//gets the data
519+
while (resultSet.next()) {
520+
objectList.add(this.loadFromResultSet(resultSet));
521+
}
522+
523+
//get the total number of rows
524+
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
525+
int nrTotalRows = 0;
526+
527+
if (resultSet != null && resultSet.next()) {
528+
nrTotalRows = resultSet.getInt(1);
529+
}
530+
531+
if (objectList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
532+
LOG.error("Partial Result in the query.");
533+
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
534+
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
535+
response = new AnswerList<>(objectList, nrTotalRows);
536+
} else if (objectList.size() <= 0) {
537+
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
538+
response = new AnswerList<>(objectList, nrTotalRows);
539+
} else {
540+
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
541+
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
542+
response = new AnswerList<>(objectList, nrTotalRows);
543+
}
544+
545+
} catch (SQLException exception) {
546+
LOG.error("Unable to execute query : " + exception.toString());
547+
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
548+
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
549+
550+
} finally {
551+
if (resultSet != null) {
552+
resultSet.close();
553+
}
554+
}
555+
556+
} catch (SQLException exception) {
557+
LOG.error("Unable to execute query : " + exception.toString());
558+
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
559+
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
560+
} finally {
561+
if (preStat != null) {
562+
preStat.close();
563+
}
564+
}
565+
566+
} catch (SQLException exception) {
567+
LOG.error("Unable to execute query : " + exception.toString());
568+
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
569+
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
570+
} finally {
571+
try {
572+
if (!this.databaseSpring.isOnTransaction()) {
573+
if (connection != null) {
574+
connection.close();
575+
}
576+
}
577+
} catch (SQLException exception) {
578+
LOG.warn("Unable to close connection : " + exception.toString());
579+
}
580+
}
581+
582+
response.setResultMessage(msg);
583+
response.setDataList(objectList);
584+
return response;
585+
}
586+
479587
@Override
480588
public Answer create(CountryEnvironmentParameters object) {
481589
MessageEvent msg = null;

source/src/main/java/org/cerberus/core/crud/entity/CountryEnvParam.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class CountryEnvParam {
2828
private String system;
2929
private String country;
3030
private String environment;
31+
3132
private String description;
3233
private String build;
3334
private String revision;

source/src/main/java/org/cerberus/core/crud/entity/CountryEnvironmentParameters.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class CountryEnvironmentParameters {
5151
private String environment;
5252
@Id
5353
private String application;
54+
5455
private String ip;
5556
private String domain;
5657
private String url;

source/src/main/java/org/cerberus/core/crud/entity/TestCaseExecution.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ public class TestCaseExecution {
129129
private TestCase testCaseObj;
130130
private Tag tagObj;
131131
private CountryEnvParam countryEnvParam;
132-
private CountryEnvironmentParameters countryEnvironmentParameters;
132+
private String currentApplication; // Allow to move the application environment context in case of a call to a service.
133+
private CountryEnvironmentParameters countryEnvApplicationParam; // Main value from application of the testcase.
134+
private HashMap<String, CountryEnvironmentParameters> countryEnvApplicationParams; // All applications values from all application existing on the same env/system and linked to main environement of the testcase.
133135
private Invariant environmentObj;
134136
private Invariant environmentDataObj;
135137
private Invariant priorityObj;
@@ -301,6 +303,20 @@ public void addSecrets(List<String> secrets) {
301303
});
302304
}
303305

306+
public void addcountryEnvApplicationParam(CountryEnvironmentParameters countryEnvApplication) {
307+
if (countryEnvApplication != null) {
308+
this.countryEnvApplicationParams.put(countryEnvApplication.getApplication(), countryEnvApplication);
309+
}
310+
}
311+
312+
public void addcountryEnvApplicationParams(List<CountryEnvironmentParameters> countryEnvApplications) {
313+
LOG.debug(countryEnvApplications);
314+
countryEnvApplications.forEach(countryEnvApplication -> {
315+
LOG.debug(countryEnvApplication);
316+
this.countryEnvApplicationParams.put(countryEnvApplication.getApplication(), countryEnvApplication);
317+
});
318+
}
319+
304320
/**
305321
* Convert the current TestCaseExecution into JSON format
306322
*

source/src/main/java/org/cerberus/core/crud/factory/impl/FactoryTestCaseExecution.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public TestCaseExecution create(long id, String test, String testCase, String de
5353
String browser, String version, String platform, long start, long end, String controlStatus, String controlMessage,
5454
String application, Application applicationObj, String url, String tag, int verbose, int screenshot, int video, int pageSource, int robotLog, int consoleLog,
5555
boolean synchroneous, String timeout, String outputFormat, String status, String crbVersion, TestCase tCase, CountryEnvParam countryEnvParam,
56-
CountryEnvironmentParameters countryEnvironmentParameters, int manualURL, String myHost, String myContextRoot, String myLoginRelativeURL, String myEnvData,
56+
CountryEnvironmentParameters countryEnvApplicationParam, int manualURL, String myHost, String myContextRoot, String myLoginRelativeURL, String myEnvData,
5757
String seleniumIP, String seleniumPort, List<TestCaseStepExecution> testCaseStepExecution, MessageGeneral resultMessage, String executor,
5858
int numberOfRetries, String screenSize, Robot robotObj, String robotProvider, String robotSessionId,
5959
String conditionOperator, String conditionVal1Init, String conditionVal2Init, String conditionVal3Init, String conditionVal1, String conditionVal2, String conditionVal3,
@@ -94,7 +94,7 @@ public TestCaseExecution create(long id, String test, String testCase, String de
9494
newTce.setVideo(video);
9595
newTce.setTestCaseObj(tCase);
9696
newTce.setCountryEnvParam(countryEnvParam);
97-
newTce.setCountryEnvironmentParameters(countryEnvironmentParameters);
97+
newTce.setCountryEnvApplicationParam(countryEnvApplicationParam);
9898
newTce.setManualURL(manualURL);
9999
newTce.setMyHost(myHost);
100100
newTce.setMyContextRoot(myContextRoot);
@@ -142,6 +142,7 @@ public TestCaseExecution create(long id, String test, String testCase, String de
142142
newTce.setDateModif(dateModif);
143143
newTce.setNetworkTrafficIndexList(new ArrayList<>());
144144
newTce.setSecrets(new HashMap<>());
145+
newTce.setCountryEnvApplicationParams(new HashMap<>());
145146

146147
return newTce;
147148
}

source/src/main/java/org/cerberus/core/crud/service/ICountryEnvironmentParametersService.java

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public interface ICountryEnvironmentParametersService {
7777
*/
7878
public AnswerList<CountryEnvironmentParameters> readByVarious(String system, String country, String environment, String application);
7979

80+
/**
81+
*
82+
* @param system
83+
* @param country
84+
* @param environment
85+
* @return
86+
*/
87+
public AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment);
88+
8089
/**
8190
*
8291
* @param object

source/src/main/java/org/cerberus/core/crud/service/ITestCaseExecutionService.java

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Date;
3131
import java.util.List;
3232
import java.util.Map;
33+
import org.json.JSONArray;
3334

3435
/**
3536
* @author bcivel
@@ -287,4 +288,14 @@ public TestCaseExecution findLastTCExecutionInGroup(String test, String testCase
287288
*/
288289
public List<TestCaseExecution> readLastExecutionAndExecutionInQueueByTag(String tag) throws ParseException, CerberusException;
289290

291+
/**
292+
*
293+
* @param test
294+
* @param testCase
295+
* @param tag
296+
* @param numberOfExecution
297+
* @return
298+
* @throws CerberusException
299+
*/
300+
public JSONArray getLastByCriteria(String test, String testCase, String tag, Integer numberOfExecution) throws CerberusException;
290301
}

source/src/main/java/org/cerberus/core/crud/service/impl/CountryEnvironmentParametersService.java

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public AnswerList<CountryEnvironmentParameters> readByVarious(String system, Str
7575
return countryEnvironmentParametersDao.readByVariousByCriteria(system, country, environment, application, 0, 0, null, null, null, null);
7676
}
7777

78+
@Override
79+
public AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment) {
80+
return countryEnvironmentParametersDao.readDependenciesByVarious(system, country, environment);
81+
}
82+
7883
@Override
7984
public AnswerList<CountryEnvironmentParameters> readByVariousByCriteria(String system, String country, String environment, String application, int start, int amount, String column, String dir, String searchTerm, String individualSearch) {
8085
return countryEnvironmentParametersDao.readByVariousByCriteria(system, country, environment, application, start, amount, column, dir, searchTerm, individualSearch);

0 commit comments

Comments
 (0)