private TestStartResponse doStartTest(TestStartRequest startRequest, BindingResult result) {
if(result.hasErrors() ||
Strings.nullToEmpty(startRequest.getProfile()).trim().isEmpty() ||
Strings.nullToEmpty(startRequest.getTestHandle()).trim().isEmpty() ||
startRequest.getProfile().contains("/")) {
return new TestStartResponse(Status.illegalArgument());
}
if(!assertTestHandleIsAvailable(startRequest.getTestHandle())) {
return new TestStartResponse(Status.illegalArgument("Test handle " + startRequest.getTestHandle() + " already used"));
}
Test test = new Test(startRequest,
Status.pending(), System.currentTimeMillis());
if(mTestQueue.offer(test)) {
mTests.put(startRequest.getTestHandle(), test);
return new TestStartResponse(Status.ok());
} else {
return new TestStartResponse(Status.queueFull());
}
}