diff --git a/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java index cced224..1f7535d 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java @@ -13,6 +13,7 @@ import io.swagger.annotations.Api; import com.plannaplan.App; import com.plannaplan.services.AssignmentService; +import com.plannaplan.services.ExchangeService; /** * Rest controller to enpoint that help deveopler test the app @@ -27,13 +28,26 @@ public class DeveloperController { @Autowired private AssignmentService assignmentService; + @Autowired + private ExchangeService exchangeService; + /** * @return if accept algoythm was perfomed */ @PreAuthorize("hasRole('ROLE_DEVELOPER')") - @PostMapping(path = "/algoythm/accept") + @PostMapping(path = "/algorythm/accept") public ResponseEntity performAcceptAlgorythm() { this.assignmentService.callAcceptAlgorythm(); return new ResponseEntity<>("Success", HttpStatus.OK); } + + /** + * @return if accept algoythm was perfomed + */ + @PreAuthorize("hasRole('ROLE_DEVELOPER')") + @PostMapping(path = "/algorythm/exchange") + public ResponseEntity performExchangeAlgorythm() { + this.exchangeService.performExchange(); + return new ResponseEntity<>("Success", HttpStatus.OK); + } } diff --git a/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java index e47527e..59deca5 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java @@ -21,14 +21,15 @@ import com.plannaplan.types.UserRoles; @SpringBootTest @ContextConfiguration public class DeveloperControllerTest extends AbstractControllerTest { - private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algoythm/accept"; + private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algorythm/accept"; + private static final String EXCHANGE_ENDPOINT = "/api/v1/developer/algorythm/exchange"; @Autowired private UserService userService; @Test public void shouldFailWithWrongAcces() throws Exception { - final String mail = "shouldFailWithWrongAcces@ConfigController.test"; + final String mail = "shouldFailWithWrongAcces@DeveloperController.test"; final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER)); final String token = this.userService.login(usr).getToken(); @@ -41,7 +42,7 @@ public class DeveloperControllerTest extends AbstractControllerTest { @Test public void shouldOkPerformingAcceptAlgotyrhm() throws Exception { - final String mail = "shouldOkPerformingAcceptAlgotyrhm@ConfigController.test"; + final String mail = "shouldOkPerformingAcceptAlgotyrhm@DeveloperController.test"; final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); final String token = this.userService.login(usr).getToken(); @@ -57,4 +58,37 @@ public class DeveloperControllerTest extends AbstractControllerTest { mockMvc.perform(post(ACCEPT_ENDPOINT)).andExpect(status().is4xxClientError()); } + + @Test + public void shouldFailExchangeWithWrongAcces() throws Exception { + final String mail = "shouldFailExchangeWithWrongAcces@DeveloperController.test"; + final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER)); + + final String token = this.userService.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().is4xxClientError()); + + } + + @Test + public void shouldOkExchangeAlgotyrhm() throws Exception { + final String mail = "shouldOkExchangeAlgotyrhm@DeveloperController.test"; + final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); + + final String token = this.userService.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); + + } + + @Test + public void shouldFailExchaneWithNoToken() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(EXCHANGE_ENDPOINT)).andExpect(status().is4xxClientError()); + + } + }