Added call perform algorythm enpoint
This commit is contained in:
parent
7b9e334328
commit
7f647f9b8a
@ -1,9 +1,9 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
* UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
*/
|
||||
|
||||
|
||||
public enum UserRoles {
|
||||
STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
STUDENT, DEANERY, ADMIN, TEST_USER, DEVELOPER
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
|
||||
/**
|
||||
* Rest controller to enpoint that help deveopler test the app
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/developer")
|
||||
@Api(tags = {
|
||||
"DeveloperController" }, value = "DeveloperController", description = "All endpoints to use in development time to help app testing")
|
||||
public class DeveloperController {
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
/**
|
||||
* @return if accept algoythm was perfomed
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
||||
@PostMapping(path = "/algoythm/accept")
|
||||
public ResponseEntity<String> performAcceptAlgorythm() {
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -10,7 +10,8 @@ import org.springframework.security.core.GrantedAuthority;
|
||||
* Users Roles for spring app
|
||||
*/
|
||||
public enum AuthorityRoles implements GrantedAuthority {
|
||||
STUDENT("ROLE_STUDENT"), DEANERY("ROLE_DEANERY"), ADMIN("ROLE_ADMIN"), TEST_USER("ROLE_TESTUSER");
|
||||
STUDENT("ROLE_STUDENT"), DEANERY("ROLE_DEANERY"), ADMIN("ROLE_ADMIN"), TEST_USER("ROLE_TESTUSER"),
|
||||
DEVELOPER("ROLE_DEVELOPER");
|
||||
|
||||
private String role;
|
||||
|
||||
@ -39,6 +40,8 @@ public enum AuthorityRoles implements GrantedAuthority {
|
||||
return Optional.of(AuthorityRoles.STUDENT);
|
||||
case TEST_USER:
|
||||
return Optional.of(AuthorityRoles.TEST_USER);
|
||||
case DEVELOPER:
|
||||
return Optional.of(AuthorityRoles.DEVELOPER);
|
||||
default:
|
||||
return Optional.empty();
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class DeveloperControllerTest extends AbstractControllerTest {
|
||||
private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algoythm/accept";
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAcces() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAcces@ConfigController.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(ACCEPT_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkPerformingAcceptAlgotyrhm() throws Exception {
|
||||
final String mail = "shouldOkPerformingAcceptAlgotyrhm@ConfigController.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(ACCEPT_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoToken() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ACCEPT_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user