Added missing config tests. Ready to pull. Other resposnes to fix in another task

This commit is contained in:
BuildTools 2020-12-01 17:31:55 +01:00
parent 7e45da1306
commit b2b9178bc1
2 changed files with 20 additions and 4 deletions

View File

@ -34,7 +34,7 @@ public class ConfigController {
private ConfiguratorService contrl; private ConfiguratorService contrl;
@PostMapping("/config") @PostMapping("/config")
// @PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@ApiOperation("Imports data to system. To call you need to provide ADMIN token") @ApiOperation("Imports data to system. To call you need to provide ADMIN token")
public ResponseEntity<String> configApp( public ResponseEntity<String> configApp(
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) { @RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {

View File

@ -28,7 +28,6 @@ public class ConfigControllerTest extends AbstractControllerTest {
private static final String FILE_NAME = "Zajecia.xlsx"; private static final String FILE_NAME = "Zajecia.xlsx";
private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config"; private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config";
private static final String TEST_MAIL = "notexisting@mail.domain";
@Autowired @Autowired
private UserService service; private UserService service;
@ -45,12 +44,13 @@ public class ConfigControllerTest extends AbstractControllerTest {
@Test @Test
public void shouldReturnOKAuthorized() throws Exception { public void shouldReturnOKAuthorized() throws Exception {
final User usr = new User(null, null, TEST_MAIL, UserRoles.ADMIN); final String mail = "shouldReturnOKAuthorized@ConfigController.test";
final User usr = new User(null, null, mail, UserRoles.ADMIN);
this.service.save(usr); this.service.save(usr);
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME); final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
final MockMultipartFile file = new MockMultipartFile("file", inputStream); final MockMultipartFile file = new MockMultipartFile("file", inputStream);
final String token = this.service.login(TEST_MAIL); final String token = this.service.login(mail);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token)) mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
@ -58,4 +58,20 @@ public class ConfigControllerTest extends AbstractControllerTest {
} }
@Test
public void shouldReturnDenyNoAdminAuthorized() throws Exception {
final String mail = "shouldReturnDenyNoAdminAuthorized@ConfigController.test";
final User usr = new User(null, null, mail, UserRoles.TEST_USER);
this.service.save(usr);
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
final MockMultipartFile file = new MockMultipartFile("file", inputStream);
final String token = this.service.login(mail);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
} }