Skip to content

Commit 5bba57c

Browse files
committed
TestLink import feature improvements (preconditions support).
Default value for test case status is now 1st invariant on the list.
1 parent 9e5aaea commit 5bba57c

17 files changed

+163
-51
lines changed

source/src/main/java/org/cerberus/core/api/controllers/TestcaseController.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.cerberus.core.crud.service.ITestCaseStepActionControlService;
5858
import org.cerberus.core.crud.service.ITestCaseStepActionService;
5959
import org.cerberus.core.crud.service.ITestCaseStepService;
60+
import static org.cerberus.core.engine.execution.enums.ConditionOperatorEnum.CONDITIONOPERATOR_ALWAYS;
6061
import org.cerberus.core.exception.CerberusException;
6162
import org.json.JSONException;
6263
import org.json.JSONObject;
@@ -226,12 +227,12 @@ public String createSimplifiedTestcase(
226227
.application(newTestcase.getApplication())
227228
.description(newTestcase.getDescription())
228229
.priority(1)
229-
.status("WORKING")
230-
.conditionOperator("always")
230+
.status(invariantService.convert(invariantService.readFirstByIdName(Invariant.IDNAME_TCSTATUS)).getValue())
231+
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
231232
.conditionValue1("")
232233
.conditionValue2("")
233234
.conditionValue3("")
234-
.type("AUTOMATED")
235+
.type(TestCase.TESTCASE_TYPE_AUTOMATED)
235236
.isActive(true)
236237
.isActivePROD(true)
237238
.isActiveQA(true)
@@ -261,8 +262,8 @@ public String createSimplifiedTestcase(
261262
.sort(1)
262263
.isUsingLibraryStep(false)
263264
.libraryStepStepId(0)
264-
.loop("onceIfConditionTrue")
265-
.conditionOperator("always")
265+
.loop(TestCaseStep.LOOP_ONCEIFCONDITIONTRUE)
266+
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
266267
.description("Go to the homepage and take a screenshot")
267268
.usrCreated(login)
268269
.build());
@@ -274,7 +275,7 @@ public String createSimplifiedTestcase(
274275
.stepId(0)
275276
.actionId(0)
276277
.sort(1)
277-
.conditionOperator("always")
278+
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
278279
.conditionValue1("")
279280
.conditionValue2("")
280281
.conditionValue3("")
@@ -283,7 +284,7 @@ public String createSimplifiedTestcase(
283284
.value2("")
284285
.value3("")
285286
.description("Open the homepage")
286-
.conditionOperator("always")
287+
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
287288
.usrCreated(login)
288289
.build());
289290

@@ -295,7 +296,7 @@ public String createSimplifiedTestcase(
295296
.actionId(0)
296297
.controlId(0)
297298
.sort(1)
298-
.conditionOperator("always")
299+
.conditionOperator(CONDITIONOPERATOR_ALWAYS.getCondition())
299300
.conditionValue1("")
300301
.conditionValue2("")
301302
.conditionValue3("")

source/src/main/java/org/cerberus/core/config/SwaggerConfiguration.java

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class SwaggerConfiguration {
5353
private static final Tag QUEUEDEXECUTION_TAG = new Tag("Queued Execution", "Queued Execution endpoint");
5454
private static final Tag USER_TAG = new Tag("User", "User endpoint");
5555
private static final Tag APPLICATION_TAG = new Tag("Application", "Application endpoint");
56+
private static final Tag MANAGE_TAG = new Tag("Manage", "Cerberus Management endpoint");
5657

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

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

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public interface IInvariantDAO {
4545
*/
4646
Invariant readByKey(String id, String value) throws CerberusException;
4747

48+
/**
49+
* Get a {@link Invariant} in database
50+
*
51+
* @param id
52+
* @return
53+
* @throws org.cerberus.core.exception.CerberusException
54+
*/
55+
Invariant readFirstByIdName(String id) throws CerberusException;
56+
4857
/**
4958
* @param idName
5059
* @return

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

+19
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ public Invariant readByKey(String id, String value) throws CerberusException {
8989
);
9090
}
9191

92+
@Override
93+
public Invariant readFirstByIdName(String id) throws CerberusException {
94+
final String query = "SELECT * FROM `invariant` WHERE `idname` = ? order by sort LIMIT 1;";
95+
96+
// Debug message on SQL.
97+
if (LOG.isDebugEnabled()) {
98+
LOG.debug("SQL.param.id : " + id);
99+
}
100+
101+
return RequestDbUtils.executeQuery(databaseSpring, query,
102+
ps -> {
103+
ps.setString(1, id);
104+
},
105+
resultSet -> {
106+
return loadFromResultSet(resultSet);
107+
}
108+
);
109+
}
110+
92111
@Override
93112
public List<Invariant> readByIdname(String idName) throws CerberusException {
94113

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

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class Invariant {
5353
public static final String IDNAME_PRIORITY = "PRIORITY";
5454
public static final String IDNAME_ENVIRONMENT = "ENVIRONMENT";
5555
public static final String IDNAME_SYSTEM = "SYSTEM";
56+
public static final String IDNAME_TCSTATUS = "TCSTATUS";
5657

5758
public String getDescription() {
5859
return description;

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

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public class TestCase {
113113
@EqualsAndHashCode.Exclude
114114
private List<TestCaseDep> dependencies;
115115

116+
public static final String TESTCASE_STATUS_WORKING = "WORKING";
117+
116118
public static final String TESTCASE_TYPE_MANUAL = "MANUAL";
117119
public static final String TESTCASE_TYPE_AUTOMATED = "AUTOMATED";
118120
public static final String TESTCASE_TYPE_PRIVATE = "PRIVATE";

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

+6
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ public interface IInvariantService {
206206
*/
207207
AnswerItem<Invariant> readByKey(String id, String value);
208208

209+
/**
210+
* @param id
211+
* @return
212+
*/
213+
AnswerItem<Invariant> readFirstByIdName(String id);
214+
209215
/**
210216
* @param invariant
211217
* @return

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

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public AnswerItem<Invariant> readByKey(String id, String value) {
6868
return AnswerUtil.convertToAnswerItem(() -> invariantDao.readByKey(id, value));
6969
}
7070

71+
@Override
72+
public AnswerItem<Invariant> readFirstByIdName(String id) {
73+
return AnswerUtil.convertToAnswerItem(() -> invariantDao.readFirstByIdName(id));
74+
}
75+
7176
/**
7277
* Use readByIdName instead to avoid Answer
7378
*

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ public boolean hasPermissionsRead(TestCase testCase, HttpServletRequest request)
661661
@Override
662662
public boolean hasPermissionsUpdate(TestCase testCase, HttpServletRequest request) {
663663
// Access right calculation.
664-
if (testCase.getStatus().equalsIgnoreCase("WORKING")) { // If testcase is WORKING only TestAdmin can update it
664+
if (testCase.getStatus().equalsIgnoreCase(TestCase.TESTCASE_STATUS_WORKING)) { // If testcase is WORKING only TestAdmin can update it
665665
return request.isUserInRole("TestAdmin");
666666
} else {
667667
return request.isUserInRole("Test");
@@ -671,7 +671,7 @@ public boolean hasPermissionsUpdate(TestCase testCase, HttpServletRequest reques
671671
@Override
672672
public boolean hasPermissionsUpdateFromStatus(String status, HttpServletRequest request) {
673673
// Access right calculation.
674-
if (status.equalsIgnoreCase("WORKING")) { // If testcase is WORKING only TestAdmin can update it
674+
if (status.equalsIgnoreCase(TestCase.TESTCASE_STATUS_WORKING)) { // If testcase is WORKING only TestAdmin can update it
675675
return request.isUserInRole("TestAdmin");
676676
} else {
677677
return request.isUserInRole("Test");

source/src/main/java/org/cerberus/core/servlet/crud/test/CreateTestCaseCountry.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
public class CreateTestCaseCountry extends HttpServlet {
5959

6060
private static final Logger LOG = LogManager.getLogger(CreateTestCaseCountry.class);
61-
61+
6262
/**
6363
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
6464
* methods.
@@ -130,11 +130,11 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
130130
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. You must belong to Test Privilege."));
131131
ans.setResultMessage(msg);
132132

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

140140
} else {

source/src/main/java/org/cerberus/core/servlet/crud/test/DeleteTestCaseCountry.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
public class DeleteTestCaseCountry extends HttpServlet {
5858

5959
private static final Logger LOG = LogManager.getLogger(DeleteTestCaseCountry.class);
60-
60+
6161
/**
6262
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
6363
* methods.
@@ -123,11 +123,11 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
123123
.replace("%REASON%", "Not enought privilege to create the testCaseCountry. You must belong to Test Privilege."));
124124
ans.setResultMessage(msg);
125125

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

133133
} else {

source/src/main/java/org/cerberus/core/servlet/crud/test/UpdateTestCaseMass.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
136136
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
137137
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)
138138
.replace("%OPERATION%", "Update")
139-
.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."));
139+
.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."));
140140
ans.setResultMessage(msg);
141141
massErrorCounter++;
142142
output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());

source/src/main/java/org/cerberus/core/servlet/crud/test/UpdateTestCaseProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
127127
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
128128
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")
129129
.replace("%OPERATION%", "Update")
130-
.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."));
130+
.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."));
131131
ans.setResultMessage(msg);
132132

133133
} else {

source/src/main/java/org/cerberus/core/servlet/crud/test/UpdateTestCaseWithDependencies.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
155155
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
156156
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")
157157
.replace("%OPERATION%", "Update")
158-
.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."));
158+
.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."));
159159
ans.setResultMessage(msg);
160160

161161
} else { // Test Case exist and we can update it so Global update start here

source/src/main/java/org/cerberus/core/servlet/crud/test/testcase/ImportTestCaseFromSIDE.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected void processRequest(HttpServletRequest httpServletRequest, HttpServlet
165165
newTC.setConditionOperator("always");
166166
newTC.setOrigine(TestCase.TESTCASE_ORIGIN_SIDE);
167167
newTC.setRefOrigine(test.getString("id"));
168-
newTC.setStatus("WORKING");
168+
newTC.setStatus(invariantService.convert(invariantService.readFirstByIdName(Invariant.IDNAME_TCSTATUS)).getValue());
169169
newTC.setUsrCreated(userCreated);
170170

171171
countries.forEach(country -> {

source/src/main/java/org/cerberus/core/servlet/crud/test/testcase/ImportTestCaseFromTestLink.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected void processRequest(HttpServletRequest httpServletRequest, HttpServlet
152152
SAXParser saxParser = factory.newSAXParser();
153153

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

157157
saxParser.parse(is, handler);
158158

0 commit comments

Comments
 (0)