All developers endpoints
This commit is contained in:
parent
d1a54a93d6
commit
265315b874
@ -11,8 +11,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.models.TourData;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.ConfiguratorService;
|
||||
import com.plannaplan.services.ExchangeService;
|
||||
|
||||
/**
|
||||
@ -25,14 +29,19 @@ import com.plannaplan.services.ExchangeService;
|
||||
"DeveloperController" }, value = "DeveloperController", description = "All endpoints to use in development time to help app testing")
|
||||
public class DeveloperController {
|
||||
|
||||
private static final long ONE_DAY = 86400000;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Autowired
|
||||
private ExchangeService exchangeService;
|
||||
|
||||
@Autowired
|
||||
private ConfiguratorService configurationController;
|
||||
|
||||
/**
|
||||
* @return if accept algoythm was perfomed
|
||||
* @return if accept algorythm was perfomed
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/algorythm/accept")
|
||||
@ -42,7 +51,7 @@ public class DeveloperController {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if accept algoythm was perfomed
|
||||
* @return if exchange algorythm was perfomed
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/algorythm/exchange")
|
||||
@ -50,4 +59,45 @@ public class DeveloperController {
|
||||
this.exchangeService.performExchange();
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/tours/first")
|
||||
public ResponseEntity<String> setFirstTour() {
|
||||
this.configurationController.saveTours(
|
||||
new TourData(new Date(System.currentTimeMillis() - ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + ONE_DAY)),
|
||||
new TourData(new Date(System.currentTimeMillis() + 2 * ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + 3 * ONE_DAY)));
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/tours/second")
|
||||
public ResponseEntity<String> setSecondTour() {
|
||||
this.configurationController.saveTours(
|
||||
new TourData(new Date(System.currentTimeMillis() - 3 * ONE_DAY),
|
||||
new Date(System.currentTimeMillis() - 2 * ONE_DAY)),
|
||||
new TourData(new Date(System.currentTimeMillis() - ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + ONE_DAY)));
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/tours/no")
|
||||
public ResponseEntity<String> setNoTour() {
|
||||
this.configurationController.saveTours(
|
||||
new TourData(new Date(System.currentTimeMillis() - ONE_DAY), new Date(System.currentTimeMillis())),
|
||||
new TourData(new Date(System.currentTimeMillis() + ONE_DAY),
|
||||
new Date(System.currentTimeMillis() + 2 * ONE_DAY)));
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,15 @@ import com.plannaplan.types.UserRoles;
|
||||
public class DeveloperControllerTest extends AbstractControllerTest {
|
||||
private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algorythm/accept";
|
||||
private static final String EXCHANGE_ENDPOINT = "/api/v1/developer/algorythm/exchange";
|
||||
private static final String FIRST_TOUR_ENDPOINT = "/api/v1/developer/tours/first";
|
||||
private static final String NO_TOUR_ENDPOINT = "/api/v1/developer/tours/no";
|
||||
private static final String SECOND_TOUR_ENDPOINT = "/api/v1/developer/tours/second";
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/* ACCEPT TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAcces@DeveloperController.test";
|
||||
@ -59,6 +64,8 @@ public class DeveloperControllerTest extends AbstractControllerTest {
|
||||
|
||||
}
|
||||
|
||||
/* EXCHANGE TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailExchangeWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailExchangeWithWrongAcces@DeveloperController.test";
|
||||
@ -91,4 +98,108 @@ public class DeveloperControllerTest extends AbstractControllerTest {
|
||||
|
||||
}
|
||||
|
||||
/* FIRST TOUR */
|
||||
|
||||
@Test
|
||||
public void shouldFailFirstTourWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailFirstTourWithWrongAcces@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(FIRST_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkFirstTourAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkFirstTourAlgotyrhm@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(FIRST_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFirstTourWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(FIRST_TOUR_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* SECOND TOUR */
|
||||
|
||||
@Test
|
||||
public void shouldFailSecondTourWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailSecondTourWithWrongAcces@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(SECOND_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkSecondTourAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkSecondTourAlgotyrhm@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(SECOND_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailSecondTourWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(SECOND_TOUR_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* NO TOUR */
|
||||
|
||||
@Test
|
||||
public void shouldNoTourWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldNoTourWithWrongAcces@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(NO_TOUR_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkNoAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkNoAlgotyrhm@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(NO_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailNoTourWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(NO_TOUR_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user