Compare commits
	
		
			14 Commits
		
	
	
		
			Add-licenc
			...
			c89d629c61
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c89d629c61 | |||
|  | 5ed445449c | ||
|  | 0103a028b4 | ||
|  | b740562e9d | ||
|  | 4cf6cb58cb | ||
| 27b357fc86 | |||
| 3269a36239 | |||
|  | 2d28abefea | ||
|  | ad3d4e6900 | ||
|  | 3222faeab2 | ||
|  | c5f09a91ec | ||
|  | 11ec43911e | ||
| 77c3b9e3a5 | |||
|  | d4514affcc | 
							
								
								
									
										0
									
								
								buisnesslogic/COPYING → COPYING
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								buisnesslogic/COPYING → COPYING
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										86
									
								
								buisnesslogic/src/main/java/com/plannaplan/models/ExportData.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										86
									
								
								buisnesslogic/src/main/java/com/plannaplan/models/ExportData.java
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,86 @@ | ||||
| package com.plannaplan.models; | ||||
|  | ||||
| import java.util.stream.Collectors; | ||||
| import java.util.stream.Stream; | ||||
|  | ||||
| /** | ||||
|  * Container to keep data to export | ||||
|  */ | ||||
| public class ExportData { | ||||
|  | ||||
|     private static final String GROUP_FIELD = "gr_nr"; | ||||
|     private static final String USER_FIELD = "user_id"; | ||||
|     private static final String CYKL_FIELD = "zaj_cykl_id"; | ||||
|  | ||||
|     private String userId; | ||||
|     private String zajCyklId; | ||||
|     private String grNr; | ||||
|  | ||||
|     /** | ||||
|      * @param userId    usosid | ||||
|      * @param zajCyklId course cycle | ||||
|      * @param grNr      group number | ||||
|      */ | ||||
|     public ExportData(String userId, String zajCyklId, String grNr) { | ||||
|         this.setUserId(userId); | ||||
|         this.setZajCyklId(zajCyklId); | ||||
|         this.setGrNr(grNr); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return group number | ||||
|      */ | ||||
|     public String getGrNr() { | ||||
|         return grNr; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param grNr group number | ||||
|      */ | ||||
|     public void setGrNr(String grNr) { | ||||
|         this.grNr = grNr; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return course cycle | ||||
|      */ | ||||
|     public String getZajCyklId() { | ||||
|         return zajCyklId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param zajCyklId course cycle | ||||
|      */ | ||||
|     public void setZajCyklId(String zajCyklId) { | ||||
|         this.zajCyklId = zajCyklId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return usosid | ||||
|      */ | ||||
|     public String getUserId() { | ||||
|         return userId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param userId usosid | ||||
|      */ | ||||
|     public void setUserId(String userId) { | ||||
|         this.userId = userId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return csv fromated line | ||||
|      */ | ||||
|     public String convertToCSVRecord() { | ||||
|         return Stream.of(this.userId, this.zajCyklId, this.grNr).collect(Collectors.joining(",")); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return csv formated first line | ||||
|      */ | ||||
|     public static String getCSVHeader() { | ||||
|         return USER_FIELD + ", " + CYKL_FIELD + ", " + GROUP_FIELD; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,10 +1,12 @@ | ||||
| package com.plannaplan.services; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Optional; | ||||
|  | ||||
| import com.plannaplan.entities.Commision; | ||||
| import com.plannaplan.entities.User; | ||||
| import com.plannaplan.models.ExportData; | ||||
| import com.plannaplan.repositories.AssignmentRepository; | ||||
| import com.plannaplan.repositories.CommisionRepository; | ||||
|  | ||||
| @@ -22,6 +24,8 @@ public class CommisionService { | ||||
|     private CommisionRepository repo; | ||||
|     @Autowired | ||||
|     private AssignmentRepository aRepository; | ||||
|     @Autowired | ||||
|     private UserService userService; | ||||
|  | ||||
|     public CommisionService() { | ||||
|     } | ||||
| @@ -77,4 +81,21 @@ public class CommisionService { | ||||
|     public long getCommisionsAmmount() { | ||||
|         return this.repo.count(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return list of ExportData inmstancces keeping data to exprt to file | ||||
|      */ | ||||
|     public List<ExportData> getExportData() { | ||||
|         final List<ExportData> response = new ArrayList<>(); | ||||
|  | ||||
|         this.userService.getAllStudents().forEach(student -> { | ||||
|             student.getStudentRegisteredGrups().forEach(group -> { | ||||
|                 response.add(new ExportData(student.getUsosId(), Integer.toString(group.getZajCykId()), | ||||
|                         Integer.toString(group.getGrNr()))); | ||||
|             }); | ||||
|         }); | ||||
|  | ||||
|         return response; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
							
								
								
									
										14
									
								
								buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										14
									
								
								buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| package com.plannaplan.models; | ||||
|  | ||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| public class ExportDataTest { | ||||
|  | ||||
|     @Test | ||||
|     public void shouldConvertDataToCSVRecord() { | ||||
|         final ExportData data = new ExportData("4234", "242352", "12"); | ||||
|         assertTrue(data.convertToCSVRecord().equals("4234,242352,12")); | ||||
|     } | ||||
| } | ||||
| @@ -62,6 +62,14 @@ | ||||
|       <version>4.5.10</version> | ||||
|     </dependency> | ||||
|  | ||||
|     <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> | ||||
|     <dependency> | ||||
|       <groupId>commons-io</groupId> | ||||
|       <artifactId>commons-io</artifactId> | ||||
|       <version>2.5</version> | ||||
|     </dependency> | ||||
|  | ||||
|  | ||||
|     <dependency> | ||||
|       <groupId>org.springframework.boot</groupId> | ||||
|       <artifactId>spring-boot-starter-web</artifactId> | ||||
|   | ||||
| @@ -12,12 +12,15 @@ import io.swagger.annotations.ApiParam; | ||||
| import java.util.List; | ||||
| import java.util.Optional; | ||||
|  | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
|  | ||||
| import com.plannaplan.App; | ||||
| import com.plannaplan.entities.Assignment; | ||||
| import com.plannaplan.entities.Commision; | ||||
| import com.plannaplan.entities.Groups; | ||||
| import com.plannaplan.entities.User; | ||||
| import com.plannaplan.exceptions.UserNotFoundException; | ||||
| import com.plannaplan.models.ExportData; | ||||
| import com.plannaplan.responses.mappers.CommisionResponseMappers; | ||||
| import com.plannaplan.responses.models.CommisionResponse; | ||||
| import com.plannaplan.services.AssignmentService; | ||||
| @@ -27,6 +30,8 @@ import com.plannaplan.services.GroupService; | ||||
| import com.plannaplan.types.AppState; | ||||
| import com.plannaplan.types.UserRoles; | ||||
|  | ||||
| import org.apache.commons.io.IOUtils; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.http.HttpStatus; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| @@ -37,11 +42,14 @@ import org.springframework.util.Assert; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RequestParam; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.Iterator; | ||||
|  | ||||
| import com.plannaplan.responses.mappers.AssignmentResponseMappers; | ||||
| import com.plannaplan.responses.models.AssignmentDetailedResponse; | ||||
| import com.plannaplan.responses.models.AssignmentResponse; | ||||
|  | ||||
| /** | ||||
| @@ -161,6 +169,28 @@ public class CommisionController extends TokenBasedController { | ||||
|                 } | ||||
|  | ||||
|                 return new ResponseEntity<>(result, HttpStatus.OK); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * @return list of user latests assignmets | ||||
|          * @throws UserNotFoundException if user was not found bny token | ||||
|          */ | ||||
|         @GetMapping("/user/assignments") | ||||
|         @ApiOperation("Return list of latest user commision assignments. User is recognized via token") | ||||
|         public ResponseEntity<List<AssignmentDetailedResponse>> getAllAssignmets() throws UserNotFoundException { | ||||
|                 final User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException()); | ||||
|  | ||||
|                 final Optional<Commision> latestCommision = this.commisionService.getNewestCommision(user); | ||||
|  | ||||
|                 if (latestCommision.isEmpty()) { | ||||
|                         return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); | ||||
|                 } | ||||
|  | ||||
|                 final List<AssignmentDetailedResponse> response = AssignmentResponseMappers | ||||
|                                 .mapAssignmetnToDetialedResponse(latestCommision.get().getAssignments()); | ||||
|  | ||||
|                 return new ResponseEntity<>(response, HttpStatus.OK); | ||||
|         } | ||||
|  | ||||
|         /** | ||||
| @@ -236,4 +266,32 @@ public class CommisionController extends TokenBasedController { | ||||
|                 return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK); | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * @param response spring response to set headers | ||||
|          */ | ||||
|         @GetMapping("/export/csv") | ||||
|         @PreAuthorize("hasRole('ROLE_ADMIN')") | ||||
|         @ApiOperation(value = "Export acceptes assignmetns as csv file to import to usos. You need to provide ADMIN token in order to get access to this data.") | ||||
|         public void getFile(HttpServletResponse response) { | ||||
|                 try { | ||||
|                         String csvString = ExportData.getCSVHeader() + "\n"; | ||||
|                         final Iterator<ExportData> it = this.commisionService.getExportData().iterator(); | ||||
|                         while (it.hasNext()) { | ||||
|                                 final ExportData data = it.next(); | ||||
|                                 csvString += (data.convertToCSVRecord() + "\n"); | ||||
|                         } | ||||
|  | ||||
|                         final InputStream is = IOUtils.toInputStream(csvString, "UTF-8"); | ||||
|  | ||||
|                         IOUtils.copy(is, response.getOutputStream()); | ||||
|                         response.setContentType("application/csv"); | ||||
|                         response.setHeader("Content-Disposition", "attachment; filename=\"export.csv\""); | ||||
|                         response.flushBuffer(); | ||||
|                 } catch (IOException ex) { | ||||
|  | ||||
|                         throw new RuntimeException("IOError writing file to output stream"); | ||||
|                 } | ||||
|  | ||||
|         } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -88,6 +88,15 @@ public class ExchangeController extends TokenBasedController { | ||||
|         final Assignment assignmentInstance = assignment.get(); | ||||
|         final Groups groupInstance = group.get(); | ||||
|  | ||||
|         if (assignmentInstance.getGroup().getCourseId() != null | ||||
|                 && assignmentInstance.getGroup().getCourseId().getId() != groupInstance.getCourseId().getId()) { | ||||
|             return new ResponseEntity<>("You can performe exchange only within one course.", HttpStatus.BAD_REQUEST); | ||||
|         } | ||||
|  | ||||
|         if (assignmentInstance.getGroup().getType() != groupInstance.getType()) { | ||||
|             return new ResponseEntity<>("You can't exchange lecture to class and otherwise.", HttpStatus.BAD_REQUEST); | ||||
|         } | ||||
|  | ||||
|         if (!(assignmentInstance.getCommision().getCommisionOwner().getId().equals(asker.getId()) | ||||
|                 && assignmentInstance.isAccepted())) { | ||||
|             return new ResponseEntity<>( | ||||
|   | ||||
| @@ -4,10 +4,13 @@ import java.util.List; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| import com.plannaplan.entities.Assignment; | ||||
| import com.plannaplan.entities.Course; | ||||
| import com.plannaplan.entities.Groups; | ||||
| import com.plannaplan.responses.models.AssignmentDetailedResponse; | ||||
| import com.plannaplan.responses.models.AssignmentResponse; | ||||
| import com.plannaplan.types.GroupType; | ||||
|  | ||||
| @@ -69,4 +72,15 @@ public class AssignmentResponseMappers { | ||||
|         } | ||||
|         return response; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * map assignmetn to detailed response | ||||
|      *  | ||||
|      * @param assignments list of assignments to map | ||||
|      * @return list of responses | ||||
|      */ | ||||
|     public static final List<AssignmentDetailedResponse> mapAssignmetnToDetialedResponse(List<Assignment> assignments) { | ||||
|         return assignments.stream().filter(Objects::nonNull).map(AssignmentDetailedResponse::new) | ||||
|                 .collect(Collectors.toList()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,71 @@ | ||||
| package com.plannaplan.responses.models; | ||||
|  | ||||
| import com.plannaplan.entities.Assignment; | ||||
| import com.plannaplan.entities.Groups; | ||||
|  | ||||
| /** | ||||
|  * Assignment detailed response for api | ||||
|  */ | ||||
| public class AssignmentDetailedResponse { | ||||
|     public Long id; | ||||
|     public String name; | ||||
|     private int day; | ||||
|     private String time; | ||||
|     private String endTime; | ||||
|     private String lecturer; | ||||
|  | ||||
|     /** | ||||
|      * @param assignment Assignment instance to map | ||||
|      */ | ||||
|     public AssignmentDetailedResponse(Assignment assignment) { | ||||
|         final Groups group = assignment.getGroup(); | ||||
|         this.id = assignment.getId(); | ||||
|         this.name = group.getCourseId().getName(); | ||||
|         this.day = group.getDay().label; | ||||
|         this.time = group.getTimeString(); | ||||
|         this.endTime = group.getEndTimeString(); | ||||
|         this.lecturer = group.getLecturer().toString(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return day as a value from 0-6 | ||||
|      */ | ||||
|     public int getDay() { | ||||
|         return day; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return lecturer string fromated | ||||
|      */ | ||||
|     public String getLecturer() { | ||||
|         return lecturer; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return time formated string | ||||
|      */ | ||||
|     public String getEndTime() { | ||||
|         return endTime; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return time formated string | ||||
|      */ | ||||
|     public String getTime() { | ||||
|         return time; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return name of course that group belongs to | ||||
|      */ | ||||
|     public String getName() { | ||||
|         return this.name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return db id of assignment | ||||
|      */ | ||||
|     public Long getId() { | ||||
|         return this.id; | ||||
|     } | ||||
| } | ||||
| @@ -18,6 +18,7 @@ import com.plannaplan.entities.User; | ||||
| import com.plannaplan.services.UserService; | ||||
| import com.plannaplan.types.UserRoles; | ||||
|  | ||||
| import static org.junit.Assert.assertTrue; | ||||
| import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*; | ||||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||||
| @@ -31,11 +32,13 @@ public class CommisionControllerTest extends AbstractControllerTest { | ||||
|     private UserService service; | ||||
|  | ||||
|     private static User user; | ||||
|     private static User admin; | ||||
|     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_ADMIN_EMAIL = "commisions.admin@notexisiting,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"; | ||||
| @@ -44,6 +47,9 @@ public class CommisionControllerTest extends AbstractControllerTest { | ||||
|     private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user"; | ||||
|     private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user"; | ||||
|     private static final String GET_USER_SCHEDULE_ENDPOINT = "/api/v1/commisions/user/schedule"; | ||||
|     private static final String GET_ASSIGNMENTS_ENDPOINT = "/api/v1/commisions/user/assignments"; | ||||
|  | ||||
|     private static final String EXPORT_DATA = "/api/v1/commisions/export/csv"; | ||||
|  | ||||
|     private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), | ||||
|             MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); | ||||
| @@ -254,6 +260,10 @@ public class CommisionControllerTest extends AbstractControllerTest { | ||||
|                     UserRoles.STUDENT); | ||||
|             this.service.save(otherUser); | ||||
|         } | ||||
|         if (CommisionControllerTest.admin == null) { | ||||
|             CommisionControllerTest.admin = new User(null, null, TEST_COMMISIONS_ADMIN_EMAIL, UserRoles.ADMIN); | ||||
|             this.service.save(admin); | ||||
|         } | ||||
|         if (CommisionControllerTest.asker == null) { | ||||
|             CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY); | ||||
|             this.service.save(asker); | ||||
| @@ -264,4 +274,50 @@ public class CommisionControllerTest extends AbstractControllerTest { | ||||
|             this.service.save(otherAsker); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldExportData() throws Exception { | ||||
|         this.checkUsers(); | ||||
|         final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null); | ||||
|         final String token = this.service.login(admin).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldNotExportDataDueToWrongPermision() throws Exception { | ||||
|         this.checkUsers(); | ||||
|         final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null); | ||||
|         final String token = this.service.login(student).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().is4xxClientError()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldExportDataBeCsvFile() throws Exception { | ||||
|         this.checkUsers(); | ||||
|         final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null); | ||||
|         final String token = this.service.login(admin).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|  | ||||
|         assertTrue( | ||||
|                 mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk()) | ||||
|                         .andReturn().getResponse().getContentAsString().contains("user_id, zaj_cykl_id, gr_nr")); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldRetrunOkForAssignmentEnpoint() throws Exception { | ||||
|         this.checkUsers(); | ||||
|         final User admin = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null); | ||||
|         final String token = this.service.login(admin).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|  | ||||
|         mockMvc.perform(get(GET_ASSIGNMENTS_ENDPOINT).header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().isOk()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -22,11 +22,13 @@ import java.nio.charset.Charset; | ||||
|  | ||||
| import com.plannaplan.entities.Assignment; | ||||
| import com.plannaplan.entities.Commision; | ||||
| import com.plannaplan.entities.Course; | ||||
| import com.plannaplan.entities.Exchange; | ||||
| import com.plannaplan.entities.Groups; | ||||
| import com.plannaplan.entities.User; | ||||
| import com.plannaplan.services.AssignmentService; | ||||
| import com.plannaplan.services.CommisionService; | ||||
| import com.plannaplan.services.CourseService; | ||||
| import com.plannaplan.services.ExchangeService; | ||||
| import com.plannaplan.services.GroupService; | ||||
| import com.plannaplan.services.UserService; | ||||
| @@ -57,11 +59,14 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|     @Autowired | ||||
|     private ExchangeService exchangeService; | ||||
|  | ||||
|     @Autowired | ||||
|     private CourseService courseService; | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldGetAllUsersExchanges() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|         "shouldGetAllUsersExchanges@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|                 "shouldGetAllUsersExchanges@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null)); | ||||
| @@ -70,26 +75,27 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         this.exchangeService.save(new Exchange(assignment, groupDesired)); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/all").header("Authorization", "Bearer " + | ||||
|         token)).andExpect(status().isOk()); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/all").header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().isOk()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailGettingNotExistingExchange() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailGettingNotExistingExchange@ExchangeController.test", UserRoles.STUDENT)); | ||||
|                 "shouldFailGettingNotExistingExchange@ExchangeController.test", UserRoles.STUDENT)); | ||||
|  | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token)).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldGetSingleExchange() throws Exception{ | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldGetSingleExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|     public void shouldGetSingleExchange() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, "shouldGetSingleExchange@ExchangeController.test", | ||||
|                 "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null)); | ||||
| @@ -98,14 +104,14 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired)); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + | ||||
|         token)).andExpect(status().isOk()); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().isOk()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailGettingExchangeDueToPermission() throws Exception{ | ||||
|     public void shouldFailGettingExchangeDueToPermission() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailGettingExchangeDueToPermission@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|                 "shouldFailGettingExchangeDueToPermission@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null)); | ||||
|         final Commision commision = this.commisionService.save(new Commision(user)); | ||||
| @@ -113,32 +119,33 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired)); | ||||
|  | ||||
|         final User user2 = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailGettingExchangeDueToPermission2@ExchangeController.test", "11112", UserRoles.STUDENT, 321)); | ||||
|                 "shouldFailGettingExchangeDueToPermission2@ExchangeController.test", "11112", UserRoles.STUDENT, 321)); | ||||
|         final String token2 = this.userService.login(user2).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + | ||||
|         token2)).andExpect(status().is4xxClientError()); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token2)) | ||||
|                 .andExpect(status().is4xxClientError()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailPostDueToAssignmentNotFound() throws Exception{ | ||||
|     public void shouldFailPostDueToAssignmentNotFound() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailPostDueToAssignmentNotFound@ExchangeController.test", UserRoles.STUDENT)); | ||||
|                 "shouldFailPostDueToAssignmentNotFound@ExchangeController.test", UserRoles.STUDENT)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null)); | ||||
|  | ||||
|         MockMvc mockMvc = | ||||
|         MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ user.getId() +", \"group\": "+ group.getId() +" }")).andExpect(status().isBadRequest()); | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform( | ||||
|                 post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8) | ||||
|                         .content("{\"assignment\": " + user.getId() + ", \"group\": " + group.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldInsertExchange() throws Exception{ | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|     public void shouldInsertExchange() throws Exception { | ||||
|         final User user = this.userService.save( | ||||
|                 new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null)); | ||||
| @@ -148,49 +155,55 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         this.assignmentService.callAcceptAlgorythm(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ assignment.getId() +", \"group\": "+ groupDesired.getId() +" }")).andExpect(status().isOk()); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token) | ||||
|                 .contentType(APPLICATION_JSON_UTF8) | ||||
|                 .content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }")) | ||||
|                 .andExpect(status().isOk()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailInsertExchangeDueToMissingGroup() throws Exception{ | ||||
|     public void shouldFailInsertExchangeDueToMissingGroup() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailInsertExchangeDueToMissingGroup@ExchangeController.test", UserRoles.STUDENT)); | ||||
|                 "shouldFailInsertExchangeDueToMissingGroup@ExchangeController.test", UserRoles.STUDENT)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ user.getId() +" }")).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token) | ||||
|                 .contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": " + user.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailInsertExchangeDueToMissingAssignment() throws Exception{ | ||||
|     public void shouldFailInsertExchangeDueToMissingAssignment() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailInsertExchangeDueToMissingAssignment@ExchangeController.test", UserRoles.STUDENT)); | ||||
|                 "shouldFailInsertExchangeDueToMissingAssignment@ExchangeController.test", UserRoles.STUDENT)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null)); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8).content("{\"group\": "+ group.getId() +" }")).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token) | ||||
|                 .contentType(APPLICATION_JSON_UTF8).content("{\"group\": " + group.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailInsertExchangeDueToMissingParam() throws Exception{ | ||||
|     public void shouldFailInsertExchangeDueToMissingParam() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailInsertExchangeDueToMissingParam@ExchangeController.test", UserRoles.STUDENT)); | ||||
|                 "shouldFailInsertExchangeDueToMissingParam@ExchangeController.test", UserRoles.STUDENT)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8)).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform( | ||||
|                 post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldDenyExchangeDueToAssigmentOverlapping() throws Exception{ | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|         "shouldDenyExchangeDueToAssigmentOverlapping@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|     public void shouldDenyExchangeDueToAssigmentOverlapping() throws Exception { | ||||
|         final User user = this.userService | ||||
|                 .save(new User(null, null, "shouldDenyExchangeDueToAssigmentOverlapping@ExchangeController.test", | ||||
|                         "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Commision commision = this.commisionService.save(new Commision(user)); | ||||
| @@ -198,30 +211,34 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         this.exchangeService.save(new Exchange(assignment, group)); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ user.getId() +", \"group\": "+ group.getId() +" }")).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform( | ||||
|                 post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8) | ||||
|                         .content("{\"assignment\": " + user.getId() + ", \"group\": " + group.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldDenyPostDueToAssignmentNotAccepted() throws Exception{ | ||||
|     public void shouldDenyPostDueToAssignmentNotAccepted() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldDenyPostDueToAssignmentNotAccepted@ExchangeController.test", UserRoles.STUDENT)); | ||||
|                 "shouldDenyPostDueToAssignmentNotAccepted@ExchangeController.test", UserRoles.STUDENT)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null)); | ||||
|         final Groups group2 = this.groupService.save(new Groups(213, "A2-2", null, 420, WeekDay.MONDAY, null)); | ||||
|         final Commision commision =  this.commisionService.save(new Commision(user)); | ||||
|         final Assignment assignment = this.assignmentService.save(new Assignment(group,commision)); | ||||
|         final Commision commision = this.commisionService.save(new Commision(user)); | ||||
|         final Assignment assignment = this.assignmentService.save(new Assignment(group, commision)); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ assignment.getId() +", \"group\": "+ group2.getId() +" }")).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform( | ||||
|                 post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8) | ||||
|                         .content("{\"assignment\": " + assignment.getId() + ", \"group\": " + group2.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldDeleteExchange() throws Exception{ | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldDeleteExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|     public void shouldDeleteExchange() throws Exception { | ||||
|         final User user = this.userService.save( | ||||
|                 new User(null, null, "shouldDeleteExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null)); | ||||
| @@ -230,14 +247,14 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired)); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + | ||||
|         token)).andExpect(status().isOk()); | ||||
|         mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().isOk()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailDeleteDueToWrongPermissions() throws Exception{ | ||||
|     public void shouldFailDeleteDueToWrongPermissions() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailDeleteDueToWrongPermissions@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|                 "shouldFailDeleteDueToWrongPermissions@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null)); | ||||
|         final Commision commision = this.commisionService.save(new Commision(user)); | ||||
| @@ -245,39 +262,41 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired)); | ||||
|  | ||||
|         final User user2 = this.userService.save(new User(null, null, | ||||
|         "shouldFailDeleteDueToWrongPermissions@ExchangeController2.test", "11112", UserRoles.STUDENT, 322)); | ||||
|                 "shouldFailDeleteDueToWrongPermissions@ExchangeController2.test", "11112", UserRoles.STUDENT, 322)); | ||||
|         final String token2 = this.userService.login(user2).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + | ||||
|         token2)).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token2)) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailDeleteDueToMissingParam() throws Exception{ | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|         "shouldFailDeleteDueToMissingParam@ExchangeController.test", UserRoles.STUDENT)); | ||||
|     public void shouldFailDeleteDueToMissingParam() throws Exception { | ||||
|         final User user = this.userService.save( | ||||
|                 new User(null, null, "shouldFailDeleteDueToMissingParam@ExchangeController.test", UserRoles.STUDENT)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(delete(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError()); | ||||
|         mockMvc.perform(delete(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().is4xxClientError()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldFailDeleteDueToExchangeNotFound() throws Exception{ | ||||
|     public void shouldFailDeleteDueToExchangeNotFound() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                                 "shouldFailDeleteDueToExchangeNotFound@ExchangeController.test", UserRoles.STUDENT)); | ||||
|                 "shouldFailDeleteDueToExchangeNotFound@ExchangeController.test", UserRoles.STUDENT)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + | ||||
|         token)).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token)) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldFailPostDueToGroupAlreadyAccepted() throws Exception{ | ||||
|         final User user = this.userService.save(new User(null, null, "shouldFailPostDueToGroupAlreadyAccepted@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|     public void shouldFailPostDueToGroupAlreadyAccepted() throws Exception { | ||||
|         final User user = this.userService.save(new User(null, null, | ||||
|                 "shouldFailPostDueToGroupAlreadyAccepted@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups group2 = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null)); | ||||
| @@ -288,7 +307,55 @@ public class ExchangeControllerTest extends AbstractControllerTest { | ||||
|         this.exchangeService.save(new Exchange(assignment, group2)); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + | ||||
|         token).contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": "+ assignment.getId() +", \"group\": "+ group2.getId() +" }")).andExpect(status().isBadRequest()); | ||||
|         mockMvc.perform( | ||||
|                 post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8) | ||||
|                         .content("{\"assignment\": " + assignment.getId() + ", \"group\": " + group2.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldFailForDiffrentCoursesExchange() throws Exception { | ||||
|         final User user = this.userService.save( | ||||
|                 new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Course course = this.courseService | ||||
|                 .save(new Course("shouldFailForDiffrentCoursesExchangeCourse", "SFFDCEC")); | ||||
|         final Course course2 = this.courseService | ||||
|                 .save(new Course("shouldFailForDiffrentCoursesExchangeCourse2", "SFFDCEC-2")); | ||||
|         final Groups group = this.groupService.save(new Groups(215, "A2-2", course, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", course2, 530, WeekDay.MONDAY, null)); | ||||
|         final Commision commision = this.commisionService.save(new Commision(user)); | ||||
|         final Assignment assignment = this.assignmentService.save(new Assignment(group, commision)); | ||||
|  | ||||
|         this.assignmentService.callAcceptAlgorythm(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token) | ||||
|                 .contentType(APPLICATION_JSON_UTF8) | ||||
|                 .content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) | ||||
|     public void shouldFailForDiffrentGroupTypesExchange() throws Exception { | ||||
|         final User user = this.userService.save( | ||||
|                 new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320)); | ||||
|         final String token = this.userService.login(user).getToken(); | ||||
|         final Course course = this.courseService | ||||
|                 .save(new Course("shouldFailForDiffrentCoursesExchangeCourse", "SFFDCEC")); | ||||
|         final Groups group = this.groupService.save(new Groups(12, "A2-2", course, 520, WeekDay.TUESDAY, null)); | ||||
|         final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", course, 530, WeekDay.MONDAY, null)); | ||||
|         final Commision commision = this.commisionService.save(new Commision(user)); | ||||
|         final Assignment assignment = this.assignmentService.save(new Assignment(group, commision)); | ||||
|  | ||||
|         this.assignmentService.callAcceptAlgorythm(); | ||||
|  | ||||
|         MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); | ||||
|         mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token) | ||||
|                 .contentType(APPLICATION_JSON_UTF8) | ||||
|                 .content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }")) | ||||
|                 .andExpect(status().isBadRequest()); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user