Skip to content

Commit

Permalink
TestLink import feature improvements (preconditions support).
Browse files Browse the repository at this point in the history
Default value for test case status is now 1st invariant on the list.
  • Loading branch information
vertigo17 committed Jan 5, 2025
1 parent 9e5aaea commit 5bba57c
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.cerberus.core.crud.service.ITestCaseStepActionControlService;
import org.cerberus.core.crud.service.ITestCaseStepActionService;
import org.cerberus.core.crud.service.ITestCaseStepService;
import static org.cerberus.core.engine.execution.enums.ConditionOperatorEnum.CONDITIONOPERATOR_ALWAYS;
import org.cerberus.core.exception.CerberusException;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -226,12 +227,12 @@ public String createSimplifiedTestcase(
.application(newTestcase.getApplication())
.description(newTestcase.getDescription())
.priority(1)
.status("WORKING")
.conditionOperator("always")
.status(invariantService.convert(invariantService.readFirstByIdName(Invariant.IDNAME_TCSTATUS)).getValue())
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
.conditionValue1("")
.conditionValue2("")
.conditionValue3("")
.type("AUTOMATED")
.type(TestCase.TESTCASE_TYPE_AUTOMATED)
.isActive(true)
.isActivePROD(true)
.isActiveQA(true)
Expand Down Expand Up @@ -261,8 +262,8 @@ public String createSimplifiedTestcase(
.sort(1)
.isUsingLibraryStep(false)
.libraryStepStepId(0)
.loop("onceIfConditionTrue")
.conditionOperator("always")
.loop(TestCaseStep.LOOP_ONCEIFCONDITIONTRUE)
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
.description("Go to the homepage and take a screenshot")
.usrCreated(login)
.build());
Expand All @@ -274,7 +275,7 @@ public String createSimplifiedTestcase(
.stepId(0)
.actionId(0)
.sort(1)
.conditionOperator("always")
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
.conditionValue1("")
.conditionValue2("")
.conditionValue3("")
Expand All @@ -283,7 +284,7 @@ public String createSimplifiedTestcase(
.value2("")
.value3("")
.description("Open the homepage")
.conditionOperator("always")
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
.usrCreated(login)
.build());

Expand All @@ -295,7 +296,7 @@ public String createSimplifiedTestcase(
.actionId(0)
.controlId(0)
.sort(1)
.conditionOperator("always")
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
.conditionValue1("")
.conditionValue2("")
.conditionValue3("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SwaggerConfiguration {
private static final Tag QUEUEDEXECUTION_TAG = new Tag("Queued Execution", "Queued Execution endpoint");
private static final Tag USER_TAG = new Tag("User", "User endpoint");
private static final Tag APPLICATION_TAG = new Tag("Application", "Application endpoint");
private static final Tag MANAGE_TAG = new Tag("Manage", "Cerberus Management endpoint");

private static final String LICENSE_URL = "https://www.gnu.org/licenses/gpl-3.0.en.html";
private static final String GITHUB_REPOSITORY = "https://github.com/cerberustesting/cerberus-source";
Expand Down Expand Up @@ -95,6 +96,7 @@ private Docket configureVersion(String version) {
.tags(QUEUEDEXECUTION_TAG)
.tags(USER_TAG)
.tags(APPLICATION_TAG)
.tags(MANAGE_TAG)
.useDefaultResponseMessages(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public interface IInvariantDAO {
*/
Invariant readByKey(String id, String value) throws CerberusException;

/**
* Get a {@link Invariant} in database
*
* @param id
* @return
* @throws org.cerberus.core.exception.CerberusException
*/
Invariant readFirstByIdName(String id) throws CerberusException;

/**
* @param idName
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ public Invariant readByKey(String id, String value) throws CerberusException {
);
}

@Override
public Invariant readFirstByIdName(String id) throws CerberusException {
final String query = "SELECT * FROM `invariant` WHERE `idname` = ? order by sort LIMIT 1;";

// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL.param.id : " + id);
}

return RequestDbUtils.executeQuery(databaseSpring, query,
ps -> {
ps.setString(1, id);
},
resultSet -> {
return loadFromResultSet(resultSet);
}
);
}

@Override
public List<Invariant> readByIdname(String idName) throws CerberusException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Invariant {
public static final String IDNAME_PRIORITY = "PRIORITY";
public static final String IDNAME_ENVIRONMENT = "ENVIRONMENT";
public static final String IDNAME_SYSTEM = "SYSTEM";
public static final String IDNAME_TCSTATUS = "TCSTATUS";

public String getDescription() {
return description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public class TestCase {
@EqualsAndHashCode.Exclude
private List<TestCaseDep> dependencies;

public static final String TESTCASE_STATUS_WORKING = "WORKING";

public static final String TESTCASE_TYPE_MANUAL = "MANUAL";
public static final String TESTCASE_TYPE_AUTOMATED = "AUTOMATED";
public static final String TESTCASE_TYPE_PRIVATE = "PRIVATE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ public interface IInvariantService {
*/
AnswerItem<Invariant> readByKey(String id, String value);

/**
* @param id
* @return
*/
AnswerItem<Invariant> readFirstByIdName(String id);

/**
* @param invariant
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public AnswerItem<Invariant> readByKey(String id, String value) {
return AnswerUtil.convertToAnswerItem(() -> invariantDao.readByKey(id, value));
}

@Override
public AnswerItem<Invariant> readFirstByIdName(String id) {
return AnswerUtil.convertToAnswerItem(() -> invariantDao.readFirstByIdName(id));
}

/**
* Use readByIdName instead to avoid Answer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ public boolean hasPermissionsRead(TestCase testCase, HttpServletRequest request)
@Override
public boolean hasPermissionsUpdate(TestCase testCase, HttpServletRequest request) {
// Access right calculation.
if (testCase.getStatus().equalsIgnoreCase("WORKING")) { // If testcase is WORKING only TestAdmin can update it
if (testCase.getStatus().equalsIgnoreCase(TestCase.TESTCASE_STATUS_WORKING)) { // If testcase is WORKING only TestAdmin can update it
return request.isUserInRole("TestAdmin");
} else {
return request.isUserInRole("Test");
Expand All @@ -671,7 +671,7 @@ public boolean hasPermissionsUpdate(TestCase testCase, HttpServletRequest reques
@Override
public boolean hasPermissionsUpdateFromStatus(String status, HttpServletRequest request) {
// Access right calculation.
if (status.equalsIgnoreCase("WORKING")) { // If testcase is WORKING only TestAdmin can update it
if (status.equalsIgnoreCase(TestCase.TESTCASE_STATUS_WORKING)) { // If testcase is WORKING only TestAdmin can update it
return request.isUserInRole("TestAdmin");
} else {
return request.isUserInRole("Test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
public class CreateTestCaseCountry extends HttpServlet {

private static final Logger LOG = LogManager.getLogger(CreateTestCaseCountry.class);

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
Expand Down Expand Up @@ -130,11 +130,11 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. You must belong to Test Privilege."));
ans.setResultMessage(msg);

} else if ((tc.getStatus().equalsIgnoreCase("WORKING")) && !(request.isUserInRole("TestAdmin"))) { // If Test Case is WORKING we need TestAdmin priviliges.
} else if ((tc.getStatus().equalsIgnoreCase(TestCase.TESTCASE_STATUS_WORKING)) && !(request.isUserInRole("TestAdmin"))) { // If Test Case is WORKING we need TestAdmin priviliges.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseCountry")
.replace("%OPERATION%", "Create")
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. The test case is in WORKING status and needs TestAdmin privilege to be updated"));
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. The test case is in " + TestCase.TESTCASE_STATUS_WORKING + " status and needs TestAdmin privilege to be updated"));
ans.setResultMessage(msg);

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
public class DeleteTestCaseCountry extends HttpServlet {

private static final Logger LOG = LogManager.getLogger(DeleteTestCaseCountry.class);

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
Expand Down Expand Up @@ -123,11 +123,11 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. You must belong to Test Privilege."));
ans.setResultMessage(msg);

} else if ((tc.getStatus().equalsIgnoreCase("WORKING")) && !(request.isUserInRole("TestAdmin"))) { // If Test Case is WORKING we need TestAdmin priviliges.
} else if ((tc.getStatus().equalsIgnoreCase(TestCase.TESTCASE_STATUS_WORKING)) && !(request.isUserInRole("TestAdmin"))) { // If Test Case is WORKING we need TestAdmin priviliges.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseCountry")
.replace("%OPERATION%", "Create")
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. The test case is in WORKING status and needs TestAdmin privilege to be updated"));
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. The test case is in " + TestCase.TESTCASE_STATUS_WORKING + " status and needs TestAdmin privilege to be updated"));
ans.setResultMessage(msg);

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)
.replace("%OPERATION%", "Update")
.replace("%REASON%", "Not enought privilege to update the testcase. You must belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));
.replace("%REASON%", "Not enought privilege to update the testcase. You must belong to Test Privilege or even TestAdmin in case the test is in " + TestCase.TESTCASE_STATUS_WORKING + " status."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")
.replace("%OPERATION%", "Update")
.replace("%REASON%", "Not enought privilege to update the testcase. You mut belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));
.replace("%REASON%", "Not enought privilege to update the testcase. You mut belong to Test Privilege or even TestAdmin in case the test is in " + TestCase.TESTCASE_STATUS_WORKING + " status."));
ans.setResultMessage(msg);

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")
.replace("%OPERATION%", "Update")
.replace("%REASON%", "Not enought privilege to update the testcase. You mut belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));
.replace("%REASON%", "Not enought privilege to update the testcase. You mut belong to Test Privilege or even TestAdmin in case the test is in " + TestCase.TESTCASE_STATUS_WORKING + " status."));
ans.setResultMessage(msg);

} else { // Test Case exist and we can update it so Global update start here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected void processRequest(HttpServletRequest httpServletRequest, HttpServlet
newTC.setConditionOperator("always");
newTC.setOrigine(TestCase.TESTCASE_ORIGIN_SIDE);
newTC.setRefOrigine(test.getString("id"));
newTC.setStatus("WORKING");
newTC.setStatus(invariantService.convert(invariantService.readFirstByIdName(Invariant.IDNAME_TCSTATUS)).getValue());
newTC.setUsrCreated(userCreated);

countries.forEach(country -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected void processRequest(HttpServletRequest httpServletRequest, HttpServlet
SAXParser saxParser = factory.newSAXParser();

// parse XML and map to object,
MapTestLinkObjectHandlerSax handler = new MapTestLinkObjectHandlerSax(targetFolder, targetApplication, userCreated, testcaseService);
MapTestLinkObjectHandlerSax handler = new MapTestLinkObjectHandlerSax(targetFolder, targetApplication, userCreated, testcaseService, invariantService);

saxParser.parse(is, handler);

Expand Down
Loading

0 comments on commit 5bba57c

Please sign in to comment.