Developer exchange endpoint

This commit is contained in:
Filip Izydorczyk 2021-01-19 12:13:26 +01:00
parent 7f647f9b8a
commit d1a54a93d6
2 changed files with 52 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import io.swagger.annotations.Api;
import com.plannaplan.App; import com.plannaplan.App;
import com.plannaplan.services.AssignmentService; import com.plannaplan.services.AssignmentService;
import com.plannaplan.services.ExchangeService;
/** /**
* Rest controller to enpoint that help deveopler test the app * Rest controller to enpoint that help deveopler test the app
@ -27,13 +28,26 @@ public class DeveloperController {
@Autowired @Autowired
private AssignmentService assignmentService; private AssignmentService assignmentService;
@Autowired
private ExchangeService exchangeService;
/** /**
* @return if accept algoythm was perfomed * @return if accept algoythm was perfomed
*/ */
@PreAuthorize("hasRole('ROLE_DEVELOPER')") @PreAuthorize("hasRole('ROLE_DEVELOPER')")
@PostMapping(path = "/algoythm/accept") @PostMapping(path = "/algorythm/accept")
public ResponseEntity<String> performAcceptAlgorythm() { public ResponseEntity<String> performAcceptAlgorythm() {
this.assignmentService.callAcceptAlgorythm(); this.assignmentService.callAcceptAlgorythm();
return new ResponseEntity<>("Success", HttpStatus.OK); return new ResponseEntity<>("Success", HttpStatus.OK);
} }
/**
* @return if accept algoythm was perfomed
*/
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
@PostMapping(path = "/algorythm/exchange")
public ResponseEntity<String> performExchangeAlgorythm() {
this.exchangeService.performExchange();
return new ResponseEntity<>("Success", HttpStatus.OK);
}
} }

View File

@ -21,14 +21,15 @@ import com.plannaplan.types.UserRoles;
@SpringBootTest @SpringBootTest
@ContextConfiguration @ContextConfiguration
public class DeveloperControllerTest extends AbstractControllerTest { 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 @Autowired
private UserService userService; private UserService userService;
@Test @Test
public void shouldFailWithWrongAcces() throws Exception { 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 User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken(); final String token = this.userService.login(usr).getToken();
@ -41,7 +42,7 @@ public class DeveloperControllerTest extends AbstractControllerTest {
@Test @Test
public void shouldOkPerformingAcceptAlgotyrhm() throws Exception { 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 User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER));
final String token = this.userService.login(usr).getToken(); 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()); 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());
}
} }