Skip to content

Commit

Permalink
When callService that is attached to an application, host and context…
Browse files Browse the repository at this point in the history
…root 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).
  • Loading branch information
vertigo17 committed Jun 29, 2024
1 parent 037fe63 commit be92e37
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
*/
package org.cerberus.core.apiprivate;

import java.sql.Timestamp;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cerberus.core.crud.entity.TestCaseExecution;
import org.cerberus.core.crud.service.impl.TestCaseExecutionService;
import org.cerberus.core.crud.service.ITestCaseExecutionService;
import org.cerberus.core.engine.entity.ExecutionUUID;
import org.cerberus.core.engine.execution.IExecutionStartService;
import org.cerberus.core.exception.CerberusException;
import org.cerberus.core.util.servlet.ServletUtil;
import org.json.JSONArray;
Expand All @@ -39,7 +38,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.support.WebApplicationContextUtils;

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

@Autowired
TestCaseExecutionService executionService;

private ITestCaseExecutionService executionService;
@Autowired
private ExecutionUUID executionUUIDObject;

Expand Down Expand Up @@ -105,47 +102,8 @@ public String getRunning(
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);

JSONObject jsonResponse = new JSONObject();

try {

// FIXME The executionUUIDObject unfortunatly does not return the Component Class content.
// ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
LOG.debug(executionUUIDObject.getExecutionUUIDList());
JSONArray executionArray = new JSONArray();
// for (Object ex : executionUUIDObject.getExecutionUUIDList().values()) {
// TestCaseExecution execution = (TestCaseExecution) ex;
// JSONObject object = new JSONObject();
// object.put("id", execution.getId());
// object.put("test", execution.getTest());
// object.put("testcase", execution.getTestCase());
// object.put("system", execution.getApplicationObj().getSystem());
// object.put("application", execution.getApplication());
// object.put("environment", execution.getEnvironmentData());
// object.put("country", execution.getCountry());
// object.put("robotIP", execution.getSeleniumIP());
// object.put("tag", execution.getTag());
// object.put("start", new Timestamp(execution.getStart()));
// executionArray.put(object);
// }
jsonResponse.put("runningExecutionsList", executionArray);

JSONObject queueStatus = new JSONObject();
// queueStatus.put("queueSize", executionUUIDObject.getQueueSize());
// queueStatus.put("globalLimit", executionUUIDObject.getGlobalLimit());
// queueStatus.put("running", executionUUIDObject.getRunning());
// FIXME Force the servlet result to 0.
queueStatus.put("queueSize", 0);
queueStatus.put("globalLimit", 0);
queueStatus.put("running", 0);
jsonResponse.put("queueStats", queueStatus);

return jsonResponse.toString();
return executionUUIDObject.getRunningStatus().toString();

} catch (Exception ex) {
LOG.warn(ex, ex);
return "error " + ex.getMessage();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public interface ICountryEnvironmentParametersDAO {
*/
AnswerList<CountryEnvironmentParameters> readByVariousByCriteria(String system, String country, String environment, String application, int start, int amount, String column, String dir, String searchTerm, String individualSearch);

/**
*
* @param system
* @param country
* @param environment
* @return
*/
AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment);

/**
*
* @param object
Expand All @@ -106,5 +115,4 @@ public interface ICountryEnvironmentParametersDAO {
*/
Answer update(CountryEnvironmentParameters object);


}
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,114 @@ public AnswerList<CountryEnvironmentParameters> readByVariousByCriteria(String s
return response;
}

@Override
public AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment) {
AnswerList<CountryEnvironmentParameters> response = new AnswerList<>();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<CountryEnvironmentParameters> objectList = new ArrayList<>();

StringBuilder query = new StringBuilder();
//SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
//were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS cea.* FROM countryenvironmentparameters cea");
query.append(" JOIN application app on app.Application = cea.Application and app.`System` = cea.`System` ");
query.append(" JOIN (SELECT systemLink , CountryLink , EnvironmentLink from countryenvlink where `system` = ? and Country = ? and Environment = ? ) as lnk ");
query.append(" where cea.`system` = lnk.systemLink and cea.`Country` = lnk.CountryLink and cea.`Environment` = lnk.EnvironmentLink ; ");

// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
LOG.debug("SQL.param.system : " + system);
LOG.debug("SQL.param.country : " + country);
LOG.debug("SQL.param.environment : " + environment);
}

Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
int i = 1;
if (!StringUtil.isEmpty(system)) {
preStat.setString(i++, system);
}
if (!StringUtil.isEmpty(country)) {
preStat.setString(i++, country);
}
if (!StringUtil.isEmpty(environment)) {
preStat.setString(i++, environment);
}
ResultSet resultSet = preStat.executeQuery();
try {
//gets the data
while (resultSet.next()) {
objectList.add(this.loadFromResultSet(resultSet));
}

//get the total number of rows
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
int nrTotalRows = 0;

if (resultSet != null && resultSet.next()) {
nrTotalRows = resultSet.getInt(1);
}

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.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList<>(objectList, nrTotalRows);
} else if (objectList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList<>(objectList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
response = new AnswerList<>(objectList, nrTotalRows);
}

} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));

} finally {
if (resultSet != null) {
resultSet.close();
}
}

} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (preStat != null) {
preStat.close();
}
}

} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}

