Merge
This commit is contained in:
commit
0fbc6d6baa
@ -41,4 +41,14 @@ public class GroupService {
|
|||||||
public Optional<Groups> getGroupById(Long id) {
|
public Optional<Groups> getGroupById(Long id) {
|
||||||
return this.repo.findById(id);
|
return this.repo.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
||||||
|
for (Long oneId : ids) {
|
||||||
|
if (this.repo.existsById(oneId) == false) {
|
||||||
|
return Optional.of(oneId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -49,4 +49,8 @@ public class UserService {
|
|||||||
return this.repo.searchForUsers(query, UserRoles.STUDENT);
|
return this.repo.searchForUsers(query, UserRoles.STUDENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<User> getById(Long userId) {
|
||||||
|
return this.repo.findById(userId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -3,12 +3,14 @@ package com.plannaplan.controllers;
|
|||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.App;
|
import com.plannaplan.App;
|
||||||
import com.plannaplan.entities.Assignment;
|
import com.plannaplan.entities.Assignment;
|
||||||
@ -21,19 +23,21 @@ import com.plannaplan.responses.models.CommisionResponse;
|
|||||||
import com.plannaplan.services.AssignmentService;
|
import com.plannaplan.services.AssignmentService;
|
||||||
import com.plannaplan.services.CommisionService;
|
import com.plannaplan.services.CommisionService;
|
||||||
import com.plannaplan.services.GroupService;
|
import com.plannaplan.services.GroupService;
|
||||||
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
|
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
|
||||||
@Api(tags = {
|
@Api(tags = { "Commisions" }, value = "Commisions", description = "Commision is representation of student selected assignments at time. All assignments are attached to some commision so we can see current assignments and also browse histroy of changes for given user")
|
||||||
"Commisions" }, value = "Commisions", description = "Commision is representation of student selected assignments at time. All assignments are attached to some commision so we can see current assignments and also browse histroy of changes for given user")
|
|
||||||
public class CommisionController extends TokenBasedController {
|
public class CommisionController extends TokenBasedController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -48,23 +52,46 @@ public class CommisionController extends TokenBasedController {
|
|||||||
public CommisionController() {
|
public CommisionController() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/user")
|
@PostMapping(value = { "/user", "/user/{id}" })
|
||||||
@ApiOperation(value = "Create commision with assignents to given groups. If group doesn't exist error will be thrown")
|
@ApiOperation(value = "Create commision with assignents to given groups. If group doesn't exist error will be thrown")
|
||||||
public ResponseEntity<String> addCommision(
|
public ResponseEntity<String> addCommision(
|
||||||
@RequestBody @ApiParam(value = "List of groups ids user want to assign to. If group doesnt exisit error will be thrown") List<Long> groups)
|
@RequestBody @ApiParam(value = "List of groups ids user want to assign to. If group doesnt exisit error will be thrown") List<Long> groups,
|
||||||
throws UserNotFoundException {
|
@PathVariable(name = "id", required = false) Long userId) {
|
||||||
|
|
||||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
try {
|
||||||
Commision com = new Commision(user);
|
|
||||||
|
final User asker = this.getCurrentUser()
|
||||||
|
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||||
|
|
||||||
|
final User user = userId != null
|
||||||
|
? userService.getById(userId).orElseThrow(
|
||||||
|
() -> new UserNotFoundException("Given user id not exist"))
|
||||||
|
: asker;
|
||||||
|
|
||||||
|
Assert.isTrue((asker.getRole() == UserRoles.DEANERY && user.getRole() == UserRoles.STUDENT
|
||||||
|
|| (asker.getId().equals(user.getId()) && user.getRole() == UserRoles.STUDENT)),
|
||||||
|
"Incorrect attempt to change plan");
|
||||||
|
|
||||||
|
Optional<Long> notExistingGroup = this.groupServcicxe.findNotExistingGroup(groups);
|
||||||
|
Assert.isTrue(!notExistingGroup.isPresent(), "Group "
|
||||||
|
+ notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist");
|
||||||
|
|
||||||
|
final Commision com = new Commision(user);
|
||||||
this.commisionService.save(com);
|
this.commisionService.save(com);
|
||||||
|
|
||||||
groups.stream().forEach((groupId) -> {
|
groups.stream().forEach((groupId) -> {
|
||||||
Groups group = this.groupServcicxe.getGroupById(groupId).orElseThrow(() -> new NullPointerException());
|
Groups group = this.groupServcicxe.getGroupById(groupId)
|
||||||
|
.orElseThrow(() -> new NullPointerException());
|
||||||
Assignment a = new Assignment(group, com);
|
Assignment a = new Assignment(group, com);
|
||||||
this.assignmentService.save(a);
|
this.assignmentService.save(a);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new ResponseEntity<>("Succes", HttpStatus.OK);
|
return new ResponseEntity<>("Succes", HttpStatus.OK);
|
||||||
|
} catch (UserNotFoundException exception) {
|
||||||
|
return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND);
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/user")
|
@GetMapping("/user")
|
||||||
@ -76,4 +103,15 @@ public class CommisionController extends TokenBasedController {
|
|||||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
|
@GetMapping("/user/{id}")
|
||||||
|
@ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token")
|
||||||
|
public ResponseEntity<List<CommisionResponse>> getCommision(@PathVariable(name = "id") Long userId)
|
||||||
|
throws UserNotFoundException {
|
||||||
|
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
|
||||||
|
List<CommisionResponse> result = CommisionResponseMappers
|
||||||
|
.mapToResponse(this.commisionService.getUsersCommisions(user));
|
||||||
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
public abstract class AbstractControllerTest {
|
||||||
|
@Autowired
|
||||||
|
protected WebApplicationContext webApplicationContext;
|
||||||
|
|
||||||
|
}
|
@ -12,7 +12,6 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||||
@ -21,14 +20,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class AssignmentsControllerTest {
|
public class AssignmentsControllerTest extends AbstractControllerTest {
|
||||||
|
|
||||||
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/user";
|
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/user";
|
||||||
private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain";
|
private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain";
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext webApplicationContext;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService service;
|
private UserService service;
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@ -26,19 +25,25 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class CommisionControllerTest {
|
public class CommisionControllerTest extends AbstractControllerTest {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext webApplicationContext;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService service;
|
private UserService service;
|
||||||
|
|
||||||
private static User user;
|
private static User user;
|
||||||
|
private static User otherUser;
|
||||||
|
private static User asker;
|
||||||
|
private static User otherAsker;
|
||||||
|
|
||||||
|
private static final String TEST_COMMISIONS_STUDENT_EMAIL = "commisions.student@notexisting.domain";
|
||||||
|
private static final String TEST_COMMISIONS_OTHER_STUDENT_EMAIL = "commisions.student2@notexisting.domain";
|
||||||
|
private static final String TEST_COMMISIONS_DEANERY_EMAIL = "commisions.deanery@notexisting.domain";
|
||||||
|
private static final String TEST_COMMISIONS_OTHER_DEANERY_EMAIL = "commisions.deanery2@notexisting.domain";
|
||||||
|
|
||||||
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/user";
|
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/user";
|
||||||
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||||
private static final String TEST_COMMISIONS_EMAIL = "commisions@notexisting.domain";
|
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||||
|
|
||||||
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
||||||
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
||||||
|
|
||||||
@ -51,8 +56,8 @@ public class CommisionControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailedAddingCommisionDueToNoArgs() throws Exception {
|
public void shouldFailedAddingCommisionDueToNoArgs() throws Exception {
|
||||||
this.checkUser();
|
this.checkUsers();
|
||||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
final String token = this.service.login(TEST_COMMISIONS_STUDENT_EMAIL);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token))
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
@ -61,8 +66,8 @@ public class CommisionControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnOkAddingCommision() throws Exception {
|
public void shouldReturnOkAddingCommision() throws Exception {
|
||||||
this.checkUser();
|
this.checkUsers();
|
||||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
final String token = this.service.login(TEST_COMMISIONS_STUDENT_EMAIL);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||||
@ -77,18 +82,122 @@ public class CommisionControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnOkGettingAllCommisions() throws Exception {
|
public void shouldReturnOkGettingAllCommisions() throws Exception {
|
||||||
this.checkUser();
|
this.checkUsers();
|
||||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
final String token = this.service.login(TEST_COMMISIONS_STUDENT_EMAIL);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT).header("Authorization", "Bearer " + token))
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkUser() {
|
@Test
|
||||||
|
public void shouldAddCommisionWithSelfIdPrivided() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_STUDENT_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
||||||
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailCommisionWithSomeoneIdPrividedAsStudent() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_STUDENT_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherUser.getId().toString())
|
||||||
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailCommisionAsDeanaryWithNoId() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_DEANERY_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||||
|
.contentType(APPLICATION_JSON_UTF8).content("[]")).andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailCommisionWithSelfIdPrividedAsDeanary() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_DEANERY_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.asker.getId().toString())
|
||||||
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAddCommisionWithSomeoneIdPrividedAsDeanary() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_DEANERY_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherUser.getId().toString())
|
||||||
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailCommisionWithOtherDeanaryIdPrividedAsDeanary() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_DEANERY_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherAsker.getId().toString())
|
||||||
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldGetStudentCommisionsListByDeanary() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_DEANERY_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
||||||
|
.header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailStudentCommisionsListByOtherStudent() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
|
||||||
|
final String token = this.service.login(TEST_COMMISIONS_STUDENT_EMAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
||||||
|
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkUsers() {
|
||||||
if (CommisionControllerTest.user == null) {
|
if (CommisionControllerTest.user == null) {
|
||||||
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_EMAIL, UserRoles.TEST_USER);
|
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT);
|
||||||
this.service.save(user);
|
this.service.save(user);
|
||||||
}
|
}
|
||||||
|
if (CommisionControllerTest.otherUser == null) {
|
||||||
|
CommisionControllerTest.otherUser = new User(null, null, TEST_COMMISIONS_OTHER_STUDENT_EMAIL,
|
||||||
|
UserRoles.STUDENT);
|
||||||
|
this.service.save(otherUser);
|
||||||
|
}
|
||||||
|
if (CommisionControllerTest.asker == null) {
|
||||||
|
CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY);
|
||||||
|
this.service.save(asker);
|
||||||
|
}
|
||||||
|
if (CommisionControllerTest.otherAsker == null) {
|
||||||
|
CommisionControllerTest.otherAsker = new User(null, null, TEST_COMMISIONS_OTHER_DEANERY_EMAIL,
|
||||||
|
UserRoles.DEANERY);
|
||||||
|
this.service.save(otherAsker);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,20 +20,16 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class ConfigControllerTest {
|
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";
|
private static final String TEST_MAIL = "notexisting@mail.domain";
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext webApplicationContext;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService service;
|
private UserService service;
|
||||||
|
|
||||||
|
@ -2,13 +2,11 @@ package com.plannaplan.controllers;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
@ -16,14 +14,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class CoursesControllerTest {
|
public class CoursesControllerTest extends AbstractControllerTest {
|
||||||
|
|
||||||
private static final String COURSES_ENDPOINT = "/api/v1/courses/all";
|
private static final String COURSES_ENDPOINT = "/api/v1/courses/all";
|
||||||
private static final String COURSESGROUPS_ENDPOINT = "/api/v1/courses/all?groups=true";
|
private static final String COURSESGROUPS_ENDPOINT = "/api/v1/courses/all?groups=true";
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext webApplicationContext;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnAllCoursesOk() throws Exception {
|
public void shouldReturnAllCoursesOk() throws Exception {
|
||||||
|
|
||||||
|
@ -2,13 +2,11 @@ package com.plannaplan.controllers;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
@ -16,11 +14,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class GroupControllerTest {
|
|
||||||
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/course";
|
|
||||||
|
|
||||||
@Autowired
|
public class GroupControllerTest extends AbstractControllerTest {
|
||||||
private WebApplicationContext webApplicationContext;
|
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/course";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailWithNoParaeter() throws Exception {
|
public void shouldFailWithNoParaeter() throws Exception {
|
||||||
@ -31,6 +27,6 @@ public class GroupControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnGroupsOk() throws Exception {
|
public void shouldReturnGroupsOk() throws Exception {
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT + "/2" )).andExpect(status().isOk());
|
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT + "/2")).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,11 @@ package com.plannaplan.controllers;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
@ -17,10 +15,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class TokenControllerTest {
|
public class TokenControllerTest extends AbstractControllerTest {
|
||||||
private final String TOKEN_ENDPOINT = "/token";
|
private final String TOKEN_ENDPOINT = "/token";
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext webApplicationContext;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailWithNoParameter() throws Exception {
|
public void shouldFailWithNoParameter() throws Exception {
|
||||||
|
@ -12,7 +12,6 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||||
@ -21,11 +20,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class UsersControllerTest {
|
|
||||||
private static final String ENDPOINT = "/api/v1/users/student/search";
|
|
||||||
|
|
||||||
@Autowired
|
public class UsersControllerTest extends AbstractControllerTest {
|
||||||
private WebApplicationContext webApplicationContext;
|
private static final String ENDPOINT = "/api/v1/users/student/search";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService service;
|
private UserService service;
|
||||||
|
Loading…
Reference in New Issue
Block a user