Skip to content

Commit

Permalink
Merge pull request #52 from mendix/uia/827-test-group-color
Browse files Browse the repository at this point in the history
[UIA-827] Release of version 9.4.3
  • Loading branch information
ozgeMendix authored May 1, 2024
2 parents a37a89b + 7a7acba commit 9242fa1
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 262 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [9.4.3] - 2024-05-01

### Fixed:
- We fixed an issue where the result of a test suite was not updated after running an individual test
- We fixed an issue in transaction handling for teardown microflows that could result in a database lock
- We changed the length to limited for the 'Name' attribute in the UnitTest entity

## [9.4.2] - 2024-02-07

### Fixed:
Expand Down
Binary file added dist/UnitTesting_9.4.3.mpk
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.mendix.UnitTesting</groupId>
<artifactId>UnitTesting</artifactId>
<version>9.4.2</version>
<version>9.4.3</version>

<repositories>
<repository>
Expand Down
Binary file modified src/UnitTesting.mpr
Binary file not shown.
14 changes: 6 additions & 8 deletions src/javasource/unittesting/AbstractUnitTest.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package unittesting;

public class AbstractUnitTest
{
private static long startTime;
public class AbstractUnitTest {
private static long startTime;
private static long endTime;

public static long getTestRunTime() {
return endTime - startTime;
}

public void startTimeMeasure() {
startTime = System.currentTimeMillis();
}

public void endTimeMeasure() {
endTime = System.currentTimeMillis();
}

public void reportStep(String lastStep1)
{

public void reportStep(String lastStep1) {
TestManager.instance().reportStep(lastStep1);
}
}
80 changes: 38 additions & 42 deletions src/javasource/unittesting/RemoteApiServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ public class RemoteApiServlet extends RequestHandler {
private static final Object COMMAND_START = "start";
private static final Object COMMAND_STATUS = "status";
private static final String PARAM_PASSWORD = "password";

private final String password;
private boolean detectedUnitTests = false;

private final static ILogNode LOG = TestManager.LOG;
private volatile TestSuiteRunner testSuiteRunner;

public RemoteApiServlet(String password) {
this.password = password;
}

@Override
protected void processRequest(IMxRuntimeRequest req,
IMxRuntimeResponse resp, String path) throws Exception {

protected void processRequest(IMxRuntimeRequest req, IMxRuntimeResponse resp, String path) throws Exception {

HttpServletRequest request = req.getHttpServletRequest();
HttpServletResponse response = resp.getHttpServletResponse();

try {
if (!"POST".equals(request.getMethod()))
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
Expand All @@ -57,12 +56,10 @@ else if (COMMAND_STATUS.equals(path))
serveRunStatus(request, response, path);
else
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
write(response, e.getMessage());
}
catch (InvalidCredentialsException e) {
} catch (InvalidCredentialsException e) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
write(response, "Invalid password provided");
}
Expand All @@ -74,60 +71,59 @@ private void write(HttpServletResponse response, String data) {
} catch (Exception e) {
throw new RuntimeException(e);
}

}

private synchronized void serveRunStatus(HttpServletRequest request,
HttpServletResponse response, String path) throws Exception {
private synchronized void serveRunStatus(HttpServletRequest request, HttpServletResponse response, String path)
throws Exception {
JSONObject input = parseInput(request);
verifyPassword(input);

if (testSuiteRunner == null) {
throw new IllegalArgumentException("No testrun was started yet");
}

response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Content-Type", "application/json");
write(response, testSuiteRunner.getStatus().toString(4));
}

private synchronized void serveRunStart(HttpServletRequest request,
HttpServletResponse response, String path) throws IOException, CoreException, InvalidCredentialsException {
private synchronized void serveRunStart(HttpServletRequest request, HttpServletResponse response, String path)
throws IOException, CoreException, InvalidCredentialsException {
JSONObject input = parseInput(request);
verifyPassword(input);

IContext context = Core.createSystemContext();
if (!detectedUnitTests) {
TestManager.instance().findAllTests(context);
detectedUnitTests = true;
}

if (testSuiteRunner != null && !testSuiteRunner.isFinished()) {
throw new IllegalArgumentException("Cannot start a test run while another test run is still running");
}

LOG.info("[remote api] starting new test run");
testSuiteRunner = new TestSuiteRunner();

Thread t = new Thread() {
@Override
public void run() {
testSuiteRunner.run();
}
};

t.start();
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}



private void verifyPassword(JSONObject input) throws InvalidCredentialsException {
if (!input.has(PARAM_PASSWORD)) {
LOG.warn("[remote api] Missing password");
throw new IllegalArgumentException("No '" + PARAM_PASSWORD + "' attribute found in the JSON body. Please provide a password");
throw new IllegalArgumentException(
"No '" + PARAM_PASSWORD + "' attribute found in the JSON body. Please provide a password");
}

if (!password.equals(input.getString(PARAM_PASSWORD))) {
LOG.warn("[remote api] Invalid password");
throw new InvalidCredentialsException();
Expand All @@ -143,7 +139,7 @@ private class TestSuiteRunner {
boolean finished = false;
long startTime = System.currentTimeMillis();
long totalTime = -1;

public void run() {
try {
TestManager.instance().runTestSuites();
Expand All @@ -153,9 +149,9 @@ public void run() {
totalTime = System.currentTimeMillis() - startTime;
finished = true;
LOG.info("[remote api] finished test run");
}
}
}

public synchronized boolean isFinished() {
return finished;
}
Expand All @@ -164,46 +160,46 @@ public synchronized JSONObject getStatus() throws CoreException {
JSONObject result = new JSONObject();
result.put("completed", this.finished);
result.put("runtime", totalTime);

IContext context = Core.createSystemContext();
long count = 0l;
long failures = 0l;

List<IMendixObject> testSuites = Core.retrieveXPathQuery(context, String.format("//%s", TestSuite.entityName));

List<IMendixObject> testSuites = Core.retrieveXPathQuery(context,
String.format("//%s", TestSuite.entityName));

for (IMendixObject mxObject : testSuites) {
TestSuite testSuite = TestSuite.initialize(context, mxObject);
count += testSuite.getTestCount();
failures += testSuite.getTestFailedCount();
}

result.put("tests", count);
result.put("failures", failures);

JSONArray failedTests = new JSONArray();
result.put("failed_tests", failedTests);

StringBuilder query = new StringBuilder();
query.append(String.format("//%s", UnitTest.entityName));
// Failed tests
query.append("[" + UnitTest.MemberNames.Result + "=\"" + UnitTestResult._2_Failed + "\"]");
// In test suites that are not running anymore
query.append("[" + UnitTest.MemberNames.UnitTest_TestSuite + "/" + TestSuite.entityName + "/"
+ TestSuite.MemberNames.Result + "=\"" + UnitTestResult._2_Failed + "\"]");

List<IMendixObject> unitTests = Core.retrieveXPathQuery(context, query.toString());

for(IMendixObject mxObject : unitTests)
{
for (IMendixObject mxObject : unitTests) {
UnitTest test = UnitTest.initialize(context, mxObject);
JSONObject i = new JSONObject();
i.put("name", test.getName());
i.put("error", test.getResultMessage());
i.put("step", test.getLastStep());
failedTests.put(i);
}

return result;
}
}
}
}
Loading

0 comments on commit 9242fa1

Please sign in to comment.