response.setResultMessage(msg);
response.setDataList(objectList);
return response;
}

@Override
public Answer create(CountryEnvironmentParameters object) {
MessageEvent msg = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class CountryEnvParam {
private String system;
private String country;
private String environment;

private String description;
private String build;
private String revision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class CountryEnvironmentParameters {
private String environment;
@Id
private String application;

private String ip;
private String domain;
private String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ public class TestCaseExecution {
private TestCase testCaseObj;
private Tag tagObj;
private CountryEnvParam countryEnvParam;
private CountryEnvironmentParameters countryEnvironmentParameters;
private String currentApplication; // Allow to move the application environment context in case of a call to a service.
private CountryEnvironmentParameters countryEnvApplicationParam; // Main value from application of the testcase.
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.
private Invariant environmentObj;
private Invariant environmentDataObj;
private Invariant priorityObj;
Expand Down Expand Up @@ -301,6 +303,20 @@ public void addSecrets(List<String> secrets) {
});
}

public void addcountryEnvApplicationParam(CountryEnvironmentParameters countryEnvApplication) {
if (countryEnvApplication != null) {
this.countryEnvApplicationParams.put(countryEnvApplication.getApplication(), countryEnvApplication);
}
}

public void addcountryEnvApplicationParams(List<CountryEnvironmentParameters> countryEnvApplications) {
LOG.debug(countryEnvApplications);
countryEnvApplications.forEach(countryEnvApplication -> {
LOG.debug(countryEnvApplication);
this.countryEnvApplicationParams.put(countryEnvApplication.getApplication(), countryEnvApplication);
});
}

/**
* Convert the current TestCaseExecution into JSON format
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TestCaseExecution create(long id, String test, String testCase, String de
String browser, String version, String platform, long start, long end, String controlStatus, String controlMessage,
String application, Application applicationObj, String url, String tag, int verbose, int screenshot, int video, int pageSource, int robotLog, int consoleLog,
boolean synchroneous, String timeout, String outputFormat, String status, String crbVersion, TestCase tCase, CountryEnvParam countryEnvParam,
CountryEnvironmentParameters countryEnvironmentParameters, int manualURL, String myHost, String myContextRoot, String myLoginRelativeURL, String myEnvData,
CountryEnvironmentParameters countryEnvApplicationParam, int manualURL, String myHost, String myContextRoot, String myLoginRelativeURL, String myEnvData,
String seleniumIP, String seleniumPort, List<TestCaseStepExecution> testCaseStepExecution, MessageGeneral resultMessage, String executor,
int numberOfRetries, String screenSize, Robot robotObj, String robotProvider, String robotSessionId,
String conditionOperator, String conditionVal1Init, String conditionVal2Init, String conditionVal3Init, String conditionVal1, String conditionVal2, String conditionVal3,
Expand Down Expand Up @@ -94,7 +94,7 @@ public TestCaseExecution create(long id, String test, String testCase, String de
newTce.setVideo(video);
newTce.setTestCaseObj(tCase);
newTce.setCountryEnvParam(countryEnvParam);
newTce.setCountryEnvironmentParameters(countryEnvironmentParameters);
newTce.setCountryEnvApplicationParam(countryEnvApplicationParam);
newTce.setManualURL(manualURL);
newTce.setMyHost(myHost);
newTce.setMyContextRoot(myContextRoot);
Expand Down Expand Up @@ -142,6 +142,7 @@ public TestCaseExecution create(long id, String test, String testCase, String de
newTce.setDateModif(dateModif);
newTce.setNetworkTrafficIndexList(new ArrayList<>());
newTce.setSecrets(new HashMap<>());
newTce.setCountryEnvApplicationParams(new HashMap<>());

return newTce;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public interface ICountryEnvironmentParametersService {
*/
public AnswerList<CountryEnvironmentParameters> readByVarious(String system, String country, String environment, String application);

/**
*
* @param system
* @param country
* @param environment
* @return
*/
public AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment);

/**
*
* @param object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;

/**
* @author bcivel
Expand Down Expand Up @@ -287,4 +288,14 @@ public TestCaseExecution findLastTCExecutionInGroup(String test, String testCase
*/
public List<TestCaseExecution> readLastExecutionAndExecutionInQueueByTag(String tag) throws ParseException, CerberusException;

/**
*
* @param test
* @param testCase
* @param tag
* @param numberOfExecution
* @return
* @throws CerberusException
*/
public JSONArray getLastByCriteria(String test, String testCase, String tag, Integer numberOfExecution) throws CerberusException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public AnswerList<CountryEnvironmentParameters> readByVarious(String system, Str
return countryEnvironmentParametersDao.readByVariousByCriteria(system, country, environment, application, 0, 0, null, null, null, null);
}

@Override
public AnswerList<CountryEnvironmentParameters> readDependenciesByVarious(String system, String country, String environment) {
return countryEnvironmentParametersDao.readDependenciesByVarious(system, country, environment);
}

@Override
public AnswerList<CountryEnvironmentParameters> readByVariousByCriteria(String system, String country, String environment, String application, int start, int amount, String column, String dir, String searchTerm, String individualSearch) {
return countryEnvironmentParametersDao.readByVariousByCriteria(system, country, environment, application, start, amount, column, dir, searchTerm, individualSearch);
Expand Down
Loading

0 comments on commit be92e37

Please sign in to comment.