fixed most of the tests
This commit is contained in:
parent
af74eaaeeb
commit
1c9b924eab
|
@ -1,33 +0,0 @@
|
|||
package ch.unisg.roster.roster.adapter.in.web;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.unisg.roster.roster.application.port.in.ApplyForTaskCommand;
|
||||
import ch.unisg.roster.roster.application.port.in.ApplyForTaskUseCase;
|
||||
import ch.unisg.roster.roster.domain.ExecutorInfo;
|
||||
import ch.unisg.roster.roster.domain.Task;
|
||||
|
||||
@RestController
|
||||
public class ApplyForTaskController {
|
||||
private final ApplyForTaskUseCase applyForTaskUseCase;
|
||||
|
||||
public ApplyForTaskController(ApplyForTaskUseCase applyForTaskUseCase) {
|
||||
this.applyForTaskUseCase = applyForTaskUseCase;
|
||||
}
|
||||
|
||||
// TODO fix return type
|
||||
/**
|
||||
* Checks if task is available for the requesting executor.
|
||||
* @return a task or null if no task found
|
||||
**/
|
||||
@PostMapping(path = "/task/apply", consumes = {"application/json"})
|
||||
public Task applyForTask(@RequestBody ExecutorInfo executorInfo) {
|
||||
|
||||
ApplyForTaskCommand command = new ApplyForTaskCommand(executorInfo.getExecutorType(),
|
||||
executorInfo.getExecutorURI());
|
||||
|
||||
return applyForTaskUseCase.applyForTask(command);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package ch.unisg.roster.roster.adapter.in.web;
|
||||
|
||||
import ch.unisg.roster.roster.domain.Roster;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.unisg.roster.roster.application.port.in.ApplyForTaskCommand;
|
||||
import ch.unisg.roster.roster.application.port.in.ApplyForTaskUseCase;
|
||||
import ch.unisg.roster.roster.domain.ExecutorInfo;
|
||||
import ch.unisg.roster.roster.domain.Task;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
@RestController
|
||||
public class ApplyForTaskWebController {
|
||||
private final ApplyForTaskUseCase applyForTaskUseCase;
|
||||
|
||||
public ApplyForTaskWebController(ApplyForTaskUseCase applyForTaskUseCase) {
|
||||
this.applyForTaskUseCase = applyForTaskUseCase;
|
||||
}
|
||||
|
||||
// TODO fix return type
|
||||
/**
|
||||
* Checks if task is available for the requesting executor.
|
||||
* @return a task or null if no task found
|
||||
**/
|
||||
@PostMapping(path = "/task/apply", consumes = {"application/json"})
|
||||
public ResponseEntity<String> applyForTask (@RequestBody ExecutorInfo executorInfo) {
|
||||
|
||||
ApplyForTaskCommand command = new ApplyForTaskCommand(executorInfo.getExecutorType(),
|
||||
executorInfo.getExecutorURI());
|
||||
|
||||
Task task = applyForTaskUseCase.applyForTask(command);
|
||||
|
||||
if (task == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
String executorType = command.getTaskType().toString();
|
||||
String executorURI = command.getExecutorURI().toString();
|
||||
|
||||
String jsonPayLoad = new JSONObject()
|
||||
.put("executorType", executorType)
|
||||
.put("executorURI", executorURI)
|
||||
.toString();
|
||||
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add("Content-Type", "application/json");
|
||||
|
||||
return new ResponseEntity<>(jsonPayLoad, responseHeaders, HttpStatus.OK);
|
||||
} catch (ConstraintViolationException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@ package ch.unisg.roster.roster;
|
|||
|
||||
import ch.unisg.roster.roster.application.port.in.AddRosterItemPort;
|
||||
import ch.unisg.roster.roster.domain.Roster;
|
||||
import ch.unisg.roster.roster.domain.Task;
|
||||
import ch.unisg.roster.roster.domain.valueobject.ExecutorType;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -28,10 +30,12 @@ public class AddNewAssignmentToRosterServiceSystemTest {
|
|||
|
||||
String rosterItemId = "TEST-ID";
|
||||
String executorType = "TEST-TYPE";
|
||||
String executorURI = "http://localhost:6969";
|
||||
String executorURI = "TEST-URI";
|
||||
|
||||
ResponseEntity response = whenAddNewAssignmentToRoster(rosterItemId, executorType, executorURI);
|
||||
|
||||
System.out.println(response.getBody().toString());
|
||||
response.getBody().
|
||||
JSONObject responseJson = new JSONObject(response.getBody().toString());
|
||||
String respRosterItemId = responseJson.getString("rosterItemId");
|
||||
String respExecutorType = responseJson.getString("executorType");
|
||||
|
@ -51,7 +55,10 @@ public class AddNewAssignmentToRosterServiceSystemTest {
|
|||
String executorType,
|
||||
String executorURI) throws JSONException {
|
||||
|
||||
Roster.getInstance().getRosterMap().clear();
|
||||
Roster roster = Roster.getInstance();
|
||||
roster.getRosterMap().clear();
|
||||
roster.addTaskToQueue(new Task(rosterItemId, new ExecutorType(executorType), executorURI));
|
||||
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Content-Type", "application/json");
|
||||
|
|
|
@ -5,7 +5,6 @@ import ch.unisg.common.valueobject.ExecutorURI;
|
|||
import ch.unisg.roster.roster.adapter.out.persistence.mongodb.RosterRepository;
|
||||
import ch.unisg.roster.roster.application.port.in.ApplyForTaskCommand;
|
||||
import ch.unisg.roster.roster.application.port.in.ApplyForTaskUseCase;
|
||||
import ch.unisg.roster.roster.domain.ExecutorInfo;
|
||||
import ch.unisg.roster.roster.domain.RosterItem;
|
||||
import ch.unisg.roster.roster.domain.Task;
|
||||
import ch.unisg.roster.roster.domain.valueobject.ExecutorType;
|
||||
|
@ -21,8 +20,8 @@ import static org.mockito.BDDMockito.then;
|
|||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(controllers = ApplyForTaskController.class)
|
||||
public class ApplyForTaskControllerTest {
|
||||
@WebMvcTest(controllers = ApplyForTaskWebController.class)
|
||||
public class ApplyForTaskWebControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
Loading…
Reference in New Issue
Block a user